Skip to content

Commit

Permalink
Optimise imports using inject function (#8557)
Browse files Browse the repository at this point in the history
* optimise AuthGuard

* optimise UploadBase

* optimise BaseAuthenticationService

* optimise FormComponent

* optimise BaseCloudService

* optimise card view
  • Loading branch information
DenysVuika committed Jun 5, 2023
1 parent 991f111 commit f5abce8
Show file tree
Hide file tree
Showing 36 changed files with 99 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* limitations under the License.
*/

import { Component, NgZone } from '@angular/core';
import { Component } from '@angular/core';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { TranslationService, setupTestBed } from '@alfresco/adf-core';
import { setupTestBed } from '@alfresco/adf-core';
import { UploadBase } from './upload-base';
import { UploadFilesEvent } from '../upload-files.event';
import { ContentTestingModule } from '../../../testing/content.testing.module';
Expand All @@ -32,12 +32,6 @@ import { FileUploadErrorEvent } from '../../../common/events/file.event';
template: 'test component'
})
export class UploadTestComponent extends UploadBase {

constructor(protected uploadService: UploadService,
protected translationService: TranslationService,
protected ngZone: NgZone) {
super(uploadService, translationService, ngZone);
}
}

const file = { name: 'bigFile.png', size: 1000 } as File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ import { FileInfo, TranslationService } from '@alfresco/adf-core';
import { FileUploadErrorEvent } from '../../../common/events/file.event';
import { FileModel } from '../../../common/models/file.model';
import { UploadService } from '../../../common/services/upload.service';
import { EventEmitter, Input, Output, OnInit, OnDestroy, NgZone, Directive } from '@angular/core';
import { EventEmitter, Input, Output, OnInit, OnDestroy, NgZone, Directive, inject } from '@angular/core';
import { Subject } from 'rxjs';
import { UploadFilesEvent } from '../upload-files.event';
import { takeUntil } from 'rxjs/operators';

