view-roles.component.ts 2.24 KB
import { DOCUMENT } from '@angular/common';
import { Component, Inject, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material';
import { AddRoleDialogComponent } from '../add-role-dialog/add-role-dialog.component';

const defaultDialogConfig = new MatDialogConfig();

@Component({
  selector: 'app-view-roles',
  templateUrl: './view-roles.component.html',
  styleUrls: ['./view-roles.component.scss']
})
export class ViewRolesComponent implements OnInit {

  roleDataSOurce=ROLE_DATA;

  dialogRef: MatDialogRef<any> | null;
  lastAfterClosedResult: string;
  lastBeforeCloseResult: string;
  actionsAlignment: string;

  config = {
    disableClose: false,
    panelClass: 'custom-overlay-pane-class',
    hasBackdrop: true,
    backdropClass: '',
    width: '500px',
    height: '300px',
    minWidth: '',
    minHeight: '',
    maxWidth: defaultDialogConfig.maxWidth,
    maxHeight: '',
    position: {
      top: '',
      bottom: '',
      left: '',
      right: ''
    },
  };
  numTemplateOpens = 0;

  @ViewChild(TemplateRef) template: TemplateRef<any>;

  constructor(public dialog: MatDialog, @Inject(DOCUMENT) doc: any) {
    dialog.afterOpen.subscribe(() => {
      if (!doc.body.classList.contains('no-scroll')) {
        doc.body.classList.add('no-scroll');
      }
    });
    dialog.afterAllClosed.subscribe(() => {
      doc.body.classList.remove('no-scroll');
    });
  }
  addRoleDialog() {
    this.dialogRef = this.dialog.open(AddRoleDialogComponent, this.config);
    this.dialogRef.beforeClose().subscribe((result: string) => {
      this.lastBeforeCloseResult = result;
    });
    this.dialogRef.afterClosed().subscribe((result: string) => {
      this.lastAfterClosedResult = result;
      this.dialogRef = null;
    });
  }

  ngOnInit() {
  }

}
export interface RoleDataElement {
  roleId: number;
  roleName: string;
  status: number;
}
const ROLE_DATA: RoleDataElement[] = [
  {
    roleId: 1,
    roleName: "CS",
    status: 0
  }, {
    roleId: 2,
    roleName: "ADMIN",
    status: 0
  }, {
    roleId: 3,
    roleName: "SUPER ADMIN",
    status: 0
  }, {
    roleId: 4,
    roleName: "OPERATOR",
    status: 0
  }, {
    roleId: 5,
    roleName: "DEVELOPER",
    status: 0
  },

];