armisa-models
Version:
models of armisa!
115 lines (105 loc) • 3.1 kB
text/typescript
import { MainStateManager } from "../../MainStateManager";
import { INaming } from "../../NamingCaption";
import { IParentFormManager } from "../../Page/ElementsOfFormFactory";
import { AuthFactory } from "../AuthFactory";
import { MenuItemFactory } from "./2-MenuItemFactory";
export type ISystems =
| 'acc'
| 'wrh'
| 'sal'
| 'pur'
| 'pay'
| 'aut'
| 'ast'
| 'war'
| 'pro'
| 'tre'
| 'DD'
| 'PM'
| 'COG'
| 'PMS'
| 'WF';
export type ITypeOfFormForRoute = {
id: number;
code: number;
name: string;
};
export type IRoutes = {
path: string;
Page: React.ComponentType<{ parentFormManager: IParentFormManager, typeOfForm?: ITypeOfFormForRoute; }>;
exact?: boolean;
typeOfForm?: ITypeOfFormForRoute;
};
export class MenuFactory {
public forceUpdate = () => { };
public forceUpdateAfterSystemsChange = () => { };
public visible: boolean = true;
constructor(
public mainStateManager: MainStateManager,
public authFactory: AuthFactory
) {
}
public menuItems: MenuItemFactory[] = [];
public get visibleMenuItems() {
return this.menuItems.filter(i => i.isSystemSelected && i.isInRole);
}
public routes: IRoutes[] = [];
public addNewItem(
caption: INaming | string,
path?: string,
Page?: React.ComponentType<{ parentFormManager: IParentFormManager }>,
exact?: boolean,
onClick?: () => void,
accounting?: boolean,
purchase?: boolean,
sale?: boolean,
treasury?: boolean,
warehouse?: boolean,
produce?: boolean,
pms?: boolean,
costOfGoods?: boolean,
payment?: boolean,
asset?: boolean,
warranty?: boolean,
automation?: boolean,
dailyDistribution?: boolean,
preventindMaintainance?: boolean,
workflow?: boolean,
users?: number[],
): MenuItemFactory {
let captionFinal = '';
if (caption) {
if (typeof caption === 'string') {
captionFinal = caption;
} else if (caption) {
captionFinal = this.mainStateManager.getCaptionNaming(caption);
}
}
const item = new MenuItemFactory(
this,
captionFinal,
accounting || false,
purchase || false,
sale || false,
treasury || false,
warehouse || false,
produce || false,
pms || false,
costOfGoods || false,
payment || false,
asset || false,
warranty || false,
automation || false,
dailyDistribution || false,
preventindMaintainance || false,
workflow || false,
users,
path,
Page,
exact,
onClick
);
this.menuItems.push(item);
return item;
}
}