@Directive()
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export abstract class UploadBase implements OnInit, OnDestroy {
protected uploadService = inject(UploadService);
protected translationService = inject(TranslationService);
protected ngZone = inject(NgZone);

/** Sets a limit on the maximum size (in bytes) of a file to be uploaded.
* Has no effect if undefined.
Expand Down Expand Up @@ -82,11 +85,6 @@ export abstract class UploadBase implements OnInit, OnDestroy {

protected onDestroy$ = new Subject<boolean>();

constructor(protected uploadService: UploadService,
protected translationService: TranslationService,
protected ngZone: NgZone) {
}

ngOnInit() {
this.uploadService.fileUploadError
.pipe(takeUntil(this.onDestroy$))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
* limitations under the License.
*/

import {
EXTENDIBLE_COMPONENT, FileUtils,
LogService, TranslationService
} from '@alfresco/adf-core';
import { EXTENDIBLE_COMPONENT, FileUtils, LogService } from '@alfresco/adf-core';
import {
Component, EventEmitter, forwardRef, Input,
OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation, NgZone
OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation, inject
} from '@angular/core';
import { UploadService } from '../../common/services/upload.service';
import { NodesApiService } from '../../common/services/nodes-api.service';
import { ContentService } from '../../common/services/content.service';
import { AllowableOperationsEnum } from '../../common/models/allowable-operations.enum';
Expand All @@ -43,6 +39,9 @@ import { NodeAllowableOperationSubject } from '../../interfaces/node-allowable-o
encapsulation: ViewEncapsulation.None
})
export class UploadButtonComponent extends UploadBase implements OnInit, OnChanges, NodeAllowableOperationSubject {
private contentService = inject(ContentService);
private nodesApiService = inject(NodesApiService);
protected logService = inject(LogService);

/** Allows/disallows upload folders (only for Chrome). */
@Input()
Expand All @@ -66,20 +65,10 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang

/** Emitted when create permission is missing. */
@Output()
permissionEvent: EventEmitter<PermissionModel> = new EventEmitter<PermissionModel>();
permissionEvent = new EventEmitter<PermissionModel>();

private hasAllowableOperations: boolean = false;

protected permissionValue: Subject<boolean> = new Subject<boolean>();

constructor(protected uploadService: UploadService,
private contentService: ContentService,
private nodesApiService: NodesApiService,
protected translationService: TranslationService,
protected logService: LogService,
protected ngZone: NgZone) {
super(uploadService, translationService, ngZone);
}
protected permissionValue = new Subject<boolean>();

ngOnInit() {
this.permissionValue.subscribe((permission: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
* limitations under the License.
*/

import {
EXTENDIBLE_COMPONENT, FileInfo, FileUtils,
NotificationService, TranslationService
} from '@alfresco/adf-core';
import { Component, forwardRef, ViewEncapsulation, NgZone } from '@angular/core';
import { EXTENDIBLE_COMPONENT, FileInfo, FileUtils, NotificationService } from '@alfresco/adf-core';
import { Component, forwardRef, ViewEncapsulation, inject } from '@angular/core';
import { NodeAllowableOperationSubject } from '../../interfaces/node-allowable-operation-subject.interface';
import { UploadBase } from './base-upload/upload-base';
import { AllowableOperationsEnum } from '../../common/models/allowable-operations.enum';
import { UploadService } from '../../common/services/upload.service';
import { ContentService } from '../../common/services/content.service';
import { FileModel } from '../../common/models/file.model';

Expand All @@ -38,14 +34,8 @@ import { FileModel } from '../../common/models/file.model';
encapsulation: ViewEncapsulation.None
})
export class UploadDragAreaComponent extends UploadBase implements NodeAllowableOperationSubject {

constructor(protected uploadService: UploadService,
protected translationService: TranslationService,
private notificationService: NotificationService,
private contentService: ContentService,
protected ngZone: NgZone) {
super(uploadService, translationService, ngZone);
}
private notificationService = inject(NotificationService);
private contentService = inject(ContentService);

/**
* Method called when files are dropped in the drag area.
Expand Down
20 changes: 7 additions & 13 deletions lib/core/src/lib/auth/guard/auth-guard-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ import {
UrlTree
} from '@angular/router';
import { AuthenticationService } from '../services/authentication.service';
import {
AppConfigService,
AppConfigValues
} from '../../app-config/app-config.service';
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
import { OauthConfigModel } from '../models/oauth-config.model';
import { MatDialog } from '@angular/material/dialog';
import { StorageService } from '../../common/services/storage.service';
import { Observable } from 'rxjs';
import { inject } from '@angular/core';

export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
protected authenticationService = inject(AuthenticationService);
protected router = inject(Router);
protected appConfigService = inject(AppConfigService);
protected dialog = inject(MatDialog);
private storageService = inject(StorageService);

protected get withCredentials(): boolean {
return this.appConfigService.get<boolean>(
Expand All @@ -42,15 +45,6 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
);
}

constructor(
protected authenticationService: AuthenticationService,
protected router: Router,
protected appConfigService: AppConfigService,
protected dialog: MatDialog,
private storageService: StorageService
) {
}

abstract checkLogin(
activeRoute: ActivatedRouteSnapshot,
redirectUrl: string
Expand Down
15 changes: 1 addition & 14 deletions lib/core/src/lib/auth/guard/auth-guard-bpm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,13 @@
*/

import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Router, UrlTree } from '@angular/router';
import { AppConfigService } from '../../app-config/app-config.service';
import { AuthenticationService } from '../services/authentication.service';
import { ActivatedRouteSnapshot, UrlTree } from '@angular/router';
import { AuthGuardBase } from './auth-guard-base';
import { MatDialog } from '@angular/material/dialog';
import { StorageService } from '../../common/services/storage.service';

@Injectable({
providedIn: 'root'
})
export class AuthGuardBpm extends AuthGuardBase {

constructor(authenticationService: AuthenticationService,
router: Router,
appConfigService: AppConfigService,
dialog: MatDialog,
storageService: StorageService) {
super(authenticationService, router, appConfigService, dialog, storageService);
}

async checkLogin(_: ActivatedRouteSnapshot, redirectUrl: string): Promise<boolean | UrlTree> {
if (this.authenticationService.isBpmLoggedIn() || this.withCredentials) {
return true;
Expand Down
17 changes: 1 addition & 16 deletions lib/core/src/lib/auth/guard/auth-guard-ecm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,13 @@
*/

import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot, Router, UrlTree
} from '@angular/router';
import { AuthenticationService } from '../services/authentication.service';
import { AppConfigService } from '../../app-config/app-config.service';
import { ActivatedRouteSnapshot, UrlTree } from '@angular/router';
import { AuthGuardBase } from './auth-guard-base';
import { MatDialog } from '@angular/material/dialog';
import { StorageService } from '../../common/services/storage.service';

@Injectable({
providedIn: 'root'
})
export class AuthGuardEcm extends AuthGuardBase {

constructor(authenticationService: AuthenticationService,
router: Router,
appConfigService: AppConfigService,
dialog: MatDialog,
storageService: StorageService) {
super(authenticationService, router, appConfigService, dialog, storageService);
}

async checkLogin(_: ActivatedRouteSnapshot, redirectUrl: string): Promise<boolean | UrlTree> {
if (this.authenticationService.isEcmLoggedIn() || this.withCredentials) {
return true;
Expand Down
15 changes: 3 additions & 12 deletions lib/core/src/lib/auth/guard/auth-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
*/

import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Router, UrlTree } from '@angular/router';
import { AuthenticationService } from '../services/authentication.service';
import { AppConfigService } from '../../app-config/app-config.service';
import { ActivatedRouteSnapshot, UrlTree } from '@angular/router';
import { AuthGuardBase } from './auth-guard-base';
import { JwtHelperService } from '../services/jwt-helper.service';
import { MatDialog } from '@angular/material/dialog';
import { StorageService } from '../../common/services/storage.service';

@Injectable({
providedIn: 'root'
Expand All @@ -31,13 +27,8 @@ export class AuthGuard extends AuthGuardBase {

ticketChangeBind: any;

constructor(private jwtHelperService: JwtHelperService,
authenticationService: AuthenticationService,
router: Router,
appConfigService: AppConfigService,
dialog: MatDialog,
storageService: StorageService) {
super(authenticationService, router, appConfigService, dialog, storageService);
constructor(private jwtHelperService: JwtHelperService) {
super();
this.ticketChangeBind = this.ticketChange.bind(this);

window.addEventListener('storage', this.ticketChangeBind);
Expand Down
15 changes: 0 additions & 15 deletions lib/core/src/lib/auth/mock/authentication.service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,11 @@
import { Observable, of, throwError } from 'rxjs';
import { Injectable } from '@angular/core';
import { AuthenticationService } from '../services/authentication.service';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { CookieService } from '../../common/services/cookie.service';
import { LogService } from '../../common/services/log.service';
import { StorageService } from '../../common/services/storage.service';
import { AppConfigService } from '../../app-config/app-config.service';

@Injectable({
providedIn: 'root'
})
export class AuthenticationMock extends AuthenticationService {
constructor(
appConfig: AppConfigService,
storageService: StorageService,
alfrescoApi: AlfrescoApiService,
cookie: CookieService,
logService: LogService
) {
super(alfrescoApi, appConfig, cookie, logService, storageService);
}

login(username: string, password: string): Observable<{ type: string; ticket: any }> {
if (username === 'fake-username' && password === 'fake-password') {
return of({ type: 'type', ticket: 'ticket' });
Expand Down
25 changes: 9 additions & 16 deletions lib/core/src/lib/auth/oidc/oidc-authentication.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,29 @@
* limitations under the License.
*/

import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
import { EMPTY, Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { AppConfigValues } from '../../app-config/app-config.service';
import { BaseAuthenticationService } from '../../services/base-authentication.service';
import { CookieService } from '../../common/services/cookie.service';
import { JwtHelperService } from '../services/jwt-helper.service';
import { LogService } from '../../common/services/log.service';
import { AuthConfigService } from '../oidc/auth-config.service';
import { AuthService } from './auth.service';

@Injectable({
providedIn: 'root'
})
export class OIDCAuthenticationService extends BaseAuthenticationService {
private authStorage = inject(OAuthStorage);
private oauthService = inject(OAuthService);
private readonly authConfig = inject(AuthConfigService);
private readonly auth = inject(AuthService);

readonly supportCodeFlow = true;

constructor(
alfrescoApi: AlfrescoApiService,
appConfig: AppConfigService,
cookie: CookieService,
logService: LogService,
private authStorage: OAuthStorage,
private oauthService: OAuthService,
private readonly authConfig: AuthConfigService,
private readonly auth: AuthService
) {
super(alfrescoApi, appConfig, cookie, logService);
constructor() {
super();
this.alfrescoApi.alfrescoApiInitialized.subscribe(() => {
this.alfrescoApi.getInstance().reply('logged-in', () => {
this.onLogin.next();
Expand Down
18 changes: 5 additions & 13 deletions lib/core/src/lib/auth/services/authentication.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
* limitations under the License.
*/

import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { Observable, from } from 'rxjs';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { CookieService } from '../../common/services/cookie.service';
import { LogService } from '../../common/services/log.service';
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
import { AppConfigValues } from '../../app-config/app-config.service';
import { map, catchError, tap } from 'rxjs/operators';
import { JwtHelperService } from './jwt-helper.service';
import { StorageService } from '../../common/services/storage.service';
Expand All @@ -30,16 +27,11 @@ import { BaseAuthenticationService } from '../../services/base-authentication.se
providedIn: 'root'
})
export class AuthenticationService extends BaseAuthenticationService {
private storageService = inject(StorageService);
readonly supportCodeFlow = false;

constructor(
alfrescoApi: AlfrescoApiService,
appConfig: AppConfigService,
cookie: CookieService,
logService: LogService,
private storageService: StorageService
) {
super(alfrescoApi, appConfig, cookie, logService);
constructor() {
super();
this.alfrescoApi.alfrescoApiInitialized.subscribe(() => {
this.alfrescoApi.getInstance().reply('logged-in', () => {
this.onLogin.next();
Expand Down

0 comments on commit f5abce8

Please sign in to comment.