File

src/app/layouts/main-layout/sidebar.component.ts

Implements

OnDestroy

Metadata

selector crm-sidebar
templateUrl ./sidebar.component.html

Index

Properties
Methods

Constructor

constructor(ps: PermissionsService, profileService: ProfileService)
Parameters :
Name Type Optional Description
ps PermissionsService
profileService ProfileService

Methods

closeOtherDropdown
closeOtherDropdown(sd: DropdownDirective)
Parameters :
Name Type Optional Description
sd DropdownDirective
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
Private setPermissions
setPermissions()
Returns : void

Properties

actions
actions:
Default value : Actions
dropdownDirectives
dropdownDirectives:
Decorators : ViewChildren
Private profileSubscription
profileSubscription: Subscription
Type : Subscription
Public ps
ps: PermissionsService
Type : PermissionsService
Private psSubscription
psSubscription: Subscription
Type : Subscription
showAdmin
showAdmin: boolean
Type : boolean
showInvites
showInvites: boolean
Type : boolean
showRoot
showRoot: boolean
Type : boolean
Default value : false
showUsers
showUsers: boolean
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>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""