Skip to content

Commit 24e6cdd

Browse files
100553: Removed possibility to updated schema name, element and qualifier
1 parent 792a614 commit 24e6cdd

4 files changed

Lines changed: 75 additions & 81 deletions

File tree

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

Lines changed: 12 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';
@@ -30,15 +29,15 @@ describe('MetadataSchemaFormComponent', () => {
3029
return {
3130
patchValue: () => {
3231
},
33-
markAsUntouched(opts?: any) {
32+
reset(_value?: any, _options?: { onlySelf?: boolean; emitEvent?: boolean; }): void {
3433
},
3534
};
3635
}
3736
};
3837
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
3938

4039
beforeEach(waitForAsync(() => {
41-
TestBed.configureTestingModule({
40+
return TestBed.configureTestingModule({
4241
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
4342
declarations: [MetadataSchemaFormComponent, EnumKeysPipe],
4443
providers: [
@@ -66,7 +65,7 @@ describe('MetadataSchemaFormComponent', () => {
6665
const expected = Object.assign(new MetadataSchema(), {
6766
namespace: namespace,
6867
prefix: prefix
69-
});
68+
} as MetadataSchema);
7069

7170
beforeEach(() => {
7271
spyOn(component.submitForm, 'emit');
@@ -81,31 +80,29 @@ describe('MetadataSchemaFormComponent', () => {
8180
fixture.detectChanges();
8281
});
8382

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

9189
describe('with an active schema', () => {
9290
const expectedWithId = Object.assign(new MetadataSchema(), {
9391
id: 1,
9492
namespace: namespace,
9593
prefix: prefix
96-
});
94+
} as MetadataSchema);
9795

9896
beforeEach(() => {
9997
spyOn(registryService, 'getActiveMetadataSchema').and.returnValue(observableOf(expectedWithId));
10098
component.onSubmit();
10199
fixture.detectChanges();
102100
});
103101

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

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

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,21 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
8787
name: 'name',
8888
validators: {
8989
required: null,
90-
pattern: '^[^ ,_]{1,32}$'
90+
pattern: '^[^. ,_]{1,32}$',
9191
},
9292
required: true,
93+
errorMessages: {
94+
pattern: 'error.validation.metadata.namespace.invalid-pattern',
95+
},
9396
});
9497
this.namespace = new DynamicInputModel({
9598
id: 'namespace',
9699
label: namespace,
97100
name: 'namespace',
98101
validators: {
99102
required: null,
100-
pattern: '^[^.]*$',
101103
},
102104
required: true,
103-
errorMessages: {
104-
pattern: 'error.validation.metadata.namespace.invalid-pattern',
105-
},
106105
});
107106
this.formModel = [
108107
new DynamicFormGroupModel(
@@ -112,13 +111,18 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
112111
})
113112
];
114113
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
115-
this.registryService.getActiveMetadataSchema().subscribe((schema) => {
116-
this.formGroup.patchValue({
117-
metadatadataschemagroup:{
118-
name: schema != null ? schema.prefix : '',
119-
namespace: schema != null ? schema.namespace : ''
120-
}
121-
});
114+
this.registryService.getActiveMetadataSchema().subscribe((schema: MetadataSchema) => {
115+
if (schema == null) {
116+
this.clearFields();
117+
} else {
118+
this.formGroup.patchValue({
119+
metadatadataschemagroup: {
120+
name: schema.prefix,
121+
namespace: schema.namespace,
122+
},
123+
});
124+
this.name.disabled = true;
125+
}
122126
});
123127
});
124128
}
@@ -136,10 +140,10 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
136140
* When the schema has no id attached -> Create new schema
137141
* Emit the updated/created schema using the EventEmitter submitForm
138142
*/
139-
onSubmit() {
143+
onSubmit(): void {
140144
this.registryService.clearMetadataSchemaRequests().subscribe();
141145
this.registryService.getActiveMetadataSchema().pipe(take(1)).subscribe(
142-
(schema) => {
146+
(schema: MetadataSchema) => {
143147
const values = {
144148
prefix: this.name.value,
145149
namespace: this.namespace.value
@@ -151,9 +155,9 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
151155
} else {
152156
this.registryService.createOrUpdateMetadataSchema(Object.assign(new MetadataSchema(), schema, {
153157
id: schema.id,
154-
prefix: (values.prefix ? values.prefix : schema.prefix),
155-
namespace: (values.namespace ? values.namespace : schema.namespace)
156-
})).subscribe((updatedSchema) => {
158+
prefix: schema.prefix,
159+
namespace: values.namespace,
160+
})).subscribe((updatedSchema: MetadataSchema) => {
157161
this.submitForm.emit(updatedSchema);
158162
});
159163
}
@@ -166,14 +170,9 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
166170
/**
167171
* Reset all input-fields to be empty
168172
*/
169-
clearFields() {
170-
this.formGroup.markAsUntouched();
171-
this.formGroup.patchValue({
172-
metadatadataschemagroup:{
173-
name: '',
174-
namespace: ''
175-
}
176-
});
173+
clearFields(): void {
174+
this.formGroup.reset('metadatadataschemagroup');
175+
this.name.disabled = false;
177176
}
178177

179178
/**

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ describe('MetadataFieldFormComponent', () => {
4040
return {
4141
patchValue: () => {
4242
},
43-
markAsUntouched(opts?: any) {
43+
reset(_value?: any, _options?: { onlySelf?: boolean; emitEvent?: boolean; }): void {
4444
},
4545
};
4646
}
4747
};
4848
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
4949

5050
beforeEach(waitForAsync(() => {
51-
TestBed.configureTestingModule({
51+
return TestBed.configureTestingModule({
5252
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
5353
declarations: [MetadataFieldFormComponent, EnumKeysPipe],
5454
providers: [
@@ -100,11 +100,10 @@ describe('MetadataFieldFormComponent', () => {
100100
fixture.detectChanges();
101101
});
102102

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

110109
describe('with an active field', () => {
@@ -122,11 +121,10 @@ describe('MetadataFieldFormComponent', () => {
122121
fixture.detectChanges();
123122
});
124123

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

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,20 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
142142
})
143143
];
144144
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
145-
this.registryService.getActiveMetadataField().subscribe((field) => {
146-
this.formGroup.patchValue({
147-
metadatadatafieldgroup: {
148-
element: field != null ? field.element : '',
149-
qualifier: field != null ? field.qualifier : '',
150-
scopeNote: field != null ? field.scopeNote : ''
151-
}
152-
});
145+
this.registryService.getActiveMetadataField().subscribe((field: MetadataField): void => {
146+
if (field == null) {
147+
this.clearFields();
148+
} else {
149+
this.formGroup.patchValue({
150+
metadatadatafieldgroup: {
151+
element: field.element,
152+
qualifier: field.qualifier,
153+
scopeNote: field.scopeNote,
154+
},
155+
});
156+
this.element.disabled = true;
157+
this.qualifier.disabled = true;
158+
}
153159
});
154160
});
155161
}
@@ -167,25 +173,24 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
167173
* When the field has no id attached -> Create new field
168174
* Emit the updated/created field using the EventEmitter submitForm
169175
*/
170-
onSubmit() {
176+
onSubmit(): void {
171177
this.registryService.getActiveMetadataField().pipe(take(1)).subscribe(
172-
(field) => {
173-
const values = {
174-
element: this.element.value,
175-
qualifier: this.qualifier.value,
176-
scopeNote: this.scopeNote.value
177-
};
178+
(field: MetadataField) => {
178179
if (field == null) {
179-
this.registryService.createMetadataField(Object.assign(new MetadataField(), values), this.metadataSchema).subscribe((newField) => {
180+
this.registryService.createMetadataField(Object.assign(new MetadataField(), {
181+
element: this.element.value,
182+
qualifier: this.qualifier.value,
183+
scopeNote: this.scopeNote.value,
184+
}), this.metadataSchema).subscribe((newField: MetadataField) => {
180185
this.submitForm.emit(newField);
181186
});
182187
} else {
183188
this.registryService.updateMetadataField(Object.assign(new MetadataField(), field, {
184189
id: field.id,
185-
element: (values.element ? values.element : field.element),
186-
qualifier: (values.qualifier ? values.qualifier : field.qualifier),
187-
scopeNote: (values.scopeNote ? values.scopeNote : field.scopeNote)
188-
})).subscribe((updatedField) => {
190+
element: field.element,
191+
qualifier: field.qualifier,
192+
scopeNote: this.scopeNote.value,
193+
})).subscribe((updatedField: MetadataField) => {
189194
this.submitForm.emit(updatedField);
190195
});
191196
}
@@ -198,15 +203,10 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
198203
/**
199204
* Reset all input-fields to be empty
200205
*/
201-
clearFields() {
202-
this.formGroup.markAsUntouched();
203-
this.formGroup.patchValue({
204-
metadatadatafieldgroup: {
205-
element: '',
206-
qualifier: '',
207-
scopeNote: ''
208-
}
209-
});
206+
clearFields(): void {
207+
this.formGroup.reset('metadatadatafieldgroup');
208+
this.element.disabled = false;
209+
this.qualifier.disabled = false;
210210
}
211211

212212
/**

0 commit comments

Comments
 (0)