64503: Feedback 2019-10-24 ; loading, message fix, notification clearing

This commit is contained in:
Kristof De Langhe
2019-10-31 12:41:03 +01:00
parent dc9520a832
commit 404729faa3
5 changed files with 45 additions and 15 deletions

View File

@@ -159,7 +159,7 @@
"collection.edit.tabs.roles.head": "Assign Roles", "collection.edit.tabs.roles.head": "Assign Roles",
"collection.edit.tabs.roles.title": "Collection Edit - Roles", "collection.edit.tabs.roles.title": "Collection Edit - Roles",
"collection.edit.tabs.source.external": "This collection harvests its content from an external source", "collection.edit.tabs.source.external": "This collection harvests its content from an external source",
"collection.edit.tabs.source.form.errors.provider.required": "You must provide a set id of the target collection.", "collection.edit.tabs.source.form.errors.oaiSource.required": "You must provide a set id of the target collection.",
"collection.edit.tabs.source.form.harvestType": "Content being harvested", "collection.edit.tabs.source.form.harvestType": "Content being harvested",
"collection.edit.tabs.source.form.head": "Configure an external source", "collection.edit.tabs.source.form.head": "Configure an external source",
"collection.edit.tabs.source.form.metadataConfigId": "Metadata Format", "collection.edit.tabs.source.form.metadataConfigId": "Metadata Format",
@@ -478,6 +478,7 @@
"loading.browse-by-page": "Loading page...", "loading.browse-by-page": "Loading page...",
"loading.collection": "Loading collection...", "loading.collection": "Loading collection...",
"loading.collections": "Loading collections...", "loading.collections": "Loading collections...",
"loading.content-source": "Loading content source...",
"loading.community": "Loading community...", "loading.community": "Loading community...",
"loading.default": "Loading...", "loading.default": "Loading...",
"loading.item": "Loading item...", "loading.item": "Loading item...",

View File

@@ -18,11 +18,12 @@
</button> </button>
</div> </div>
<h4>{{ 'collection.edit.tabs.source.head' | translate }}</h4> <h4>{{ 'collection.edit.tabs.source.head' | translate }}</h4>
<div class="form-check mb-4"> <div *ngIf="contentSource" class="form-check mb-4">
<input type="checkbox" class="form-check-input" id="externalSourceCheck" [checked]="(contentSource?.harvestType !== harvestTypeNone)" (change)="changeExternalSource()"> <input type="checkbox" class="form-check-input" id="externalSourceCheck" [checked]="(contentSource?.harvestType !== harvestTypeNone)" (change)="changeExternalSource()">
<label class="form-check-label" for="externalSourceCheck">{{ 'collection.edit.tabs.source.external' | translate }}</label> <label class="form-check-label" for="externalSourceCheck">{{ 'collection.edit.tabs.source.external' | translate }}</label>
</div> </div>
<h4 *ngIf="(contentSource?.harvestType !== harvestTypeNone)">{{ 'collection.edit.tabs.source.form.head' | translate }}</h4> <ds-loading *ngIf="!contentSource" [message]="'loading.content-source' | translate"></ds-loading>
<h4 *ngIf="contentSource && (contentSource?.harvestType !== harvestTypeNone)">{{ 'collection.edit.tabs.source.form.head' | translate }}</h4>
</div> </div>
<ds-form *ngIf="formGroup && contentSource && (contentSource?.harvestType !== harvestTypeNone)" <ds-form *ngIf="formGroup && contentSource && (contentSource?.harvestType !== harvestTypeNone)"
[formId]="'collection-source-form-id'" [formId]="'collection-source-form-id'"

View File

