Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- export interface BadgeItem {
- type: string;
- value: string;
- }
- export interface Saperator {
- name: string;
- type ? : string;
- }
- export interface ChildrenItems {
- state: string;
- name: string;
- type ? : string;
- }
- export interface Menu {
- state: string;
- name: string;
- type: string;
- icon: string;
- badge ? : BadgeItem[];
- saperator ? : Saperator[];
- children ? : ChildrenItems[];
- }
- const MENUITEMS = [
- {
- state: '',
- name: 'Personal',
- type: 'saperator',
- icon: 'av_timer'
- },
- {
- state: 'dashboards',
- name: 'Dashboards',
- type: 'sub',
- icon: 'av_timer',
- children: [
- { state: 'dashboard1', name: 'Dashboard 1', UAC: 0 },
- { state: 'dashboard2', name: 'Dashboard 2', UAC: 128 },
- ]
- },
- {
- state: 'apps',
- name: 'Apps',
- type: 'sub',
- icon: 'apps',
- children: [
- { state: 'calendar', name: 'Calendar' },
- { state: 'messages', name: 'Mail box' },
- { state: 'chat', name: 'Chat' },
- { state: 'taskboard', name: 'Taskboard' }
- ],
- UAC: 256
- },
- {
- state: '',
- name: 'Forms, Table & Widgets',
- type: 'saperator',
- icon: 'av_timer'
- }, {
- state: 'datatables',
- name: 'Data Tables',
- type: 'sub',
- icon: 'border_all',
- children: [
- { state: 'basicdatatable', name: 'Basic Data Table' },
- { state: 'filter', name: 'Filterable' },
- { state: 'editing', name: 'Editing' },
- ]
- }, {
- state: 'pages',
- name: 'Pages',
- type: 'sub',
- icon: 'content_copy',
- children: [
- { state: 'icons', name: 'Material Icons' },
- { state: 'timeline', name: 'Timeline' },
- { state: 'invoice', name: 'Invoice' },
- { state: 'pricing', name: 'Pricing' },
- { state: 'helper', name: 'Helper Classes' }
- ]
- }
- ];
- @Injectable()
- export class MenuItems {
- getMenuitem(): Menu[] {
- // Get the JSON form of the stored user object
- let currentUser = JSON.parse(localStorage.getItem('currentUser'));
- // If the user has logged in, then this user object will be non null
- if (currentUser && currentUser.token)
- {
- var filtered_MENUITEMS = MENUITEMS.filter(obj => {
- let parentUAC: boolean = true;
- // Or are we using a UAC value instead.
- if(obj.UAC)
- {
- // Current User UAC could be 256, using bit manipulation for the number of departments and roles.
- parentUAC = ((obj.UAC & currentUser.UAC) > 0) ? true : false;
- }
- // We are going to show the parent, now check the children.
- if( (parentUAC == true) && (obj.children) )
- {
- // Need code in here to check for children of the menu item and removing if it's not meant to be visible.
- }
- return parentUAC;
- });
- return filtered_MENUITEMS;
- }
- else
- {
- return MENUITEMS;
- }
- }
- }
Add Comment
Please, Sign In to add comment