Skip to content

Commit

Permalink
menus working
Browse files Browse the repository at this point in the history
  • Loading branch information
jcii committed Nov 20, 2022
1 parent c14f774 commit f034e77
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 42 deletions.
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 16 additions & 25 deletions src/app/app.menu.component.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
import { Component, Input, OnInit, Inject, forwardRef } from "@angular/core";
import {
trigger,
state,
style,
transition,
animate,
} from "@angular/animations";
import { Location } from "@angular/common";
import { Router } from "@angular/router";
import { MenuItem } from "primeng/api";
import { AppComponent } from "./app.component";
import { loadMenuRules } from "./load-menu-rules";
import { AuthService } from "./shared/index";
import { MenuRule } from "./menu-rule";

@Component({
selector: "app-menu",
template: `
<ul class="layout-menu">
<li
app-menuitem
*ngFor="let item of model; let i = index"
[item]="item"
[index]="i"
[root]="true"
></li>
</ul>
`,
templateUrl: `
<ul class="layout-menu">
<li
app-menuitem
*ngFor="let item of model; let i = index"
[item]="item"
[index]="i"
[root]="true"
></li>
</ul>
`,
})
export class AppMenuComponent implements OnInit {
@Input() reset: boolean;

model: any[];

constructor(public app: AppComponent, private auth: AuthService) {
constructor(
@Inject(forwardRef(() => AppComponent)) public app: AppComponent,
private auth: AuthService
) {
console.log(".ctor: AppMenuComponent");
}

ngOnInit(): void {
console.log(".ngOnInit: AppMenuComponent");

this.auth.authorize().subscribe(
(user) => {
this.model = loadMenuRules(user.profile.roles);
// return new Array<MenuRule>();
return new Array<MenuRule>();
},
(unauthorized) => {
console.log("Not signed in: ", unauthorized);
Expand Down
127 changes: 127 additions & 0 deletions src/app/load-menu-rules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { MenuRule, LRole } from "./menu-rule";

export function loadMenuRules(authList: string[]): Array<MenuRule> {
const rules = [
new MenuRule({
id: 0,
label: "Hiring portal",
icon: "pi pi-fw pi-home",
visible: true,
authorizedRoles: [LRole.ADMIN, LRole.HIRER],
items: [
new MenuRule({
id: 1,
label: "Place an order",
icon: "pi pi-fw pi-home",
routerLink: ["/online-orders/introduction"],
authorizedRoles: [LRole.ADMIN, LRole.HIRER],
visible: true,
}),
new MenuRule({
id: 2,
label: "My profile",
icon: "pi pi-fw pi-home",
routerLink: ["/employers"],
authorizedRoles: [LRole.ADMIN, LRole.HIRER],
visible: true,
}),
new MenuRule({
id: 3,
label: "My work orders",
icon: "pi pi-fw pi-home",
routerLink: ["/my-work-orders"],
authorizedRoles: [LRole.ADMIN, LRole.HIRER],
visible: true,
}),
],
}),
new MenuRule({
id: 5,
label: "Manager portal",
authorizedRoles: [LRole.ADMIN, LRole.MANAGER],

items: [
new MenuRule({
id: 9,
label: "Reports",
icon: "pi pi-fw pi-home",
routerLink: ["/reports"],
authorizedRoles: [LRole.ADMIN, LRole.MANAGER],
visible: true,
}),
new MenuRule({
id: 10,
label: "Exports",
icon: "pi pi-fw pi-home",
routerLink: ["/exports"],
authorizedRoles: [LRole.ADMIN, LRole.MANAGER],
visible: true,
}),
],
}),

new MenuRule({
id: 12,
label: "Configuration",
icon: "pi pi-fw pi-home",
routerLink: ["/configuration"],
authorizedRoles: [LRole.ADMIN],
visible: true,
items: [
// new MenuRule({
// id: 11,
// label: 'Auth diagnostics',
// icon: 'perm_identity',
// routerLink: ['/auth/dashboard'],
// authorizedRoles: [
// LRole.ADMIN,
// LRole.CHECKIN,
// LRole.MANAGER,
// LRole.PHONEDESK,
// LRole.TEACHER,
// LRole.USER
// ]
// }),
new MenuRule({
id: 13,
label: "Machete Settings",
icon: "pi pi-fw pi-home",
routerLink: ["configuration/settings"],
authorizedRoles: [LRole.ADMIN],
visible: true,
}),
new MenuRule({
id: 14,
label: "Transport Providers",
icon: "pi pi-fw pi-home",
routerLink: ["configuration/transport-providers"],
authorizedRoles: [LRole.ADMIN],
visible: true,
}),
],
}),
// Hide unfinished work
// !! TODO finish the workers in list feature
// new MenuRule({
// id: 14,
// label: 'Workers',
// icon: 'assignment_ind',
// routerLink: ['/workers'],
// authorizedRoles: [
// LRole.ADMIN,
// LRole.MANAGER
// ]
// }),
];
// lambda-fu
if (authList == null || authList === undefined) {
return new Array<MenuRule>();
}
return rules.filter(
(rule) =>
Array.isArray(rule.authorizedRoles) &&
rule.authorizedRoles.findIndex(
(role) => authList.findIndex((auth) => auth === role) > -1
) > -1
);
}
1 change: 1 addition & 0 deletions src/app/menu-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class MenuRule {
url?: string[];
authorizedRoles?: string[];
items?: MenuRule[];
visible: boolean;

public constructor(init?: Partial<MenuRule>) {
Object.assign(this, init);
Expand Down
3 changes: 1 addition & 2 deletions src/app/online-orders/transport-providers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export class TransportProvidersService {
constructor(
private client: TransportProvidersClient,
private appMessages: MessagesService,
@Optional() @SkipSelf() parentModule?: TransportProvidersService,
private client: TransportProvidersClient
@Optional() @SkipSelf() parentModule?: TransportProvidersService
) {
// enforce app singleton pattern
if (parentModule) {
Expand Down

0 comments on commit f034e77

Please sign in to comment.