sidebar.component.ts 2.6 KB

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