Skip to content

Commit 0dbc419

Browse files
author
Andrea Barbasso
committed
[DSC-1652] refactor translateService calls, change default values for timeouts
1 parent edaf963 commit 0dbc419

6 files changed

Lines changed: 27 additions & 30 deletions

File tree

src/app/shared/loading/loading.component.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class LoadingComponent implements OnDestroy, OnInit {
2323
@Input() message: string;
2424
@Input() showMessage = true;
2525

26-
@Input() enableFallbackMessages = environment.loader.enableFallbackMessagesByDefault;
26+
@Input() showFallbackMessages = environment.loader.showFallbackMessagesByDefault;
2727
@Input() warningMessage: string;
2828
@Input() warningMessageDelay = environment.loader.warningMessageDelay;
2929
@Input() errorMessage: string;
@@ -37,8 +37,6 @@ export class LoadingComponent implements OnDestroy, OnInit {
3737
readonly MessageType = MessageType;
3838
messageToShow: MessageType = this.showMessage ? MessageType.LOADING : undefined;
3939

40-
private subscriptions: Subscription[] = [];
41-
4240
warningTimeout: any;
4341
errorTimeout: any;
4442

@@ -49,22 +47,12 @@ export class LoadingComponent implements OnDestroy, OnInit {
4947
}
5048

5149
ngOnInit() {
52-
if (this.showMessage && this.message === undefined) {
53-
this.subscriptions.push(this.translate.get('loading.default').subscribe((message: string) => {
54-
this.message = message;
55-
}));
50+
if (this.showMessage) {
51+
this.message = this.message || this.translate.instant('loading.default');
5652
}
57-
if (this.enableFallbackMessages) {
58-
if (!this.warningMessage) {
59-
this.subscriptions.push(this.translate.get('loading.warning').subscribe((warningMessage: string) => {
60-
this.warningMessage = warningMessage;
61-
}));
62-
}
63-
if (!this.errorMessage) {
64-
this.subscriptions.push(this.translate.get('loading.error').subscribe((errorMessage: string) => {
65-
this.errorMessage = errorMessage;
66-
}));
67-
}
53+
if (this.showFallbackMessages) {
54+
this.warningMessage = this.warningMessage || this.translate.instant('loading.warning');
55+
this.errorMessage = this.errorMessage || this.translate.instant('loading.error');
6856
if (this.warningMessageDelay > 0) {
6957
this.warningTimeout = setTimeout(() => {
7058
this.messageToShow = MessageType.WARNING;
@@ -81,11 +69,6 @@ export class LoadingComponent implements OnDestroy, OnInit {
8169
}
8270

8371
ngOnDestroy() {
84-
if (this.subscriptions.length > 0) {
85-
this.subscriptions.forEach((sub) => {
86-
sub.unsubscribe();
87-
});
88-
}
8972
if (hasValue(this.warningTimeout)) {
9073
clearTimeout(this.warningTimeout);
9174
}

src/app/shared/loading/themed-loading.component.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,22 @@ export class ThemedLoadingComponent extends ThemedComponent<LoadingComponent> {
1616
@Input() message: string;
1717
@Input() showMessage: boolean;
1818
@Input() spinner: boolean;
19+
@Input() showFallbackMessages: boolean;
20+
@Input() warningMessage: string;
21+
@Input() warningMessageDelay: number;
22+
@Input() errorMessage: string;
23+
@Input() errorMessageDelay: number;
1924

20-
protected inAndOutputNames: (keyof LoadingComponent & keyof this)[] = ['message', 'showMessage', 'spinner'];
25+
protected inAndOutputNames: (keyof LoadingComponent & keyof this)[] = [
26+
'message',
27+
'showMessage',
28+
'spinner',
29+
'showFallbackMessages',
30+
'warningMessage',
31+
'warningMessageDelay',
32+
'errorMessage',
33+
'errorMessageDelay'
34+
];
2135

2236
constructor(
2337
protected resolver: ComponentFactoryResolver,

src/app/shared/search/search-results/search-results.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h2 *ngIf="!disableHeader">{{ (configuration ? configuration + '.search.results.
2222
(selectObject)="selectObject.emit($event)">
2323
</ds-viewable-collection>
2424
</div>
25-
<ds-themed-loading *ngIf="isLoading()" message="{{'loading.search-results' | translate}}"></ds-themed-loading>
25+
<ds-themed-loading *ngIf="isLoading()" message="{{'loading.search-results' | translate}}" [showFallbackMessages]="true"></ds-themed-loading>
2626
<ds-error *ngIf="showError()"
2727
message="{{errorMessageLabel() | translate}}"></ds-error>
2828
<div *ngIf="searchResults?.payload?.page.length == 0 || searchResults?.statusCode == 400">

src/config/default-app-config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,8 @@ export class DefaultAppConfig implements AppConfig {
763763
};
764764

765765
loader: LoaderConfig = {
766-
enableFallbackMessagesByDefault: false,
767-
warningMessageDelay: 10000, // 10 seconds
768-
errorMessageDelay: 30000, // 30 seconds
766+
showFallbackMessagesByDefault: false,
767+
warningMessageDelay: 5000, // 5 seconds
768+
errorMessageDelay: 15000, // 15 seconds
769769
};
770770
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Config } from './config.interface';
22

33
export interface LoaderConfig extends Config {
4-
enableFallbackMessagesByDefault: boolean;
4+
showFallbackMessagesByDefault: boolean;
55
warningMessageDelay: number;
66
errorMessageDelay: number;
77
}

src/environments/environment.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ export const environment: BuildConfig = {
579579
},
580580

581581
loader: {
582-
enableFallbackMessagesByDefault: true,
582+
showFallbackMessagesByDefault: true,
583583
warningMessageDelay: 1000,
584584
errorMessageDelay: 2000,
585585
},

0 commit comments

Comments
 (0)