@@ -30,6 +30,7 @@ import { GLOBAL_CONFIG, GlobalConfig } from '../../../../config';
import { CollectionDataService } from '../../../core/data/collection-data.service'; import { CollectionDataService } from '../../../core/data/collection-data.service';
import { getSucceededRemoteData } from '../../../core/shared/operators'; import { getSucceededRemoteData } from '../../../core/shared/operators';
import { MetadataConfig } from '../../../core/shared/metadata-config.model'; import { MetadataConfig } from '../../../core/shared/metadata-config.model';
import { INotification } from '../../../shared/notifications/models/notification.model';
/** /**
* Component for managing the content source of the collection * Component for managing the content source of the collection
@@ -214,6 +215,13 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
*/ */
previouslySelectedHarvestType = ContentSourceHarvestType.Metadata; previouslySelectedHarvestType = ContentSourceHarvestType.Metadata;
/**
* Notifications displayed after clicking submit
* These are cleaned up every time a user submits the form to prevent error or other notifications from staying active
* while they shouldn't be.
*/
displayedNotifications: INotification[] = [];
public constructor(public objectUpdatesService: ObjectUpdatesService, public constructor(public objectUpdatesService: ObjectUpdatesService,
public notificationsService: NotificationsService, public notificationsService: NotificationsService,
protected location: Location, protected location: Location,
@@ -269,7 +277,10 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
this.updateSub = this.update$.subscribe((update: FieldUpdate) => { this.updateSub = this.update$.subscribe((update: FieldUpdate) => {
if (update) { if (update) {
const field = update.field as ContentSource; const field = update.field as ContentSource;
const defaultConfigId = this.contentSource.metadataConfigs[0].id; let defaultConfigId;
if (hasValue(this.contentSource) && isNotEmpty(this.contentSource.metadataConfigs)) {
defaultConfigId = this.contentSource.metadataConfigs[0].id;
}
this.formGroup.patchValue({ this.formGroup.patchValue({
oaiSourceContainer: { oaiSourceContainer: {
oaiSource: field.oaiSource oaiSource: field.oaiSource
@@ -355,9 +366,14 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
map((col) => col.payload.uuid), map((col) => col.payload.uuid),
switchMap((uuid) => this.collectionService.updateContentSource(uuid, this.contentSource)), switchMap((uuid) => this.collectionService.updateContentSource(uuid, this.contentSource)),
take(1) take(1)
).subscribe((contentSource: ContentSource) => { ).subscribe((result: ContentSource | INotification) => {
this.initializeOriginalContentSource(contentSource); if (hasValue((result as any).harvestType)) {
this.notificationsService.success(this.getNotificationTitle('saved'), this.getNotificationContent('saved')); this.clearNotifications();
this.initializeOriginalContentSource(result as ContentSource);
this.displayedNotifications.push(this.notificationsService.success(this.getNotificationTitle('saved'), this.getNotificationContent('saved')));
} else {
this.displayedNotifications.push(result as INotification);
}
}); });
} }
@@ -419,6 +435,16 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
this.objectUpdatesService.saveAddFieldUpdate(this.url, cloneDeep(this.contentSource)); this.objectUpdatesService.saveAddFieldUpdate(this.url, cloneDeep(this.contentSource));
} }
/**
* Clear possible active notifications
*/
clearNotifications() {
this.displayedNotifications.forEach((notification: INotification) => {
this.notificationsService.remove(notification);
});
this.displayedNotifications = [];
}
/** /**
* Make sure open subscriptions are closed * Make sure open subscriptions are closed
*/ */

View File

@@ -38,6 +38,7 @@ import { ResponseParsingService } from './parsing.service';
import { GenericConstructor } from '../shared/generic-constructor'; import { GenericConstructor } from '../shared/generic-constructor';
import { DSpaceObject } from '../shared/dspace-object.model'; import { DSpaceObject } from '../shared/dspace-object.model';
import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model'; import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model';
import { INotification } from '../../shared/notifications/models/notification.model';
@Injectable() @Injectable()
export class CollectionDataService extends ComColDataService<Collection> { export class CollectionDataService extends ComColDataService<Collection> {
@@ -140,7 +141,7 @@ export class CollectionDataService extends ComColDataService<Collection> {
* @param collectionId * @param collectionId
* @param contentSource * @param contentSource
*/ */
updateContentSource(collectionId: string, contentSource: ContentSource): Observable<ContentSource> { updateContentSource(collectionId: string, contentSource: ContentSource): Observable<ContentSource | INotification> {
const requestId = this.requestService.generateRequestId(); const requestId = this.requestService.generateRequestId();
const serializedContentSource = new DSpaceRESTv2Serializer(ContentSource).serialize(contentSource); const serializedContentSource = new DSpaceRESTv2Serializer(ContentSource).serialize(contentSource);
const request$ = this.getHarvesterEndpoint(collectionId).pipe( const request$ = this.getHarvesterEndpoint(collectionId).pipe(
@@ -166,9 +167,9 @@ export class CollectionDataService extends ComColDataService<Collection> {
if (!response.isSuccessful) { if (!response.isSuccessful) {
if (hasValue((response as any).errorMessage)) { if (hasValue((response as any).errorMessage)) {
if (response.statusCode === 422) { if (response.statusCode === 422) {
this.notificationsService.error(this.translate.instant(this.errorTitle), this.translate.instant(this.contentSourceError), new NotificationOptions(-1)); return this.notificationsService.error(this.translate.instant(this.errorTitle), this.translate.instant(this.contentSourceError), new NotificationOptions(-1));
} else { } else {
this.notificationsService.error(this.translate.instant(this.errorTitle), (response as any).errorMessage, new NotificationOptions(-1)); return this.notificationsService.error(this.translate.instant(this.errorTitle), (response as any).errorMessage, new NotificationOptions(-1));
} }
} }
} else { } else {
@@ -176,10 +177,11 @@ export class CollectionDataService extends ComColDataService<Collection> {
} }
}), }),
isNotEmptyOperator(), isNotEmptyOperator(),
map((response: ContentSourceSuccessResponse) => { map((response: ContentSourceSuccessResponse | INotification) => {
if (isNotEmpty(response.contentsource)) { if (isNotEmpty((response as any).contentsource)) {
return response.contentsource; return (response as ContentSourceSuccessResponse).contentsource;
} }
return response as INotification;
}) })
); );
} }

View File

@@ -20,8 +20,8 @@ export class ContentSourceResponseParsingService implements ResponseParsingServi
const deserialized = new DSpaceRESTv2Serializer(ContentSource).deserialize(payload); const deserialized = new DSpaceRESTv2Serializer(ContentSource).deserialize(payload);
let metadataConfigs = []; let metadataConfigs = [];
if (payload._embedded && payload._embedded.metadata_configs && payload._embedded.metadata_configs.configs) { if (payload._embedded && payload._embedded.harvestermetadata && payload._embedded.harvestermetadata.configs) {
metadataConfigs = new DSpaceRESTv2Serializer(MetadataConfig).serializeArray(payload._embedded.metadata_configs.configs); metadataConfigs = new DSpaceRESTv2Serializer(MetadataConfig).serializeArray(payload._embedded.harvestermetadata.configs);
} }
deserialized.metadataConfigs = metadataConfigs; deserialized.metadataConfigs = metadataConfigs;