From a9b2684e464208650a227af016d1b2c62e2e6e57 Mon Sep 17 00:00:00 2001 From: Bertrand Zuchuat Date: Thu, 24 Oct 2024 11:07:27 +0200 Subject: [PATCH] refactor: add config constant Co-Authored-by: Bertrand Zuchuat --- .../app/home/dialog/app-dialog.component.ts | 7 ++++-- .../src/app/home/toast/toast.component.ts | 6 +++++ .../src/app/menu/menu.component.ts | 8 +++---- .../app/search-bar/search-bar.component.ts | 8 ++++--- .../src/lib/record/detail/detail.component.ts | 4 +++- .../src/lib/record/editor/editor.component.ts | 22 ++++++++++++++----- .../load-template-form.component.ts | 4 +++- .../src/lib/record/record-ui.service.ts | 8 +++++-- projects/rero/ng-core/src/lib/utils/config.ts | 19 ++++++++++++++++ projects/rero/ng-core/src/public-api.ts | 19 ++++++++-------- 10 files changed, 76 insertions(+), 29 deletions(-) create mode 100644 projects/rero/ng-core/src/lib/utils/config.ts diff --git a/projects/ng-core-tester/src/app/home/dialog/app-dialog.component.ts b/projects/ng-core-tester/src/app/home/dialog/app-dialog.component.ts index b0b0cfe6..cf09383e 100644 --- a/projects/ng-core-tester/src/app/home/dialog/app-dialog.component.ts +++ b/projects/ng-core-tester/src/app/home/dialog/app-dialog.component.ts @@ -16,6 +16,7 @@ */ import { Component, inject } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; +import { CONFIG } from '@rero/ng-core'; import { ConfirmationService, MessageService } from 'primeng/api'; @Component({ @@ -42,7 +43,8 @@ export class AppDialogComponent { this.messageService.add({ severity: 'info', summary: this.translate.instant('Confirmed'), - detail: this.translate.instant('You have accepted') + detail: this.translate.instant('You have accepted'), + life: CONFIG.MESSAGE_LIFE }); }, reject: () => { @@ -50,7 +52,8 @@ export class AppDialogComponent { severity: 'error', summary: this.translate.instant('Rejected'), detail: this.translate.instant('You have rejected'), - life: 3000 + sticky: true, + closable: true }); } }); diff --git a/projects/ng-core-tester/src/app/home/toast/toast.component.ts b/projects/ng-core-tester/src/app/home/toast/toast.component.ts index e18be9c3..4962a558 100644 --- a/projects/ng-core-tester/src/app/home/toast/toast.component.ts +++ b/projects/ng-core-tester/src/app/home/toast/toast.component.ts @@ -66,6 +66,12 @@ export class ToastComponent implements OnInit { message.summary = this.toastType.name; message.detail = this.toastMessage; } + if (message.severity === 'error') { + message.sticky = true; + message.closable = true; + } else { + message.life = 5000; + } this.messageService.add(message); } } diff --git a/projects/ng-core-tester/src/app/menu/menu.component.ts b/projects/ng-core-tester/src/app/menu/menu.component.ts index 42fb2b8f..07fc0a6a 100644 --- a/projects/ng-core-tester/src/app/menu/menu.component.ts +++ b/projects/ng-core-tester/src/app/menu/menu.component.ts @@ -15,10 +15,10 @@ * along with this program. If not, see . */ import { Component, OnInit, inject } from '@angular/core'; -import { MenuItem, MessageService } from 'primeng/api'; import { Router } from '@angular/router'; -import { CoreConfigService } from '@rero/ng-core'; import { LangChangeEvent, TranslateService } from '@ngx-translate/core'; +import { CONFIG, CoreConfigService } from '@rero/ng-core'; +import { MenuItem, MessageService } from 'primeng/api'; @Component({ selector: 'app-menu', @@ -42,7 +42,7 @@ export class MenuComponent implements OnInit { icon: 'pi pi-home', command: () => { this.router.navigate(['/']); - this.messageService.add({ severity: 'success', detail: 'Home menu selected', life: 2000 }); + this.messageService.add({ severity: 'success', detail: 'Home menu selected', life: CONFIG.MESSAGE_LIFE }); } }, { @@ -165,7 +165,7 @@ export class MenuComponent implements OnInit { styleClass: undefined, command: () => { this.translateService.use(language); - this.messageService.add({ severity: 'info', detail: `Language change to ${language}`, life: 2000 }); + this.messageService.add({ severity: 'info', detail: `Language change to ${language}`, life: CONFIG.MESSAGE_LIFE }); } } languageMenu.items.push(lang); diff --git a/projects/ng-core-tester/src/app/search-bar/search-bar.component.ts b/projects/ng-core-tester/src/app/search-bar/search-bar.component.ts index d3d8fc6f..04989f09 100644 --- a/projects/ng-core-tester/src/app/search-bar/search-bar.component.ts +++ b/projects/ng-core-tester/src/app/search-bar/search-bar.component.ts @@ -17,7 +17,7 @@ import { Component, inject, input, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; -import { IAutoComplete, IRecordType, Record } from '@rero/ng-core'; +import { CONFIG, IAutoComplete, IRecordType, Record } from '@rero/ng-core'; import { MessageService } from 'primeng/api'; /** @@ -68,7 +68,8 @@ export class SearchBarComponent implements OnInit { this.messageService.add({ severity: 'success', summary: 'DOCUMENTS', - detail: 'navigate to document: ' + event.value + detail: 'navigate to document: ' + event.value, + life: CONFIG.MESSAGE_LIFE }); this.router.navigate(['/record', 'search', 'documents', 'detail', event.value]); break; @@ -76,7 +77,8 @@ export class SearchBarComponent implements OnInit { this.messageService.add({ severity: 'success', summary: 'ORGANISATIONS', - detail: 'navigate to organisation: ' + event.value + detail: 'navigate to organisation: ' + event.value, + life: CONFIG.MESSAGE_LIFE }); break; } diff --git a/projects/rero/ng-core/src/lib/record/detail/detail.component.ts b/projects/rero/ng-core/src/lib/record/detail/detail.component.ts index 7d0ffebe..b8e280e7 100644 --- a/projects/rero/ng-core/src/lib/record/detail/detail.component.ts +++ b/projects/rero/ng-core/src/lib/record/detail/detail.component.ts @@ -110,7 +110,9 @@ export class DetailComponent implements OnInit, OnDestroy { this.messageService.add({ severity: 'error', summary: this.translate.instant(this.type), - detail: this.translate.instant('You cannot read this record') + detail: this.translate.instant('You cannot read this record'), + sticky: true, + closable: true }) this.location.back(); } diff --git a/projects/rero/ng-core/src/lib/record/editor/editor.component.ts b/projects/rero/ng-core/src/lib/record/editor/editor.component.ts index 5f524f1c..b50cccd6 100644 --- a/projects/rero/ng-core/src/lib/record/editor/editor.component.ts +++ b/projects/rero/ng-core/src/lib/record/editor/editor.component.ts @@ -32,6 +32,7 @@ import { AbstractCanDeactivateComponent } from '../../component/abstract-can-dea import { Error } from '../../error/error'; import { RouteCollectionService } from '../../route/route-collection.service'; import { LoggerService } from '../../service/logger.service'; +import { CONFIG } from '../../utils/config'; import { RecordUiService } from '../record-ui.service'; import { RecordService } from '../record.service'; import { JSONSchemaService } from './services/jsonschema.service'; @@ -271,7 +272,8 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O this.messageService.add({ severity: 'success', summary: this.translateService.instant('Template'), - detail: this.translateService.instant('Template loaded') + detail: this.translateService.instant('Template loaded'), + life: CONFIG.MESSAGE_LIFE }); return { result: true, @@ -313,7 +315,9 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O this.messageService.add({ severity: 'error', summary: this.translateService.instant(this.recordType), - detail: this.translateService.instant('You cannot update this record') + detail: this.translateService.instant('You cannot update this record'), + sticky: true, + closable: true }); this.location.back(); } else { @@ -491,7 +495,9 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O this.messageService.add({ severity: 'error', summary: this.translateService.instant(this.recordType), - detail: this.translateService.instant('The form contains errors.') + errorMessage + detail: this.translateService.instant('The form contains errors.') + errorMessage, + sticky: true, + closable: true }); this.isSaveButtonDisabled = false; return; @@ -535,7 +541,8 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O this.messageService.add({ severity: 'success', summary: this.translateService.instant(this.recordType), - detail: this.translateService.instant(result.message) + detail: this.translateService.instant(result.message), + life: CONFIG.MESSAGE_LIFE }); this.recordUiService.redirectAfterSave( result.record.id, @@ -574,7 +581,8 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O this.messageService.add({ severity: 'success', summary: this.translateService.instant(this.editorSettings.template.recordType), - detail: this.translateService.instant('Record created.') + detail: this.translateService.instant('Record created.'), + life: CONFIG.MESSAGE_LIFE }); this.recordUiService.redirectAfterSave( createdRecord.id, @@ -589,7 +597,9 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O this.messageService.add({ severity: 'error', summary: this.translateService.instant(this.editorSettings.template.recordType), - detail: error.title + detail: error.title, + sticky: true, + closable: true }); } }) diff --git a/projects/rero/ng-core/src/lib/record/editor/widgets/load-template-form/load-template-form.component.ts b/projects/rero/ng-core/src/lib/record/editor/widgets/load-template-form/load-template-form.component.ts index 5ca97e42..70cb060f 100644 --- a/projects/rero/ng-core/src/lib/record/editor/widgets/load-template-form/load-template-form.component.ts +++ b/projects/rero/ng-core/src/lib/record/editor/widgets/load-template-form/load-template-form.component.ts @@ -111,7 +111,9 @@ export class LoadTemplateFormComponent implements OnInit { this.messageService.add({ severity: 'error', summary: this.translateService.instant('Error'), - detail: error.message + detail: error.message, + sticky: true, + closable: true }); } ); diff --git a/projects/rero/ng-core/src/lib/record/record-ui.service.ts b/projects/rero/ng-core/src/lib/record/record-ui.service.ts index 36fc70a0..b5d2fe89 100644 --- a/projects/rero/ng-core/src/lib/record/record-ui.service.ts +++ b/projects/rero/ng-core/src/lib/record/record-ui.service.ts @@ -21,6 +21,7 @@ import { TranslateService } from '@ngx-translate/core'; import { ConfirmationService, MessageService } from 'primeng/api'; import { BehaviorSubject, Observable, of } from 'rxjs'; import { first, map } from 'rxjs/operators'; +import { CONFIG } from '../utils/config'; import { ActionStatus } from './action-status'; import { RecordService } from './record.service'; @@ -63,7 +64,8 @@ export class RecordUiService { this.messageService.add({ severity: 'info', summary: this.translateService.instant('Confirmed'), - detail: this.translateService.instant('Record deleted.') + detail: this.translateService.instant('Record deleted.'), + life: CONFIG.MESSAGE_LIFE }); }, error: (error: any) => { @@ -71,7 +73,9 @@ export class RecordUiService { this.messageService.add({ severity: 'error', summary: this.translateService.instant('Error'), - detail: this.translateService.instant(error.title) + detail: this.translateService.instant(error.title), + sticky: true, + closable: true }); } }); diff --git a/projects/rero/ng-core/src/lib/utils/config.ts b/projects/rero/ng-core/src/lib/utils/config.ts new file mode 100644 index 00000000..7ec04cad --- /dev/null +++ b/projects/rero/ng-core/src/lib/utils/config.ts @@ -0,0 +1,19 @@ +/* + * RERO angular core + * Copyright (C) 2024 RERO + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +export const CONFIG = { + MESSAGE_LIFE: 5000 // Message lifetime in ms +} diff --git a/projects/rero/ng-core/src/public-api.ts b/projects/rero/ng-core/src/public-api.ts index 6e81a5b6..e6d2390d 100644 --- a/projects/rero/ng-core/src/public-api.ts +++ b/projects/rero/ng-core/src/public-api.ts @@ -14,7 +14,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - export * from './lib/api/api.service'; export * from './lib/component/abstract-can-deactivate.component'; export * from './lib/core-config.service'; @@ -48,7 +47,15 @@ export * from './lib/record/detail/detail.directive'; export * from './lib/record/detail/view/detail-record'; export * from './lib/record/editor/editor.component'; export * from './lib/record/editor/extensions'; +export * from './lib/record/editor/formly/primeng/date-picker/date-picker'; +export * from './lib/record/editor/formly/primeng/input/src/input.module'; +export * from './lib/record/editor/formly/primeng/input/src/input.type'; +export * from './lib/record/editor/formly/primeng/multi-checkbox/multi-checkbox'; +export * from './lib/record/editor/formly/primeng/multi-select/multi-select'; +export * from './lib/record/editor/formly/primeng/remote-autocomplete/remote-autocomplete'; export * from './lib/record/editor/formly/primeng/remote-autocomplete/remote-autocomplete.service'; +export * from './lib/record/editor/formly/primeng/select/select'; +export * from './lib/record/editor/formly/primeng/tree-select/tree-select'; export * from './lib/record/editor/services/jsonschema.service'; export * from './lib/record/editor/type/array-type/array-type.component'; export * from './lib/record/editor/type/multischema/multischema.component'; @@ -86,6 +93,7 @@ export * from './lib/translate/translate-language.pipe'; export * from './lib/translate/translate-language.service'; export * from './lib/translate/translate-loader'; export * from './lib/translate/translate-service'; +export * from './lib/utils/config'; export * from './lib/utils/sort-by-keys'; export * from './lib/utils/utils'; export * from './lib/validator/time.validator'; @@ -93,12 +101,3 @@ export * from './lib/validator/unique.validator'; export * from './lib/validator/validators'; export * from './lib/widget/menu/menu.component'; export * from './lib/widget/sort-list/sort-list.component'; - -export * from './lib/record/editor/formly/primeng/date-picker/date-picker'; -export * from './lib/record/editor/formly/primeng/input/src/input.module'; -export * from './lib/record/editor/formly/primeng/input/src/input.type'; -export * from './lib/record/editor/formly/primeng/multi-checkbox/multi-checkbox'; -export * from './lib/record/editor/formly/primeng/multi-select/multi-select'; -export * from './lib/record/editor/formly/primeng/remote-autocomplete/remote-autocomplete'; -export * from './lib/record/editor/formly/primeng/select/select'; -export * from './lib/record/editor/formly/primeng/tree-select/tree-select';