src/app/layouts/main-layout/sidebar.component.ts
selector | crm-sidebar |
templateUrl | ./sidebar.component.html |
Properties |
|
Methods |
constructor(ps: PermissionsService, profileService: ProfileService)
|
||||||||||||
Parameters :
|
closeOtherDropdown | ||||||||
closeOtherDropdown(sd: DropdownDirective)
|
||||||||
Parameters :
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
Private setPermissions |
setPermissions()
|
Returns :
void
|
actions |
actions:
|
Default value : Actions
|
dropdownDirectives |
dropdownDirectives:
|
Decorators : ViewChildren
|
Private profileSubscription |
profileSubscription:
|
Type : Subscription
|
Public ps |
ps:
|
Type : PermissionsService
|
Private psSubscription |
psSubscription:
|
Type : Subscription
|
showAdmin |
showAdmin:
|
Type : boolean
|
showInvites |
showInvites:
|
Type : boolean
|
showRoot |
showRoot:
|
Type : boolean
|
Default value : false
|
showUsers |
showUsers:
|
Type : boolean
|
import {Component, ViewChildren, OnDestroy} from "@angular/core";
import {DropdownDirective} from "./dropdown.directive";
import {PermissionsService} from "../../core/auth/permissions.service";
import {Actions} from "../../core/models/auth/action.type";
import {Subscription} from "rxjs";
import {ProfileService} from "../../core/profile/profile.service";
@Component({
selector: 'crm-sidebar',
templateUrl: './sidebar.component.html',
styles: []
})
export class SidebarComponent implements OnDestroy {
showAdmin: boolean;
showInvites: boolean;
showUsers: boolean;
showRoot: boolean = false;
actions = Actions;
private psSubscription: Subscription;
private profileSubscription: Subscription;
constructor(public ps: PermissionsService, private profileService: ProfileService) {
this.setPermissions();
this.psSubscription = this.ps.changes.subscribe(() => this.setPermissions());
this.profileSubscription = this.profileService.profileState.subscribe(() => this.setPermissions());
}
ngOnDestroy() {
this.psSubscription.unsubscribe();
this.profileSubscription.unsubscribe();
}
@ViewChildren(DropdownDirective) dropdownDirectives;
closeOtherDropdown(sd: DropdownDirective) {
this.dropdownDirectives.forEach((entry: DropdownDirective) => {
if (entry !== sd) {
entry.close()
}
});
}
private setPermissions() {
this.showAdmin = this.ps.isAllow(Actions.UsersManagement);
this.showInvites = this.ps.isAllow(Actions.InviteUser);
this.showUsers = this.ps.isAllow(Actions.UsersManagement);
this.showRoot = this.ps.isAllow(Actions.CompaniesManagement);
}
}
<div class="sidebar">
<nav class="sidebar-nav">
<ul class="nav">
<li class="nav-item">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/contacts']"><i class="icon-people"></i>Contacts</a>
</li>
<li class="nav-item nav-dropdown" routerLinkActive="open" *ngIf="showAdmin">
<a class="nav-link nav-dropdown-toggle" href="#"><i class="icon-star"></i> Admin</a>
<ul class="nav-dropdown-items">
<li class="nav-item" *ngIf="showInvites">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/admin', 'invites']">
<i class="icon-puzzle"></i> Invites</a>
</li>
<li class="nav-item" *ngIf="showUsers">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/admin', 'users']">
<i class="icon-user"></i> Users</a>
</li>
<li class="nav-item" *ngIf="showRoot">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/root']">
<i class="icon-user"></i> Root</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>