Skip to content

Commit d59249b

Browse files
[DURACOM-413] update error handling/validation + resync translations
1 parent 88d13c7 commit d59249b

8 files changed

Lines changed: 69 additions & 11 deletions

File tree

src/app/submission/edit/submission-edit.component.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ describe('SubmissionEditComponent Component', () => {
5151

5252
const submissionId = '826';
5353
const route: ActivatedRouteStub = new ActivatedRouteStub();
54-
const submissionObject: any = mockSubmissionObject;
54+
const submissionObject: any = Object.assign({}, mockSubmissionObject, {
55+
collection: {
56+
...mockSubmissionObject.collection,
57+
hasMetadata: (_: string) => true,
58+
firstMetadataValue: (_: string) => true,
59+
},
60+
});
5561

5662
beforeEach(waitForAsync(() => {
5763
itemDataService = jasmine.createSpyObj('itemDataService', {

src/app/submission/edit/submission-edit.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,8 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
160160
this.router.navigate(['/mydspace']);
161161
} else {
162162
const collection = submissionObjectRD.payload.collection as Collection;
163-
const entityType = collection.hasMetadata('dspace.entity.type') ? collection.firstMetadataValue('dspace.entity.type') : null;
164-
if (hasValue(entityType)) {
165-
this.entityType = entityType;
166-
}
163+
this.entityType = (hasValue(collection) && collection.hasMetadata('dspace.entity.type'))
164+
? collection.firstMetadataValue('dspace.entity.type') : null;
167165
const { errors } = submissionObjectRD.payload;
168166
this.submissionErrors = parseSectionErrors(errors);
169167
this.submissionId = submissionObjectRD.payload.id.toString();

src/app/submission/sections/custom-url/submission-section-custom-url.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ <h4 >{{'submission.sections.custom-url.label.previous-urls' | translate}}</h4>
3333
}
3434
</ul>
3535
</div>
36-
3736
}
3837
</div>

src/app/submission/sections/custom-url/submission-section-custom-url.component.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import {
2+
AfterViewInit,
23
Component,
34
Inject,
5+
ViewChild,
46
} from '@angular/core';
7+
import {
8+
AbstractControl,
9+
ValidationErrors,
10+
} from '@angular/forms';
511
import { JsonPatchOperationPathCombiner } from '@dspace/core/json-patch/builder/json-patch-operation-path-combiner';
612
import { JsonPatchOperationsBuilder } from '@dspace/core/json-patch/builder/json-patch-operations-builder';
713
import { SubmissionSectionError } from '@dspace/core/submission/models/submission-section-error.model';
@@ -40,6 +46,8 @@ import { SectionFormOperationsService } from '../form/section-form-operations.se
4046
import { SectionModelComponent } from '../models/section.model';
4147
import { SectionDataObject } from '../models/section-data.model';
4248
import { SectionsService } from '../sections.service';
49+
50+
4351
/**
4452
* This component represents the submission section to select the Creative Commons license.
4553
*/
@@ -53,7 +61,7 @@ import { SectionsService } from '../sections.service';
5361
],
5462
standalone: true,
5563
})
56-
export class SubmissionSectionCustomUrlComponent extends SectionModelComponent {
64+
export class SubmissionSectionCustomUrlComponent extends SectionModelComponent implements AfterViewInit {
5765

5866
/**
5967
* The form id
@@ -103,6 +111,13 @@ export class SubmissionSectionCustomUrlComponent extends SectionModelComponent {
103111
*/
104112
redirectedUrls: string[] = [];
105113

114+
private readonly errorMessagePrefix = 'error.validation.custom-url.';
115+
116+
/**
117+
* The FormComponent reference
118+
*/
119+
@ViewChild('formRef') public formRef: FormComponent;
120+
106121
constructor(
107122
protected sectionService: SectionsService,
108123
protected operationsBuilder: JsonPatchOperationsBuilder,
@@ -181,7 +196,6 @@ export class SubmissionSectionCustomUrlComponent extends SectionModelComponent {
181196
* the section data retrieved from the server
182197
*/
183198
initForm(sectionData: WorkspaceitemSectionCustomUrlObject): void {
184-
const model =
185199
this.formModel = [
186200
new DynamicInputModel({
187201
id: 'url',
@@ -198,6 +212,42 @@ export class SubmissionSectionCustomUrlComponent extends SectionModelComponent {
198212
this.updateSectionData(sectionData);
199213
}
200214

215+
customUrlValidator = (_: AbstractControl): ValidationErrors | null => {
216+
if (this.sectionData.errorsToShow?.length) {
217+
const urlErrors = this.sectionData.errorsToShow.map((error) =>
218+
error.message.replace(this.errorMessagePrefix, ''));
219+
const validationErrors: ValidationErrors = {};
220+
221+
urlErrors.forEach((error) => {
222+
validationErrors[error] = true;
223+
});
224+
return validationErrors;
225+
}
226+
return null;
227+
};
228+
229+
/**
230+
* Update control status
231+
* @param addValidator
232+
*/
233+
updateControlStatus(addValidator = false): void {
234+
const control = this.formRef?.formGroup?.get('url');
235+
if (control) {
236+
if (addValidator) {
237+
control.addValidators(this.customUrlValidator);
238+
// reset errors on user input
239+
this.subs.push(control.valueChanges.subscribe(() => {
240+
control.setErrors(null);
241+
}));
242+
}
243+
control.updateValueAndValidity({ onlySelf: true, emitEvent: false });
244+
}
245+
}
246+
247+
ngAfterViewInit(): void {
248+
this.updateControlStatus(true);
249+
}
250+
201251
/**
202252
* When an information is changed build the formOperations
203253
* If the submission scope is in EditItem also manage redirected-urls formOperations
@@ -250,6 +300,7 @@ export class SubmissionSectionCustomUrlComponent extends SectionModelComponent {
250300
if (isNotEmpty(errors) || isNotEmpty(this.sectionData.errorsToShow)) {
251301
this.sectionService.checkSectionErrors(this.submissionId, this.sectionData.id, this.formId, errors, this.sectionData.errorsToShow);
252302
this.sectionData.errorsToShow = errors;
303+
this.updateControlStatus(true);
253304
}
254305
}),
255306
);

src/app/submission/utils/submission.mock.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ export const mockSubmissionObject = {
404404
language: null,
405405
value: 'Collection of Sample Items',
406406
},
407+
{
408+
key: 'dspace.entity.type',
409+
language: null,
410+
value: 'Entity type of Sample Collection',
411+
},
407412
],
408413
_links: {
409414
license: { href: 'https://rest.api/dspace-spring-rest/api/core/collections/1c11f3f1-ba1f-4f36-908a-3f1ea9a557eb/license' },

src/assets/i18n/gu.json5

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4765,6 +4765,7 @@
47654765
"item.preview.dc.identifier.openalex": "ઓપનએલેક્સ પરિચયકર્તા",
47664766

47674767
// "item.preview.dc.description": "Description",
4768+
// TODO Source message changed - Revise the translation
47684769
"item.preview.dc.description": "વર્ણન:",
47694770

47704771
// "item.select.confirm": "Confirm selected",

src/assets/i18n/mr.json5

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4760,6 +4760,7 @@
47604760
"item.preview.dc.identifier.openalex": "OpenAlex ओळखकर्ता",
47614761

47624762
// "item.preview.dc.description": "Description",
4763+
// TODO Source message changed - Revise the translation
47634764
"item.preview.dc.description": "वर्णन:",
47644765

47654766
// "item.select.confirm": "Confirm selected",

src/config/default-app-config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ export class DefaultAppConfig implements AppConfig {
137137
validatorMap: {
138138
required: 'required',
139139
regex: 'pattern',
140-
conflict: 'conflict',
141-
empty: 'empty',
142-
'invalid-characters': 'invalid-characters',
143140
},
144141
};
145142

0 commit comments

Comments
 (0)