import { IMenuItemAdmin } from '../../../models/admin/company/menu-management/menu-management'; export enum MenuItemType { // Will have URL that has a predefined page in the UI that the router will handle RouterPath = 0, // A URL that is external to the UI Url = 1, // Will have URL dynamically create the router will handle StaticContent = 2, // A menu item that can have children but no URL or content Group = 3 } export const mapFrontendMenuBooleans = (menuItems: IMenuItemAdmin[]): IMenuItemAdmin[] => { menuItems.forEach((mi) => { mi.IsHttp = mi.Type === MenuItemType.Url; mi.IsRouterPath = mi.Type === MenuItemType.RouterPath || mi.Type === MenuItemType.StaticContent; mi.IsGroup = mi.Type === MenuItemType.Group; mapFrontendMenuBooleans(mi.ChildNode); }); return menuItems; }; export class MenuItemAdmin implements IMenuItemAdmin { IsActive: boolean; IsEditable: boolean; IsInherited: boolean; IsMovable: boolean; IsPartiallyLoaded: boolean; AllowChildren: boolean; Content: string; ImageVideo: File; ImageVideoFileName: string; isAdd?: boolean; ChildNode: IMenuItemAdmin[]; id: string = "0"; IsMobile: boolean; isSettings: boolean; level?: number; Name: string; Type: number; URL: string; MenuAdminId: number; LstMenuAdmin: IMenuItemAdmin[]; ParentId: number = 0; CompanyId: number = 1; ADMINID: number = 0; ImageVideoData: string = ""; get IsHttp() { return this.Type === MenuItemType.Url; } set IsHttp(value) { if (value) { this.Type = MenuItemType.Url; } else { this.Type = MenuItemType.StaticContent; } } get IsRouterPath() { return this.Type === MenuItemType.RouterPath || this.Type === MenuItemType.StaticContent; } set IsRouterPath(value) { throw Error('IsRouterPath is read-only... cannot be set'); } get IsGroup() { return this.Type === MenuItemType.Group; } set IsGroup(value) { if (value) { this.Type = MenuItemType.Group; } else { this.Type = MenuItemType.RouterPath; } } } export const mapFrontendMenuBooleansAdmin = (menuItems: IMenuItemAdmin[]): IMenuItemAdmin[] => { return menuItems.map((mi) => { const newInstance = new MenuItemAdmin(); Object.assign(newInstance, mi); newInstance.ChildNode = mapFrontendMenuBooleansAdmin(mi.ChildNode); return newInstance; }); };