From e39ddec3be2b1946d11531b96708cceb2ee31b53 Mon Sep 17 00:00:00 2001 From: "kim.tran" Date: Fri, 26 Jan 2024 09:56:45 +0100 Subject: [PATCH 1/2] feat: displayedColumnsChange output added, edit paths in createTranslateLoader, encodeParam --- libs/portal-integration-angular/src/index.ts | 1 - .../interactive-data-view.component.ts | 6 ++- .../src/lib/core/portal-core.module.ts | 2 - .../add-initialize-module-guard.utils.spec.ts | 38 +++++++++---------- .../add-initialize-module-guard.utils.ts | 4 +- .../utils/create-translate-loader.utils.ts | 12 +++++- .../utils/portal-api-configuration.utils.ts | 8 ++++ .../initialize-module-guard.service.ts | 4 +- update-guide.md | 9 ++++- 9 files changed, 53 insertions(+), 31 deletions(-) diff --git a/libs/portal-integration-angular/src/index.ts b/libs/portal-integration-angular/src/index.ts index 339d1a37..afe00173 100644 --- a/libs/portal-integration-angular/src/index.ts +++ b/libs/portal-integration-angular/src/index.ts @@ -89,7 +89,6 @@ export * from './lib/model/person.model' export * from './lib/model/page-info.model' export * from './lib/model/portal' export * from './lib/model/user-profile.model' -export * from './lib/model/user-profile.model' export * from './lib/model/data-table-column.model' export * from './lib/model/column-type.model' export * from './lib/model/data-sort-direction' diff --git a/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts b/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts index 26c7c449..0190851f 100644 --- a/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts +++ b/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts @@ -70,7 +70,8 @@ export class InteractiveDataViewComponent implements OnInit { @Output() deleteItem = new EventEmitter() @Output() viewItem = new EventEmitter() @Output() editItem = new EventEmitter() - @Output() dataViewLayoutChange: EventEmitter = new EventEmitter() + @Output() dataViewLayoutChange = new EventEmitter<'grid' | 'list' | 'table'>() + @Output() displayedColumnsChange = new EventEmitter() displayedColumns: DataTableColumn[] = [] selectedGroupKey = '' isDeleteItemObserved: boolean | undefined @@ -135,6 +136,7 @@ export class InteractiveDataViewComponent implements OnInit { column.predefinedGroupKeys?.includes(this.defaultGroupKey) ) } + this.displayedColumnsChange.emit(this.displayedColumns) if (!this.groupSelectionNoGroupSelectedKey) { this.groupSelectionNoGroupSelectedKey = 'OCX_INTERACTIVE_DATA_VIEW.NO_GROUP_SELECTED' } @@ -188,6 +190,7 @@ export class InteractiveDataViewComponent implements OnInit { onColumnGroupSelectionChange(event: GroupSelectionChangedEvent) { this.displayedColumns = event.activeColumns this.selectedGroupKey = event.groupKey + this.displayedColumnsChange.emit(this.displayedColumns) } registerEventListenerForDataView() { @@ -220,5 +223,6 @@ export class InteractiveDataViewComponent implements OnInit { onColumnSelectionChange(event: ColumnSelectionChangedEvent) { this.displayedColumns = event.activeColumns this.selectedGroupKey = this.customGroupKey + this.displayedColumnsChange.emit(this.displayedColumns) } } diff --git a/libs/portal-integration-angular/src/lib/core/portal-core.module.ts b/libs/portal-integration-angular/src/lib/core/portal-core.module.ts index 94bfd1e4..fbedfd83 100644 --- a/libs/portal-integration-angular/src/lib/core/portal-core.module.ts +++ b/libs/portal-integration-angular/src/lib/core/portal-core.module.ts @@ -56,7 +56,6 @@ import { HelpItemEditorComponent } from './components/help-item-editor/help-item import { NoHelpItemComponent } from './components/no-help-item/no-help-item.component' import { DataListGridComponent } from './components/data-list-grid/data-list-grid.component' import { PrimeNgModule } from './primeng.module' -import { MockAuthService } from '../mock-auth/mock-auth.service' import { ConfirmDialogModule } from 'primeng/confirmdialog' import { DataTableComponent } from './components/data-table/data-table.component' import de from '@angular/common/locales/de' @@ -167,7 +166,6 @@ export class MyMissingTranslationHandler implements MissingTranslationHandler { ], providers: [ ConfigurationService, - MockAuthService, { provide: LOCALE_ID, useFactory: (translate: TranslateService) => { diff --git a/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.spec.ts b/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.spec.ts index e0da53d9..c8d0632b 100644 --- a/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.spec.ts +++ b/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.spec.ts @@ -1,11 +1,11 @@ import { TranslateService } from '@ngx-translate/core' import { AppStateService } from '../../services/app-state.service' import { ConfigurationService } from '../../services/configuration.service' -import { InitializeModuleGuard } from '../../services/initialize-module-guard.service' +import { InitializeModuleGuardService } from '../../services/initialize-module-guard.service' import { UserService } from '../../services/user.service' import { addInitializeModuleGuard } from './add-initialize-module-guard.utils' -class MockInitializeModuleGuard extends InitializeModuleGuard { +class MockInitializeModuleGuard extends InitializeModuleGuardService { constructor( translateService: TranslateService, configService: ConfigurationService, @@ -30,11 +30,11 @@ describe('AddInitializeGuard', () => { const expectedRoutes = [ { path: 'testPathAddInitializerModuleGuard1', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, { path: 'testPathAddInitializerModuleGuard2', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, ] const modifiedRoutes = addInitializeModuleGuard(testRoutesNoCanActivate) @@ -61,15 +61,15 @@ describe('AddInitializeGuard', () => { const expectedRoutes = [ { path: 'testPathHasMockInitializeModueGuard1', - canActivate: [MockInitializeModuleGuard, InitializeModuleGuard], + canActivate: [MockInitializeModuleGuard, InitializeModuleGuardService], }, { path: 'testPath', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, { path: 'testPathHasMockInitializeModueGuard2', - canActivate: [MockInitializeModuleGuard, InitializeModuleGuard], + canActivate: [MockInitializeModuleGuard, InitializeModuleGuardService], }, ] const modifiedRoutes = addInitializeModuleGuard(testRoutesWithMockInitializeModuleGuard) @@ -85,41 +85,41 @@ describe('AddInitializeGuard', () => { }, { path: 'testPathHasInitializeModueGuard1', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, { path: 'testPathHasInitializeModueGuard2', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, { path: 'testPath2', }, { path: 'testPathHasInitializeModueGuard3', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, ] const expectedRoutes = [ { path: 'testPath1', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, { path: 'testPathHasInitializeModueGuard1', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, { path: 'testPathHasInitializeModueGuard2', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, { path: 'testPath2', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, { path: 'testPathHasInitializeModueGuard3', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, ] const modifiedRoutes = addInitializeModuleGuard(testRoutesWithInitializeModuleGuard) @@ -153,7 +153,7 @@ describe('AddInitializeGuard', () => { }, { path: 'someTestPath1', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, { path: 'testPathHasRedirectTo2', @@ -161,7 +161,7 @@ describe('AddInitializeGuard', () => { }, { path: 'someTestPath2', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, ] const modifiedRoutes = addInitializeModuleGuard(testRoutesWithRedirectTo) @@ -214,7 +214,7 @@ describe('AddInitializeGuard', () => { }, { path: 'testPathHasMockInitializeModueGuard2', - canActivate: [InitializeModuleGuard], + canActivate: [InitializeModuleGuardService], }, ] @@ -229,7 +229,7 @@ describe('AddInitializeGuard', () => { }, { path: 'testPathHasMockInitializeModueGuard2', - canActivate: [InitializeModuleGuard, MockInitializeModuleGuard], + canActivate: [InitializeModuleGuardService, MockInitializeModuleGuard], }, ] const modifiedRoutes = addInitializeModuleGuard(testRoutesWithMockInitializeModuleGuard, MockInitializeModuleGuard) diff --git a/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.ts b/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.ts index 0bb601e9..745a51ae 100644 --- a/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.ts +++ b/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.ts @@ -1,9 +1,9 @@ import { CanActivateFn, Route } from '@angular/router' -import { InitializeModuleGuard } from '../../services/initialize-module-guard.service' +import { InitializeModuleGuardService } from '../../services/initialize-module-guard.service' export function addInitializeModuleGuard( routes: Route[], - initializeModuleGuard: typeof InitializeModuleGuard | CanActivateFn = InitializeModuleGuard + initializeModuleGuard: typeof InitializeModuleGuardService | CanActivateFn = InitializeModuleGuardService ): Route[] { return routes.map((r) => { if (r.redirectTo) { diff --git a/libs/portal-integration-angular/src/lib/core/utils/create-translate-loader.utils.ts b/libs/portal-integration-angular/src/lib/core/utils/create-translate-loader.utils.ts index 7a09e908..a33296b8 100644 --- a/libs/portal-integration-angular/src/lib/core/utils/create-translate-loader.utils.ts +++ b/libs/portal-integration-angular/src/lib/core/utils/create-translate-loader.utils.ts @@ -1,3 +1,4 @@ +import { Location } from '@angular/common' import { HttpClient } from '@angular/common/http' import { TranslateLoader } from '@ngx-translate/core' import { TranslateHttpLoader } from '@ngx-translate/http-loader' @@ -12,9 +13,16 @@ export function createTranslateLoader(http: HttpClient, appStateService: AppStat filter(([, isLoading]) => !isLoading), map(([currentMfe]) => { return new TranslateCombinedLoader( - new TranslateHttpLoader(http, `${currentMfe.remoteBaseUrl}/assets/i18n/`, '.json'), + // translations of shell or of app in standalone mode new TranslateHttpLoader(http, `./assets/i18n/`, '.json'), - new TranslateHttpLoader(http, `./onecx-portal-lib/assets/i18n/`, '.json') + // translations of portal-integration-angular of app + new TranslateHttpLoader( + http, + Location.joinWithSlash(currentMfe.remoteBaseUrl, `onecx-portal-lib/assets/i18n/`), + '.json' + ), + // translations of the app + new TranslateHttpLoader(http, Location.joinWithSlash(currentMfe.remoteBaseUrl, `assets/i18n/`), '.json') ) }) ) diff --git a/libs/portal-integration-angular/src/lib/core/utils/portal-api-configuration.utils.ts b/libs/portal-integration-angular/src/lib/core/utils/portal-api-configuration.utils.ts index 463bf790..fbfe0fc3 100644 --- a/libs/portal-integration-angular/src/lib/core/utils/portal-api-configuration.utils.ts +++ b/libs/portal-integration-angular/src/lib/core/utils/portal-api-configuration.utils.ts @@ -5,6 +5,7 @@ import { ConfigurationService } from '../../services/configuration.service' type Config = { credentials: { [key: string]: string | (() => string | undefined) } + encodeParam: (param: unknown) => string selectHeaderContentType(contentTypes: string[]): string | undefined selectHeaderAccept(accepts: string[]): string | undefined isJsonMime(mime: string): boolean @@ -29,6 +30,13 @@ export class PortalApiConfiguration { this.configuration.credentials = value } + get encodeParam(): (param: unknown) => string { + return this.configuration.encodeParam + } + set encocdeParam(value: (param: unknown) => string) { + this.configuration.encodeParam = value + } + constructor( private configurationClassOfGenerator: unknown, private apiPrefix: string, diff --git a/libs/portal-integration-angular/src/lib/services/initialize-module-guard.service.ts b/libs/portal-integration-angular/src/lib/services/initialize-module-guard.service.ts index 151e975d..6d2daf86 100644 --- a/libs/portal-integration-angular/src/lib/services/initialize-module-guard.service.ts +++ b/libs/portal-integration-angular/src/lib/services/initialize-module-guard.service.ts @@ -6,8 +6,8 @@ import { AppStateService } from './app-state.service' import { ConfigurationService } from './configuration.service' import { UserService } from './user.service' -@Injectable() -export class InitializeModuleGuard implements CanActivate { +@Injectable({ providedIn: 'any' }) +export class InitializeModuleGuardService implements CanActivate { private SUPPORTED_LANGS = ['en', 'de'] private DEFAULT_LANG = 'en' constructor( diff --git a/update-guide.md b/update-guide.md index 23c8e749..57ae2be8 100644 --- a/update-guide.md +++ b/update-guide.md @@ -22,7 +22,12 @@ - .getCurrentUser(), .getUserRoles() and to get other user related data is now done with userService.profile$ ## ConfigurationService -- lang and lang$ are now defined in UserService as lang$ +- lang and lang$ are now defined in UserService as lang$: BehaviorSubject and to get the value use: +``` +userService.lang$.getValue() +or +userService.lang$.value +``` - to get the portal ID use: ``` configService.getProperty(CONFIG_KEY.TKIT_PORTAL_ID) @@ -52,7 +57,7 @@ await appStateService.currentPortal$.publish(Portal) loader: { provide: TranslateLoader, useFactory: createTranslateLoader, - deps: [HttpClient, AppStateService, ConfigurationService], + deps: [HttpClient, AppStateService], }, ``` From 0362f71ed524229d9eeb65b515ec357802c3d0b7 Mon Sep 17 00:00:00 2001 From: "kim.tran" Date: Fri, 26 Jan 2024 10:24:38 +0100 Subject: [PATCH 2/2] fix: revert breaking changes --- .../interactive-data-view.component.ts | 6 +-- .../add-initialize-module-guard.utils.spec.ts | 38 +++++++++---------- .../add-initialize-module-guard.utils.ts | 4 +- .../initialize-module-guard.service.ts | 2 +- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts b/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts index 0190851f..26c7c449 100644 --- a/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts +++ b/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts @@ -70,8 +70,7 @@ export class InteractiveDataViewComponent implements OnInit { @Output() deleteItem = new EventEmitter() @Output() viewItem = new EventEmitter() @Output() editItem = new EventEmitter() - @Output() dataViewLayoutChange = new EventEmitter<'grid' | 'list' | 'table'>() - @Output() displayedColumnsChange = new EventEmitter() + @Output() dataViewLayoutChange: EventEmitter = new EventEmitter() displayedColumns: DataTableColumn[] = [] selectedGroupKey = '' isDeleteItemObserved: boolean | undefined @@ -136,7 +135,6 @@ export class InteractiveDataViewComponent implements OnInit { column.predefinedGroupKeys?.includes(this.defaultGroupKey) ) } - this.displayedColumnsChange.emit(this.displayedColumns) if (!this.groupSelectionNoGroupSelectedKey) { this.groupSelectionNoGroupSelectedKey = 'OCX_INTERACTIVE_DATA_VIEW.NO_GROUP_SELECTED' } @@ -190,7 +188,6 @@ export class InteractiveDataViewComponent implements OnInit { onColumnGroupSelectionChange(event: GroupSelectionChangedEvent) { this.displayedColumns = event.activeColumns this.selectedGroupKey = event.groupKey - this.displayedColumnsChange.emit(this.displayedColumns) } registerEventListenerForDataView() { @@ -223,6 +220,5 @@ export class InteractiveDataViewComponent implements OnInit { onColumnSelectionChange(event: ColumnSelectionChangedEvent) { this.displayedColumns = event.activeColumns this.selectedGroupKey = this.customGroupKey - this.displayedColumnsChange.emit(this.displayedColumns) } } diff --git a/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.spec.ts b/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.spec.ts index c8d0632b..e0da53d9 100644 --- a/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.spec.ts +++ b/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.spec.ts @@ -1,11 +1,11 @@ import { TranslateService } from '@ngx-translate/core' import { AppStateService } from '../../services/app-state.service' import { ConfigurationService } from '../../services/configuration.service' -import { InitializeModuleGuardService } from '../../services/initialize-module-guard.service' +import { InitializeModuleGuard } from '../../services/initialize-module-guard.service' import { UserService } from '../../services/user.service' import { addInitializeModuleGuard } from './add-initialize-module-guard.utils' -class MockInitializeModuleGuard extends InitializeModuleGuardService { +class MockInitializeModuleGuard extends InitializeModuleGuard { constructor( translateService: TranslateService, configService: ConfigurationService, @@ -30,11 +30,11 @@ describe('AddInitializeGuard', () => { const expectedRoutes = [ { path: 'testPathAddInitializerModuleGuard1', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, { path: 'testPathAddInitializerModuleGuard2', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, ] const modifiedRoutes = addInitializeModuleGuard(testRoutesNoCanActivate) @@ -61,15 +61,15 @@ describe('AddInitializeGuard', () => { const expectedRoutes = [ { path: 'testPathHasMockInitializeModueGuard1', - canActivate: [MockInitializeModuleGuard, InitializeModuleGuardService], + canActivate: [MockInitializeModuleGuard, InitializeModuleGuard], }, { path: 'testPath', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, { path: 'testPathHasMockInitializeModueGuard2', - canActivate: [MockInitializeModuleGuard, InitializeModuleGuardService], + canActivate: [MockInitializeModuleGuard, InitializeModuleGuard], }, ] const modifiedRoutes = addInitializeModuleGuard(testRoutesWithMockInitializeModuleGuard) @@ -85,41 +85,41 @@ describe('AddInitializeGuard', () => { }, { path: 'testPathHasInitializeModueGuard1', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, { path: 'testPathHasInitializeModueGuard2', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, { path: 'testPath2', }, { path: 'testPathHasInitializeModueGuard3', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, ] const expectedRoutes = [ { path: 'testPath1', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, { path: 'testPathHasInitializeModueGuard1', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, { path: 'testPathHasInitializeModueGuard2', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, { path: 'testPath2', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, { path: 'testPathHasInitializeModueGuard3', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, ] const modifiedRoutes = addInitializeModuleGuard(testRoutesWithInitializeModuleGuard) @@ -153,7 +153,7 @@ describe('AddInitializeGuard', () => { }, { path: 'someTestPath1', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, { path: 'testPathHasRedirectTo2', @@ -161,7 +161,7 @@ describe('AddInitializeGuard', () => { }, { path: 'someTestPath2', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, ] const modifiedRoutes = addInitializeModuleGuard(testRoutesWithRedirectTo) @@ -214,7 +214,7 @@ describe('AddInitializeGuard', () => { }, { path: 'testPathHasMockInitializeModueGuard2', - canActivate: [InitializeModuleGuardService], + canActivate: [InitializeModuleGuard], }, ] @@ -229,7 +229,7 @@ describe('AddInitializeGuard', () => { }, { path: 'testPathHasMockInitializeModueGuard2', - canActivate: [InitializeModuleGuardService, MockInitializeModuleGuard], + canActivate: [InitializeModuleGuard, MockInitializeModuleGuard], }, ] const modifiedRoutes = addInitializeModuleGuard(testRoutesWithMockInitializeModuleGuard, MockInitializeModuleGuard) diff --git a/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.ts b/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.ts index 745a51ae..0bb601e9 100644 --- a/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.ts +++ b/libs/portal-integration-angular/src/lib/core/utils/add-initialize-module-guard.utils.ts @@ -1,9 +1,9 @@ import { CanActivateFn, Route } from '@angular/router' -import { InitializeModuleGuardService } from '../../services/initialize-module-guard.service' +import { InitializeModuleGuard } from '../../services/initialize-module-guard.service' export function addInitializeModuleGuard( routes: Route[], - initializeModuleGuard: typeof InitializeModuleGuardService | CanActivateFn = InitializeModuleGuardService + initializeModuleGuard: typeof InitializeModuleGuard | CanActivateFn = InitializeModuleGuard ): Route[] { return routes.map((r) => { if (r.redirectTo) { diff --git a/libs/portal-integration-angular/src/lib/services/initialize-module-guard.service.ts b/libs/portal-integration-angular/src/lib/services/initialize-module-guard.service.ts index 6d2daf86..91ea3113 100644 --- a/libs/portal-integration-angular/src/lib/services/initialize-module-guard.service.ts +++ b/libs/portal-integration-angular/src/lib/services/initialize-module-guard.service.ts @@ -7,7 +7,7 @@ import { ConfigurationService } from './configuration.service' import { UserService } from './user.service' @Injectable({ providedIn: 'any' }) -export class InitializeModuleGuardService implements CanActivate { +export class InitializeModuleGuard implements CanActivate { private SUPPORTED_LANGS = ['en', 'de'] private DEFAULT_LANG = 'en' constructor(