Skip to content

Commit

Permalink
se arreglo el sidebar dependiendo del role del usuario
Browse files Browse the repository at this point in the history
  • Loading branch information
matias1305 committed Dec 11, 2018
1 parent c7e7f14 commit ff9f64d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
21 changes: 11 additions & 10 deletions src/app/services/sidebar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ export class SidebarService {
menu:any=[];

constructor() {
this.defMenu();
setInterval( () => { this.defMenu(); }, 5000);
}

defMenu(){
if (JSON.parse(localStorage.getItem("user")).role === 'admin'){
this.menu = MENU_ADMIN;
}else if (JSON.parse(localStorage.getItem("user")).role === 'normal'){
this.menu = CATEGORIES;
}
// Esta preguntando que usuario esta conectado
setInterval( () => {
if( localStorage.getItem("user") ) {
let role = JSON.parse(localStorage.getItem("user")).role;
if (role === 'admin'){
this.menu = MENU_ADMIN;
}else if (role === 'normal'){
this.menu = CATEGORIES;
}
}
}, 500);
}
}
10 changes: 8 additions & 2 deletions src/app/shared/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ export class SidebarComponent implements OnInit {
constructor( private _dbService:DatabaseService,
private router: Router,
private _sidebar:SidebarService ) {
this.menu = this._sidebar.menu;
this.role = JSON.parse(localStorage.getItem("user")).role;
setInterval( () => {
this.menu = this._sidebar.menu;
if(localStorage.getItem("user")) {
this.role = JSON.parse(localStorage.getItem("user")).role;
}else {
this.role = '';
}
}, 500)
}

ngOnInit() {
Expand Down

0 comments on commit ff9f64d

Please sign in to comment.