Skip to content

Commit

Permalink
Merge branch 'dspace-cris-2023_02_x' into main-cris
Browse files Browse the repository at this point in the history
  • Loading branch information
atarix83 committed Mar 22, 2024
2 parents 021eb43 + 07b6d05 commit e270018
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 7,979 deletions.
7,948 changes: 0 additions & 7,948 deletions nohup.out

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
Component,
ComponentFactoryResolver,
ContentChildren,
EventEmitter, Inject,
EventEmitter,
Inject,
Input,
NgZone,
OnChanges,
Expand Down Expand Up @@ -58,7 +59,9 @@ import { TranslateService } from '@ngx-translate/core';
import { ReorderableRelationship } from './existing-metadata-list-element/existing-metadata-list-element.component';

import { DYNAMIC_FORM_CONTROL_TYPE_ONEBOX } from './models/onebox/dynamic-onebox.model';
import { DYNAMIC_FORM_CONTROL_TYPE_SCROLLABLE_DROPDOWN } from './models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
import {
DYNAMIC_FORM_CONTROL_TYPE_SCROLLABLE_DROPDOWN
} from './models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
import { DYNAMIC_FORM_CONTROL_TYPE_TAG } from './models/tag/dynamic-tag.model';
import { DYNAMIC_FORM_CONTROL_TYPE_DSDATEPICKER } from './models/date-picker/date-picker.model';
import { DYNAMIC_FORM_CONTROL_TYPE_LOOKUP } from './models/lookup/dynamic-lookup.model';
Expand All @@ -70,7 +73,9 @@ import { DsDynamicTagComponent } from './models/tag/dynamic-tag.component';
import { DsDatePickerComponent } from './models/date-picker/date-picker.component';
import { DsDynamicListComponent } from './models/list/dynamic-list.component';
import { DsDynamicOneboxComponent } from './models/onebox/dynamic-onebox.component';
import { DsDynamicScrollableDropdownComponent } from './models/scrollable-dropdown/dynamic-scrollable-dropdown.component';
import {
DsDynamicScrollableDropdownComponent
} from './models/scrollable-dropdown/dynamic-scrollable-dropdown.component';
import { DsDynamicLookupComponent } from './models/lookup/dynamic-lookup.component';
import { DsDynamicFormGroupComponent } from './models/form-group/dynamic-form-group.component';
import { DsDynamicFormArrayComponent } from './models/array-group/dynamic-form-array.component';
Expand All @@ -82,7 +87,9 @@ import { CustomSwitchComponent } from './models/custom-switch/custom-switch.comp
import { find, map, startWith, switchMap, take } from 'rxjs/operators';
import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
import { DsDynamicTypeBindRelationService } from './ds-dynamic-type-bind-relation.service';
import { DsDynamicRelationInlineGroupComponent } from './models/relation-inline-group/dynamic-relation-inline-group.components';
import {
DsDynamicRelationInlineGroupComponent
} from './models/relation-inline-group/dynamic-relation-inline-group.components';
import { SearchResult } from '../../../search/models/search-result.model';
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
Expand Down Expand Up @@ -497,6 +504,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
* Unsubscribe from all subscriptions
*/
ngOnDestroy(): void {
super.ngOnDestroy();
this.subs
.filter((sub) => hasValue(sub))
.forEach((sub) => sub.unsubscribe());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import {
REQUIRED_MATCHER_PROVIDER,
} from '@ng-dynamic-forms/core';

import {
mockInputWithTypeBindModel, MockRelationModel
} from '../../../mocks/form-models.mock';
import { mockInputWithTypeBindModel, MockRelationModel } from '../../../mocks/form-models.mock';
import { DsDynamicTypeBindRelationService } from './ds-dynamic-type-bind-relation.service';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import {UntypedFormControl, ReactiveFormsModule} from '@angular/forms';
import { ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
import { FormBuilderService } from '../form-builder.service';
import { getMockFormBuilderService } from '../../../mocks/form-builder-service.mock';
import { Injector } from '@angular/core';
import { VocabularyEntryDetail } from '../../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';

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

beforeEach(inject([DsDynamicTypeBindRelationService, DynamicFormRelationService],
(relationService: DsDynamicTypeBindRelationService,
formRelationService: DynamicFormRelationService,
formRelationService: DynamicFormRelationService
) => {
service = relationService;
dynamicFormRelationService = formRelationService;
}));
service = relationService;
dynamicFormRelationService = formRelationService;
}));

