mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Optimise imports using inject function (#8557)
* optimise AuthGuard * optimise UploadBase * optimise BaseAuthenticationService * optimise FormComponent * optimise BaseCloudService * optimise card view
This commit is contained in:
@@ -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>(
|
||||
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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'
|
||||
@@ -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);
|
||||
|
@@ -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' });
|
||||
|
@@ -15,16 +15,13 @@
|
||||
* 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';
|
||||
|
||||
@@ -32,19 +29,15 @@ import { AuthService } from './auth.service';
|
||||
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();
|
||||
|
@@ -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';
|
||||
@@ -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();
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Input, OnDestroy, Directive } from '@angular/core';
|
||||
import { Input, OnDestroy, Directive, inject } from '@angular/core';
|
||||
import { CardViewUpdateService } from '../services/card-view-update.service';
|
||||
import { CardViewItem } from '../interfaces/card-view.interfaces';
|
||||
import { CardViewBaseItemModel } from '../models/card-view-baseitem.model';
|
||||
@@ -25,13 +25,14 @@ import { takeUntil } from 'rxjs/operators';
|
||||
@Directive()
|
||||
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
||||
export abstract class BaseCardView<T extends CardViewItem> implements OnDestroy {
|
||||
protected cardViewUpdateService = inject(CardViewUpdateService);
|
||||
|
||||
@Input()
|
||||
property: T;
|
||||
|
||||
protected destroy$ = new Subject<boolean>();
|
||||
|
||||
constructor(protected cardViewUpdateService: CardViewUpdateService) {
|
||||
constructor() {
|
||||
this.cardViewUpdateService.updateItem$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((itemModel: CardViewBaseItemModel) => {
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { Component, ViewEncapsulation } from '@angular/core';
|
||||
import { CardViewArrayItemModel } from '../../models/card-view-arrayitem.model';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { BaseCardView } from '../base-card-view';
|
||||
|
||||
@Component({
|
||||
@@ -27,11 +26,6 @@ import { BaseCardView } from '../base-card-view';
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class CardViewArrayItemComponent extends BaseCardView<CardViewArrayItemModel> {
|
||||
|
||||
constructor(cardViewUpdateService: CardViewUpdateService) {
|
||||
super(cardViewUpdateService);
|
||||
}
|
||||
|
||||
clicked(): void {
|
||||
if (this.isClickable()) {
|
||||
this.cardViewUpdateService.clicked(this.property);
|
||||
|
@@ -18,7 +18,6 @@
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { MatCheckboxChange } from '@angular/material/checkbox';
|
||||
import { CardViewBoolItemModel } from '../../models/card-view-boolitem.model';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { BaseCardView } from '../base-card-view';
|
||||
|
||||
@Component({
|
||||
@@ -27,14 +26,9 @@ import { BaseCardView } from '../base-card-view';
|
||||
})
|
||||
|
||||
export class CardViewBoolItemComponent extends BaseCardView<CardViewBoolItemModel> {
|
||||
|
||||
@Input()
|
||||
editable: boolean;
|
||||
|
||||
constructor(cardViewUpdateService: CardViewUpdateService) {
|
||||
super(cardViewUpdateService);
|
||||
}
|
||||
|
||||
isEditable() {
|
||||
return this.editable && this.property.editable;
|
||||
}
|
||||
|
@@ -21,7 +21,6 @@ import { DatetimeAdapter, MAT_DATETIME_FORMATS, MatDatetimepickerComponent } fro
|
||||
import { MAT_MOMENT_DATETIME_FORMATS, MomentDatetimeAdapter } from '@mat-datetimepicker/moment';
|
||||
import moment, { Moment } from 'moment';
|
||||
import { CardViewDateItemModel } from '../../models/card-view-dateitem.model';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { UserPreferencesService, UserPreferenceValues } from '../../../common/services/user-preferences.service';
|
||||
import { MomentDateAdapter } from '../../../common/utils/moment-date-adapter';
|
||||
import { MOMENT_DATE_FORMATS } from '../../../common/utils/moment-date-formats.model';
|
||||
@@ -66,13 +65,12 @@ export class CardViewDateItemComponent extends BaseCardView<CardViewDateItemMode
|
||||
|
||||
private onDestroy$ = new Subject<boolean>();
|
||||
|
||||
constructor(cardViewUpdateService: CardViewUpdateService,
|
||||
private dateAdapter: DateAdapter<Moment>,
|
||||
constructor(private dateAdapter: DateAdapter<Moment>,
|
||||
private userPreferencesService: UserPreferencesService,
|
||||
private appConfig: AppConfigService,
|
||||
private clipboardService: ClipboardService,
|
||||
private translateService: TranslationService) {
|
||||
super(cardViewUpdateService);
|
||||
super();
|
||||
this.dateFormat = this.appConfig.get('dateValues.defaultDateFormat');
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
import { Component, Input, OnChanges, ViewEncapsulation } from '@angular/core';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { CardViewKeyValuePairsItemModel } from '../../models/card-view.models';
|
||||
import { CardViewKeyValuePairsItemType } from '../../interfaces/card-view.interfaces';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
@@ -37,10 +36,6 @@ export class CardViewKeyValuePairsItemComponent extends BaseCardView<CardViewKey
|
||||
values: CardViewKeyValuePairsItemType[];
|
||||
matTableValues: MatTableDataSource<CardViewKeyValuePairsItemType>;
|
||||
|
||||
constructor(cardViewUpdateService: CardViewUpdateService) {
|
||||
super(cardViewUpdateService);
|
||||
}
|
||||
|
||||
ngOnChanges() {
|
||||
this.values = this.property.value || [];
|
||||
this.matTableValues = new MatTableDataSource(this.values);
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { CardViewMapItemModel } from '../../models/card-view-mapitem.model';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { BaseCardView } from '../base-card-view';
|
||||
|
||||
@Component({
|
||||
@@ -33,10 +32,6 @@ export class CardViewMapItemComponent extends BaseCardView<CardViewMapItemModel>
|
||||
@Input()
|
||||
displayEmpty: boolean = true;
|
||||
|
||||
constructor(cardViewUpdateService: CardViewUpdateService) {
|
||||
super(cardViewUpdateService);
|
||||
}
|
||||
|
||||
showProperty() {
|
||||
return this.displayEmpty || !this.property.isEmpty();
|
||||
}
|
||||
|
@@ -15,9 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
|
||||
import { Component, Input, OnChanges, OnDestroy, OnInit, inject } from '@angular/core';
|
||||
import { CardViewSelectItemModel } from '../../models/card-view-selectitem.model';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { BehaviorSubject, combineLatest, Observable, Subject } from 'rxjs';
|
||||
import { CardViewSelectItemOption } from '../../interfaces/card-view.interfaces';
|
||||
import { MatSelectChange } from '@angular/material/select';
|
||||
@@ -31,6 +30,7 @@ import { takeUntil, map } from 'rxjs/operators';
|
||||
styleUrls: ['./card-view-selectitem.component.scss']
|
||||
})
|
||||
export class CardViewSelectItemComponent extends BaseCardView<CardViewSelectItemModel<string | number>> implements OnInit, OnChanges, OnDestroy {
|
||||
private appConfig = inject(AppConfigService);
|
||||
static HIDE_FILTER_LIMIT = 5;
|
||||
|
||||
@Input() editable: boolean = false;
|
||||
@@ -51,10 +51,6 @@ export class CardViewSelectItemComponent extends BaseCardView<CardViewSelectItem
|
||||
|
||||
list$: Observable<CardViewSelectItemOption<string | number>[]> = null;
|
||||
|
||||
constructor(cardViewUpdateService: CardViewUpdateService, private appConfig: AppConfigService) {
|
||||
super(cardViewUpdateService);
|
||||
}
|
||||
|
||||
ngOnChanges(): void {
|
||||
this.value = this.property.value;
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { ChangeDetectorRef, Component, Input, OnChanges, OnDestroy, SimpleChanges, ViewEncapsulation } from '@angular/core';
|
||||
import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { BaseCardView } from '../base-card-view';
|
||||
import { MatChipInputEvent } from '@angular/material/chips';
|
||||
import { ClipboardService } from '../../../clipboard/clipboard.service';
|
||||
@@ -67,11 +66,10 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
|
||||
|
||||
private onDestroy$ = new Subject<boolean>();
|
||||
|
||||
constructor(cardViewUpdateService: CardViewUpdateService,
|
||||
private clipboardService: ClipboardService,
|
||||
constructor(private clipboardService: ClipboardService,
|
||||
private translateService: TranslationService,
|
||||
private cd: ChangeDetectorRef) {
|
||||
super(cardViewUpdateService);
|
||||
super();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
|
@@ -23,36 +23,35 @@ import { AppConfigService, AppConfigValues } from '../app-config/app-config.serv
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { CookieService } from '../common/services/cookie.service';
|
||||
import { LogService } from '../common/services/log.service';
|
||||
import { inject } from '@angular/core';
|
||||
|
||||
const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME';
|
||||
const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30;
|
||||
|
||||
export abstract class BaseAuthenticationService {
|
||||
protected alfrescoApi = inject(AlfrescoApiService);
|
||||
protected appConfig = inject(AppConfigService);
|
||||
protected cookie = inject(CookieService);
|
||||
private logService = inject(LogService);
|
||||
|
||||
protected bearerExcludedUrls: readonly string[] = ['resources/', 'assets/', 'auth/realms', 'idp/'];
|
||||
protected redirectUrl: RedirectionModel = null;
|
||||
|
||||
onLogin = new ReplaySubject<any>(1);
|
||||
onLogout = new ReplaySubject<any>(1);
|
||||
|
||||
_peopleApi: PeopleApi;
|
||||
private _peopleApi: PeopleApi;
|
||||
get peopleApi(): PeopleApi {
|
||||
this._peopleApi = this._peopleApi ?? new PeopleApi(this.alfrescoApi.getInstance());
|
||||
return this._peopleApi;
|
||||
}
|
||||
|
||||
_profileApi: UserProfileApi;
|
||||
private _profileApi: UserProfileApi;
|
||||
get profileApi(): UserProfileApi {
|
||||
this._profileApi = this._profileApi ?? new UserProfileApi(this.alfrescoApi.getInstance());
|
||||
return this._profileApi;
|
||||
}
|
||||
|
||||
constructor(
|
||||
protected alfrescoApi: AlfrescoApiService,
|
||||
protected appConfig: AppConfigService,
|
||||
protected cookie: CookieService,
|
||||
private logService: LogService
|
||||
) {}
|
||||
|
||||
abstract readonly supportCodeFlow: boolean;
|
||||
abstract getToken(): string;
|
||||
abstract isLoggedIn(): boolean;
|
||||
|
Reference in New Issue
Block a user