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

@@ -181,6 +181,24 @@
"scopenote": "Scope Note" "scopenote": "Scope Note"
}, },
"no-items": "No metadata fields to show." "no-items": "No metadata fields to show."
},
"notification": {
"success": "Success",
"failure": "Error",
"created": "Successfully created metadata schema \"{{prefix}}\"",
"edited": "Successfully edited metadata schema \"{{prefix}}\"",
"deleted": {
"success": "Successfully deleted {{amount}} metadata schemas",
"failure": "Failed to delete {{amount}} metadata schemas"
},
"field": {
"created": "Successfully created metadata field \"{{field}}\"",
"edited": "Successfully edited metadata field \"{{field}}\"",
"deleted": {
"success": "Successfully deleted {{amount}} metadata fields",
"failure": "Failed to delete {{amount}} metadata fields"
}
}
} }
}, },
"bitstream-formats": { "bitstream-formats": {

View File

@@ -1,6 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { RegistryService } from '../../../core/registry/registry.service'; import { RegistryService } from '../../../core/registry/registry.service';
import { Observable } from 'rxjs'; import { Observable, combineLatest as observableCombineLatest } from 'rxjs';
import { RemoteData } from '../../../core/data/remote-data'; import { RemoteData } from '../../../core/data/remote-data';
import { PaginatedList } from '../../../core/data/paginated-list'; import { PaginatedList } from '../../../core/data/paginated-list';
import { MetadataSchema } from '../../../core/metadata/metadataschema.model'; import { MetadataSchema } from '../../../core/metadata/metadataschema.model';
@@ -11,6 +11,7 @@ import { RestResponse } from '../../../core/cache/response.models';
import { zip } from 'rxjs/internal/observable/zip'; import { zip } from 'rxjs/internal/observable/zip';
import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { Route, Router } from '@angular/router'; import { Route, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
@Component({ @Component({
selector: 'ds-metadata-registry', selector: 'ds-metadata-registry',
@@ -28,7 +29,8 @@ export class MetadataRegistryComponent {
constructor(private registryService: RegistryService, constructor(private registryService: RegistryService,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private router: Router) { private router: Router,
private translateService: TranslateService) {
this.updateSchemas(); this.updateSchemas();
} }
@@ -91,10 +93,10 @@ export class MetadataRegistryComponent {
const successResponses = responses.filter((response: RestResponse) => response.isSuccessful); const successResponses = responses.filter((response: RestResponse) => response.isSuccessful);
const failedResponses = responses.filter((response: RestResponse) => !response.isSuccessful); const failedResponses = responses.filter((response: RestResponse) => !response.isSuccessful);
if (successResponses.length > 0) { if (successResponses.length > 0) {
this.notificationsService.success('Success', `Successfully deleted ${successResponses.length} metadata schemas`); this.showNotification(true, successResponses.length);
} }
if (failedResponses.length > 0) { if (failedResponses.length > 0) {
this.notificationsService.error('Error', `Failed to delete ${failedResponses.length} metadata schemas`); this.showNotification(false, failedResponses.length);
} }
this.registryService.deselectAllMetadataSchema(); this.registryService.deselectAllMetadataSchema();
this.router.navigate([], { queryParams: { page: 1 }, queryParamsHandling: 'merge'}); this.router.navigate([], { queryParams: { page: 1 }, queryParamsHandling: 'merge'});
@@ -103,4 +105,20 @@ export class MetadataRegistryComponent {
} }
) )
} }
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}.deleted.${suffix}`, { amount: amount })
);
messages.subscribe(([head, content]) => {
if (success) {
this.notificationsService.success(head, content)
} else {
this.notificationsService.error(head, content)
}
});
}
} }

View File

@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { RegistryService } from '../../../core/registry/registry.service'; import { RegistryService } from '../../../core/registry/registry.service';
import { ActivatedRoute, Router } from '@angular/router'; 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 { RemoteData } from '../../../core/data/remote-data';
import { PaginatedList } from '../../../core/data/paginated-list'; import { PaginatedList } from '../../../core/data/paginated-list';
import { MetadataField } from '../../../core/metadata/metadatafield.model'; 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 { RestResponse } from '../../../core/cache/response.models';
import { zip } from 'rxjs/internal/observable/zip'; import { zip } from 'rxjs/internal/observable/zip';
import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
@Component({ @Component({
selector: 'ds-metadata-schema', selector: 'ds-metadata-schema',
@@ -33,7 +34,8 @@ export class MetadataSchemaComponent implements OnInit {
constructor(private registryService: RegistryService, constructor(private registryService: RegistryService,
private route: ActivatedRoute, private route: ActivatedRoute,
private notificationsService: NotificationsService, 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 successResponses = responses.filter((response: RestResponse) => response.isSuccessful);
const failedResponses = responses.filter((response: RestResponse) => !response.isSuccessful); const failedResponses = responses.filter((response: RestResponse) => !response.isSuccessful);
if (successResponses.length > 0) { if (successResponses.length > 0) {
this.notificationsService.success('Success', `Successfully deleted ${successResponses.length} metadata fields`); this.showNotification(true, successResponses.length);
} }
if (failedResponses.length > 0) { if (failedResponses.length > 0) {
this.notificationsService.error('Error', `Failed to delete ${failedResponses.length} metadata fields`); this.showNotification(false, failedResponses.length);
} }
this.registryService.deselectAllMetadataField(); this.registryService.deselectAllMetadataField();
this.router.navigate([], { queryParams: { page: 1 }, queryParamsHandling: 'merge'}); 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)
}
});
}
} }

View File

@@ -56,6 +56,7 @@ import { NotificationsService } from '../../shared/notifications/notifications.s
import { NotificationOptions } from '../../shared/notifications/models/notification-options.model'; import { NotificationOptions } from '../../shared/notifications/models/notification-options.model';
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
import { HttpHeaders } from '@angular/common/http'; import { HttpHeaders } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
const metadataRegistryStateSelector = (state: AppState) => state.metadataRegistry; const metadataRegistryStateSelector = (state: AppState) => state.metadataRegistry;
const editMetadataSchemaSelector = createSelector(metadataRegistryStateSelector, (metadataState: MetadataRegistryState) => metadataState.editSchema); const editMetadataSchemaSelector = createSelector(metadataRegistryStateSelector, (metadataState: MetadataRegistryState) => metadataState.editSchema);
@@ -74,7 +75,8 @@ export class RegistryService {
private rdb: RemoteDataBuildService, private rdb: RemoteDataBuildService,
private halService: HALEndpointService, private halService: HALEndpointService,
private store: Store<AppState>, private store: Store<AppState>,
private notificationsService: NotificationsService) { private notificationsService: NotificationsService,
private translateService: TranslateService) {
} }
@@ -352,7 +354,7 @@ export class RegistryService {
this.notificationsService.error('Server Error:', (response as any).errorMessage, new NotificationOptions(-1)); this.notificationsService.error('Server Error:', (response as any).errorMessage, new NotificationOptions(-1));
} }
} else { } else {
this.notificationsService.success('Success', `Successfully ${isUpdate ? 'updated' : 'created'} metadata schema "${schema.prefix}"`); this.showNotifications(true, isUpdate, false, { prefix: schema.prefix });
return response; return response;
} }
}), }),
@@ -413,7 +415,8 @@ export class RegistryService {
this.notificationsService.error('Server Error:', (response as any).errorMessage, new NotificationOptions(-1)); this.notificationsService.error('Server Error:', (response as any).errorMessage, new NotificationOptions(-1));
} }
} else { } else {
this.notificationsService.success('Success', `Successfully ${isUpdate ? 'updated' : 'created'} metadata field "${field.schema.prefix}.${field.element}.${field.qualifier}"`); const fieldString = `${field.schema.prefix}.${field.element}${field.qualifier ? `.${field.qualifier}` : ''}`;
this.showNotifications(true, isUpdate, true, { field: fieldString });
return response; return response;
} }
}), }),
@@ -458,4 +461,21 @@ export class RegistryService {
getResponseFromEntry() getResponseFromEntry()
); );
} }
private showNotifications(success: boolean, edited: boolean, isField: boolean, options: any) {
const prefix = 'admin.registries.schema.notification';
const suffix = success ? 'success' : 'failure';
const editedString = edited ? 'edited' : 'created';
const messages = observableCombineLatest(
this.translateService.get(success ? `${prefix}.${suffix}` : `${prefix}.${suffix}`),
this.translateService.get(`${prefix}${isField ? '.field' : ''}.${editedString}`, options)
);
messages.subscribe(([head, content]) => {
if (success) {
this.notificationsService.success(head, content)
} else {
this.notificationsService.error(head, content)
}
});
}
} }