58789: Notifications loaded through messages

This commit is contained in:
Kristof De Langhe
2019-01-22 17:52:32 +01:00
parent fe44146291
commit 7f991d2a06
4 changed files with 85 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { RegistryService } from '../../../core/registry/registry.service';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { Observable, combineLatest as observableCombineLatest } from 'rxjs';
import { RemoteData } from '../../../core/data/remote-data';
import { PaginatedList } from '../../../core/data/paginated-list';
import { MetadataField } from '../../../core/metadata/metadatafield.model';
@@ -12,6 +12,7 @@ import { hasValue } from '../../../shared/empty.util';
import { RestResponse } from '../../../core/cache/response.models';
import { zip } from 'rxjs/internal/observable/zip';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'ds-metadata-schema',
@@ -33,7 +34,8 @@ export class MetadataSchemaComponent implements OnInit {
constructor(private registryService: RegistryService,
private route: ActivatedRoute,
private notificationsService: NotificationsService,
private router: Router) {
private router: Router,
private translateService: TranslateService) {
}
@@ -111,10 +113,10 @@ export class MetadataSchemaComponent implements OnInit {
const successResponses = responses.filter((response: RestResponse) => response.isSuccessful);
const failedResponses = responses.filter((response: RestResponse) => !response.isSuccessful);
if (successResponses.length > 0) {
this.notificationsService.success('Success', `Successfully deleted ${successResponses.length} metadata fields`);
this.showNotification(true, successResponses.length);
}
if (failedResponses.length > 0) {
this.notificationsService.error('Error', `Failed to delete ${failedResponses.length} metadata fields`);
this.showNotification(false, failedResponses.length);
}
this.registryService.deselectAllMetadataField();
this.router.navigate([], { queryParams: { page: 1 }, queryParamsHandling: 'merge'});
@@ -123,4 +125,20 @@ export class MetadataSchemaComponent implements OnInit {
}
)
}
showNotification(success: boolean, amount: number) {
const prefix = 'admin.registries.schema.notification';
const suffix = success ? 'success' : 'failure';
const messages = observableCombineLatest(
this.translateService.get(success ? `${prefix}.${suffix}` : `${prefix}.${suffix}`),
this.translateService.get(`${prefix}.field.deleted.${suffix}`, { amount: amount })
);
messages.subscribe(([head, content]) => {
if (success) {
this.notificationsService.success(head, content)
} else {
this.notificationsService.error(head, content)
}
});
}
}