diff --git a/src/app/services/orientation.service.ts b/src/app/services/orientation.service.ts index 5a9b3606dcbda05b0f7ee059366caf8c395582c1..24d0202f19a2efff8fefa5e76451fc118b9d53eb 100644 --- a/src/app/services/orientation.service.ts +++ b/src/app/services/orientation.service.ts @@ -6,7 +6,9 @@ import { IOnlineMediation } from '../form/orientation-form-view/interfaces/onlin import { IOrientation } from '../form/orientation-form-view/interfaces/orientation.interface'; import { Structure } from '../models/structure.model'; import { User } from '../models/user.model'; +import { Action, Status, Type } from '../profile/dashboard/orientation.enum'; +type AllowedColor = 'white' | 'black' | 'red' | 'blue' | 'dark-blue' | 'grey' | 'green' | 'light-green'; @Injectable({ providedIn: 'root', }) @@ -53,4 +55,72 @@ export class OrientationService { public saveOrientation(newOrientation: IOrientation): Observable<IOrientation> { return this.http.post<IOrientation>('/api/orientation', newOrientation); } + + /** + * Calculate days ago from date + */ + 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)); + } + + /** + * variables for dashboard + */ + private readonly allowedColors: AllowedColor[] = [ + 'white', + 'black', + 'red', + 'blue', + 'dark-blue', + 'grey', + 'green', + 'light-green', + ]; + + private readonly enumMap = { + status: Status, + action: Action, + type: Type, + }; + + /** + * Get label from orientation enum + */ + public getLabel(category: 'status' | 'action' | 'type', slug: string): string { + return this.getProperty(category, slug, 'label', slug); + } + + /** + * Get color from orientation enum + */ + 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'; + } + + /** + * Get icon from orientation enum + */ + public getIcon(category: 'status' | 'action' | 'type', slug: string): string { + return this.getProperty(category, slug, 'icon', 'default-icon'); + } + + /** + * helper method to get a property from the enum + */ + 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; + } + + /** + * Get type from orientation enum + */ + public getType(type: string): any { + const displayType = Type[type as keyof typeof Type]; + return displayType; + } }