From e70fc9ec8cff01e02896c34090c41672465b8dc1 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Tue, 25 Feb 2020 12:35:13 +0300 Subject: [PATCH] fix: fix some errors caused by Angular 9 --- .../components/dynamic-layout.component.ts | 21 ++++++++++++------- .../core/src/lib/guards/auth.guard.ts | 21 ++++++++++++++----- .../core/src/lib/states/config.state.ts | 2 ++ .../core/src/lib/states/profile.state.ts | 2 ++ .../states/replaceable-components.state.ts | 2 ++ .../core/src/lib/states/session.state.ts | 2 ++ .../lib/states/feature-management.state.ts | 2 ++ .../lib/services/identity-config.service.ts | 20 ++++++++++++------ .../identity/src/lib/states/identity.state.ts | 2 ++ .../lib/states/permission-management.state.ts | 7 ++++++- .../setting-management-config.service.ts | 12 ++++++++--- .../setting-management.component.ts | 16 +++++++------- .../lib/states/setting-management.state.ts | 7 ++++++- .../src/lib/states/tenant-management.state.ts | 2 ++ .../application-layout.component.html | 4 +++- .../src/lib/states/layout.state.ts | 2 ++ .../src/lib/handlers/error.handler.ts | 3 ++- 17 files changed, 94 insertions(+), 33 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/components/dynamic-layout.component.ts b/npm/ng-packs/packages/core/src/lib/components/dynamic-layout.component.ts index 40954268e8..7fc1826efe 100644 --- a/npm/ng-packs/packages/core/src/lib/components/dynamic-layout.component.ts +++ b/npm/ng-packs/packages/core/src/lib/components/dynamic-layout.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnDestroy, Type } from '@angular/core'; +import { Component, Input, OnDestroy, Type, Injector } from '@angular/core'; import { ActivatedRoute, NavigationEnd, Router, UrlSegment } from '@angular/router'; import { Select, Store } from '@ngxs/store'; import { Observable } from 'rxjs'; @@ -14,8 +14,10 @@ import { takeUntilDestroy } from '../utils/rxjs-utils'; template: ` - - ` + + `, }) export class DynamicLayoutComponent implements OnDestroy { @Select(ConfigState.getOne('requirements')) requirements$: Observable; @@ -25,18 +27,23 @@ export class DynamicLayoutComponent implements OnDestroy { constructor(private router: Router, private route: ActivatedRoute, private store: Store) { const { requirements: { layouts }, - routes + routes, } = this.store.selectSnapshot(ConfigState.getAll); if ((this.route.snapshot.data || {}).layout) { this.layout = layouts .filter(l => !!l) - .find((l: any) => snq(() => l.type.toLowerCase().indexOf(this.route.snapshot.data.layout), -1) > -1); + .find( + (l: any) => + snq(() => l.type.toLowerCase().indexOf(this.route.snapshot.data.layout), -1) > -1, + ); } - this.router.events.pipe(takeUntilDestroy(this)).subscribe(event => { + router.events.pipe(takeUntilDestroy(this)).subscribe(event => { if (event instanceof NavigationEnd) { - const { segments } = this.router.parseUrl(event.url).root.children.primary; + const segments = snq(() => router.parseUrl(event.url).root.children.primary.segments, [ + { path: router.url.replace('/', '') }, + ] as any); const layout = (this.route.snapshot.data || {}).layout || findLayout(segments, routes); diff --git a/npm/ng-packs/packages/core/src/lib/guards/auth.guard.ts b/npm/ng-packs/packages/core/src/lib/guards/auth.guard.ts index cbd59fb5df..1e9dc52bb3 100644 --- a/npm/ng-packs/packages/core/src/lib/guards/auth.guard.ts +++ b/npm/ng-packs/packages/core/src/lib/guards/auth.guard.ts @@ -1,5 +1,11 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { Injectable, Injector } from '@angular/core'; +import { + ActivatedRouteSnapshot, + CanActivate, + Router, + RouterStateSnapshot, + UrlTree, +} from '@angular/router'; import { OAuthService } from 'angular-oauth2-oidc'; import { Observable } from 'rxjs'; @@ -7,14 +13,19 @@ import { Observable } from 'rxjs'; providedIn: 'root', }) export class AuthGuard implements CanActivate { - constructor(private oauthService: OAuthService, private router: Router) {} + constructor(private oauthService: OAuthService, private injector: Injector) {} + + canActivate( + _: ActivatedRouteSnapshot, + state: RouterStateSnapshot, + ): Observable | boolean | UrlTree { + const router = this.injector.get(Router); - canActivate(_: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean | UrlTree { const hasValidAccessToken = this.oauthService.hasValidAccessToken(); if (hasValidAccessToken) { return hasValidAccessToken; } - return this.router.createUrlTree(['/account/login'], { state: { redirectUrl: state.url } }); + return router.createUrlTree(['/account/login'], { state: { redirectUrl: state.url } }); } } diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index ff964cfe92..3e4c544f11 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -14,11 +14,13 @@ import { Config } from '../models/config'; import { ApplicationConfigurationService } from '../services/application-configuration.service'; import { organizeRoutes } from '../utils/route-utils'; import { SessionState } from './session.state'; +import { Injectable } from '@angular/core'; @State({ name: 'ConfigState', defaults: {} as Config.State, }) +@Injectable() export class ConfigState { @Selector() static getAll(state: Config.State) { diff --git a/npm/ng-packs/packages/core/src/lib/states/profile.state.ts b/npm/ng-packs/packages/core/src/lib/states/profile.state.ts index 47e0506f2e..0469b8b16b 100644 --- a/npm/ng-packs/packages/core/src/lib/states/profile.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/profile.state.ts @@ -3,11 +3,13 @@ import { tap } from 'rxjs/operators'; import { ChangePassword, GetProfile, UpdateProfile } from '../actions/profile.actions'; import { Profile } from '../models/profile'; import { ProfileService } from '../services/profile.service'; +import { Injectable } from '@angular/core'; @State({ name: 'ProfileState', defaults: {} as Profile.State, }) +@Injectable() export class ProfileState { @Selector() static getProfile({ profile }: Profile.State): Profile.Response { diff --git a/npm/ng-packs/packages/core/src/lib/states/replaceable-components.state.ts b/npm/ng-packs/packages/core/src/lib/states/replaceable-components.state.ts index 41c69df94f..4f496a7f30 100644 --- a/npm/ng-packs/packages/core/src/lib/states/replaceable-components.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/replaceable-components.state.ts @@ -2,11 +2,13 @@ import { State, Action, StateContext, Selector, createSelector } from '@ngxs/sto import { AddReplaceableComponent } from '../actions/replaceable-components.actions'; import { ReplaceableComponents } from '../models/replaceable-components'; import snq from 'snq'; +import { Injectable } from '@angular/core'; @State({ name: 'ReplaceableComponentsState', defaults: { replaceableComponents: [] } as ReplaceableComponents.State, }) +@Injectable() export class ReplaceableComponentsState { @Selector() static getAll({ diff --git a/npm/ng-packs/packages/core/src/lib/states/session.state.ts b/npm/ng-packs/packages/core/src/lib/states/session.state.ts index 7ea742dce7..9342bacd62 100644 --- a/npm/ng-packs/packages/core/src/lib/states/session.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/session.state.ts @@ -20,11 +20,13 @@ import { import { ABP, Session } from '../models'; import { LocalizationService } from '../services/localization.service'; import { OAuthService } from 'angular-oauth2-oidc'; +import { Injectable } from '@angular/core'; @State({ name: 'SessionState', defaults: { sessionDetail: { openedTabCount: 0 } } as Session.State, }) +@Injectable() export class SessionState { @Selector() static getLanguage({ language }: Session.State): string { diff --git a/npm/ng-packs/packages/feature-management/src/lib/states/feature-management.state.ts b/npm/ng-packs/packages/feature-management/src/lib/states/feature-management.state.ts index 34dd78b0fb..676918708c 100644 --- a/npm/ng-packs/packages/feature-management/src/lib/states/feature-management.state.ts +++ b/npm/ng-packs/packages/feature-management/src/lib/states/feature-management.state.ts @@ -3,11 +3,13 @@ import { tap } from 'rxjs/operators'; import { GetFeatures, UpdateFeatures } from '../actions/feature-management.actions'; import { FeatureManagement } from '../models/feature-management'; import { FeatureManagementService } from '../services/feature-management.service'; +import { Injectable } from '@angular/core'; @State({ name: 'FeatureManagementState', defaults: { features: {} } as FeatureManagement.State, }) +@Injectable() export class FeatureManagementState { @Selector() static getFeatures({ features }: FeatureManagement.State) { diff --git a/npm/ng-packs/packages/identity-config/src/lib/services/identity-config.service.ts b/npm/ng-packs/packages/identity-config/src/lib/services/identity-config.service.ts index 47a36bba9d..d1b52fed8b 100644 --- a/npm/ng-packs/packages/identity-config/src/lib/services/identity-config.service.ts +++ b/npm/ng-packs/packages/identity-config/src/lib/services/identity-config.service.ts @@ -1,13 +1,11 @@ -import { addAbpRoutes, eLayoutType, RestService } from '@abp/ng.core'; +import { addAbpRoutes, eLayoutType } from '@abp/ng.core'; import { Injectable } from '@angular/core'; -import { Router } from '@angular/router'; -import { Observable } from 'rxjs'; @Injectable({ providedIn: 'root', }) export class IdentityConfigService { - constructor(private router: Router, private restService: RestService) { + constructor() { addAbpRoutes([ { name: 'AbpUiNavigation::Menu:Administration', @@ -24,8 +22,18 @@ export class IdentityConfigService { layout: eLayoutType.application, iconClass: 'fa fa-id-card-o', children: [ - { path: 'roles', name: 'AbpIdentity::Roles', order: 1, requiredPolicy: 'AbpIdentity.Roles' }, - { path: 'users', name: 'AbpIdentity::Users', order: 2, requiredPolicy: 'AbpIdentity.Users' }, + { + path: 'roles', + name: 'AbpIdentity::Roles', + order: 1, + requiredPolicy: 'AbpIdentity.Roles', + }, + { + path: 'users', + name: 'AbpIdentity::Users', + order: 2, + requiredPolicy: 'AbpIdentity.Users', + }, ], }, ]); diff --git a/npm/ng-packs/packages/identity/src/lib/states/identity.state.ts b/npm/ng-packs/packages/identity/src/lib/states/identity.state.ts index 142fa79b74..0b1fd24c9c 100644 --- a/npm/ng-packs/packages/identity/src/lib/states/identity.state.ts +++ b/npm/ng-packs/packages/identity/src/lib/states/identity.state.ts @@ -15,11 +15,13 @@ import { } from '../actions/identity.actions'; import { Identity } from '../models/identity'; import { IdentityService } from '../services/identity.service'; +import { Injectable } from '@angular/core'; @State({ name: 'IdentityState', defaults: { roles: {}, selectedRole: {}, users: {}, selectedUser: {} } as Identity.State, }) +@Injectable() export class IdentityState { @Selector() static getRoles({ roles }: Identity.State): Identity.RoleItem[] { diff --git a/npm/ng-packs/packages/permission-management/src/lib/states/permission-management.state.ts b/npm/ng-packs/packages/permission-management/src/lib/states/permission-management.state.ts index 671c9f5cf3..17999e61e8 100644 --- a/npm/ng-packs/packages/permission-management/src/lib/states/permission-management.state.ts +++ b/npm/ng-packs/packages/permission-management/src/lib/states/permission-management.state.ts @@ -3,11 +3,13 @@ import { GetPermissions, UpdatePermissions } from '../actions/permission-managem import { PermissionManagement } from '../models/permission-management'; import { PermissionManagementService } from '../services/permission-management.service'; import { tap } from 'rxjs/operators'; +import { Injectable } from '@angular/core'; @State({ name: 'PermissionManagementState', defaults: { permissionRes: {} } as PermissionManagement.State, }) +@Injectable() export class PermissionManagementState { @Selector() static getPermissionGroups({ permissionRes }: PermissionManagement.State) { @@ -22,7 +24,10 @@ export class PermissionManagementState { constructor(private permissionManagementService: PermissionManagementService) {} @Action(GetPermissions) - permissionManagementGet({ patchState }: StateContext, { payload }: GetPermissions) { + permissionManagementGet( + { patchState }: StateContext, + { payload }: GetPermissions, + ) { return this.permissionManagementService.getPermissions(payload).pipe( tap(permissionResponse => patchState({ diff --git a/npm/ng-packs/packages/setting-management-config/src/lib/services/setting-management-config.service.ts b/npm/ng-packs/packages/setting-management-config/src/lib/services/setting-management-config.service.ts index bc1dc78da3..721a5a5991 100644 --- a/npm/ng-packs/packages/setting-management-config/src/lib/services/setting-management-config.service.ts +++ b/npm/ng-packs/packages/setting-management-config/src/lib/services/setting-management-config.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable, Injector } from '@angular/core'; import { addAbpRoutes, eLayoutType, PatchRouteByName, ABP } from '@abp/ng.core'; import { getSettingTabs } from '@abp/ng.theme.shared'; import { Store } from '@ngxs/store'; @@ -7,7 +7,11 @@ import { Store } from '@ngxs/store'; providedIn: 'root', }) export class SettingManagementConfigService { - constructor(private store: Store) { + get store(): Store { + return this.injector.get(Store); + } + + constructor(private injector: Injector) { const route = { name: 'AbpSettingManagement::Settings', path: 'setting-management', @@ -23,7 +27,9 @@ export class SettingManagementConfigService { setTimeout(() => { const tabs = getSettingTabs(); if (!tabs || !tabs.length) { - this.store.dispatch(new PatchRouteByName('AbpSettingManagement::Settings', { ...route, invisible: true })); + this.store.dispatch( + new PatchRouteByName('AbpSettingManagement::Settings', { ...route, invisible: true }), + ); } }); } diff --git a/npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.ts b/npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.ts index 0c43cf6670..7a7085e4e1 100644 --- a/npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.ts +++ b/npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.ts @@ -1,11 +1,9 @@ -import { Component, TrackByFunction, OnInit } from '@angular/core'; -import { SettingTab, getSettingTabs } from '@abp/ng.theme.shared'; -import { Router } from '@angular/router'; -import { Store } from '@ngxs/store'; import { ConfigState } from '@abp/ng.core'; -import { SettingManagementState } from '../states/setting-management.state'; +import { getSettingTabs, SettingTab } from '@abp/ng.theme.shared'; +import { Component, OnInit, TrackByFunction } from '@angular/core'; +import { Store } from '@ngxs/store'; import { SetSelectedSettingTab } from '../actions/setting-management.actions'; -import { RouterState } from '@ngxs/router-plugin'; +import { SettingManagementState } from '../states/setting-management.state'; @Component({ selector: 'abp-setting-management', @@ -29,11 +27,13 @@ export class SettingManagementComponent implements OnInit { trackByFn: TrackByFunction = (_, item) => item.name; - constructor(private router: Router, private store: Store) {} + constructor(private store: Store) {} ngOnInit() { this.settings = getSettingTabs() - .filter(setting => this.store.selectSnapshot(ConfigState.getGrantedPolicy(setting.requiredPolicy))) + .filter(setting => + this.store.selectSnapshot(ConfigState.getGrantedPolicy(setting.requiredPolicy)), + ) .sort((a, b) => a.order - b.order); if (!this.selected && this.settings.length) { diff --git a/npm/ng-packs/packages/setting-management/src/lib/states/setting-management.state.ts b/npm/ng-packs/packages/setting-management/src/lib/states/setting-management.state.ts index d2914876ec..7490117b38 100644 --- a/npm/ng-packs/packages/setting-management/src/lib/states/setting-management.state.ts +++ b/npm/ng-packs/packages/setting-management/src/lib/states/setting-management.state.ts @@ -1,11 +1,13 @@ import { Action, Selector, State, StateContext } from '@ngxs/store'; import { SetSelectedSettingTab } from '../actions/setting-management.actions'; import { SettingManagement } from '../models/setting-management'; +import { Injectable } from '@angular/core'; @State({ name: 'SettingManagementState', defaults: { selectedTab: {} } as SettingManagement.State, }) +@Injectable() export class SettingManagementState { @Selector() static getSelectedTab({ selectedTab }: SettingManagement.State) { @@ -13,7 +15,10 @@ export class SettingManagementState { } @Action(SetSelectedSettingTab) - settingManagementAction({ patchState }: StateContext, { payload }: SetSelectedSettingTab) { + settingManagementAction( + { patchState }: StateContext, + { payload }: SetSelectedSettingTab, + ) { patchState({ selectedTab: payload, }); diff --git a/npm/ng-packs/packages/tenant-management/src/lib/states/tenant-management.state.ts b/npm/ng-packs/packages/tenant-management/src/lib/states/tenant-management.state.ts index bbd4a35d4f..bacd8981ec 100644 --- a/npm/ng-packs/packages/tenant-management/src/lib/states/tenant-management.state.ts +++ b/npm/ng-packs/packages/tenant-management/src/lib/states/tenant-management.state.ts @@ -10,11 +10,13 @@ import { } from '../actions/tenant-management.actions'; import { TenantManagement } from '../models/tenant-management'; import { TenantManagementService } from '../services/tenant-management.service'; +import { Injectable } from '@angular/core'; @State({ name: 'TenantManagementState', defaults: { result: {}, selectedItem: {} } as TenantManagement.State, }) +@Injectable() export class TenantManagementState { @Selector() static get({ result }: TenantManagement.State): ABP.BasicItem[] { diff --git a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.html b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.html index 8199e7d5b6..9d953dbf5e 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.html +++ b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.html @@ -147,7 +147,9 @@
diff --git a/npm/ng-packs/packages/theme-basic/src/lib/states/layout.state.ts b/npm/ng-packs/packages/theme-basic/src/lib/states/layout.state.ts index 1c90803638..f206121a61 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/states/layout.state.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/states/layout.state.ts @@ -2,11 +2,13 @@ import { Action, Selector, State, StateContext } from '@ngxs/store'; import snq from 'snq'; import { AddNavigationElement, RemoveNavigationElementByName } from '../actions/layout.actions'; import { Layout } from '../models/layout'; +import { Injectable } from '@angular/core'; @State({ name: 'LayoutState', defaults: { navigationElements: [] } as Layout.State, }) +@Injectable() export class LayoutState { @Selector() static getNavigationElements({ navigationElements }: Layout.State): Layout.NavigationElement[] { diff --git a/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts b/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts index fedf870c4a..1f221a42e9 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts @@ -220,11 +220,12 @@ export class ErrorHandler { .resolveComponentFactory(HttpErrorWrapperComponent) .create(this.injector); - for (const key in this.componentRef.instance) { + for (const key in instance) { if (this.componentRef.instance.hasOwnProperty(key)) { this.componentRef.instance[key] = instance[key]; } } + this.componentRef.instance.hideCloseIcon = this.httpErrorConfig.errorScreen.hideCloseIcon; if (this.canCreateCustomError(instance.status as ErrorScreenErrorCodes)) { this.componentRef.instance.cfRes = this.cfRes;