Guest User

Untitled

a guest
Dec 15th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2.  
  3. export interface BadgeItem {
  4. type: string;
  5. value: string;
  6. }
  7. export interface Saperator {
  8. name: string;
  9. type ? : string;
  10. }
  11. export interface ChildrenItems {
  12. state: string;
  13. name: string;
  14. type ? : string;
  15. }
  16.  
  17. export interface Menu {
  18. state: string;
  19. name: string;
  20. type: string;
  21. icon: string;
  22. badge ? : BadgeItem[];
  23. saperator ? : Saperator[];
  24. children ? : ChildrenItems[];
  25. }
  26.  
  27. const MENUITEMS = [
  28. {
  29. state: '',
  30. name: 'Personal',
  31. type: 'saperator',
  32. icon: 'av_timer'
  33. },
  34. {
  35. state: 'dashboards',
  36. name: 'Dashboards',
  37. type: 'sub',
  38. icon: 'av_timer',
  39. children: [
  40. { state: 'dashboard1', name: 'Dashboard 1', UAC: 0 },
  41. { state: 'dashboard2', name: 'Dashboard 2', UAC: 128 },
  42. ]
  43. },
  44. {
  45. state: 'apps',
  46. name: 'Apps',
  47. type: 'sub',
  48. icon: 'apps',
  49. children: [
  50. { state: 'calendar', name: 'Calendar' },
  51. { state: 'messages', name: 'Mail box' },
  52. { state: 'chat', name: 'Chat' },
  53. { state: 'taskboard', name: 'Taskboard' }
  54. ],
  55. UAC: 256
  56. },
  57. {
  58. state: '',
  59. name: 'Forms, Table & Widgets',
  60. type: 'saperator',
  61. icon: 'av_timer'
  62. }, {
  63. state: 'datatables',
  64. name: 'Data Tables',
  65. type: 'sub',
  66. icon: 'border_all',
  67.  
  68. children: [
  69. { state: 'basicdatatable', name: 'Basic Data Table' },
  70. { state: 'filter', name: 'Filterable' },
  71. { state: 'editing', name: 'Editing' },
  72. ]
  73. }, {
  74. state: 'pages',
  75. name: 'Pages',
  76. type: 'sub',
  77. icon: 'content_copy',
  78.  
  79. children: [
  80. { state: 'icons', name: 'Material Icons' },
  81. { state: 'timeline', name: 'Timeline' },
  82. { state: 'invoice', name: 'Invoice' },
  83. { state: 'pricing', name: 'Pricing' },
  84. { state: 'helper', name: 'Helper Classes' }
  85. ]
  86. }
  87.  
  88. ];
  89.  
  90. @Injectable()
  91.  
  92. export class MenuItems {
  93.  
  94. getMenuitem(): Menu[] {
  95.  
  96. // Get the JSON form of the stored user object
  97. let currentUser = JSON.parse(localStorage.getItem('currentUser'));
  98.  
  99. // If the user has logged in, then this user object will be non null
  100. if (currentUser && currentUser.token)
  101. {
  102. var filtered_MENUITEMS = MENUITEMS.filter(obj => {
  103.  
  104. let parentUAC: boolean = true;
  105.  
  106. // Or are we using a UAC value instead.
  107. if(obj.UAC)
  108. {
  109. // Current User UAC could be 256, using bit manipulation for the number of departments and roles.
  110. parentUAC = ((obj.UAC & currentUser.UAC) > 0) ? true : false;
  111. }
  112.  
  113. // We are going to show the parent, now check the children.
  114. if( (parentUAC == true) && (obj.children) )
  115. {
  116. // Need code in here to check for children of the menu item and removing if it's not meant to be visible.
  117. }
  118.  
  119. return parentUAC;
  120. });
  121.  
  122. return filtered_MENUITEMS;
  123. }
  124. else
  125. {
  126. return MENUITEMS;
  127. }
  128.  
  129. }
  130.  
  131. }
Add Comment
Please, Sign In to add comment