mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
added workspace item to fieldparsers
This commit is contained in:
@@ -10,8 +10,10 @@ import { LanguageCode } from '../../models/form-field-language-value.model';
|
||||
import { AuthorityOptions } from '../../../../../core/integration/models/authority-options.model';
|
||||
import { hasValue } from '../../../../empty.util';
|
||||
import { FormFieldMetadataValueObject } from '../../models/form-field-metadata-value.model';
|
||||
import { Workspaceitem } from '../../../../../core/submission/models/workspaceitem.model';
|
||||
|
||||
export interface DsDynamicInputModelConfig extends DynamicInputModelConfig {
|
||||
workspaceItem: Workspaceitem;
|
||||
authorityOptions?: AuthorityOptions;
|
||||
languageCodes?: LanguageCode[];
|
||||
language?: string;
|
||||
@@ -24,12 +26,14 @@ export class DsDynamicInputModel extends DynamicInputModel {
|
||||
@serializable() private _languageCodes: LanguageCode[];
|
||||
@serializable() private _language: string;
|
||||
@serializable() languageUpdates: Subject<string>;
|
||||
@serializable() workspaceItem: Workspaceitem;
|
||||
|
||||
constructor(config: DsDynamicInputModelConfig, layout?: DynamicFormControlLayout) {
|
||||
super(config, layout);
|
||||
|
||||
this.readOnly = config.readOnly;
|
||||
this.value = config.value;
|
||||
this.workspaceItem = config.workspaceItem;
|
||||
this.language = config.language;
|
||||
if (!this.language) {
|
||||
// TypeAhead
|
||||
|
@@ -96,6 +96,7 @@ export class DsDynamicRelationGroupComponent extends DynamicFormControlComponent
|
||||
config,
|
||||
this.model.scopeUUID,
|
||||
{},
|
||||
this.model.workspaceItem,
|
||||
this.model.submissionScope,
|
||||
this.model.readOnly);
|
||||
this.initChipsFromModelValue();
|
||||
|
@@ -29,6 +29,8 @@ import { DynamicRowArrayModel } from './ds-dynamic-form-ui/models/ds-dynamic-row
|
||||
import { DsDynamicInputModel } from './ds-dynamic-form-ui/models/ds-dynamic-input.model';
|
||||
import { FormFieldMetadataValueObject } from './models/form-field-metadata-value.model';
|
||||
import { isNgbDateStruct } from '../../date.util';
|
||||
import { WorkspaceitemSectionFormObject } from '../../../core/submission/models/workspaceitem-section-form.model';
|
||||
import { Workspaceitem } from '../../../core/submission/models/workspaceitem.model';
|
||||
|
||||
@Injectable()
|
||||
export class FormBuilderService extends DynamicFormService {
|
||||
@@ -198,13 +200,13 @@ export class FormBuilderService extends DynamicFormService {
|
||||
return result;
|
||||
}
|
||||
|
||||
modelFromConfiguration(json: string | SubmissionFormsModel, scopeUUID: string, initFormValues: any = {}, submissionScope?: string, readOnly = false): DynamicFormControlModel[] | never {
|
||||
modelFromConfiguration(json: string | SubmissionFormsModel, scopeUUID: string, initFormValues: any = {}, wsi: Workspaceitem, submissionScope?: string, readOnly = false): DynamicFormControlModel[] | never {
|
||||
let rows: DynamicFormControlModel[] = [];
|
||||
const rawData = typeof json === 'string' ? JSON.parse(json, JSONUtils.parseReviver) : json;
|
||||
|
||||
if (rawData.rows && !isEmpty(rawData.rows)) {
|
||||
rawData.rows.forEach((currentRow) => {
|
||||
const rowParsed = new RowParser(currentRow, scopeUUID, initFormValues, submissionScope, readOnly).parse();
|
||||
const rowParsed = new RowParser(currentRow, scopeUUID, initFormValues, wsi, submissionScope, readOnly).parse();
|
||||
if (isNotNull(rowParsed)) {
|
||||
if (Array.isArray(rowParsed)) {
|
||||
rows = rows.concat(rowParsed);
|
||||
|
@@ -1,7 +1,11 @@
|
||||
import { FieldParser } from './field-parser';
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||
import { DynamicFormControlLayout, DynamicInputModel, DynamicInputModelConfig } from '@ng-dynamic-forms/core';
|
||||
import {
|
||||
DynamicFormControlLayout,
|
||||
DynamicInputModel,
|
||||
DynamicInputModelConfig
|
||||
} from '@ng-dynamic-forms/core';
|
||||
import {
|
||||
CONCAT_FIRST_INPUT_SUFFIX,
|
||||
CONCAT_GROUP_SUFFIX,
|
||||
@@ -11,6 +15,7 @@ import {
|
||||
} from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
|
||||
import { isNotEmpty } from '../../../empty.util';
|
||||
import { ParserOptions } from './parser-options';
|
||||
import { Workspaceitem } from '../../../../core/submission/models/workspaceitem.model';
|
||||
|
||||
export class ConcatFieldParser extends FieldParser {
|
||||
|
||||
@@ -18,9 +23,10 @@ export class ConcatFieldParser extends FieldParser {
|
||||
protected initFormValues,
|
||||
protected parserOptions: ParserOptions,
|
||||
protected separator: string,
|
||||
protected workspaceItem: Workspaceitem,
|
||||
protected firstPlaceholder: string = null,
|
||||
protected secondPlaceholder: string = null) {
|
||||
super(configData, initFormValues, parserOptions);
|
||||
super(configData, initFormValues, parserOptions, workspaceItem);
|
||||
|
||||
this.separator = separator;
|
||||
this.firstPlaceholder = firstPlaceholder;
|
||||
|
@@ -12,12 +12,12 @@ import { DynamicFormControlLayout } from '@ng-dynamic-forms/core';
|
||||
import { setLayout } from './parser.utils';
|
||||
import { AuthorityOptions } from '../../../../core/integration/models/authority-options.model';
|
||||
import { ParserOptions } from './parser-options';
|
||||
import { Workspaceitem } from '../../../../core/submission/models/workspaceitem.model';
|
||||
|
||||
export abstract class FieldParser {
|
||||
|
||||
protected fieldId: string;
|
||||
|
||||
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions) {
|
||||
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions, protected workspaceItem: Workspaceitem) {
|
||||
}
|
||||
|
||||
public abstract modelFactory(fieldValue?: FormFieldMetadataValueObject, label?: boolean): any;
|
||||
@@ -184,6 +184,7 @@ export abstract class FieldParser {
|
||||
// Set read only option
|
||||
controlModel.readOnly = this.parserOptions.readOnly;
|
||||
controlModel.disabled = this.parserOptions.readOnly;
|
||||
controlModel.workspaceItem = this.workspaceItem;
|
||||
|
||||
// Set label
|
||||
this.setLabel(controlModel, label, labelEmpty);
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
import { ConcatFieldParser } from './concat-field-parser';
|
||||
import { ParserOptions } from './parser-options';
|
||||
import { Workspaceitem } from '../../../../core/submission/models/workspaceitem.model';
|
||||
|
||||
export class NameFieldParser extends ConcatFieldParser {
|
||||
|
||||
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions) {
|
||||
super(configData, initFormValues, parserOptions, ',', 'form.last-name', 'form.first-name');
|
||||
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions, wsi: Workspaceitem) {
|
||||
super(configData, initFormValues, parserOptions, ',', wsi, 'form.last-name', 'form.first-name');
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import { FormFieldModel } from '../models/form-field.model';
|
||||
import { ParserType } from './parser-type';
|
||||
import { ParserOptions } from './parser-options';
|
||||
import { ParserFactory } from './parser-factory';
|
||||
import { Workspaceitem } from '../../../../core/submission/models/workspaceitem.model';
|
||||
|
||||
export const ROW_ID_PREFIX = 'df-row-group-config-';
|
||||
|
||||
@@ -19,6 +20,7 @@ export class RowParser {
|
||||
constructor(protected rowData,
|
||||
protected scopeUUID,
|
||||
protected initFormValues: any,
|
||||
protected wsi: Workspaceitem,
|
||||
protected submissionScope,
|
||||
protected readOnly: boolean) {
|
||||
this.authorityOptions = new IntegrationSearchOptions(scopeUUID);
|
||||
@@ -49,7 +51,7 @@ export class RowParser {
|
||||
const layoutFieldClass = (fieldData.style || layoutDefaultGridClass) + layoutClass;
|
||||
const parserCo = ParserFactory.getConstructor(fieldData.input.type as ParserType);
|
||||
if (parserCo) {
|
||||
fieldModel = new parserCo(fieldData, this.initFormValues, parserOptions).parse();
|
||||
fieldModel = new parserCo(fieldData, this.initFormValues, parserOptions, this.wsi).parse();
|
||||
} else {
|
||||
throw new Error(`unknown form control model type "${fieldData.input.type}" defined for Input field with label "${fieldData.label}".`, );
|
||||
}
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
import { ConcatFieldParser } from './concat-field-parser';
|
||||
import { ParserOptions } from './parser-options';
|
||||
import { Workspaceitem } from '../../../../core/submission/models/workspaceitem.model';
|
||||
|
||||
export class SeriesFieldParser extends ConcatFieldParser {
|
||||
|
||||
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions) {
|
||||
super(configData, initFormValues, parserOptions, ';');
|
||||
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions, wsi: Workspaceitem) {
|
||||
super(configData, initFormValues, parserOptions, ';', wsi);
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import { AuthorityOptions } from '../../core/integration/models/authority-option
|
||||
import { AuthorityValue } from '../../core/integration/models/authority.value';
|
||||
import { FormFieldMetadataValueObject } from '../form/builder/models/form-field-metadata-value.model';
|
||||
import { DynamicRowGroupModel } from '../form/builder/ds-dynamic-form-ui/models/ds-dynamic-row-group-model';
|
||||
import { Workspaceitem } from '../../core/submission/models/workspaceitem.model';
|
||||
|
||||
export const qualdropSelectConfig = {
|
||||
name: 'dc.identifier_QUALDROP_METADATA',
|
||||
@@ -55,7 +56,8 @@ export const qualdropInputConfig = {
|
||||
id: 'dc_identifier_QUALDROP_VALUE',
|
||||
readOnly: false,
|
||||
disabled: false,
|
||||
value: 'test'
|
||||
value: 'test',
|
||||
workspaceItem: new Workspaceitem()
|
||||
};
|
||||
|
||||
export const mockQualdropSelectModel = new DynamicSelectModel(qualdropSelectConfig);
|
||||
@@ -130,7 +132,8 @@ const relationGroupConfig = {
|
||||
'issue test 1',
|
||||
'issue test 2'
|
||||
],
|
||||
}
|
||||
},
|
||||
workspaceItem: new Workspaceitem()
|
||||
};
|
||||
|
||||
export const MockRelationModel: DynamicRelationGroupModel = new DynamicRelationGroupModel(relationGroupConfig);
|
||||
@@ -156,7 +159,8 @@ export const inputWithLanguageAndAuthorityConfig = {
|
||||
value: 'testWithLanguageAndAuthority',
|
||||
display: 'testWithLanguageAndAuthority',
|
||||
id: 'testWithLanguageAndAuthority',
|
||||
}
|
||||
},
|
||||
workspaceItem: new Workspaceitem()
|
||||
};
|
||||
|
||||
export const mockInputWithLanguageAndAuthorityModel = new DsDynamicInputModel(inputWithLanguageAndAuthorityConfig);
|
||||
@@ -177,7 +181,8 @@ export const inputWithLanguageConfig = {
|
||||
id: 'testWithLanguage',
|
||||
readOnly: false,
|
||||
disabled: false,
|
||||
value: 'testWithLanguage'
|
||||
value: 'testWithLanguage',
|
||||
workspaceItem: new Workspaceitem()
|
||||
};
|
||||
|
||||
export const mockInputWithLanguageModel = new DsDynamicInputModel(inputWithLanguageConfig);
|
||||
@@ -203,7 +208,8 @@ export const inputWithLanguageAndAuthorityArrayConfig = {
|
||||
value: 'testLanguageAndAuthorityArray',
|
||||
display: 'testLanguageAndAuthorityArray',
|
||||
id: 'testLanguageAndAuthorityArray',
|
||||
}]
|
||||
}],
|
||||
workspaceItem: new Workspaceitem()
|
||||
};
|
||||
|
||||
export const mockInputWithLanguageAndAuthorityArrayModel = new DsDynamicInputModel(inputWithLanguageAndAuthorityArrayConfig);
|
||||
@@ -213,7 +219,8 @@ export const inputWithFormFieldValueConfig = {
|
||||
id: 'testWithFormField',
|
||||
readOnly: false,
|
||||
disabled: false,
|
||||
value: new FormFieldMetadataValueObject('testWithFormFieldValue')
|
||||
value: new FormFieldMetadataValueObject('testWithFormFieldValue'),
|
||||
workspaceItem: new Workspaceitem()
|
||||
};
|
||||
|
||||
export const mockInputWithFormFieldValueModel = new DsDynamicInputModel(inputWithFormFieldValueConfig);
|
||||
@@ -223,7 +230,8 @@ export const inputWithAuthorityValueConfig = {
|
||||
id: 'testWithAuthorityField',
|
||||
readOnly: false,
|
||||
disabled: false,
|
||||
value: Object.assign({}, new AuthorityValue(), { value: 'testWithAuthorityValue', id: 'testWithAuthorityValue', display: 'testWithAuthorityValue' })
|
||||
value: Object.assign({}, new AuthorityValue(), { value: 'testWithAuthorityValue', id: 'testWithAuthorityValue', display: 'testWithAuthorityValue' }),
|
||||
workspaceItem: new Workspaceitem()
|
||||
};
|
||||
|
||||
export const mockInputWithAuthorityValueModel = new DsDynamicInputModel(inputWithAuthorityValueConfig);
|
||||
@@ -233,7 +241,8 @@ export const inputWithObjectValueConfig = {
|
||||
id: 'testWithObjectValue',
|
||||
readOnly: false,
|
||||
disabled: false,
|
||||
value: { value: 'testWithObjectValue', id: 'testWithObjectValue', display: 'testWithObjectValue' }
|
||||
value: { value: 'testWithObjectValue', id: 'testWithObjectValue', display: 'testWithObjectValue' },
|
||||
workspaceItem: new Workspaceitem()
|
||||
};
|
||||
|
||||
export const mockInputWithObjectValueModel = new DsDynamicInputModel(inputWithObjectValueConfig);
|
||||
@@ -248,6 +257,7 @@ export const fileFormEditInputConfig = {
|
||||
id: 'dc_title',
|
||||
readOnly: false,
|
||||
disabled: false,
|
||||
workspaceItem: new Workspaceitem()
|
||||
};
|
||||
|
||||
export const mockFileFormEditInputModel = new DsDynamicInputModel(fileFormEditInputConfig);
|
||||
|
@@ -43,6 +43,10 @@ import { DsDynamicInputModel } from '../../../shared/form/builder/ds-dynamic-for
|
||||
import { SubmissionSectionError } from '../../objects/submission-objects.reducer';
|
||||
import { DynamicFormControlEvent, DynamicFormControlEventType } from '@ng-dynamic-forms/core';
|
||||
import { JsonPatchOperationPathCombiner } from '../../../core/json-patch/builder/json-patch-operation-path-combiner';
|
||||
import { WorkspaceitemDataService } from '../../../core/submission/workspaceitem-data.service';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
import { Workspaceitem } from '../../../core/submission/models/workspaceitem.model';
|
||||
|
||||
function getMockSubmissionFormsConfigService(): SubmissionFormsConfigService {
|
||||
return jasmine.createSpyObj('FormOperationsService', {
|
||||
@@ -179,6 +183,7 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
{ provide: 'collectionIdProvider', useValue: collectionId },
|
||||
{ provide: 'sectionDataProvider', useValue: sectionObject },
|
||||
{ provide: 'submissionIdProvider', useValue: submissionId },
|
||||
{ provide: WorkspaceitemDataService, useValue: {getById: observableOf(new RemoteData(false, false, true, null, new Workspaceitem()))}},
|
||||
ChangeDetectorRef,
|
||||
SubmissionSectionformComponent
|
||||
],
|
||||
|
@@ -15,7 +15,10 @@ import { hasValue, isNotEmpty, isUndefined } from '../../../shared/empty.util';
|
||||
import { ConfigData } from '../../../core/config/config-data';
|
||||
import { JsonPatchOperationPathCombiner } from '../../../core/json-patch/builder/json-patch-operation-path-combiner';
|
||||
import { SubmissionFormsModel } from '../../../core/config/models/config-submission-forms.model';
|
||||
import { SubmissionSectionError, SubmissionSectionObject } from '../../objects/submission-objects.reducer';
|
||||
import {
|
||||
SubmissionSectionError,
|
||||
SubmissionSectionObject
|
||||
} from '../../objects/submission-objects.reducer';
|
||||
import { FormFieldPreviousValueObject } from '../../../shared/form/builder/models/form-field-previous-value-object';
|
||||
import { GLOBAL_CONFIG } from '../../../../config';
|
||||
import { GlobalConfig } from '../../../../config/global-config.interface';
|
||||
@@ -28,6 +31,11 @@ import { NotificationsService } from '../../../shared/notifications/notification
|
||||
import { SectionsService } from '../sections.service';
|
||||
import { difference } from '../../../shared/object.util';
|
||||
import { WorkspaceitemSectionFormObject } from '../../../core/submission/models/workspaceitem-section-form.model';
|
||||
import { Workspaceitem } from '../../../core/submission/models/workspaceitem.model';
|
||||
import { WorkspaceitemDataService } from '../../../core/submission/workspaceitem-data.service';
|
||||
import { combineLatest as combineLatestObservable } from 'rxjs';
|
||||
import { getSucceededRemoteData } from '../../../core/shared/operators';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
|
||||
/**
|
||||
* This component represents a section that contains a Form.
|
||||
@@ -94,6 +102,7 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
||||
*/
|
||||
protected subs: Subscription[] = [];
|
||||
|
||||
protected workspaceItem;
|
||||
/**
|
||||
* The FormComponent reference
|
||||
*/
|
||||
@@ -125,6 +134,7 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
||||
protected sectionService: SectionsService,
|
||||
protected submissionService: SubmissionService,
|
||||
protected translate: TranslateService,
|
||||
protected workspaceItemDataService: WorkspaceitemDataService,
|
||||
@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
|
||||
@Inject('collectionIdProvider') public injectedCollectionId: string,
|
||||
@Inject('sectionDataProvider') public injectedSectionData: SectionDataObject,
|
||||
@@ -138,16 +148,20 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
||||
onSectionInit() {
|
||||
this.pathCombiner = new JsonPatchOperationPathCombiner('sections', this.sectionData.id);
|
||||
this.formId = this.formService.getUniqueId(this.sectionData.id);
|
||||
|
||||
this.formConfigService.getConfigByHref(this.sectionData.config).pipe(
|
||||
map((configData: ConfigData) => configData.payload),
|
||||
tap((config: SubmissionFormsModel) => this.formConfig = config),
|
||||
flatMap(() => this.sectionService.getSectionData(this.submissionId, this.sectionData.id)),
|
||||
flatMap(() =>
|
||||
combineLatestObservable(
|
||||
this.sectionService.getSectionData(this.submissionId, this.sectionData.id),
|
||||
this.workspaceItemDataService.findById(this.submissionId).pipe(getSucceededRemoteData())
|
||||
)),
|
||||
take(1))
|
||||
.subscribe((sectionData: WorkspaceitemSectionFormObject) => {
|
||||
.subscribe(([sectionData, workspaceItem]: [WorkspaceitemSectionFormObject, RemoteData<Workspaceitem>]) => {
|
||||
if (isUndefined(this.formModel)) {
|
||||
this.sectionData.errors = [];
|
||||
// Is the first loading so init form
|
||||
this.workspaceItem = workspaceItem;
|
||||
this.initForm(sectionData);
|
||||
this.sectionData.data = sectionData;
|
||||
this.subscriptions();
|
||||
@@ -212,7 +226,9 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
||||
this.formConfig,
|
||||
this.collectionId,
|
||||
sectionData,
|
||||
this.submissionService.getSubmissionScope());
|
||||
this.workspaceItem,
|
||||
this.submissionService.getSubmissionScope()
|
||||
);
|
||||
} catch (e) {
|
||||
const msg: string = this.translate.instant('error.submission.sections.init-form-error') + e.toString();
|
||||
const sectionError: SubmissionSectionError = {
|
||||
|
@@ -84,7 +84,7 @@ export class SectionsService {
|
||||
} else if (!isEqual(currentErrors, prevErrors)) { // compare previous error list with the current one
|
||||
const dispatchedErrors = [];
|
||||
|
||||
// Itereate over the current error list
|
||||
// Iterate over the current error list
|
||||
currentErrors.forEach((error: SubmissionSectionError) => {
|
||||
const errorPaths: SectionErrorPath[] = parseSectionErrorPaths(error.path);
|
||||
|
||||
|
@@ -169,6 +169,7 @@ export class SubmissionSectionUploadFileEditComponent implements OnChanges {
|
||||
configForm,
|
||||
this.collectionId,
|
||||
this.fileData.metadata,
|
||||
undefined,
|
||||
this.submissionService.getSubmissionScope()
|
||||
);
|
||||
formModel.push(new DynamicFormGroupModel(metadataGroupModelConfig, BITSTREAM_METADATA_FORM_GROUP_LAYOUT));
|
||||
|
Reference in New Issue
Block a user