68346: edit-bitstream cache issues fixes

This commit is contained in:
Kristof De Langhe
2020-03-13 16:39:43 +01:00
parent 1ea9623efc
commit a72ef836f9
3 changed files with 19 additions and 26 deletions

View File

@@ -19,7 +19,7 @@ import { DynamicCustomSwitchModel } from '../../shared/form/builder/ds-dynamic-f
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { BitstreamDataService } from '../../core/data/bitstream-data.service'; import { BitstreamDataService } from '../../core/data/bitstream-data.service';
import { import {
getAllSucceededRemoteData, getAllSucceededRemoteData, getAllSucceededRemoteDataPayload,
getFirstSucceededRemoteDataPayload, getFirstSucceededRemoteDataPayload,
getRemoteDataPayload, getRemoteDataPayload,
getSucceededRemoteData getSucceededRemoteData
@@ -35,6 +35,9 @@ import { Location } from '@angular/common';
import { Observable } from 'rxjs/internal/Observable'; import { Observable } from 'rxjs/internal/Observable';
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 { followLink } from '../../shared/utils/follow-link-config.model';
import { ObjectCacheService } from '../../core/cache/object-cache.service';
import { RequestService } from '../../core/data/request.service';
@Component({ @Component({
selector: 'ds-edit-bitstream-page', selector: 'ds-edit-bitstream-page',
@@ -266,18 +269,15 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
*/ */
protected subs: Subscription[] = []; protected subs: Subscription[] = [];
/**
* Denotes whether or not we're awaiting the server's response after a save
*/
private _saveResponsePending: boolean;
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private location: Location, private location: Location,
private formService: DynamicFormService, private formService: DynamicFormService,
private translate: TranslateService, private translate: TranslateService,
private bitstreamService: BitstreamDataService, private bitstreamService: BitstreamDataService,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private bitstreamFormatService: BitstreamFormatDataService) { private bitstreamFormatService: BitstreamFormatDataService,
private objectCache: ObjectCacheService,
private requestService: RequestService) {
} }
/** /**
@@ -295,7 +295,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
const bitstream$ = this.bitstreamRD$.pipe( const bitstream$ = this.bitstreamRD$.pipe(
getSucceededRemoteData(), getSucceededRemoteData(),
getRemoteDataPayload(), getRemoteDataPayload(),
switchMap((bitstream: Bitstream) => this.bitstreamService.findById(bitstream.id).pipe( switchMap((bitstream: Bitstream) => this.bitstreamService.findById(bitstream.id, followLink('format')).pipe(
getAllSucceededRemoteData(), getAllSucceededRemoteData(),
getRemoteDataPayload(), getRemoteDataPayload(),
filter((bs: Bitstream) => hasValue(bs))) filter((bs: Bitstream) => hasValue(bs)))
@@ -316,13 +316,6 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
this.formats = allFormats.page; this.formats = allFormats.page;
this.updateFormatModel(); this.updateFormatModel();
this.updateForm(this.bitstream); this.updateForm(this.bitstream);
if (this._saveResponsePending) {
this.notificationsService.success(
this.translate.instant(this.NOTIFICATIONS_PREFIX + 'saved.title'),
this.translate.instant(this.NOTIFICATIONS_PREFIX + 'saved.content')
);
this._saveResponsePending = false;
}
}) })
); );
@@ -347,14 +340,14 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
primaryBitstream: false primaryBitstream: false
}, },
descriptionContainer: { descriptionContainer: {
description: bitstream.description description: bitstream.firstMetadataValue('dc.description')
}, },
formatContainer: { formatContainer: {
newFormat: hasValue(bitstream.firstMetadata('dc.format')) ? bitstream.firstMetadata('dc.format').value : undefined newFormat: hasValue(bitstream.firstMetadata('dc.format')) ? bitstream.firstMetadata('dc.format').value : undefined
} }
}); });
this.bitstream.format.pipe( this.bitstream.format.pipe(
getFirstSucceededRemoteDataPayload() getAllSucceededRemoteDataPayload()
).subscribe((format: BitstreamFormat) => { ).subscribe((format: BitstreamFormat) => {
this.originalFormat = format; this.originalFormat = format;
this.formGroup.patchValue({ this.formGroup.patchValue({
@@ -463,18 +456,17 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
bitstream$.pipe( bitstream$.pipe(
switchMap(() => { switchMap(() => {
if (isNewFormat) {
const operation = Object.assign({op: 'replace', path: '/format', value: selectedFormat._links.self});
this.bitstreamService.patch(this.bitstream.self, [operation]);
}
return this.bitstreamService.update(this.bitstream).pipe( return this.bitstreamService.update(this.bitstream).pipe(
getFirstSucceededRemoteDataPayload() getFirstSucceededRemoteDataPayload()
); );
}) })
).subscribe(() => { ).subscribe(() => {
this.bitstreamService.commitUpdates(); this.bitstreamService.commitUpdates();
this._saveResponsePending = true; this.notificationsService.success(
this.translate.instant(this.NOTIFICATIONS_PREFIX + 'saved.title'),
this.translate.instant(this.NOTIFICATIONS_PREFIX + 'saved.content')
);
this.requestService.removeByHrefSubstring(this.bitstream.self + '/format');
}); });
} }

View File

@@ -102,9 +102,8 @@ export class ServerSyncBufferEffects {
map((entry: ObjectCacheEntry) => { map((entry: ObjectCacheEntry) => {
if (isNotEmpty(entry.patches)) { if (isNotEmpty(entry.patches)) {
const flatPatch: Operation[] = [].concat(...entry.patches.map((patch) => patch.operations)); const flatPatch: Operation[] = [].concat(...entry.patches.map((patch) => patch.operations));
const objectPatch = flatPatch.filter((op: Operation) => op.path.startsWith('/metadata') || op.op === 'move'); if (isNotEmpty(flatPatch)) {
if (isNotEmpty(objectPatch)) { this.requestService.configure(new PatchRequest(this.requestService.generateRequestId(), href, flatPatch));
this.requestService.configure(new PatchRequest(this.requestService.generateRequestId(), href, objectPatch));
} }
} }
return new ApplyPatchObjectCacheAction(href); return new ApplyPatchObjectCacheAction(href);

View File

@@ -119,6 +119,8 @@ export class HeadRequest extends RestRequest {
} }
export class PatchRequest extends RestRequest { export class PatchRequest extends RestRequest {
public responseMsToLive = 60 * 15 * 1000;
constructor( constructor(
public uuid: string, public uuid: string,
public href: string, public href: string,