diff --git a/src/app/item-page/full/full-item-page.component.html b/src/app/item-page/full/full-item-page.component.html index 6a6e1f31573..4556077d5ce 100644 --- a/src/app/item-page/full/full-item-page.component.html +++ b/src/app/item-page/full/full-item-page.component.html @@ -47,7 +47,12 @@ {{mdEntry.key}} - + + + + + + diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/clarin-name.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/clarin-name.model.ts index 99b1c3fcee5..9b5c6cf3d06 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/clarin-name.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/clarin-name.model.ts @@ -38,7 +38,7 @@ export class DynamicClarinNameModel extends DynamicConcatModel { constructor(config: DynamicConcatModelConfig, layout?: DynamicFormControlLayout) { super(config, layout); - this.separator = ','; + this.separator = ', '; this.relationship = config.relationship; this.repeatable = config.repeatable; this.required = config.required; diff --git a/src/app/shared/form/builder/parsers/clarin-name-field-parser.spec.ts b/src/app/shared/form/builder/parsers/clarin-name-field-parser.spec.ts index 3692c3e3c2e..a2b313ba69a 100644 --- a/src/app/shared/form/builder/parsers/clarin-name-field-parser.spec.ts +++ b/src/app/shared/form/builder/parsers/clarin-name-field-parser.spec.ts @@ -94,7 +94,7 @@ describe('ClarinNameFieldParser test suite', () => { const fieldModel = parser.parse(); - expect((fieldModel as DynamicConcatModel).separator).toBe(','); + expect((fieldModel as DynamicConcatModel).separator).toBe(', '); }); it('should set init value properly', () => { diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index d0ea3a1bd28..f1a253b85f7 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -301,6 +301,7 @@ import { ClarinDateService } from './clarin-date.service'; import { ItemIdentifierService } from './item-identifier.service'; import { ClarinLicenseRequiredInfoCheckedPipe } from './utils/clarin-license-required-info-checked.pipe'; import { DsLangPipe } from './utils/ds-lang.pipe'; +import { FormatAuthorPipe } from './utils/format-author.pipe'; const MODULES = [ CommonModule, @@ -349,7 +350,8 @@ const PIPES = [ CharToEndPipe, ClarinSafeHtmlPipe, ReplacePipe, - DsLangPipe + DsLangPipe, + FormatAuthorPipe ]; const COMPONENTS = [ diff --git a/src/app/shared/utils/format-author.pipe.spec.ts b/src/app/shared/utils/format-author.pipe.spec.ts new file mode 100644 index 00000000000..8929d36564f --- /dev/null +++ b/src/app/shared/utils/format-author.pipe.spec.ts @@ -0,0 +1,28 @@ +import { FormatAuthorPipe } from './format-author.pipe'; + +describe('FormatAuthorPipe', () => { + let pipe: FormatAuthorPipe; + + beforeEach(() => { + pipe = new FormatAuthorPipe(); + }); + + it('should create', () => { + expect(pipe).toBeTruthy(); + }); + + it('should add single space after comma when missing', () => { + expect(pipe.transform('Doe,John')).toEqual('Doe, John'); + }); + + it('should keep single space after comma unchanged', () => { + expect(pipe.transform('Doe, John')).toEqual('Doe, John'); + }); + + it('should return value as-is when there is no comma', () => { + expect(pipe.transform('')).toEqual(''); + expect(pipe.transform(null as any)).toBeNull(); + expect(pipe.transform('John Doe')).toEqual('John Doe'); + expect(pipe.transform(undefined as any)).toBeUndefined(); + }); +}); diff --git a/src/app/shared/utils/format-author.pipe.ts b/src/app/shared/utils/format-author.pipe.ts new file mode 100644 index 00000000000..4ee47905f7a --- /dev/null +++ b/src/app/shared/utils/format-author.pipe.ts @@ -0,0 +1,9 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ name: 'dsFormatAuthor' }) +export class FormatAuthorPipe implements PipeTransform { + transform(value: string): string { + // Normalise comma followed by zero or more whitespace to a single comma + space + return value?.replace(/,\s*(?=\S)/g, ', ') || value; + } +}