Skip to content

Commit

Permalink
refactor: add config constant
Browse files Browse the repository at this point in the history
Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Oct 24, 2024
1 parent 8a8ae84 commit a9b2684
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -42,15 +43,17 @@ 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: () => {
this.messageService.add({
severity: 'error',
summary: this.translate.instant('Rejected'),
detail: this.translate.instant('You have rejected'),
life: 3000
sticky: true,
closable: true
});
}
});
Expand Down
6 changes: 6 additions & 0 deletions projects/ng-core-tester/src/app/home/toast/toast.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions projects/ng-core-tester/src/app/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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',
Expand All @@ -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 });
}
},
{
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -68,15 +68,17 @@ 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;
case 'organisations':
this.messageService.add({
severity: 'success',
summary: 'ORGANISATIONS',
detail: 'navigate to organisation: ' + event.value
detail: 'navigate to organisation: ' + event.value,
life: CONFIG.MESSAGE_LIFE
});
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
22 changes: 16 additions & 6 deletions projects/rero/ng-core/src/lib/record/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
});
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
);
Expand Down
8 changes: 6 additions & 2 deletions projects/rero/ng-core/src/lib/record/record-ui.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -63,15 +64,18 @@ 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) => {
delete$.next(false);
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
});
}
});
Expand Down
19 changes: 19 additions & 0 deletions projects/rero/ng-core/src/lib/utils/config.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
export const CONFIG = {
MESSAGE_LIFE: 5000 // Message lifetime in ms
}
19 changes: 9 additions & 10 deletions projects/rero/ng-core/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export * from './lib/api/api.service';
export * from './lib/component/abstract-can-deactivate.component';
export * from './lib/core-config.service';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -86,19 +93,11 @@ 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';
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';

0 comments on commit a9b2684

Please sign in to comment.