describe('Test getTypeBindValue method', () => {
it('Should get type bind "boundType" from the given metadata object value', () => {
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
'boundType', null, null, null,'Bound Type'
);
const bindType = service.getTypeBindValue(mockMetadataValueObject);
expect(bindType).toBe('boundType');
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
'boundType', null, null, null, 'Bound Type'
);
const bindType = service.getTypeBindValue(mockMetadataValueObject);
expect(bindType).toBe('boundType');
});
it('Should get type authority key "bound-auth-key" from the given metadata object value', () => {
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
Expand All @@ -61,6 +60,19 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
const bindType = service.getTypeBindValue(mockMetadataValueObject);
expect(bindType).toBe('bound-auth-key');
});
it('Should get type bind "boundType" from the given vocabulary entry object value', () => {
const vocabularyEntry = new VocabularyEntryDetail();
vocabularyEntry.value = vocabularyEntry.display = 'boundType';
const bindType = service.getTypeBindValue(vocabularyEntry);
expect(bindType).toBe('boundType');
});
it('Should get type authority key "bound-auth-key" from the given vocabulary entry object value', () => {
const vocabularyEntry = new VocabularyEntryDetail();
vocabularyEntry.id = vocabularyEntry.authority = 'bound-auth-key';
vocabularyEntry.value = vocabularyEntry.display = 'boundType';
const bindType = service.getTypeBindValue(vocabularyEntry);
expect(bindType).toBe('bound-auth-key');
});
it('Should get passed string returned directly as string passed instead of metadata', () => {
const bindType = service.getTypeBindValue('rawString');
expect(bindType).toBe('rawString');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import {
DynamicFormControlMatcher,
DynamicFormControlModel,
DynamicFormControlRelation,
DynamicFormRelationService, MATCH_VISIBLE,
DynamicFormRelationService,
MATCH_VISIBLE,
OR_OPERATOR
} from '@ng-dynamic-forms/core';

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

/**
* Service to manage type binding for submission input fields
Expand All @@ -38,11 +40,11 @@ export class DsDynamicTypeBindRelationService {
* @param bindModelValue
* @private
*/
public getTypeBindValue(bindModelValue: string | FormFieldMetadataValueObject): string {
public getTypeBindValue(bindModelValue: string | FormFieldMetadataValueObject | VocabularyEntry): string {
let value;
if (hasNoValue(bindModelValue) || typeof bindModelValue === 'string') {
value = bindModelValue;
} else if (bindModelValue instanceof FormFieldMetadataValueObject
} else if ((bindModelValue instanceof FormFieldMetadataValueObject || bindModelValue instanceof VocabularyEntry)
&& bindModelValue.hasAuthority()) {
value = bindModelValue.authority;
} else {
Expand Down Expand Up @@ -89,7 +91,6 @@ export class DsDynamicTypeBindRelationService {
// Default to OR for operator (OR is explicitly set in field-parser.ts anyway)
const operator = relation.operator || OR_OPERATOR;


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

const updateSubject = (relatedModel.type === 'CHECKBOX_GROUP' ? relatedModel.valueUpdates : relatedModel.valueChanges);
const valueChanges = updateSubject.pipe(
startWith(initValue)
const valueChanges = this.formBuilderService.getTypeBindModelUpdates().pipe(
startWith(initValue),
);

// Build up the subscriptions to watch for changes;
Expand Down
18 changes: 15 additions & 3 deletions src/app/shared/form/builder/form-builder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
import isObject from 'lodash/isObject';
import isString from 'lodash/isString';
import mergeWith from 'lodash/mergeWith';
import { BehaviorSubject, Observable } from 'rxjs';
import { distinctUntilChanged, switchMap } from 'rxjs/operators';

import {
hasNoValue,
Expand Down Expand Up @@ -50,7 +52,7 @@ import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
@Injectable()
export class FormBuilderService extends DynamicFormService {

private typeBindModel: DynamicFormControlModel;
private typeBindModel: BehaviorSubject<DynamicFormControlModel> = new BehaviorSubject<DynamicFormControlModel>(null);

/**
* This map contains the active forms model
Expand Down Expand Up @@ -92,11 +94,21 @@ export class FormBuilderService extends DynamicFormService {
}

getTypeBindModel() {
return this.typeBindModel;
return this.typeBindModel.getValue();
}

getTypeBindModelUpdates(): Observable<any> {
return this.typeBindModel.pipe(
distinctUntilChanged(),
switchMap((bindModel: any) => {
return (bindModel.type === 'CHECKBOX_GROUP' ? bindModel.valueUpdates : bindModel.valueChanges);
}),
distinctUntilChanged()
);
}

setTypeBindModel(model: DynamicFormControlModel) {
this.typeBindModel = model;
this.typeBindModel.next(model);
}

findById(id: string, groupModel: DynamicFormControlModel[], arrayIndex = null): DynamicFormControlModel | null {
Expand Down
4 changes: 3 additions & 1 deletion src/app/shared/mocks/form-builder-service.mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FormBuilderService } from '../form/builder/form-builder.service';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { DsDynamicInputModel } from '../form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model';
import { of } from 'rxjs';

export function getMockFormBuilderService(): FormBuilderService {

Expand Down Expand Up @@ -43,7 +44,8 @@ export function getMockFormBuilderService(): FormBuilderService {
removeFormModel: {},
addFormModel: {},
updateValue: {},
addFormGroups: {}
addFormGroups: {},
getTypeBindModelUpdates: of('test')
});

}
3 changes: 2 additions & 1 deletion src/config/config.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ describe('Config Util', () => {
'dc.identifier.scopus',
'dc.identifier.isi',
'dcterms.dateSubmitted',
'dc.identifier.applicationnumber'
'dc.identifier.applicationnumber',
'dc.type'
]);

expect(appConfig.themes.length).toEqual(1);
Expand Down
2 changes: 1 addition & 1 deletion src/config/default-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class DefaultAppConfig implements AppConfig {
submission: SubmissionConfig = {
autosave: {
// NOTE: which metadata trigger an autosave
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'],
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'],
/**
* NOTE: after how many time (milliseconds) submission is saved automatically
* eg. timer: 5 * (1000 * 60); // 5 minutes
Expand Down

0 comments on commit e270018

Please sign in to comment.