254 lines
9.8 KiB
TypeScript
254 lines
9.8 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { AppMainComponent } from './app.main.component';
|
|
import { AuthService } from './domain/services/auth.service';
|
|
import { RoleIds } from './shared/global';
|
|
import { MenuItem } from 'primeng/api';
|
|
import { Store } from '@ngrx/store';
|
|
import { selectSubLimit } from './reducers';
|
|
import { FetchSubPlans } from './actions/sub-plans.actions';
|
|
import { SubKeys } from './profile/common';
|
|
|
|
@Component({
|
|
selector: 'app-menu',
|
|
template: `
|
|
<ul class="ultima-menu ultima-main-menu clearfix">
|
|
<li app-menuitem *ngFor="let item of model; let i = index;" [item]="item" [index]="i" [root]="true"></li>
|
|
</ul>
|
|
`
|
|
})
|
|
export class AppMenuComponent implements OnInit {
|
|
model: any[] = [];
|
|
|
|
constructor(
|
|
public readonly app: AppMainComponent,
|
|
private readonly authSvc: AuthService,
|
|
private readonly store: Store<{}>
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
if (this.authSvc.hasRole([RoleIds.ADMIN])) {
|
|
this.creatAdminMenu()
|
|
} else if (this.authSvc.isPartner) {
|
|
this.createPartnerMenu();
|
|
} else {
|
|
this.createUserMenu();
|
|
}
|
|
}
|
|
|
|
creatAdminMenu() {
|
|
const mItems: MenuItem[] = [
|
|
{ id: 'dashboard', label: $localize`:@@dashboard:Dashboard`, icon: 'dashboard', routerLink: ['/home'] },
|
|
{ id: 'customers', label: $localize`:@@customers:Customers`, icon: 'assignment_ind', routerLink: ['/customers'] },
|
|
{ id: 'partners', label: $localize`:@@partnerMgnt:Partner Management`, icon: 'business', routerLink: ['/partners'] },
|
|
{ label: $localize`:@@billing:Billing`, icon: 'monetization_on', routerLink: ['/billing'] },
|
|
{
|
|
id: 'tools',
|
|
label: $localize`:@@tools:Tools`, icon: 'extension',
|
|
routerLink: ['/tools'],
|
|
items: [
|
|
{ id: 'api-keys', label: $localize`:@@apiKeys:API Keys`, icon: 'vpn_key', routerLink: ['/api-keys'] },
|
|
{ id: 'dlq-monitor', label: $localize`:@@dlqMonitor:DLQ Monitor`, icon: 'bug_report', routerLink: ['/dlq'] }
|
|
]
|
|
},
|
|
{
|
|
id: 'settings',
|
|
label: $localize`:@@settings:Settings`, icon: 'settings',
|
|
routerLink: ['/settings'],
|
|
items: [
|
|
{ id: 'subscription', label: $localize`:@@promoManagement:Promo Management`, icon: 'credit_card', routerLink: ['/settings/subscription'] }
|
|
]
|
|
},
|
|
];
|
|
this.model = mItems;
|
|
}
|
|
|
|
createPartnerMenu() {
|
|
const mItems: MenuItem[] = [
|
|
{ id: 'dashboard', label: $localize`:@@dashboard:Dashboard`, icon: 'dashboard', routerLink: ['/home'] },
|
|
{
|
|
id: 'partner-customers',
|
|
label: $localize`:@@partnerCustomers:Partner Customers`,
|
|
icon: 'business',
|
|
routerLink: ['/partner-customers']
|
|
},
|
|
{
|
|
id: 'Help',
|
|
label: $localize`:@@help:Help`, icon: 'help_outline',
|
|
items: [{
|
|
label: $localize`:@@trainingVideos:Training Videos`,
|
|
icon: 'video_library',
|
|
url: 'https://www.youtube.com/watch?v=QjGZan5QdAo&list=PLSMll_kIgHA3eamxiSH0Dgl95v60okMcV',
|
|
target: '_blank'
|
|
}]
|
|
}
|
|
];
|
|
this.model = mItems;
|
|
}
|
|
|
|
createUserMenu() {
|
|
this.store.select(selectSubLimit).subscribe({
|
|
next: (subLimit) => {
|
|
const hasSubLimit = !!subLimit && (Object.keys(subLimit.package || {}).length > 0 || Object.keys(subLimit.addon || {}).length > 0);
|
|
const mItems: MenuItem[] = [
|
|
{ id: 'dashboard', label: $localize`:@@dashboard:Dashboard`, icon: 'dashboard', routerLink: ['/home'] }
|
|
];
|
|
if (hasSubLimit) {
|
|
this.addSubItems(mItems, subLimit);
|
|
}
|
|
this.model = mItems;
|
|
},
|
|
error: (err) => {
|
|
console.log(err);
|
|
}
|
|
});
|
|
this.store.dispatch(new FetchSubPlans());
|
|
}
|
|
|
|
private addSubItems(mItems: MenuItem[], subLimit: any) {
|
|
const hasTracking = subLimit?.addon?.[SubKeys.TRACKING]?.airCraft?.numOfVehicle > 0;
|
|
const hasPackage = Object.keys(subLimit.package || {}).length > 0;
|
|
const hasOnlyTracking = !hasPackage && hasTracking;
|
|
const hasOnlyPackage = hasPackage && !hasTracking;
|
|
|
|
if (hasOnlyTracking) {
|
|
this.addOnlyTrackingItems(mItems);
|
|
} else if (hasOnlyPackage) {
|
|
this.addOnlyPackageItems(mItems);
|
|
} else if (hasPackage && hasTracking) {
|
|
this.addFullAccessItems(mItems);
|
|
}
|
|
|
|
mItems.push(
|
|
{
|
|
id: 'Help',
|
|
label: $localize`:@@help:Help`, icon: 'help_outline',
|
|
items: [{
|
|
label: $localize`:@@trainingVideos:Training Videos`,
|
|
icon: 'video_library',
|
|
url: 'https://www.youtube.com/watch?v=QjGZan5QdAo&list=PLSMll_kIgHA3eamxiSH0Dgl95v60okMcV',
|
|
target: '_blank'
|
|
}]
|
|
}
|
|
)
|
|
}
|
|
|
|
private addOnlyTrackingItems(mItems: MenuItem[]) {
|
|
if (!this.authSvc.hasRole([RoleIds.INSPECTOR])) {
|
|
mItems.push(
|
|
{
|
|
id: 'entities',
|
|
label: $localize`:@@entities:Entities`, icon: 'library_books',
|
|
routerLink: ['/entities'],
|
|
items: [{ label: $localize`:@@aircraft:Aircraft`, icon: 'airplanemode_active', routerLink: ['/entities/aircraft'] }]
|
|
},
|
|
{
|
|
id: 'tools',
|
|
label: $localize`:@@tools:Tools`, icon: 'extension',
|
|
routerLink: ['/tools'],
|
|
items: [
|
|
{ id: 'settings', label: $localize`:@@settings:Settings`, icon: 'settings', routerLink: ['/tools/settings'] }
|
|
]
|
|
}
|
|
);
|
|
}
|
|
if (!this.authSvc.hasRole([RoleIds.CLIENT, RoleIds.INSPECTOR])) {
|
|
mItems.push({ id: 'track', label: $localize`:@@tracking:Tracking`, icon: 'track_changes', routerLink: ['/track'] });
|
|
}
|
|
}
|
|
|
|
private addOnlyPackageItems(mItems: MenuItem[]) {
|
|
if (this.authSvc.hasRole([RoleIds.APP, RoleIds.APP_ADM])) {
|
|
mItems.push({ id: 'accounts', label: $localize`:@@accounts:Accounts`, icon: 'assignment_ind', routerLink: ['/accounts'] });
|
|
}
|
|
|
|
if (!this.authSvc.isClientUser) {
|
|
mItems.push({ id: 'clients', label: $localize`:@@clients:Clients`, icon: 'people', routerLink: ['/clients'] });
|
|
}
|
|
mItems.push({ id: 'jobs', label: $localize`:@@jobs:Jobs`, icon: 'assignment', routerLink: ['/jobs'] });
|
|
|
|
if (!this.authSvc.hasRole([RoleIds.INSPECTOR])) {
|
|
this.addEntitiesAndToolsItems(mItems);
|
|
}
|
|
|
|
this.addInvoiceItems(mItems);
|
|
}
|
|
|
|
private addFullAccessItems(mItems: MenuItem[]) {
|
|
if (this.authSvc.hasRole([RoleIds.APP, RoleIds.APP_ADM])) {
|
|
mItems.push({ id: 'accounts', label: $localize`:@@accounts:Accounts`, icon: 'assignment_ind', routerLink: ['/accounts'] });
|
|
}
|
|
|
|
if (!this.authSvc.isClientUser) {
|
|
mItems.push({ id: 'clients', label: $localize`:@@clients:Clients`, icon: 'people', routerLink: ['/clients'] });
|
|
}
|
|
mItems.push({ id: 'jobs', label: $localize`:@@jobs:Jobs`, icon: 'assignment', routerLink: ['/jobs'] });
|
|
|
|
if (!this.authSvc.hasRole([RoleIds.INSPECTOR])) {
|
|
this.addEntitiesAndToolsItems(mItems);
|
|
}
|
|
if (!this.authSvc.hasRole([RoleIds.CLIENT, RoleIds.INSPECTOR])) {
|
|
mItems.push({ id: 'track', label: $localize`:@@tracking:Tracking`, icon: 'track_changes', routerLink: ['/track'] });
|
|
}
|
|
|
|
this.addInvoiceItems(mItems);
|
|
}
|
|
|
|
private addEntitiesAndToolsItems(mItems: MenuItem[]) {
|
|
mItems.push(
|
|
{
|
|
id: 'entities',
|
|
label: $localize`:@@entities:Entities`, icon: 'library_books',
|
|
routerLink: ['/entities'],
|
|
items: this.authSvc.isClientUser ?
|
|
[
|
|
{ label: $localize`:@@crops:Crops`, icon: 'list', routerLink: ['/entities/crops'] },
|
|
{ label: $localize`:@@products:Products`, icon: 'widgets', routerLink: ['/entities/products'] },
|
|
]
|
|
: [
|
|
{ label: $localize`:@@aircraft:Aircraft`, icon: 'airplanemode_active', routerLink: ['/entities/aircraft'] },
|
|
{ label: $localize`:@@crops:Crops`, icon: 'list', routerLink: ['/entities/crops'] },
|
|
{ label: $localize`:@@products:Products`, icon: 'widgets', routerLink: ['/entities/products'] },
|
|
{ label: $localize`:@@pilots:Pilots`, icon: 'contacts', routerLink: ['/entities/pilots'] }
|
|
]
|
|
},
|
|
{
|
|
id: 'tools',
|
|
label: $localize`:@@tools:Tools`, icon: 'extension',
|
|
routerLink: ['/tools'],
|
|
items: [
|
|
{ id: 'upload', label: $localize`:@@uploadJobData:Upload Job Data`, icon: 'cloud_upload', routerLink: ['/tools/upload'] },
|
|
{ id: 'areaLib', label: $localize`:@@manageAreasLib:Manage Areas Library`, icon: 'folder_special', routerLink: ['/tools/areas'] },
|
|
{ id: 'settings', label: $localize`:@@settings:Settings`, icon: 'settings', routerLink: ['/tools/settings'] },
|
|
...( this.authSvc.hasRole([RoleIds.APP, RoleIds.APP_ADM])
|
|
? [{ id: 'api-keys', label: $localize`:@@apiKeys:API Keys`, icon: 'vpn_key', routerLink: ['/api-keys'] }]
|
|
: [] )
|
|
]
|
|
}
|
|
);
|
|
}
|
|
|
|
private addInvoiceItems(mItems: MenuItem[]) {
|
|
if (this.authSvc.hasRole([RoleIds.APP, RoleIds.APP_ADM, RoleIds.CLIENT, RoleIds.OFFICER])) {
|
|
mItems.push({
|
|
id: 'invoice',
|
|
label: $localize`:@@invoices:Invoices`, icon: 'receipt_long',
|
|
routerLink: ['/invoices'],
|
|
items: []
|
|
});
|
|
}
|
|
const invoice = mItems.find(i => i.id === 'invoice');
|
|
if (invoice) {
|
|
if (this.authSvc.hasRole([RoleIds.APP_ADM, RoleIds.CLIENT, RoleIds.OFFICER])) {
|
|
invoice.items.push({ id: 'view', label: $localize`:@@viewInvoice:View Invoices`, icon: 'list', routerLink: ['/invoices'] });
|
|
}
|
|
if (this.authSvc.hasRole([RoleIds.APP])) {
|
|
invoice.items.push(
|
|
{ id: 'view', label: $localize`:@@viewEditInvoice:View/Edit Invoices`, icon: 'list', routerLink: ['/invoices'] },
|
|
{ id: 'costing-item', label: $localize`:@@costingItems:Costing Items`, icon: 'payments', routerLink: ['/invoices/costing-items'] },
|
|
{ id: 'settings', label: $localize`:@@invoiceSettings:Invoice Settings`, icon: 'settings', routerLink: ['/invoices/settings'] }
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|