Skip to content

Commit e270018

Browse files
committed
Merge branch 'dspace-cris-2023_02_x' into main-cris
2 parents 021eb43 + 07b6d05 commit e270018

8 files changed

+66
-7979
lines changed

nohup.out

-7,948
This file was deleted.

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
Component,
44
ComponentFactoryResolver,
55
ContentChildren,
6-
EventEmitter, Inject,
6+
EventEmitter,
7+
Inject,
78
Input,
89
NgZone,
910
OnChanges,
@@ -58,7 +59,9 @@ import { TranslateService } from '@ngx-translate/core';
5859
import { ReorderableRelationship } from './existing-metadata-list-element/existing-metadata-list-element.component';
5960

6061
import { DYNAMIC_FORM_CONTROL_TYPE_ONEBOX } from './models/onebox/dynamic-onebox.model';
61-
import { DYNAMIC_FORM_CONTROL_TYPE_SCROLLABLE_DROPDOWN } from './models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
62+
import {
63+
DYNAMIC_FORM_CONTROL_TYPE_SCROLLABLE_DROPDOWN
64+
} from './models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
6265
import { DYNAMIC_FORM_CONTROL_TYPE_TAG } from './models/tag/dynamic-tag.model';
6366
import { DYNAMIC_FORM_CONTROL_TYPE_DSDATEPICKER } from './models/date-picker/date-picker.model';
6467
import { DYNAMIC_FORM_CONTROL_TYPE_LOOKUP } from './models/lookup/dynamic-lookup.model';
@@ -70,7 +73,9 @@ import { DsDynamicTagComponent } from './models/tag/dynamic-tag.component';
7073
import { DsDatePickerComponent } from './models/date-picker/date-picker.component';
7174
import { DsDynamicListComponent } from './models/list/dynamic-list.component';
7275
import { DsDynamicOneboxComponent } from './models/onebox/dynamic-onebox.component';
73-
import { DsDynamicScrollableDropdownComponent } from './models/scrollable-dropdown/dynamic-scrollable-dropdown.component';
76+
import {
77+
DsDynamicScrollableDropdownComponent
78+
} from './models/scrollable-dropdown/dynamic-scrollable-dropdown.component';
7479
import { DsDynamicLookupComponent } from './models/lookup/dynamic-lookup.component';
7580
import { DsDynamicFormGroupComponent } from './models/form-group/dynamic-form-group.component';
7681
import { DsDynamicFormArrayComponent } from './models/array-group/dynamic-form-array.component';
@@ -82,7 +87,9 @@ import { CustomSwitchComponent } from './models/custom-switch/custom-switch.comp
8287
import { find, map, startWith, switchMap, take } from 'rxjs/operators';
8388
import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
8489
import { DsDynamicTypeBindRelationService } from './ds-dynamic-type-bind-relation.service';
85-
import { DsDynamicRelationInlineGroupComponent } from './models/relation-inline-group/dynamic-relation-inline-group.components';
90+
import {
91+
DsDynamicRelationInlineGroupComponent
92+
} from './models/relation-inline-group/dynamic-relation-inline-group.components';
8693
import { SearchResult } from '../../../search/models/search-result.model';
8794
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
8895
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
@@ -497,6 +504,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
497504
* Unsubscribe from all subscriptions
498505
*/
499506
ngOnDestroy(): void {
507+
super.ngOnDestroy();
500508
this.subs
501509
.filter((sub) => hasValue(sub))
502510
.forEach((sub) => sub.unsubscribe());

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service.spec.ts

+25-13
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import {
1111
REQUIRED_MATCHER_PROVIDER,
1212
} from '@ng-dynamic-forms/core';
1313

14-
import {
15-
mockInputWithTypeBindModel, MockRelationModel
16-
} from '../../../mocks/form-models.mock';
14+
import { mockInputWithTypeBindModel, MockRelationModel } from '../../../mocks/form-models.mock';
1715
import { DsDynamicTypeBindRelationService } from './ds-dynamic-type-bind-relation.service';
1816
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
19-
import {UntypedFormControl, ReactiveFormsModule} from '@angular/forms';
17+
import { ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
2018
import { FormBuilderService } from '../form-builder.service';
2119
import { getMockFormBuilderService } from '../../../mocks/form-builder-service.mock';
2220
import { Injector } from '@angular/core';
21+
import { VocabularyEntryDetail } from '../../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
2322

2423
describe('DSDynamicTypeBindRelationService test suite', () => {
2524
let service: DsDynamicTypeBindRelationService;
@@ -40,19 +39,19 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
4039

4140
beforeEach(inject([DsDynamicTypeBindRelationService, DynamicFormRelationService],
4241
(relationService: DsDynamicTypeBindRelationService,
43-
formRelationService: DynamicFormRelationService,
42+
formRelationService: DynamicFormRelationService
4443
) => {
45-
service = relationService;
46-
dynamicFormRelationService = formRelationService;
47-
}));
44+
service = relationService;
45+
dynamicFormRelationService = formRelationService;
46+
}));
4847

4948
describe('Test getTypeBindValue method', () => {
5049
it('Should get type bind "boundType" from the given metadata object value', () => {
51-
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
52-
'boundType', null, null, null,'Bound Type'
53-
);
54-
const bindType = service.getTypeBindValue(mockMetadataValueObject);
55-
expect(bindType).toBe('boundType');
50+
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
51+
'boundType', null, null, null, 'Bound Type'
52+
);
53+
const bindType = service.getTypeBindValue(mockMetadataValueObject);
54+
expect(bindType).toBe('boundType');
5655
});
5756
it('Should get type authority key "bound-auth-key" from the given metadata object value', () => {
5857
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
@@ -61,6 +60,19 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
6160
const bindType = service.getTypeBindValue(mockMetadataValueObject);
6261
expect(bindType).toBe('bound-auth-key');
6362
});
63+
it('Should get type bind "boundType" from the given vocabulary entry object value', () => {
64+
const vocabularyEntry = new VocabularyEntryDetail();
65+
vocabularyEntry.value = vocabularyEntry.display = 'boundType';
66+
const bindType = service.getTypeBindValue(vocabularyEntry);
67+
expect(bindType).toBe('boundType');
68+
});
69+
it('Should get type authority key "bound-auth-key" from the given vocabulary entry object value', () => {
70+
const vocabularyEntry = new VocabularyEntryDetail();
71+
vocabularyEntry.id = vocabularyEntry.authority = 'bound-auth-key';
72+
vocabularyEntry.value = vocabularyEntry.display = 'boundType';
73+
const bindType = service.getTypeBindValue(vocabularyEntry);
74+
expect(bindType).toBe('bound-auth-key');
75+
});
6476
it('Should get passed string returned directly as string passed instead of metadata', () => {
6577
const bindType = service.getTypeBindValue('rawString');
6678
expect(bindType).toBe('rawString');

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import {
1111
DynamicFormControlMatcher,
1212
DynamicFormControlModel,
1313
DynamicFormControlRelation,
14-
DynamicFormRelationService, MATCH_VISIBLE,
14+
DynamicFormRelationService,
15+
MATCH_VISIBLE,
1516
OR_OPERATOR
1617
} from '@ng-dynamic-forms/core';
1718

18-
import {hasNoValue, hasValue} from '../../../empty.util';
19+
import { hasNoValue, hasValue } from '../../../empty.util';
1920
import { FormBuilderService } from '../form-builder.service';
2021
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
2122
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './ds-dynamic-form-constants';
23+
import { VocabularyEntry } from '../../../../core/submission/vocabularies/models/vocabulary-entry.model';
2224

2325
/**
2426
* Service to manage type binding for submission input fields
@@ -38,11 +40,11 @@ export class DsDynamicTypeBindRelationService {
3840
* @param bindModelValue
3941
* @private
4042
*/
41-
public getTypeBindValue(bindModelValue: string | FormFieldMetadataValueObject): string {
43+
public getTypeBindValue(bindModelValue: string | FormFieldMetadataValueObject | VocabularyEntry): string {
4244
let value;
4345
if (hasNoValue(bindModelValue) || typeof bindModelValue === 'string') {
4446
value = bindModelValue;
45-
} else if (bindModelValue instanceof FormFieldMetadataValueObject
47+
} else if ((bindModelValue instanceof FormFieldMetadataValueObject || bindModelValue instanceof VocabularyEntry)
4648
&& bindModelValue.hasAuthority()) {
4749
value = bindModelValue.authority;
4850
} else {
@@ -89,7 +91,6 @@ export class DsDynamicTypeBindRelationService {
8991
// Default to OR for operator (OR is explicitly set in field-parser.ts anyway)
9092
const operator = relation.operator || OR_OPERATOR;
9193

92-
9394
return relation.when.reduce((hasAlreadyMatched: boolean, condition: DynamicFormControlCondition, index: number) => {
9495
// Get the DynamicFormControlModel (typeBindModel) from the form builder service, set in the form builder
9596
// in the form model at init time in formBuilderService.modelFromConfiguration (called by other form components
@@ -183,9 +184,8 @@ export class DsDynamicTypeBindRelationService {
183184
const initValue = (hasNoValue(relatedModel.value) || typeof relatedModel.value === 'string') ? relatedModel.value :
184185
(Array.isArray(relatedModel.value) ? relatedModel.value : relatedModel.value.value);
185186

186-
const updateSubject = (relatedModel.type === 'CHECKBOX_GROUP' ? relatedModel.valueUpdates : relatedModel.valueChanges);
187-
const valueChanges = updateSubject.pipe(
188-
startWith(initValue)
187+
const valueChanges = this.formBuilderService.getTypeBindModelUpdates().pipe(
188+
startWith(initValue),
189189
);
190190

191191
// Build up the subscriptions to watch for changes;

src/app/shared/form/builder/form-builder.service.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
import isObject from 'lodash/isObject';
2222
import isString from 'lodash/isString';
2323
import mergeWith from 'lodash/mergeWith';
24+
import { BehaviorSubject, Observable } from 'rxjs';
25+
import { distinctUntilChanged, switchMap } from 'rxjs/operators';
2426

2527
import {
2628
hasNoValue,
@@ -50,7 +52,7 @@ import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
5052
@Injectable()
5153
export class FormBuilderService extends DynamicFormService {
5254

53-
private typeBindModel: DynamicFormControlModel;
55+
private typeBindModel: BehaviorSubject<DynamicFormControlModel> = new BehaviorSubject<DynamicFormControlModel>(null);
5456

5557
/**
5658
* This map contains the active forms model
@@ -92,11 +94,21 @@ export class FormBuilderService extends DynamicFormService {
9294
}
9395

9496
getTypeBindModel() {
95-
return this.typeBindModel;
97+
return this.typeBindModel.getValue();
98+
}
99+
100+
getTypeBindModelUpdates(): Observable<any> {
101+
return this.typeBindModel.pipe(
102+
distinctUntilChanged(),
103+
switchMap((bindModel: any) => {
104+
return (bindModel.type === 'CHECKBOX_GROUP' ? bindModel.valueUpdates : bindModel.valueChanges);
105+
}),
106+
distinctUntilChanged()
107+
);
96108
}
97109

98110
setTypeBindModel(model: DynamicFormControlModel) {
99-
this.typeBindModel = model;
111+
this.typeBindModel.next(model);
100112
}
101113

102114
findById(id: string, groupModel: DynamicFormControlModel[], arrayIndex = null): DynamicFormControlModel | null {

src/app/shared/mocks/form-builder-service.mock.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FormBuilderService } from '../form/builder/form-builder.service';
22
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
33
import { DsDynamicInputModel } from '../form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model';
4+
import { of } from 'rxjs';
45

56
export function getMockFormBuilderService(): FormBuilderService {
67

@@ -43,7 +44,8 @@ export function getMockFormBuilderService(): FormBuilderService {
4344
removeFormModel: {},
4445
addFormModel: {},
4546
updateValue: {},
46-
addFormGroups: {}
47+
addFormGroups: {},
48+
getTypeBindModelUpdates: of('test')
4749
});
4850

4951
}

src/config/config.util.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('Config Util', () => {
2121
'dc.identifier.scopus',
2222
'dc.identifier.isi',
2323
'dcterms.dateSubmitted',
24-
'dc.identifier.applicationnumber'
24+
'dc.identifier.applicationnumber',
25+
'dc.type'
2526
]);
2627

2728
expect(appConfig.themes.length).toEqual(1);

src/config/default-app-config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class DefaultAppConfig implements AppConfig {
157157
submission: SubmissionConfig = {
158158
autosave: {
159159
// NOTE: which metadata trigger an autosave
160-
metadata: ['dc.title', 'dc.identifier.doi', 'dc.identifier.pmid', 'dc.identifier.arxiv', 'dc.identifier.patentno', 'dc.identifier.scopus', 'dc.identifier.isi', 'dcterms.dateSubmitted', 'dc.identifier.applicationnumber'],
160+
metadata: ['dc.title', 'dc.identifier.doi', 'dc.identifier.pmid', 'dc.identifier.arxiv', 'dc.identifier.patentno', 'dc.identifier.scopus', 'dc.identifier.isi', 'dcterms.dateSubmitted', 'dc.identifier.applicationnumber', 'dc.type'],
161161
/**
162162
* NOTE: after how many time (milliseconds) submission is saved automatically
163163
* eg. timer: 5 * (1000 * 60); // 5 minutes

0 commit comments

Comments
 (0)