summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/admin/menus/menus.component.ts
blob: 3575486d7e99bf2763c8255ce46a11cf9f4e273e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { AdminService } from '../admin.service';
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';

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

  constructor(public adminService: AdminService,private ngModal: NgbModal) { }

  menuHeaders = ["menuId","label","paretId","action","functionCd","active","servlet","queryString","externalUrl","target","menuSetCode","separator","imageSrc","Edit","Delete"];

  response: any;
  result: any;
  functionalMenuRes:any;
  tableData;
  dataSource: MatTableDataSource<[]>;
  closeResult: string;
  
  
  @ViewChild(MatPaginator, {}) paginator: MatPaginator;
  @ViewChild(MatSort, {}) sort: MatSort;

  ngOnInit() {
    this.getMenus();
  }

  getMenus(){
  let response;
  this.response = this.adminService.getFnMenuItems();
  this.response.subscribe(data => {
  response = data;
  this.functionalMenuRes =JSON.parse(response.data);
  this.tableData =this.functionalMenuRes.fnMenuItems;   
  this.dataSource = new MatTableDataSource(this.tableData);
  this.dataSource.paginator = this.paginator;
  this.dataSource.sort = this.sort;    
  });
 }
  removeMenuItem(item: any) {
    const modalRef = this.ngModal.open(InformationModalComponent);
    modalRef.componentInstance.title = 'Confirmation';
    let response;
    modalRef.componentInstance.message = `Are you sure you want to delete ${item.label} ?`;
    modalRef.result.then((result) => {
      if (result === 'Ok') {
        this.adminService.deleteMenu(item).subscribe(data => {
          response = data;
          this.getMenus();
        })
      }
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

  private getDismissReason(reason: any): string {
    if (reason === ModalDismissReasons.ESC) {
      return 'by pressing ESC';
    } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
      return 'by clicking on a backdrop';
    } else {
      return `with: ${reason}`;
    }

}

}