diff --git a/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.html b/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.html index ac14301625..b29cb1f2fc 100644 --- a/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.html +++ b/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.html @@ -29,4 +29,44 @@ > +
+
+ person_outline +
+

+ {{ contacts[0].firstName }} {{ contacts[0].lastName }} +

+

{{ contacts[0].phone }}

+
+
+
+
+
+ + location_on +
+

+ {{ address[0] }} +

+

+ {{ add }} +

+
+
+
+
+ +
diff --git a/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.spec.ts b/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.spec.ts index baabbdbb0f..e854e1d548 100644 --- a/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.spec.ts +++ b/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.spec.ts @@ -3,6 +3,32 @@ import { ComponentFixture, TestBed } from '@angular/core/testing' import { By } from '@angular/platform-browser' import { MetadataContactComponent } from './metadata-contact.component' +const addressCases = [ + { + address: + 'Hôtel de Rennes Métropole, 4 avenue Henri Fréville, CS 93111, RENNES, 35031, France', + expectedResult: [ + 'Hôtel de Rennes Métropole', + '4 avenue Henri Fréville', + 'CS 93111', + '35031 RENNES', + 'France', + ], + }, + { + address: '123 Main Street, Anytown, 54321', + expectedResult: ['123 Main Street', '54321 Anytown'], + }, + { + address: '123 Main Street, Anytown, France', + expectedResult: ['123 Main Street', 'Anytown', 'France'], + }, + { + address: 'Anytown, France', + expectedResult: ['Anytown', 'France'], + }, +] + describe('MetadataContactComponent', () => { let component: MetadataContactComponent let fixture: ComponentFixture @@ -80,4 +106,14 @@ describe('MetadataContactComponent', () => { expect(a.attributes.target).toBe('_blank') }) }) + + describe('#parseAddress', () => { + test.each(addressCases)( + 'adressString: $address', + ({ address, expectedResult }) => { + console.log(component) + expect(component.parseAddress(address)).toStrictEqual(expectedResult) + } + ) + }) }) diff --git a/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.ts b/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.ts index a605bc3d8b..6970eca336 100644 --- a/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.ts +++ b/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.ts @@ -34,6 +34,37 @@ export class MetadataContactComponent { ) } + parseAddress(inputAddress) { + const addressParts = inputAddress.split(',').map((part) => part.trim()) + + const addressArray = [] + + for (let i = 0; i < addressParts.length; i++) { + const part = addressParts[i] + if (part.toLowerCase().includes('cs')) { + // Handle "CS Number" in a single line + addressArray.push(part) + } else if (part.match(/^\d{5}$/)) { + // Combine postcode and city in a single line + const postcodeCity = `${part} ${addressParts[i - 1]}` + // delete duplicate city + if (postcodeCity.includes(addressParts[i - 1])) { + addressArray.pop() + } + addressArray.push(postcodeCity) + } else { + // Treat as a separate line + addressArray.push(part) + } + } + + return addressArray + } + + get address() { + return this.parseAddress(this.contacts[0].address) + } + onOrganizationClick() { this.organizationClick.emit(this.shownOrganization) }