Skip to content

Commit b434224

Browse files
Merged in task/dspace-cris-2023_02_x/DSC-1735 (pull request DSpace#1772)
Task/dspace cris 2023 02 x/DSC-1735
2 parents 76089f5 + 76d0daa commit b434224

5 files changed

Lines changed: 26 additions & 46 deletions

File tree

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
Component,
44
ComponentFactoryResolver,
55
ContentChildren,
6-
EventEmitter,
7-
Inject,
6+
EventEmitter, Inject,
87
Input,
98
NgZone,
109
OnChanges,
@@ -59,9 +58,7 @@ import { TranslateService } from '@ngx-translate/core';
5958
import { ReorderableRelationship } from './existing-metadata-list-element/existing-metadata-list-element.component';
6059

6160
import { DYNAMIC_FORM_CONTROL_TYPE_ONEBOX } from './models/onebox/dynamic-onebox.model';
62-
import {
63-
DYNAMIC_FORM_CONTROL_TYPE_SCROLLABLE_DROPDOWN
64-
} from './models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
61+
import { DYNAMIC_FORM_CONTROL_TYPE_SCROLLABLE_DROPDOWN } from './models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
6562
import { DYNAMIC_FORM_CONTROL_TYPE_TAG } from './models/tag/dynamic-tag.model';
6663
import { DYNAMIC_FORM_CONTROL_TYPE_DSDATEPICKER } from './models/date-picker/date-picker.model';
6764
import { DYNAMIC_FORM_CONTROL_TYPE_LOOKUP } from './models/lookup/dynamic-lookup.model';
@@ -73,9 +70,7 @@ import { DsDynamicTagComponent } from './models/tag/dynamic-tag.component';
7370
import { DsDatePickerComponent } from './models/date-picker/date-picker.component';
7471
import { DsDynamicListComponent } from './models/list/dynamic-list.component';
7572
import { DsDynamicOneboxComponent } from './models/onebox/dynamic-onebox.component';
76-
import {
77-
DsDynamicScrollableDropdownComponent
78-
} from './models/scrollable-dropdown/dynamic-scrollable-dropdown.component';
73+
import { DsDynamicScrollableDropdownComponent } from './models/scrollable-dropdown/dynamic-scrollable-dropdown.component';
7974
import { DsDynamicLookupComponent } from './models/lookup/dynamic-lookup.component';
8075
import { DsDynamicFormGroupComponent } from './models/form-group/dynamic-form-group.component';
8176
import { DsDynamicFormArrayComponent } from './models/array-group/dynamic-form-array.component';
@@ -87,9 +82,7 @@ import { CustomSwitchComponent } from './models/custom-switch/custom-switch.comp
8782
import { find, map, startWith, switchMap, take } from 'rxjs/operators';
8883
import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
8984
import { DsDynamicTypeBindRelationService } from './ds-dynamic-type-bind-relation.service';
90-
import {
91-
DsDynamicRelationInlineGroupComponent
92-
} from './models/relation-inline-group/dynamic-relation-inline-group.components';
85+
import { DsDynamicRelationInlineGroupComponent } from './models/relation-inline-group/dynamic-relation-inline-group.components';
9386
import { SearchResult } from '../../../search/models/search-result.model';
9487
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
9588
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
@@ -130,6 +123,7 @@ import { APP_CONFIG, AppConfig } from '../../../../../config/app-config.interfac
130123
import { itemLinksToFollow } from '../../../utils/relation-query.utils';
131124
import { DynamicConcatModel } from './models/ds-dynamic-concat.model';
132125
import { Metadata } from '../../../../core/shared/metadata.utils';
126+
import { DynamicLinkModel } from './models/ds-dynamic-link.model';
133127

134128
export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type<DynamicFormControl> | null {
135129
switch (model.type) {
@@ -555,13 +549,13 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
555549
addSecurityLevelToMetadata($event) {
556550
this.model.securityLevel = $event;
557551
this.securityLevel = $event;
558-
if (this.model.parent && this.model.parent instanceof DynamicConcatModel) {
552+
if (this.model.parent && (this.model.parent instanceof DynamicConcatModel || this.model.parent instanceof DynamicLinkModel)) {
559553
this.model.parent.securityLevel = $event;
560554
}
561555
if (this.model.value) {
562556
this.model.securityLevel = $event;
563557
this.securityLevel = $event;
564-
if (this.model.parent && this.model.parent instanceof DynamicConcatModel) {
558+
if (this.model.parent && (this.model.parent instanceof DynamicConcatModel || this.model.parent instanceof DynamicLinkModel)) {
565559
this.model.parent.securityLevel = $event;
566560
}
567561
this.change.emit(

src/app/shared/form/builder/ds-dynamic-form-ui/models/link/dynamic-link.model.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/app/shared/form/form.component.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { DynamicRowGroupModel } from './builder/ds-dynamic-form-ui/models/ds-dyn
2828
import {
2929
DynamicRelationGroupModel
3030
} from './builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.model';
31+
import { DynamicLinkModel } from './builder/ds-dynamic-form-ui/models/ds-dynamic-link.model';
32+
import { DynamicConcatModel } from './builder/ds-dynamic-form-ui/models/ds-dynamic-concat.model';
3133

3234
export interface MetadataFields {
3335
[key: string]: FormFieldMetadataValueObject[]
@@ -78,7 +80,7 @@ export class FormComponent implements OnDestroy, OnInit {
7880
@Input() submitLabel = 'form.submit';
7981

8082
/**
81-
* i18n key for the reset button
83+
* i18n key for the cancel button
8284
*/
8385
@Input() resetLabel = 'form.reset';
8486

@@ -355,7 +357,12 @@ export class FormComponent implements OnDestroy, OnInit {
355357
if (index === 0 && formArrayControl.value?.length === 1) {
356358
event.model = cloneDeep(event.model);
357359
const fieldId = event.model.id;
358-
formArrayControl.at(0).get(fieldId).setValue(null);
360+
361+
if (event.model instanceof DynamicLinkModel || event.model instanceof DynamicConcatModel) {
362+
formArrayControl.at(0).get(fieldId).reset();
363+
} else {
364+
formArrayControl.at(0).get(fieldId).setValue(null);
365+
}
359366
} else {
360367
this.formBuilderService.removeFormArrayGroup(index, formArrayControl, arrayContext);
361368
}
@@ -424,18 +431,18 @@ export class FormComponent implements OnDestroy, OnInit {
424431

425432
private updateMetadataValue(metadataFields: MetadataFields): void {
426433
const metadataKeys = hasValue(metadataFields) ? Object.keys(metadataFields) : [];
427-
const formKeys = hasValue(this.formGroup.value) ? Object.keys(this.formGroup.value) : [];
434+
const formKeys = hasValue(this.formGroup.value) ? Object.keys(this.formGroup.value).map(key => key.replace('_array', '')) : [];
428435

429436
formKeys
430437
.filter((key) => isNotEmpty(this.formGroup.value[key]))
431438
.forEach((key) => {
432-
const innerObjectKeys = (Object.keys(this.formGroup.value[key]) as any[]).map((oldKey) => oldKey.replaceAll('_', '.'));
439+
const innerObjectKeys = (Object.keys(this.formGroup.value[key] ?? {} ) as any[]).map((oldKey) => oldKey.replaceAll('_', '.'));
433440
const filteredKeys = innerObjectKeys.filter(innerKey => metadataKeys.includes(innerKey));
434441
const oldValue = this.formGroup.value[key];
435442

436443
if (filteredKeys.length > 0) {
437444
filteredKeys.forEach((oldValueKey) => {
438-
const newValue = { ...oldValue };
445+
const newValue = {...oldValue};
439446
const formattedKey = (oldValueKey as any).replaceAll('.', '_');
440447
const patchValue = {};
441448

@@ -447,6 +454,6 @@ export class FormComponent implements OnDestroy, OnInit {
447454
}
448455
});
449456
}
450-
});
457+
});
451458
}
452459
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from './form.actions';
2222
import { FormEntry, FormError, FormTouchedState } from './form.reducer';
2323
import { environment } from '../../../environments/environment';
24+
import { DynamicLinkModel } from './builder/ds-dynamic-form-ui/models/ds-dynamic-link.model';
2425

2526
@Injectable()
2627
export class FormService {
@@ -137,6 +138,7 @@ export class FormService {
137138
}
138139

139140
public addErrorToField(field: AbstractControl, model: DynamicFormControlModel, message: string) {
141+
140142
const error = {}; // create the error object
141143
const errorKey = this.getValidatorNameFromMap(message);
142144
let errorMsg = message;
@@ -163,9 +165,9 @@ export class FormService {
163165
}
164166

165167
// if the field in question is a concat group, pass down the error to its fields
166-
if (field instanceof UntypedFormGroup && model instanceof DynamicFormGroupModel && this.formBuilderService.isConcatGroup(model)) {
168+
if ((field instanceof UntypedFormGroup && model instanceof DynamicFormGroupModel && this.formBuilderService.isConcatGroup(model)) || model instanceof DynamicLinkModel) {
167169
model.group.forEach((subModel) => {
168-
const subField = field.controls[subModel.id];
170+
const subField = (field as UntypedFormGroup).controls[subModel.id];
169171

170172
this.addErrorToField(subField, subModel, message);
171173
});

src/assets/i18n/en.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,8 @@
21432143

21442144
"error.validation.groupExists": "This group already exists",
21452145

2146+
"error.validation.invalidProjectURL": "The URL of the project is invalid",
2147+
21462148
"error.validation.metadata.name.invalid-pattern": "This field cannot contain dots, commas or spaces. Please use the Element & Qualifier fields instead",
21472149

21482150
"error.validation.metadata.name.max-length": "This field may not contain more than 32 characters",

0 commit comments

Comments
 (0)