sidebar.component.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Component, OnInit } from '@angular/core';
  2. import { AuthService } from '../../../services/auth2.service';
  3. import { Router } from '@angular/router';
  4. import * as CryptoJS from 'crypto-js';
  5. declare const $: any;
  6. declare interface RouteInfo {
  7. path: string;
  8. title: string;
  9. icon: string;
  10. class: string;
  11. allowed_roles?:any;
  12. }
  13. export const ROUTES: RouteInfo[] = [
  14. { path: '/dashboard', title: 'Dashboard', icon: 'dashboard', class: '' },
  15. { path: '/assets', title: 'Plantas', icon: 'wb_sunny', class: '' },
  16. //{ path: '/profile', title: 'Perfil', icon:'person', class: '' },
  17. /*{ path: '/table-list', title: 'Table List', icon:'content_paste', class: '' },
  18. { path: '/typography', title: 'Typography', icon:'library_books', class: '' },
  19. { path: '/icons', title: 'Icons', icon:'bubble_chart', class: '' },
  20. { path: '/maps', title: 'Maps', icon:'location_on', class: '' },
  21. { path: '/notifications', title: 'Notifications', icon:'notifications', class: '' },
  22. { path: '/upgrade', title: 'Upgrade to PRO', icon:'unarchive', class: 'active-pro' },*/
  23. ];
  24. // Extra options to show to the admin
  25. export const ADMIN_ROUTES: RouteInfo[] = [
  26. { path: '/organizations', title: 'Organizaciones', icon:'location_city', class: '', allowed_roles: [2,3] },
  27. { path: '/plants', title: 'Plantas', icon: 'poll', class: '', allowed_roles: [2, 3] },
  28. { path: '/users', title: 'Usuarios', icon: 'people', class: '', allowed_roles: [3] },
  29. ];
  30. @Component({
  31. selector: 'app-sidebar',
  32. templateUrl: './sidebar.component.html',
  33. styleUrls: ['./sidebar.component.scss']
  34. })
  35. export class SidebarComponent implements OnInit {
  36. menuItems: any[];
  37. adminMenuItems: any[];
  38. adminMenu:boolean = false;
  39. role_number:any;
  40. constructor(private auth: AuthService, private router: Router) {
  41. var bytes = CryptoJS.AES.decrypt(localStorage.getItem("USER_MENU"), 'soma-inverlec-2019');
  42. this.role_number = bytes.toString(CryptoJS.enc.Utf8);
  43. }
  44. ngOnInit() {
  45. this.menuItems = ROUTES.filter(menuItem => menuItem);
  46. this.adminMenuItems = ADMIN_ROUTES.filter(menuItem => menuItem);
  47. // must be changed for the method that returns if it is an admin
  48. if (this.auth.isLoggedIn() == true && this.role_number > 1) {
  49. this.adminMenu = true;
  50. }
  51. }
  52. isMobileMenu() {
  53. if ($(window).width() > 991) {
  54. return false;
  55. }
  56. return true;
  57. };
  58. logout() {
  59. this.auth.logout();
  60. window.location.href="#/login";
  61. //this.router.navigateByUrl("login");
  62. };
  63. }