mirror of
https://github.com/bitwarden/desktop.git
synced 2024-11-24 11:55:50 +01:00
re-use various angular bits in jslib
This commit is contained in:
parent
3af510b154
commit
def6bd7874
2
jslib
2
jslib
@ -1 +1 @@
|
||||
Subproject commit 167558168c4ddff8eff67d7f12dfac47d5d25866
|
||||
Subproject commit 579f970323ea0bbc0d26f17cb9454c142f47bf6a
|
@ -4,7 +4,7 @@ import {
|
||||
Routes,
|
||||
} from '@angular/router';
|
||||
|
||||
import { AuthGuardService } from './services/auth-guard.service';
|
||||
import { AuthGuardService } from 'jslib/angular/services/auth-guard.service';
|
||||
|
||||
import { HintComponent } from './accounts/hint.component';
|
||||
import { LockComponent } from './accounts/lock.component';
|
||||
|
@ -26,15 +26,15 @@ import { SettingsComponent } from './accounts/settings.component';
|
||||
import { TwoFactorOptionsComponent } from './accounts/two-factor-options.component';
|
||||
import { TwoFactorComponent } from './accounts/two-factor.component';
|
||||
|
||||
import { ApiActionDirective } from './directives/api-action.directive';
|
||||
import { AutofocusDirective } from './directives/autofocus.directive';
|
||||
import { BlurClickDirective } from './directives/blur-click.directive';
|
||||
import { ApiActionDirective } from 'jslib/angular/directives/api-action.directive';
|
||||
import { AutofocusDirective } from 'jslib/angular/directives/autofocus.directive';
|
||||
import { BlurClickDirective } from 'jslib/angular/directives/blur-click.directive';
|
||||
import { BoxRowDirective } from './directives/box-row.directive';
|
||||
import { FallbackSrcDirective } from './directives/fallback-src.directive';
|
||||
import { StopClickDirective } from './directives/stop-click.directive';
|
||||
import { StopPropDirective } from './directives/stop-prop.directive';
|
||||
import { FallbackSrcDirective } from 'jslib/angular/directives/fallback-src.directive';
|
||||
import { StopClickDirective } from 'jslib/angular/directives/stop-click.directive';
|
||||
import { StopPropDirective } from 'jslib/angular/directives/stop-prop.directive';
|
||||
|
||||
import { I18nPipe } from './pipes/i18n.pipe';
|
||||
import { I18nPipe } from 'jslib/angular/pipes/i18n.pipe';
|
||||
import { SearchCiphersPipe } from './pipes/search-ciphers.pipe';
|
||||
|
||||
import { AddEditComponent } from './vault/add-edit.component';
|
||||
|
@ -1,32 +0,0 @@
|
||||
import {
|
||||
Directive,
|
||||
ElementRef,
|
||||
Input,
|
||||
OnChanges,
|
||||
} from '@angular/core';
|
||||
|
||||
import { ValidationService } from '../services/validation.service';
|
||||
|
||||
@Directive({
|
||||
selector: '[appApiAction]',
|
||||
})
|
||||
export class ApiActionDirective implements OnChanges {
|
||||
@Input() appApiAction: Promise<any>;
|
||||
|
||||
constructor(private el: ElementRef, private validationService: ValidationService) { }
|
||||
|
||||
ngOnChanges(changes: any) {
|
||||
if (this.appApiAction == null || this.appApiAction.then == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.el.nativeElement.loading = true;
|
||||
|
||||
this.appApiAction.then((response: any) => {
|
||||
this.el.nativeElement.loading = false;
|
||||
}, (e: any) => {
|
||||
this.el.nativeElement.loading = false;
|
||||
this.validationService.showError(e);
|
||||
});
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
import {
|
||||
Directive,
|
||||
ElementRef,
|
||||
Input,
|
||||
} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[appAutofocus]',
|
||||
})
|
||||
export class AutofocusDirective {
|
||||
@Input() set appAutofocus(condition: boolean | string) {
|
||||
this.autofocus = condition === '' || condition === true;
|
||||
}
|
||||
|
||||
private autofocus: boolean;
|
||||
|
||||
constructor(private el: ElementRef) { }
|
||||
|
||||
ngOnInit() {
|
||||
if (this.autofocus) {
|
||||
this.el.nativeElement.focus();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
import {
|
||||
Directive,
|
||||
ElementRef,
|
||||
HostListener,
|
||||
} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[appBlurClick]',
|
||||
})
|
||||
export class BlurClickDirective {
|
||||
constructor(private el: ElementRef) {
|
||||
}
|
||||
|
||||
@HostListener('click') onClick() {
|
||||
this.el.nativeElement.blur();
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
import {
|
||||
Directive,
|
||||
ElementRef,
|
||||
HostListener,
|
||||
Input,
|
||||
} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[appFallbackSrc]',
|
||||
})
|
||||
export class FallbackSrcDirective {
|
||||
@Input('appFallbackSrc') appFallbackSrc: string;
|
||||
|
||||
constructor(private el: ElementRef) {
|
||||
}
|
||||
|
||||
@HostListener('error') onError() {
|
||||
this.el.nativeElement.src = this.appFallbackSrc;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
import {
|
||||
Directive,
|
||||
HostListener,
|
||||
} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[appStopClick]',
|
||||
})
|
||||
export class StopClickDirective {
|
||||
@HostListener('click', ['$event']) onClick($event: MouseEvent) {
|
||||
$event.preventDefault();
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
import {
|
||||
Directive,
|
||||
HostListener,
|
||||
} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[appStopProp]',
|
||||
})
|
||||
export class StopPropDirective {
|
||||
@HostListener('click', ['$event']) onClick($event: MouseEvent) {
|
||||
$event.stopPropagation();
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
import {
|
||||
Pipe,
|
||||
PipeTransform,
|
||||
} from '@angular/core';
|
||||
|
||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
|
||||
@Pipe({
|
||||
name: 'i18n',
|
||||
})
|
||||
export class I18nPipe implements PipeTransform {
|
||||
constructor(private i18nService: I18nService) { }
|
||||
|
||||
transform(id: string, p1?: string, p2?: string, p3?: string): string {
|
||||
return this.i18nService.t(id, p1, p2, p3);
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
CanActivate,
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
|
||||
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||
import { UserService } from 'jslib/abstractions/user.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuardService implements CanActivate {
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService, private router: Router,
|
||||
private messagingService: MessagingService) { }
|
||||
|
||||
async canActivate() {
|
||||
const isAuthed = await this.userService.isAuthenticated();
|
||||
if (!isAuthed) {
|
||||
this.messagingService.send('logout');
|
||||
return false;
|
||||
}
|
||||
|
||||
const key = await this.cryptoService.getKey();
|
||||
if (key == null) {
|
||||
this.router.navigate(['lock']);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -14,9 +14,9 @@ import { DesktopStorageService } from '../../services/desktopStorage.service';
|
||||
import { I18nService } from '../../services/i18n.service';
|
||||
import { LogService } from '../../services/log.service';
|
||||
|
||||
import { AuthGuardService } from './auth-guard.service';
|
||||
import { AuthGuardService } from 'jslib/angular/services/auth-guard.service';
|
||||
import { BroadcasterService } from './broadcaster.service';
|
||||
import { ValidationService } from './validation.service';
|
||||
import { ValidationService } from 'jslib/angular/services/validation.service';
|
||||
|
||||
import { Analytics } from 'jslib/misc/analytics';
|
||||
|
||||
|
@ -1,37 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { ToasterService } from 'angular2-toaster';
|
||||
|
||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
|
||||
@Injectable()
|
||||
export class ValidationService {
|
||||
constructor(private toasterService: ToasterService, private i18nService: I18nService) { }
|
||||
|
||||
showError(data: any): string[] {
|
||||
const defaultErrorMessage = this.i18nService.t('unexpectedError');
|
||||
const errors: string[] = [];
|
||||
|
||||
if (data == null || typeof data !== 'object') {
|
||||
errors.push(defaultErrorMessage);
|
||||
} else if (data.validationErrors == null) {
|
||||
errors.push(data.message ? data.message : defaultErrorMessage);
|
||||
} else {
|
||||
for (const key in data.validationErrors) {
|
||||
if (!data.validationErrors.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
data.validationErrors[key].forEach((item: string) => {
|
||||
errors.push(item);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), errors[0]);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
@ -52,7 +52,9 @@ const common = {
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
alias: {
|
||||
jslib: path.join(__dirname, 'jslib/src')
|
||||
}
|
||||
},
|
||||
symlinks: false,
|
||||
modules: [path.resolve('node_modules')]
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
|
Loading…
Reference in New Issue
Block a user