Skip to content

Commit f6f68de

Browse files
authored
Merge branch 'main' into portuguese_pt-PT-message-keys
2 parents 70b1717 + 829b111 commit f6f68de

10 files changed

Lines changed: 322 additions & 114 deletions

File tree

src/app/admin/admin-registries/metadata-registry/metadata-schema-form/metadata-schema-form.component.spec.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
2-
32
import { MetadataSchemaFormComponent } from './metadata-schema-form.component';
43
import { NO_ERRORS_SCHEMA } from '@angular/core';
54
import { CommonModule } from '@angular/common';
@@ -29,14 +28,16 @@ describe('MetadataSchemaFormComponent', () => {
2928
createFormGroup: () => {
3029
return {
3130
patchValue: () => {
32-
}
31+
},
32+
reset(_value?: any, _options?: { onlySelf?: boolean; emitEvent?: boolean; }): void {
33+
},
3334
};
3435
}
3536
};
3637
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
3738

3839
beforeEach(waitForAsync(() => {
39-
TestBed.configureTestingModule({
40+
return TestBed.configureTestingModule({
4041
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
4142
declarations: [MetadataSchemaFormComponent, EnumKeysPipe],
4243
providers: [
@@ -64,7 +65,7 @@ describe('MetadataSchemaFormComponent', () => {
6465
const expected = Object.assign(new MetadataSchema(), {
6566
namespace: namespace,
6667
prefix: prefix
67-
});
68+
} as MetadataSchema);
6869

6970
beforeEach(() => {
7071
spyOn(component.submitForm, 'emit');
@@ -79,31 +80,29 @@ describe('MetadataSchemaFormComponent', () => {
7980
fixture.detectChanges();
8081
});
8182

82-
it('should emit a new schema using the correct values', waitForAsync(() => {
83-
fixture.whenStable().then(() => {
84-
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
85-
});
86-
}));
83+
it('should emit a new schema using the correct values', async () => {
84+
await fixture.whenStable();
85+
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
86+
});
8787
});
8888

8989
describe('with an active schema', () => {
9090
const expectedWithId = Object.assign(new MetadataSchema(), {
9191
id: 1,
9292
namespace: namespace,
9393
prefix: prefix
94-
});
94+
} as MetadataSchema);
9595

9696
beforeEach(() => {
9797
spyOn(registryService, 'getActiveMetadataSchema').and.returnValue(observableOf(expectedWithId));
9898
component.onSubmit();
9999
fixture.detectChanges();
100100
});
101101

102-
it('should edit the existing schema using the correct values', waitForAsync(() => {
103-
fixture.whenStable().then(() => {
104-
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
105-
});
106-
}));
102+
it('should edit the existing schema using the correct values', async () => {
103+
await fixture.whenStable();
104+
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
105+
});
107106
});
108107
});
109108
});

src/app/admin/admin-registries/metadata-registry/metadata-schema-form/metadata-schema-form.component.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,37 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
7777
}
7878

7979
ngOnInit() {
80-
combineLatest(
80+
combineLatest([
8181
this.translateService.get(`${this.messagePrefix}.name`),
8282
this.translateService.get(`${this.messagePrefix}.namespace`)
83-
).subscribe(([name, namespace]) => {
83+
]).subscribe(([name, namespace]) => {
8484
this.name = new DynamicInputModel({
8585
id: 'name',
8686
label: name,
8787
name: 'name',
8888
validators: {
8989
required: null,
90-
pattern: '^[^ ,_]{1,32}$'
90+
pattern: '^[^. ,]*$',
91+
maxLength: 32,
9192
},
9293
required: true,
94+
errorMessages: {
95+
pattern: 'error.validation.metadata.name.invalid-pattern',
96+
maxLength: 'error.validation.metadata.name.max-length',
97+
},
9398
});
9499
this.namespace = new DynamicInputModel({
95100
id: 'namespace',
96101
label: namespace,
97102
name: 'namespace',
98103
validators: {
99104
required: null,
105+
maxLength: 256,
100106
},
101107
required: true,
108+
errorMessages: {
109+
maxLength: 'error.validation.metadata.namespace.max-length',
110+
},
102111
});
103112
this.formModel = [
104113
new DynamicFormGroupModel(
@@ -108,13 +117,18 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
108117
})
109118
];
110119
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
111-
this.registryService.getActiveMetadataSchema().subscribe((schema) => {
112-
this.formGroup.patchValue({
113-
metadatadataschemagroup:{
114-
name: schema != null ? schema.prefix : '',
115-
namespace: schema != null ? schema.namespace : ''
116-
}
117-
});
120+
this.registryService.getActiveMetadataSchema().subscribe((schema: MetadataSchema) => {
121+
if (schema == null) {
122+
this.clearFields();
123+
} else {
124+
this.formGroup.patchValue({
125+
metadatadataschemagroup: {
126+
name: schema.prefix,
127+
namespace: schema.namespace,
128+
},
129+
});
130+
this.name.disabled = true;
131+
}
118132
});
119133
});
120134
}
@@ -132,10 +146,10 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
132146
* When the schema has no id attached -> Create new schema
133147
* Emit the updated/created schema using the EventEmitter submitForm
134148
*/
135-
onSubmit() {
149+
onSubmit(): void {
136150
this.registryService.clearMetadataSchemaRequests().subscribe();
137151
this.registryService.getActiveMetadataSchema().pipe(take(1)).subscribe(
138-
(schema) => {
152+
(schema: MetadataSchema) => {
139153
const values = {
140154
prefix: this.name.value,
141155
namespace: this.namespace.value
@@ -147,9 +161,9 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
147161
} else {
148162
this.registryService.createOrUpdateMetadataSchema(Object.assign(new MetadataSchema(), schema, {
149163
id: schema.id,
150-
prefix: (values.prefix ? values.prefix : schema.prefix),
151-
namespace: (values.namespace ? values.namespace : schema.namespace)
152-
})).subscribe((updatedSchema) => {
164+
prefix: schema.prefix,
165+
namespace: values.namespace,
166+
})).subscribe((updatedSchema: MetadataSchema) => {
153167
this.submitForm.emit(updatedSchema);
154168
});
155169
}
@@ -162,13 +176,9 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
162176
/**
163177
* Reset all input-fields to be empty
164178
*/
165-
clearFields() {
166-
this.formGroup.patchValue({
167-
metadatadataschemagroup:{
168-
prefix: '',
169-
namespace: ''
170-
}
171-
});
179+
clearFields(): void {
180+
this.formGroup.reset('metadatadataschemagroup');
181+
this.name.disabled = false;
172182
}
173183

174184
/**

src/app/admin/admin-registries/metadata-schema/metadata-field-form/metadata-field-form.component.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ describe('MetadataFieldFormComponent', () => {
3939
createFormGroup: () => {
4040
return {
4141
patchValue: () => {
42-
}
42+
},
43+
reset(_value?: any, _options?: { onlySelf?: boolean; emitEvent?: boolean; }): void {
44+
},
4345
};
4446
}
4547
};
4648
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
4749

4850
beforeEach(waitForAsync(() => {
49-
TestBed.configureTestingModule({
51+
return TestBed.configureTestingModule({
5052
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
5153
declarations: [MetadataFieldFormComponent, EnumKeysPipe],
5254
providers: [
@@ -98,11 +100,10 @@ describe('MetadataFieldFormComponent', () => {
98100
fixture.detectChanges();
99101
});
100102

101-
it('should emit a new field using the correct values', waitForAsync(() => {
102-
fixture.whenStable().then(() => {
103-
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
104-
});
105-
}));
103+
it('should emit a new field using the correct values', async () => {
104+
await fixture.whenStable();
105+
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
106+
});
106107
});
107108

108109
describe('with an active field', () => {
@@ -120,11 +121,10 @@ describe('MetadataFieldFormComponent', () => {
120121
fixture.detectChanges();
121122
});
122123

123-
it('should edit the existing field using the correct values', waitForAsync(() => {
124-
fixture.whenStable().then(() => {
125-
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
126-
});
127-
}));
124+
it('should edit the existing field using the correct values', async () => {
125+
await fixture.whenStable();
126+
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
127+
});
128128
});
129129
});
130130
});

src/app/admin/admin-registries/metadata-schema/metadata-field-form/metadata-field-form.component.ts

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,39 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
9898
* Initialize the component, setting up the necessary Models for the dynamic form
9999
*/
100100
ngOnInit() {
101-
combineLatest(
101+
combineLatest([
102102
this.translateService.get(`${this.messagePrefix}.element`),
103103
this.translateService.get(`${this.messagePrefix}.qualifier`),
104104
this.translateService.get(`${this.messagePrefix}.scopenote`)
105-
).subscribe(([element, qualifier, scopenote]) => {
105+
]).subscribe(([element, qualifier, scopenote]) => {
106106
this.element = new DynamicInputModel({
107107
id: 'element',
108108
label: element,
109109
name: 'element',
110110
validators: {
111111
required: null,
112+
pattern: '^[^. ,]*$',
113+
maxLength: 64,
112114
},
113115
required: true,
116+
errorMessages: {
117+
pattern: 'error.validation.metadata.element.invalid-pattern',
118+
maxLength: 'error.validation.metadata.element.max-length',
119+
},
114120
});
115121
this.qualifier = new DynamicInputModel({
116122
id: 'qualifier',
117123
label: qualifier,
118124
name: 'qualifier',
125+
validators: {
126+
pattern: '^[^. ,]*$',
127+
maxLength: 64,
128+
},
119129
required: false,
130+
errorMessages: {
131+
pattern: 'error.validation.metadata.qualifier.invalid-pattern',
132+
maxLength: 'error.validation.metadata.qualifier.max-length',
133+
},
120134
});
121135
this.scopeNote = new DynamicInputModel({
122136
id: 'scopeNote',
@@ -132,14 +146,20 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
132146
})
133147
];
134148
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
135-
this.registryService.getActiveMetadataField().subscribe((field) => {
136-
this.formGroup.patchValue({
137-
metadatadatafieldgroup: {
138-
element: field != null ? field.element : '',
139-
qualifier: field != null ? field.qualifier : '',
140-
scopeNote: field != null ? field.scopeNote : ''
141-
}
142-
});
149+
this.registryService.getActiveMetadataField().subscribe((field: MetadataField): void => {
150+
if (field == null) {
151+
this.clearFields();
152+
} else {
153+
this.formGroup.patchValue({
154+
metadatadatafieldgroup: {
155+
element: field.element,
156+
qualifier: field.qualifier,
157+
scopeNote: field.scopeNote,
158+
},
159+
});
160+
this.element.disabled = true;
161+
this.qualifier.disabled = true;
162+
}
143163
});
144164
});
145165
}
@@ -157,25 +177,24 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
157177
* When the field has no id attached -> Create new field
158178
* Emit the updated/created field using the EventEmitter submitForm
159179
*/
160-
onSubmit() {
180+
onSubmit(): void {
161181
this.registryService.getActiveMetadataField().pipe(take(1)).subscribe(
162-
(field) => {
163-
const values = {
164-
element: this.element.value,
165-
qualifier: this.qualifier.value,
166-
scopeNote: this.scopeNote.value
167-
};
182+
(field: MetadataField) => {
168183
if (field == null) {
169-
this.registryService.createMetadataField(Object.assign(new MetadataField(), values), this.metadataSchema).subscribe((newField) => {
184+
this.registryService.createMetadataField(Object.assign(new MetadataField(), {
185+
element: this.element.value,
186+
qualifier: this.qualifier.value,
187+
scopeNote: this.scopeNote.value,
188+
}), this.metadataSchema).subscribe((newField: MetadataField) => {
170189
this.submitForm.emit(newField);
171190
});
172191
} else {
173192
this.registryService.updateMetadataField(Object.assign(new MetadataField(), field, {
174193
id: field.id,
175-
element: (values.element ? values.element : field.element),
176-
qualifier: (values.qualifier ? values.qualifier : field.qualifier),
177-
scopeNote: (values.scopeNote ? values.scopeNote : field.scopeNote)
178-
})).subscribe((updatedField) => {
194+
element: field.element,
195+
qualifier: field.qualifier,
196+
scopeNote: this.scopeNote.value,
197+
})).subscribe((updatedField: MetadataField) => {
179198
this.submitForm.emit(updatedField);
180199
});
181200
}
@@ -188,14 +207,10 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
188207
/**
189208
* Reset all input-fields to be empty
190209
*/
191-
clearFields() {
192-
this.formGroup.patchValue({
193-
metadatadatafieldgroup: {
194-
element: '',
195-
qualifier: '',
196-
scopeNote: ''
197-
}
198-
});
210+
clearFields(): void {
211+
this.formGroup.reset('metadatadatafieldgroup');
212+
this.element.disabled = false;
213+
this.qualifier.disabled = false;
199214
}
200215

201216
/**

src/app/dso-shared/dso-edit-metadata/metadata-field-selector/metadata-field-selector.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { createPaginatedList } from '../../../shared/testing/utils.test';
1212
import { followLink } from '../../../shared/utils/follow-link-config.model';
1313
import { By } from '@angular/platform-browser';
1414
import { NotificationsService } from '../../../shared/notifications/notifications.service';
15+
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
1516

1617
describe('MetadataFieldSelectorComponent', () => {
1718
let component: MetadataFieldSelectorComponent;
@@ -79,7 +80,7 @@ describe('MetadataFieldSelectorComponent', () => {
7980
});
8081

8182
it('should query the registry service for metadata fields and include the schema', () => {
82-
expect(registryService.queryMetadataFields).toHaveBeenCalledWith(query, null, true, false, followLink('schema'));
83+
expect(registryService.queryMetadataFields).toHaveBeenCalledWith(query, { elementsPerPage: 10, sort: new SortOptions('fieldName', SortDirection.ASC) }, true, false, followLink('schema'));
8384
});
8485
});
8586

0 commit comments

Comments
 (0)