Skip to content

Commit 9a93fb2

Browse files
[DSC-1594] Implementing hide field inside edit bitstream view
1 parent 19a26ec commit 9a93fb2

3 files changed

Lines changed: 76 additions & 4 deletions

File tree

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import { Item } from '../../core/shared/item.model';
2525
import { MetadataValueFilter } from '../../core/shared/metadata.models';
2626
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
2727
import { PrimaryBitstreamService } from '../../core/data/primary-bitstream.service';
28+
import {VocabularyService} from '../../core/submission/vocabularies/vocabulary.service';
29+
import {VocabularyEntry} from '../../core/submission/vocabularies/models/vocabulary-entry.model';
30+
import {buildPaginatedList} from '../../core/data/paginated-list.model';
31+
import {PageInfo} from '../../core/shared/page-info.model';
2832

2933
const infoNotification: INotification = new Notification('id', NotificationType.Info, 'info');
3034
const warningNotification: INotification = new Notification('id', NotificationType.Warning, 'warning');
@@ -49,11 +53,22 @@ let fixture: ComponentFixture<EditBitstreamPageComponent>;
4953

5054
describe('EditBitstreamPageComponent', () => {
5155

56+
const entries = [
57+
Object.assign(new VocabularyEntry(), {display: 'true', value: 'true' }),
58+
Object.assign(new VocabularyEntry(), {display: 'false', value: 'false' }),
59+
];
60+
61+
const mockVocabularyService = jasmine.createSpyObj('vocabularyService', {
62+
getVocabularyEntries: jasmine.createSpy('getVocabularyEntries'),
63+
});
64+
5265
beforeEach(() => {
5366
bitstreamID = 'current-bitstream-id';
5467
currentPrimary = bitstreamID;
5568
differentPrimary = '12345-abcde-54321-edcba';
5669

70+
mockVocabularyService.getVocabularyEntries.and.returnValue(createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), entries)));
71+
5772
allFormats = [
5873
Object.assign({
5974
id: '1',
@@ -213,6 +228,7 @@ describe('EditBitstreamPageComponent', () => {
213228
{ provide: DSONameService, useValue: dsoNameService },
214229
{ provide: BitstreamFormatDataService, useValue: bitstreamFormatService },
215230
{ provide: PrimaryBitstreamService, useValue: primaryBitstreamService },
231+
{ provide: VocabularyService, useValue: mockVocabularyService},
216232
ChangeDetectorRef
217233
],
218234
schemas: [NO_ERRORS_SCHEMA]
@@ -511,6 +527,7 @@ describe('EditBitstreamPageComponent', () => {
511527
{provide: DSONameService, useValue: dsoNameService},
512528
{provide: BitstreamFormatDataService, useValue: bitstreamFormatService},
513529
{ provide: PrimaryBitstreamService, useValue: primaryBitstreamService },
530+
{ provide: VocabularyService, useValue: mockVocabularyService},
514531
ChangeDetectorRef
515532
],
516533
schemas: [NO_ERRORS_SCHEMA]
@@ -549,7 +566,7 @@ describe('EditBitstreamPageComponent', () => {
549566
});
550567
});
551568

552-
describe('ignore OTHERCONTENT bundle', () => {
569+
describe('ignore OTHERCONTENT bundle', () => {
553570

554571
const bundleName = 'OTHERCONTENT';
555572

@@ -640,6 +657,7 @@ describe('EditBitstreamPageComponent', () => {
640657
{provide: DSONameService, useValue: dsoNameService},
641658
{provide: BitstreamFormatDataService, useValue: bitstreamFormatService},
642659
{ provide: PrimaryBitstreamService, useValue: primaryBitstreamService },
660+
{ provide: VocabularyService, useValue: mockVocabularyService},
643661
ChangeDetectorRef
644662
],
645663
schemas: [NO_ERRORS_SCHEMA]

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

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ 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';
2933

3034
@Component({
3135
selector: 'ds-edit-bitstream-page',
@@ -254,6 +258,8 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
254258
}
255259
});
256260

261+
hideModel: DynamicSelectModel<string>;
262+
257263
/**
258264
* All input models in a simple array for easier iterations
259265
*/
@@ -326,6 +332,11 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
326332
host: 'col-12 d-inline-block'
327333
}
328334
},
335+
hide: {
336+
grid: {
337+
host: 'col-12 d-inline-block'
338+
}
339+
},
329340
embargo: {
330341
grid: {
331342
host: 'col-12 d-inline-block'
@@ -405,6 +416,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
405416
private notificationsService: NotificationsService,
406417
private bitstreamFormatService: BitstreamFormatDataService,
407418
private primaryBitstreamService: PrimaryBitstreamService,
419+
private vocabularyService: VocabularyService
408420
) {
409421
}
410422

@@ -446,22 +458,32 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
446458
switchMap((bundle: Bundle) => bundle.item),
447459
getFirstSucceededRemoteDataPayload(),
448460
);
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(
467+
getFirstCompletedRemoteData(),
468+
map((rq)=> rq.hasSucceeded ? rq.payload.page : []),
469+
);
449470
this.subs.push(
450-
observableCombineLatest(
471+
observableCombineLatest([
451472
bitstream$,
452473
allFormats$,
453474
bundle$,
454475
primaryBitstream$,
455476
item$,
456-
).pipe()
457-
.subscribe(([bitstream, allFormats, bundle, primaryBitstream, item]) => {
477+
hide$,
478+
]).subscribe(([bitstream, allFormats, bundle, primaryBitstream, item,entries]) => {
458479
this.bitstream = bitstream as Bitstream;
459480
this.formats = allFormats.page;
460481
this.bundle = bundle;
461482
// hasValue(primaryBitstream) because if there's no primaryBitstream on the bundle it will
462483
// be a success response, but empty
463484
this.primaryBitstreamUUID = hasValue(primaryBitstream) ? primaryBitstream.uuid : null;
464485
this.itemId = item.uuid;
486+
this.handleHideBitstream(entries);
465487
this.setIiifStatus(this.bitstream);
466488
})
467489
);
@@ -473,6 +495,26 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
473495
})
474496
);
475497
}
498+
handleHideBitstream(entries: VocabularyEntry[]) {
499+
if (isEmpty(entries)) {
500+
return;
501+
}
502+
const options = entries.map((entry) => ({label: entry.display, value: entry.value}));
503+
let hideModel = new DynamicSelectModel({
504+
id: 'hide',
505+
name: 'hide',
506+
options: options
507+
});
508+
this.hideModel = hideModel;
509+
this.inputModels.push(this.hideModel);
510+
const groupModel = new DynamicFormGroupModel({
511+
id: 'hideContainer',
512+
group: [
513+
hideModel
514+
]
515+
});
516+
this.formModel.push(groupModel);
517+
}
476518

477519
/**
478520
* Initializes the form.
@@ -500,6 +542,9 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
500542
fileTypeContainer: {
501543
fileType: bitstream.firstMetadataValue('dc.type')
502544
},
545+
hideContainer: {
546+
hide: bitstream.firstMetadataValue('bitstream.hide')
547+
},
503548
formatContainer: {
504549
newFormat: hasValue(bitstream.firstMetadata('dc.format')) ? bitstream.firstMetadata('dc.format').value : undefined
505550
}
@@ -711,6 +756,11 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
711756
} else {
712757
Metadata.setFirstValue(newMetadata, 'dc.type', rawForm.fileTypeContainer.fileType);
713758
}
759+
if (isEmpty(rawForm.hideContainer.hide)) {
760+
delete newMetadata['bitstream.hide'];
761+
} else {
762+
Metadata.setFirstValue(newMetadata, 'bitstream.hide', rawForm.hideContainer.hide);
763+
}
714764
if (this.isIIIF) {
715765
// It's helpful to remove these metadata elements entirely when the form value is empty.
716766
// This avoids potential issues on the REST side and makes it possible to do things like

src/assets/i18n/en.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,10 @@
896896

897897
"bitstream.edit.form.fileType.hint": "Personal picture, logo, main article, etc.",
898898

899+
"bitstream.edit.form.hide.label": "Hide",
900+
901+
"bitstream.edit.form.hide.hint": "Hide the bitstream on the item page.",
902+
899903
"bitstream.edit.form.selectedFormat.hint": "If the format is not in the above list, <b>select \"format not in list\" above</b> and describe it under \"Describe new format\".",
900904

901905
"bitstream.edit.form.selectedFormat.label": "Selected Format",

0 commit comments

Comments
 (0)