Skip to content

Commit

Permalink
feature(DH): Add more contact information
Browse files Browse the repository at this point in the history
  • Loading branch information
Angi-Kinas committed Jan 9, 2024
1 parent 6d6f87d commit 56e6782
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,44 @@
>
</a>
</div>
<div *ngIf="contacts[0].firstName || contacts[0].lastName" class="mb-2">
<div class="flex">
<mat-icon
class="material-symbols-outlined !w-[20px] !h-[20px] !text-[20px] opacity-75"
>person_outline</mat-icon
>
<div class="flex flex-col ml-2">
<p class="text-sm">
{{ contacts[0].firstName }} {{ contacts[0].lastName }}
</p>
<p class="text-gray-700 text-sm">{{ contacts[0].phone }}</p>
</div>
</div>
</div>
<div *ngIf="contacts[0].address" class="mb-2">
<div class="flex">
<mat-icon
class="material-symbols-outlined !w-[20px] !h-[20px] !text-[20px] opacity-75"
>
location_on</mat-icon
>
<div class="flex flex-col ml-2">
<p class="text-sm">
{{ address[0] }}
</p>
<p *ngFor="let add of address.slice(1)" class="text-gray-700 text-sm">
{{ add }}
</p>
</div>
</div>
</div>
<div
*ngIf="contacts[0].organization?.logoUrl?.href"
class="flex items-center justify-center border-solid border border-gray-300 rounded-md w-48 h-32"
>
<img
class="object-scale-down"
[src]="contacts[0].organization.logoUrl.href"
/>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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<MetadataContactComponent>
Expand Down Expand Up @@ -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)
}
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 56e6782

Please sign in to comment.