mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
Merge branch 'fix-metadata-fields-containing-dots_contribute-7.4' into fix-metadata-fields-containing-dots_contribute-main
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
|
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
|
|
||||||
import { MetadataSchemaFormComponent } from './metadata-schema-form.component';
|
import { MetadataSchemaFormComponent } from './metadata-schema-form.component';
|
||||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
@@ -30,7 +29,7 @@ describe('MetadataSchemaFormComponent', () => {
|
|||||||
return {
|
return {
|
||||||
patchValue: () => {
|
patchValue: () => {
|
||||||
},
|
},
|
||||||
markAsUntouched(opts?: any) {
|
reset(_value?: any, _options?: { onlySelf?: boolean; emitEvent?: boolean; }): void {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -38,7 +37,7 @@ describe('MetadataSchemaFormComponent', () => {
|
|||||||
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
|
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
return TestBed.configureTestingModule({
|
||||||
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
|
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
|
||||||
declarations: [MetadataSchemaFormComponent, EnumKeysPipe],
|
declarations: [MetadataSchemaFormComponent, EnumKeysPipe],
|
||||||
providers: [
|
providers: [
|
||||||
@@ -66,7 +65,7 @@ describe('MetadataSchemaFormComponent', () => {
|
|||||||
const expected = Object.assign(new MetadataSchema(), {
|
const expected = Object.assign(new MetadataSchema(), {
|
||||||
namespace: namespace,
|
namespace: namespace,
|
||||||
prefix: prefix
|
prefix: prefix
|
||||||
});
|
} as MetadataSchema);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(component.submitForm, 'emit');
|
spyOn(component.submitForm, 'emit');
|
||||||
@@ -81,11 +80,10 @@ describe('MetadataSchemaFormComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit a new schema using the correct values', waitForAsync(() => {
|
it('should emit a new schema using the correct values', async () => {
|
||||||
fixture.whenStable().then(() => {
|
await fixture.whenStable();
|
||||||
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
|
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with an active schema', () => {
|
describe('with an active schema', () => {
|
||||||
@@ -93,7 +91,7 @@ describe('MetadataSchemaFormComponent', () => {
|
|||||||
id: 1,
|
id: 1,
|
||||||
namespace: namespace,
|
namespace: namespace,
|
||||||
prefix: prefix
|
prefix: prefix
|
||||||
});
|
} as MetadataSchema);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(registryService, 'getActiveMetadataSchema').and.returnValue(observableOf(expectedWithId));
|
spyOn(registryService, 'getActiveMetadataSchema').and.returnValue(observableOf(expectedWithId));
|
||||||
@@ -101,11 +99,10 @@ describe('MetadataSchemaFormComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should edit the existing schema using the correct values', waitForAsync(() => {
|
it('should edit the existing schema using the correct values', async () => {
|
||||||
fixture.whenStable().then(() => {
|
await fixture.whenStable();
|
||||||
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
|
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -87,9 +87,12 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
|
|||||||
name: 'name',
|
name: 'name',
|
||||||
validators: {
|
validators: {
|
||||||
required: null,
|
required: null,
|
||||||
pattern: '^[^ ,_]{1,32}$'
|
pattern: '^[^. ,_]{1,32}$',
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
|
errorMessages: {
|
||||||
|
pattern: 'error.validation.metadata.namespace.invalid-pattern',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
this.namespace = new DynamicInputModel({
|
this.namespace = new DynamicInputModel({
|
||||||
id: 'namespace',
|
id: 'namespace',
|
||||||
@@ -97,12 +100,8 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
|
|||||||
name: 'namespace',
|
name: 'namespace',
|
||||||
validators: {
|
validators: {
|
||||||
required: null,
|
required: null,
|
||||||
pattern: '^[^.]*$',
|
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
errorMessages: {
|
|
||||||
pattern: 'error.validation.metadata.namespace.invalid-pattern',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
this.formModel = [
|
this.formModel = [
|
||||||
new DynamicFormGroupModel(
|
new DynamicFormGroupModel(
|
||||||
@@ -112,13 +111,18 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
|
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
|
||||||
this.registryService.getActiveMetadataSchema().subscribe((schema) => {
|
this.registryService.getActiveMetadataSchema().subscribe((schema: MetadataSchema) => {
|
||||||
|
if (schema == null) {
|
||||||
|
this.clearFields();
|
||||||
|
} else {
|
||||||
this.formGroup.patchValue({
|
this.formGroup.patchValue({
|
||||||
metadatadataschemagroup:{
|
metadatadataschemagroup: {
|
||||||
name: schema != null ? schema.prefix : '',
|
name: schema.prefix,
|
||||||
namespace: schema != null ? schema.namespace : ''
|
namespace: schema.namespace,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
this.name.disabled = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -136,10 +140,10 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
|
|||||||
* When the schema has no id attached -> Create new schema
|
* When the schema has no id attached -> Create new schema
|
||||||
* Emit the updated/created schema using the EventEmitter submitForm
|
* Emit the updated/created schema using the EventEmitter submitForm
|
||||||
*/
|
*/
|
||||||
onSubmit() {
|
onSubmit(): void {
|
||||||
this.registryService.clearMetadataSchemaRequests().subscribe();
|
this.registryService.clearMetadataSchemaRequests().subscribe();
|
||||||
this.registryService.getActiveMetadataSchema().pipe(take(1)).subscribe(
|
this.registryService.getActiveMetadataSchema().pipe(take(1)).subscribe(
|
||||||
(schema) => {
|
(schema: MetadataSchema) => {
|
||||||
const values = {
|
const values = {
|
||||||
prefix: this.name.value,
|
prefix: this.name.value,
|
||||||
namespace: this.namespace.value
|
namespace: this.namespace.value
|
||||||
@@ -151,9 +155,9 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
|
|||||||
} else {
|
} else {
|
||||||
this.registryService.createOrUpdateMetadataSchema(Object.assign(new MetadataSchema(), schema, {
|
this.registryService.createOrUpdateMetadataSchema(Object.assign(new MetadataSchema(), schema, {
|
||||||
id: schema.id,
|
id: schema.id,
|
||||||
prefix: (values.prefix ? values.prefix : schema.prefix),
|
prefix: schema.prefix,
|
||||||
namespace: (values.namespace ? values.namespace : schema.namespace)
|
namespace: values.namespace,
|
||||||
})).subscribe((updatedSchema) => {
|
})).subscribe((updatedSchema: MetadataSchema) => {
|
||||||
this.submitForm.emit(updatedSchema);
|
this.submitForm.emit(updatedSchema);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -166,14 +170,9 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* Reset all input-fields to be empty
|
* Reset all input-fields to be empty
|
||||||
*/
|
*/
|
||||||
clearFields() {
|
clearFields(): void {
|
||||||
this.formGroup.markAsUntouched();
|
this.formGroup.reset('metadatadataschemagroup');
|
||||||
this.formGroup.patchValue({
|
this.name.disabled = false;
|
||||||
metadatadataschemagroup:{
|
|
||||||
name: '',
|
|
||||||
namespace: ''
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -40,7 +40,7 @@ describe('MetadataFieldFormComponent', () => {
|
|||||||
return {
|
return {
|
||||||
patchValue: () => {
|
patchValue: () => {
|
||||||
},
|
},
|
||||||
markAsUntouched(opts?: any) {
|
reset(_value?: any, _options?: { onlySelf?: boolean; emitEvent?: boolean; }): void {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ describe('MetadataFieldFormComponent', () => {
|
|||||||
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
|
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
return TestBed.configureTestingModule({
|
||||||
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
|
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
|
||||||
declarations: [MetadataFieldFormComponent, EnumKeysPipe],
|
declarations: [MetadataFieldFormComponent, EnumKeysPipe],
|
||||||
providers: [
|
providers: [
|
||||||
@@ -100,11 +100,10 @@ describe('MetadataFieldFormComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit a new field using the correct values', waitForAsync(() => {
|
it('should emit a new field using the correct values', async () => {
|
||||||
fixture.whenStable().then(() => {
|
await fixture.whenStable();
|
||||||
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
|
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with an active field', () => {
|
describe('with an active field', () => {
|
||||||
@@ -122,11 +121,10 @@ describe('MetadataFieldFormComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should edit the existing field using the correct values', waitForAsync(() => {
|
it('should edit the existing field using the correct values', async () => {
|
||||||
fixture.whenStable().then(() => {
|
await fixture.whenStable();
|
||||||
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
|
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -142,14 +142,20 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
|
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
|
||||||
this.registryService.getActiveMetadataField().subscribe((field) => {
|
this.registryService.getActiveMetadataField().subscribe((field: MetadataField): void => {
|
||||||
|
if (field == null) {
|
||||||
|
this.clearFields();
|
||||||
|
} else {
|
||||||
this.formGroup.patchValue({
|
this.formGroup.patchValue({
|
||||||
metadatadatafieldgroup: {
|
metadatadatafieldgroup: {
|
||||||
element: field != null ? field.element : '',
|
element: field.element,
|
||||||
qualifier: field != null ? field.qualifier : '',
|
qualifier: field.qualifier,
|
||||||
scopeNote: field != null ? field.scopeNote : ''
|
scopeNote: field.scopeNote,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
this.element.disabled = true;
|
||||||
|
this.qualifier.disabled = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -167,25 +173,24 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
|
|||||||
* When the field has no id attached -> Create new field
|
* When the field has no id attached -> Create new field
|
||||||
* Emit the updated/created field using the EventEmitter submitForm
|
* Emit the updated/created field using the EventEmitter submitForm
|
||||||
*/
|
*/
|
||||||
onSubmit() {
|
onSubmit(): void {
|
||||||
this.registryService.getActiveMetadataField().pipe(take(1)).subscribe(
|
this.registryService.getActiveMetadataField().pipe(take(1)).subscribe(
|
||||||
(field) => {
|
(field: MetadataField) => {
|
||||||
const values = {
|
if (field == null) {
|
||||||
|
this.registryService.createMetadataField(Object.assign(new MetadataField(), {
|
||||||
element: this.element.value,
|
element: this.element.value,
|
||||||
qualifier: this.qualifier.value,
|
qualifier: this.qualifier.value,
|
||||||
scopeNote: this.scopeNote.value
|
scopeNote: this.scopeNote.value,
|
||||||
};
|
}), this.metadataSchema).subscribe((newField: MetadataField) => {
|
||||||
if (field == null) {
|
|
||||||
this.registryService.createMetadataField(Object.assign(new MetadataField(), values), this.metadataSchema).subscribe((newField) => {
|
|
||||||
this.submitForm.emit(newField);
|
this.submitForm.emit(newField);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.registryService.updateMetadataField(Object.assign(new MetadataField(), field, {
|
this.registryService.updateMetadataField(Object.assign(new MetadataField(), field, {
|
||||||
id: field.id,
|
id: field.id,
|
||||||
element: (values.element ? values.element : field.element),
|
element: field.element,
|
||||||
qualifier: (values.qualifier ? values.qualifier : field.qualifier),
|
qualifier: field.qualifier,
|
||||||
scopeNote: (values.scopeNote ? values.scopeNote : field.scopeNote)
|
scopeNote: this.scopeNote.value,
|
||||||
})).subscribe((updatedField) => {
|
})).subscribe((updatedField: MetadataField) => {
|
||||||
this.submitForm.emit(updatedField);
|
this.submitForm.emit(updatedField);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -198,15 +203,10 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* Reset all input-fields to be empty
|
* Reset all input-fields to be empty
|
||||||
*/
|
*/
|
||||||
clearFields() {
|
clearFields(): void {
|
||||||
this.formGroup.markAsUntouched();
|
this.formGroup.reset('metadatadatafieldgroup');
|
||||||
this.formGroup.patchValue({
|
this.element.disabled = false;
|
||||||
metadatadatafieldgroup: {
|
this.qualifier.disabled = false;
|
||||||
element: '',
|
|
||||||
qualifier: '',
|
|
||||||
scopeNote: ''
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user