Skip to content

Commit 4246199

Browse files
[DSC-1594] - Fixed cache issue + resolved PR comments
1 parent dea09f3 commit 4246199

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import { Item } from '../../core/shared/item.model';
2626
import { DsDynamicInputModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model';
2727
import { DsDynamicTextAreaModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-textarea.model';
2828
import { PrimaryBitstreamService } from '../../core/data/primary-bitstream.service';
29-
import {VocabularyService} from '../../core/submission/vocabularies/vocabulary.service';
30-
import {VocabularyOptions} from '../../core/submission/vocabularies/models/vocabulary-options.model';
31-
import {PageInfo} from '../../core/shared/page-info.model';
32-
import {VocabularyEntry} from '../../core/submission/vocabularies/models/vocabulary-entry.model';
29+
import { VocabularyService } from '../../core/submission/vocabularies/vocabulary.service';
30+
import { VocabularyOptions } from '../../core/submission/vocabularies/models/vocabulary-options.model';
31+
import { PageInfo } from '../../core/shared/page-info.model';
32+
import { VocabularyEntry } from '../../core/submission/vocabularies/models/vocabulary-entry.model';
33+
import { RequestService } from '../../core/data/request.service';
3334

3435
@Component({
3536
selector: 'ds-edit-bitstream-page',
@@ -405,6 +406,11 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
405406
*/
406407
private bundle: Bundle;
407408

409+
/**
410+
* Options for the vocabulary service
411+
*/
412+
readonly vocabularyOptions = new VocabularyOptions('truefalse', 'bitstream.hide');
413+
408414
constructor(private route: ActivatedRoute,
409415
private router: Router,
410416
private changeDetectorRef: ChangeDetectorRef,
@@ -416,7 +422,8 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
416422
private notificationsService: NotificationsService,
417423
private bitstreamFormatService: BitstreamFormatDataService,
418424
private primaryBitstreamService: PrimaryBitstreamService,
419-
private vocabularyService: VocabularyService
425+
private vocabularyService: VocabularyService,
426+
private requestService: RequestService
420427
) {
421428
}
422429

@@ -458,12 +465,8 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
458465
switchMap((bundle: Bundle) => bundle.item),
459466
getFirstSucceededRemoteDataPayload(),
460467
);
461-
const vocabularyOptions = new VocabularyOptions(
462-
'truefalse',
463-
'bitstream.hide',
464-
);
465-
const pageInfo = new PageInfo();
466-
const hide$: Observable<VocabularyEntry[]> = this.vocabularyService.getVocabularyEntries(vocabularyOptions, pageInfo).pipe(
468+
469+
const hide$: Observable<VocabularyEntry[]> = this.vocabularyService.getVocabularyEntries(this.vocabularyOptions, new PageInfo()).pipe(
467470
getFirstCompletedRemoteData(),
468471
map((rq)=> rq.hasSucceeded ? rq.payload.page : []),
469472
);
@@ -496,24 +499,31 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
496499
);
497500
}
498501
handleHideBitstream(entries: VocabularyEntry[]) {
502+
499503
if (isEmpty(entries)) {
500504
return;
501505
}
502-
const options = entries.map((entry) => ({label: entry.display, value: entry.value}));
503-
let hideModel = new DynamicSelectModel({
506+
507+
this.hideModel = new DynamicSelectModel({
504508
id: 'hide',
505509
name: 'hide',
506-
options: options
510+
options: entries.map((entry) => ({label: entry.display, value: entry.value})),
507511
});
508-
this.hideModel = hideModel;
509512
this.inputModels.push(this.hideModel);
510-
const groupModel = new DynamicFormGroupModel({
513+
this.formModel.push(new DynamicFormGroupModel({
511514
id: 'hideContainer',
512515
group: [
513-
hideModel
516+
this.hideModel
514517
]
515-
});
516-
this.formModel.push(groupModel);
518+
}));
519+
}
520+
521+
/**
522+
* Invalidates the cache for specific items based on their HREF substrings and ID bitstream.
523+
*/
524+
invalidCacheItem(){
525+
this.requestService.setStaleByHrefSubstring(this.itemId);
526+
this.requestService.setStaleByHrefSubstring(this.bitstream.id);
517527
}
518528

519529
/**
@@ -647,6 +657,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
647657
* Check for changes against the bitstream and send update requests to the REST API
648658
*/
649659
onSubmit() {
660+
650661
const updatedValues = this.formGroup.getRawValue();
651662
const updatedBitstream = this.formToBitstream(updatedValues);
652663
const selectedFormat = this.formats.find((f: BitstreamFormat) => f.id === updatedValues.formatContainer.selectedFormat);
@@ -728,6 +739,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
728739
})
729740
).subscribe(() => {
730741
this.bitstreamService.commitUpdates();
742+
this.invalidCacheItem();
731743
this.notificationsService.success(
732744
this.translate.instant(this.NOTIFICATIONS_PREFIX + 'saved.title'),
733745
this.translate.instant(this.NOTIFICATIONS_PREFIX + 'saved.content')

0 commit comments

Comments
 (0)