diff --git a/jslib b/jslib index 167558168c..579f970323 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 167558168c4ddff8eff67d7f12dfac47d5d25866 +Subproject commit 579f970323ea0bbc0d26f17cb9454c142f47bf6a diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index ed54d30de3..061effdd5b 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -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'; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 67d3197483..8328e22c06 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -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'; diff --git a/src/app/directives/api-action.directive.ts b/src/app/directives/api-action.directive.ts deleted file mode 100644 index a04eb47947..0000000000 --- a/src/app/directives/api-action.directive.ts +++ /dev/null @@ -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; - - 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); - }); - } -} diff --git a/src/app/directives/autofocus.directive.ts b/src/app/directives/autofocus.directive.ts deleted file mode 100644 index dd708e5ae4..0000000000 --- a/src/app/directives/autofocus.directive.ts +++ /dev/null @@ -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(); - } - } -} diff --git a/src/app/directives/blur-click.directive.ts b/src/app/directives/blur-click.directive.ts deleted file mode 100644 index 48555bb9ae..0000000000 --- a/src/app/directives/blur-click.directive.ts +++ /dev/null @@ -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(); - } -} diff --git a/src/app/directives/fallback-src.directive.ts b/src/app/directives/fallback-src.directive.ts deleted file mode 100644 index 3e5e338144..0000000000 --- a/src/app/directives/fallback-src.directive.ts +++ /dev/null @@ -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; - } -} diff --git a/src/app/directives/stop-click.directive.ts b/src/app/directives/stop-click.directive.ts deleted file mode 100644 index 0529556bc9..0000000000 --- a/src/app/directives/stop-click.directive.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { - Directive, - HostListener, -} from '@angular/core'; - -@Directive({ - selector: '[appStopClick]', -}) -export class StopClickDirective { - @HostListener('click', ['$event']) onClick($event: MouseEvent) { - $event.preventDefault(); - } -} diff --git a/src/app/directives/stop-prop.directive.ts b/src/app/directives/stop-prop.directive.ts deleted file mode 100644 index b241f628cc..0000000000 --- a/src/app/directives/stop-prop.directive.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { - Directive, - HostListener, -} from '@angular/core'; - -@Directive({ - selector: '[appStopProp]', -}) -export class StopPropDirective { - @HostListener('click', ['$event']) onClick($event: MouseEvent) { - $event.stopPropagation(); - } -} diff --git a/src/app/pipes/i18n.pipe.ts b/src/app/pipes/i18n.pipe.ts deleted file mode 100644 index d542af9347..0000000000 --- a/src/app/pipes/i18n.pipe.ts +++ /dev/null @@ -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); - } -} diff --git a/src/app/services/auth-guard.service.ts b/src/app/services/auth-guard.service.ts deleted file mode 100644 index bb6cdd2376..0000000000 --- a/src/app/services/auth-guard.service.ts +++ /dev/null @@ -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; - } -} diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 6af11b85bc..c750b0d155 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -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'; diff --git a/src/app/services/validation.service.ts b/src/app/services/validation.service.ts deleted file mode 100644 index cc7ee9ce65..0000000000 --- a/src/app/services/validation.service.ts +++ /dev/null @@ -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; - } -} diff --git a/webpack.renderer.js b/webpack.renderer.js index 6034338b8b..31a6897f12 100644 --- a/webpack.renderer.js +++ b/webpack.renderer.js @@ -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',