diff --git a/src/app/profile/dashboard/orientations-table/orientations-table.component.html b/src/app/profile/dashboard/orientations-table/orientations-table.component.html index 8add9b8633613f8216e51ef3acd60d291323bae8..36c80d63d06785ae18cdded79fe48cc6e7b88533 100644 --- a/src/app/profile/dashboard/orientations-table/orientations-table.component.html +++ b/src/app/profile/dashboard/orientations-table/orientations-table.component.html @@ -12,7 +12,7 @@ *ngFor="let orientation of orientations" class="row" routerLink="/profil/details-orientation/{{ orientation._id }}" - [ngClass]="daysAgo(orientation.createdAt) <= 14 ? 'new' : 'urgent'" + [ngClass]="this.orientationService.daysAgo(orientation.createdAt) <= 14 ? 'new' : 'urgent'" [attr.aria-label]=" 'Ouvrir l orientation de ' + orientation.personOriented.name + ' ' + orientation.personOriented.surname " @@ -21,7 +21,7 @@ <div class="name">{{ orientation.personOriented.name }} {{ orientation.personOriented.surname | uppercase }}</div> <div class="date inline"> <app-svg-icon [icon]="'clock'" [folder]="'ico'" [iconClass]="'icon-12'" /> - Il y a {{ daysAgo(orientation.createdAt) }} jour(s) + Il y a {{ this.orientationService.daysAgo(orientation.createdAt) }} jour(s) </div> </div> <div> @@ -75,29 +75,29 @@ <div> <app-tag-item *ngIf="orientation.status" - [label]="getLabel('status', orientation.status)" + [label]="this.orientationService.getLabel('status', orientation.status)" [size]="'small'" - [color]="getColor('status', orientation.status)" + [color]="this.orientationService.getColor('status', orientation.status)" [iconFolder]="'tags'" - [iconName]="getIcon('status', orientation.status)" + [iconName]="this.orientationService.getIcon('status', orientation.status)" /> </div> <div> <app-tag-item - *ngIf="type === 'myOrientations' && getType(orientation.accompanimentType)" - [label]="getType(orientation.accompanimentType).label" + *ngIf="type === 'myOrientations' && this.orientationService.getType(orientation.accompanimentType)" + [label]="this.orientationService.getType(orientation.accompanimentType).label" [size]="'small'" - [color]="getType(orientation.accompanimentType).color" + [color]="this.orientationService.getType(orientation.accompanimentType).color" [iconFolder]="'tags'" - [iconName]="getType(orientation.accompanimentType).icon" + [iconName]="this.orientationService.getType(orientation.accompanimentType).icon" /> <app-tag-item *ngIf="type !== 'myOrientations' && orientation.action" - [label]="getLabel('action', orientation.action)" + [label]="this.orientationService.getLabel('action', orientation.action)" [size]="'small'" - [color]="getColor('action', orientation.action)" + [color]="this.orientationService.getColor('action', orientation.action)" [iconFolder]="'tags'" - [iconName]="getIcon('action', orientation.action)" + [iconName]="this.orientationService.getIcon('action', orientation.action)" /> </div> <div class="hide-on-mobile">🢒</div> diff --git a/src/app/profile/dashboard/orientations-table/orientations-table.component.ts b/src/app/profile/dashboard/orientations-table/orientations-table.component.ts index c7dd10987a1c9dabc17979b5b725a352d90bfb32..251f71f84a201dd1bd3231bc609526bc0bbd5604 100644 --- a/src/app/profile/dashboard/orientations-table/orientations-table.component.ts +++ b/src/app/profile/dashboard/orientations-table/orientations-table.component.ts @@ -1,7 +1,5 @@ import { Component, Input } from '@angular/core'; -import { Action, Status, Type } from '../orientation.enum'; - -type AllowedColor = 'white' | 'black' | 'red' | 'blue' | 'dark-blue' | 'grey' | 'green' | 'light-green'; +import { OrientationService } from '../../../services/orientation.service'; @Component({ selector: 'app-orientations-table', @@ -9,53 +7,8 @@ type AllowedColor = 'white' | 'black' | 'red' | 'blue' | 'dark-blue' | 'grey' | styleUrls: ['./orientations-table.component.scss'], }) export class OrientationsTableComponent { + constructor(public orientationService: OrientationService) {} + @Input() orientations: any[]; @Input() type?: string; - - private readonly allowedColors: AllowedColor[] = [ - 'white', - 'black', - 'red', - 'blue', - 'dark-blue', - 'grey', - 'green', - 'light-green', - ]; - - private readonly enumMap = { - status: Status, - action: Action, - type: Type, - }; - - public daysAgo(date: string | Date): number { - const createdDate = new Date(date); - const currentDate = new Date(); - const timeDifference = currentDate.getTime() - createdDate.getTime(); - return Math.floor(timeDifference / (1000 * 60 * 60 * 24)); - } - - public getLabel(category: 'status' | 'action' | 'type', slug: string): string { - return this.getProperty(category, slug, 'label', slug); - } - - public getColor(category: 'status' | 'action' | 'type', slug: string): AllowedColor { - const color = this.getProperty(category, slug, 'color', null); - return this.allowedColors.includes(color as AllowedColor) ? (color as AllowedColor) : 'grey'; - } - - public getIcon(category: 'status' | 'action' | 'type', slug: string): string { - return this.getProperty(category, slug, 'icon', 'default-icon'); - } - - private getProperty(category: 'status' | 'action' | 'type', slug: string, property: string, fallback: any): any { - const enumObj = this.enumMap[category]; - return enumObj[slug as keyof typeof enumObj]?.[property] || fallback; - } - - public getType(type: string): any { - const displayType = Type[type as keyof typeof Type]; - return displayType; - } }