From d1511ca87b4082234dcad067e3f189c230170405 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Thu, 7 Jul 2022 21:13:05 +0300 Subject: [PATCH] RED-3800: use same base screen for admin --- angular.json | 3 - .../base-account-screen-component.scss | 1 - .../app/modules/admin/admin-routing.module.ts | 32 ++++++- .../screens/audit/audit-screen.component.html | 60 +++++-------- .../screens/audit/audit-screen.component.ts | 4 +- .../digital-signature-screen.component.html | 90 +++++++++---------- ...er-templates-listing-screen.component.html | 1 + .../general-config-screen.component.html | 49 ++++------ .../general-config-screen.component.ts | 10 +-- .../smtp-form/smtp-form.component.ts | 2 +- .../user-listing-screen.component.html | 77 +++++----------- .../user-listing-screen.component.scss | 10 +-- .../user-listing-screen.component.ts | 70 +++++++++------ .../file-preview-screen.component.scss | 4 + .../app/utils/global-error-handler.service.ts | 4 + apps/red-ui/src/assets/config/config.json | 4 +- libs/common-ui | 2 +- 17 files changed, 192 insertions(+), 231 deletions(-) diff --git a/angular.json b/angular.json index 0098b733a..0f66137ea 100644 --- a/angular.json +++ b/angular.json @@ -37,9 +37,6 @@ "@schematics/angular:guard": { "skipTests": true }, - "@schematics/angular:module": { - "skipTests": true - }, "@schematics/angular:pipe": { "skipTests": true }, diff --git a/apps/red-ui/src/app/modules/account/base-account-screen/base-account-screen-component.scss b/apps/red-ui/src/app/modules/account/base-account-screen/base-account-screen-component.scss index d94a3f70d..5eab7d790 100644 --- a/apps/red-ui/src/app/modules/account/base-account-screen/base-account-screen-component.scss +++ b/apps/red-ui/src/app/modules/account/base-account-screen/base-account-screen-component.scss @@ -15,7 +15,6 @@ .full-height { display: flex; flex-direction: row; - position: absolute; bottom: 0; width: 100%; height: calc(100% + 50px); diff --git a/apps/red-ui/src/app/modules/admin/admin-routing.module.ts b/apps/red-ui/src/app/modules/admin/admin-routing.module.ts index f657dc156..4836ff31e 100644 --- a/apps/red-ui/src/app/modules/admin/admin-routing.module.ts +++ b/apps/red-ui/src/app/modules/admin/admin-routing.module.ts @@ -166,7 +166,13 @@ const routes: Routes = [ }, { path: 'users', - component: UserListingScreenComponent, + component: BaseAdminScreenComponent, + children: [ + { + path: '', + component: UserListingScreenComponent, + }, + ], canActivate: [CompositeRouteGuard], data: { routeGuards: [AuthGuard, RedRoleGuard], @@ -196,7 +202,13 @@ const routes: Routes = [ }, { path: 'digital-signature', - component: DigitalSignatureScreenComponent, + component: BaseAdminScreenComponent, + children: [ + { + path: '', + component: DigitalSignatureScreenComponent, + }, + ], canActivate: [CompositeRouteGuard], data: { routeGuards: [AuthGuard, RedRoleGuard], @@ -205,7 +217,13 @@ const routes: Routes = [ }, { path: 'audit', - component: AuditScreenComponent, + component: BaseAdminScreenComponent, + children: [ + { + path: '', + component: AuditScreenComponent, + }, + ], canActivate: [CompositeRouteGuard], data: { routeGuards: [AuthGuard, RedRoleGuard], @@ -214,7 +232,13 @@ const routes: Routes = [ }, { path: 'general-config', - component: GeneralConfigScreenComponent, + component: BaseAdminScreenComponent, + children: [ + { + path: '', + component: GeneralConfigScreenComponent, + }, + ], canActivate: [CompositeRouteGuard], canDeactivate: [PendingChangesGuard], data: { diff --git a/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.html index 82695b091..0d72e128b 100644 --- a/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.html @@ -1,38 +1,17 @@ -
-
+ - - -
- -
-
- - -
-
-
-
+
@@ -41,20 +20,23 @@ [settings]="{ currentPage: logs?.page || 0, totalPages: totalPages }" class="mr-0" > +
·
+
- + {{ translations[category] | translate }}
+
- +
+
·
+
- + @@ -86,7 +70,7 @@
- + diff --git a/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.ts index cf934ce1d..e9311f451 100644 --- a/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.ts @@ -1,4 +1,4 @@ -import { Component, forwardRef, Injector, OnDestroy, OnInit } from '@angular/core'; +import { Component, forwardRef, inject, Injector, OnDestroy, OnInit } from '@angular/core'; import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { applyIntervalConstraints } from '@utils/date-inputs-utils'; import { DefaultListingServices, ListingComponent, LoadingService, TableColumnConfig } from '@iqser/common-ui'; @@ -9,6 +9,7 @@ import { Audit, IAudit, IAuditResponse, IAuditSearchRequest } from '@red/domain' import { AuditService } from '../../services/audit.service'; import { firstValueFrom } from 'rxjs'; import { Dayjs } from 'dayjs'; +import { RouterHistoryService } from '../../../../services/router-history.service'; const PAGE_SIZE = 50; @@ -24,6 +25,7 @@ export class AuditScreenComponent extends ListingComponent implements OnI readonly translations = auditCategoriesTranslations; readonly currentUser = this._userService.currentUser; readonly form: UntypedFormGroup = this._getForm(); + readonly routerHistoryService = inject(RouterHistoryService); categories: string[] = []; userIds: Set; logs: IAuditResponse; diff --git a/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.html index c54eeefa0..5af797c13 100644 --- a/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.html @@ -1,56 +1,46 @@ -
-
+ - +
+
+ -
- + + + + -
-
-
- +
+ - - - - - -
- - -
-
-
-
+
-
+
diff --git a/apps/red-ui/src/app/modules/admin/screens/dossier-templates-listing/dossier-templates-listing-screen/dossier-templates-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/dossier-templates-listing/dossier-templates-listing-screen/dossier-templates-listing-screen.component.html index 40f2241dd..7945336a6 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dossier-templates-listing/dossier-templates-listing-screen/dossier-templates-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/dossier-templates-listing/dossier-templates-listing-screen/dossier-templates-listing-screen.component.html @@ -1,5 +1,6 @@ diff --git a/apps/red-ui/src/app/modules/admin/screens/general-config/general-config-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/general-config/general-config-screen.component.html index e15bc83d6..d7d1b7230 100644 --- a/apps/red-ui/src/app/modules/admin/screens/general-config/general-config-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/general-config/general-config-screen.component.html @@ -1,36 +1,17 @@ -
-
+ - - -
- - -
-
-
- -
-
- -
-
- -
-
-
+
+
+
-
+
+ +
+
+ +
+
diff --git a/apps/red-ui/src/app/modules/admin/screens/general-config/general-config-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/general-config/general-config-screen.component.ts index 020d1b125..fb6bf360b 100644 --- a/apps/red-ui/src/app/modules/admin/screens/general-config/general-config-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/general-config/general-config-screen.component.ts @@ -1,9 +1,10 @@ -import { AfterViewInit, Component, ViewChild } from '@angular/core'; +import { AfterViewInit, Component, inject, ViewChild } from '@angular/core'; import { UserService } from '@services/user.service'; import { GeneralConfigFormComponent } from './general-config-form/general-config-form.component'; import { SmtpFormComponent } from './smtp-form/smtp-form.component'; import { BaseFormComponent } from '@iqser/common-ui'; import { SystemPreferencesFormComponent } from './system-preferences-form/system-preferences-form.component'; +import { RouterHistoryService } from '../../../../services/router-history.service'; @Component({ selector: 'redaction-general-config-screen', @@ -11,17 +12,14 @@ import { SystemPreferencesFormComponent } from './system-preferences-form/system styleUrls: ['./general-config-screen.component.scss'], }) export class GeneralConfigScreenComponent extends BaseFormComponent implements AfterViewInit { - readonly currentUser = this._userService.currentUser; + readonly currentUser = inject(UserService).currentUser; + readonly routerHistoryService = inject(RouterHistoryService); @ViewChild(GeneralConfigFormComponent) generalConfigFormComponent: GeneralConfigFormComponent; @ViewChild(SystemPreferencesFormComponent) systemPreferencesFormComponent: SystemPreferencesFormComponent; @ViewChild(SmtpFormComponent) smtpFormComponent: SmtpFormComponent; children: BaseFormComponent[]; - constructor(private readonly _userService: UserService) { - super(); - } - get changed(): boolean { for (const child of this.children) { if (child.changed) { diff --git a/apps/red-ui/src/app/modules/admin/screens/general-config/smtp-form/smtp-form.component.ts b/apps/red-ui/src/app/modules/admin/screens/general-config/smtp-form/smtp-form.component.ts index 2ced4dbca..37b33f4a4 100644 --- a/apps/red-ui/src/app/modules/admin/screens/general-config/smtp-form/smtp-form.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/general-config/smtp-form/smtp-form.component.ts @@ -52,7 +52,7 @@ export class SmtpFormComponent extends BaseFormComponent implements OnInit, OnDe await firstValueFrom(this._smtpConfigService.updateSMTPConfiguration(this.form.getRawValue())); this._initialConfiguration = this.form.getRawValue(); this._loadingService.stop(); - this._loadData(); + await this._loadData(); } async testConnection() { diff --git a/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.html index fa2b709a3..aabf5e7e7 100644 --- a/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.html @@ -1,58 +1,29 @@ -
-
+ - - -
- - -
-
- -
- -
- -
-
+
+
+
-
+ +
+ +
+
*:not(:last-child) { + margin-right: 6px; } diff --git a/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts index 8ad8b70c4..b86b0887c 100644 --- a/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts @@ -1,10 +1,11 @@ -import { Component, forwardRef, Injector, OnInit } from '@angular/core'; +import { Component, forwardRef, inject, Injector, OnInit } from '@angular/core'; import { UserService } from '@services/user.service'; import { AdminDialogService } from '../../services/admin-dialog.service'; import { TranslateService } from '@ngx-translate/core'; import { DonutChartConfig, User, UserTypes } from '@red/domain'; import { TranslateChartService } from '@services/translate-chart.service'; import { + ButtonConfig, CircleButtonTypes, DefaultListingServicesTmp, EntitiesService, @@ -12,6 +13,7 @@ import { ListingComponent, LoadingService, NestedFilter, + SearchPositions, TableColumnConfig, } from '@iqser/common-ui'; import { firstValueFrom, Observable } from 'rxjs'; @@ -19,6 +21,14 @@ import { map } from 'rxjs/operators'; import { rolesTranslations } from '@translations/roles-translations'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { userTypeChecker, userTypeFilters } from '../../../../utils'; +import { RouterHistoryService } from '../../../../services/router-history.service'; + +function configToFilter({ key, label }: DonutChartConfig) { + return new NestedFilter({ + id: key, + label, + }); +} @Component({ templateUrl: './user-listing-screen.component.html', @@ -33,11 +43,13 @@ import { userTypeChecker, userTypeFilters } from '../../../../utils'; ], }) export class UserListingScreenComponent extends ListingComponent implements OnInit { + readonly routerHistoryService = inject(RouterHistoryService); + readonly searchPositions = SearchPositions; readonly translations = rolesTranslations; readonly iconButtonTypes = IconButtonTypes; readonly circleButtonTypes = CircleButtonTypes; readonly currentUser = this.userService.currentUser; - readonly canDeleteSelected$ = this._canDeleteSelected$; + readonly canDeleteSelected$ = this.#canDeleteSelected$; readonly tableHeaderLabel = _('user-listing.table-header.title'); readonly tableColumnConfigs: TableColumnConfig[] = [ { label: _('user-listing.table-col-names.name'), width: '2fr' }, @@ -45,6 +57,15 @@ export class UserListingScreenComponent extends ListingComponent implement { label: _('user-listing.table-col-names.active'), class: 'flex-center' }, { label: _('user-listing.table-col-names.roles') }, ]; + readonly buttonConfigs: readonly ButtonConfig[] = [ + { + label: _('user-listing.add-new'), + action: (): void => this.openAddEditUserDialog(), + type: IconButtonTypes.primary, + icon: 'iqser:plus', + disabled$: this.userService.currentUser$.pipe(map(user => !user.isAdmin)), + }, + ]; collapsedDetails = false; chartConfig: DonutChartConfig[] = []; @@ -59,7 +80,7 @@ export class UserListingScreenComponent extends ListingComponent implement super(_injector); } - private get _canDeleteSelected$(): Observable { + get #canDeleteSelected$(): Observable { const entities$ = this.listingService.selectedEntities$; return entities$.pipe(map(all => !all.find(u => u.id === this.currentUser.id))); } @@ -69,18 +90,18 @@ export class UserListingScreenComponent extends ListingComponent implement } async ngOnInit() { - await this._loadData(); + await this.#loadData(); } - openAddEditUserDialog($event: MouseEvent, user?: User) { - this._dialogService.openDialog('addEditUser', $event, user, async () => { - await this._loadData(); + openAddEditUserDialog(event?: MouseEvent, user?: User) { + this._dialogService.openDialog('addEditUser', event, user, async () => { + await this.#loadData(); }); } openDeleteUsersDialog(userIds: string[], $event?: MouseEvent) { this._dialogService.deleteUsers(userIds, $event, async () => { - await this._loadData(); + await this.#loadData(); }); } @@ -96,20 +117,20 @@ export class UserListingScreenComponent extends ListingComponent implement this._loadingService.start(); const requestBody = { ...user, roles: user.isActive ? [] : ['RED_USER'] }; await firstValueFrom(this.userService.updateProfile(requestBody, user.id)); - await this._loadData(); + await this.#loadData(); } bulkDelete() { this.openDeleteUsersDialog(this.listingService.selectedIds as string[]); } - private async _loadData() { + async #loadData() { await firstValueFrom(this.userService.loadAll()); - this._computeStats(); + this.#computeStats(); this._loadingService.stop(); } - private _computeStats() { + #computeStats() { this.chartConfig = this._translateChartService.translateRoles( UserTypes.map(type => ({ value: this.allEntities.filter(userTypeFilters[type]).length, @@ -119,24 +140,15 @@ export class UserListingScreenComponent extends ListingComponent implement })).filter(type => type.value > 0), ); - this._computeAllFilters(); + this.#computeAllFilters(); } - private _computeAllFilters() { - const roleFilters = this.chartConfig.map( - config => - new NestedFilter({ - id: config.key, - label: config.label, - }), - ); - - this.filterService.addFilterGroups([ - { - slug: 'roleFilters', - filters: roleFilters, - checker: userTypeChecker, - }, - ]); + #computeAllFilters() { + const roleFiltersGroup = { + slug: 'roleFilters', + filters: this.chartConfig.map(configToFilter), + checker: userTypeChecker, + }; + this.filterService.addFilterGroups([roleFiltersGroup]); } } diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.scss b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.scss index e658d2b05..c18cf1e5a 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.scss +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.scss @@ -12,6 +12,10 @@ min-width: fit-content; } +.content-inner { + position: absolute; +} + .content-container { position: relative; } diff --git a/apps/red-ui/src/app/utils/global-error-handler.service.ts b/apps/red-ui/src/app/utils/global-error-handler.service.ts index 08d1c33b4..e81b42d88 100644 --- a/apps/red-ui/src/app/utils/global-error-handler.service.ts +++ b/apps/red-ui/src/app/utils/global-error-handler.service.ts @@ -4,6 +4,10 @@ import { ErrorHandler, Injectable } from '@angular/core'; export class GlobalErrorHandler extends ErrorHandler { handleError(error: Error): void { const chunkFailedMessage = /Loading chunk [\d]+ failed/; + console.write(error); + if (error.message.includes('An error happened during access validation')) { + console.log('User is not authorized to access this page'); + } if (chunkFailedMessage.test(error?.message)) { window.location.reload(); diff --git a/apps/red-ui/src/assets/config/config.json b/apps/red-ui/src/assets/config/config.json index 62578148a..0c71adeeb 100644 --- a/apps/red-ui/src/assets/config/config.json +++ b/apps/red-ui/src/assets/config/config.json @@ -1,7 +1,7 @@ { "ADMIN_CONTACT_NAME": null, "ADMIN_CONTACT_URL": null, - "API_URL": "https://dev-08.iqser.cloud/redaction-gateway-v1", + "API_URL": "https://dev-04.iqser.cloud/redaction-gateway-v1", "APP_NAME": "RedactManager", "AUTO_READ_TIME": 3, "BACKEND_APP_VERSION": "4.4.40", @@ -11,7 +11,7 @@ "MAX_RETRIES_ON_SERVER_ERROR": 3, "OAUTH_CLIENT_ID": "redaction", "OAUTH_IDP_HINT": null, - "OAUTH_URL": "https://dev-08.iqser.cloud/auth/realms/redaction", + "OAUTH_URL": "https://dev-04.iqser.cloud/auth/realms/redaction", "RECENT_PERIOD_IN_HOURS": 24, "SELECTION_MODE": "structural", "MANUAL_BASE_URL": "https://docs.redactmanager.com/preview" diff --git a/libs/common-ui b/libs/common-ui index 7835b1caf..d3fdef1b4 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 7835b1caf0c28df32abf6a8751a7fcf9d2a9716f +Subproject commit d3fdef1b4cdb16730026633f83c3cd28f0d3358a