1 import { Component, OnInit, EventEmitter, Output, Input } from '@angular/core';
2 import {CompactType, DisplayGrid, GridsterConfig, GridsterItem, GridType} from 'angular-gridster2';
3 import { DashboardReportGridService } from './dashboard-report-grid.service';
7 selector: 'app-dashboard-report-grid',
8 templateUrl: './dashboard-report-grid.component.html',
9 styleUrls: ['./dashboard-report-grid.component.css']
11 export class DashboardReportGridComponent implements OnInit {
13 options: GridsterConfig;
14 originalDashboardLength : number;
17 reportChartList : any;
18 filteredItemsData : any;
19 filteredItemsChart : any;
22 showSpinner : boolean;
24 @Input("fetchedDashboardObj") dashboard : Array<GridsterItem> = new Array();
25 // @Input("fetchedDashboardObj") fetchedDashboardObj : any;
28 @Output() transferDashboardObj = new EventEmitter<any>();
30 constructor(private _dashboardReportGridService : DashboardReportGridService) {
31 this.reportDataList = new Array();
32 this.reportChartList = new Array();
33 this.reportList = new Array();
38 this.showSpinner = true;
39 // this.dashboard = this.fetchedDashboardObj;
43 gridType: GridType.Fixed,
48 outerMarginBottom: 700,
50 scrollSensitivity: 10,
52 emptyCellDragMaxCols: null,
53 emptyCellDragMaxRows: null,
54 emptyCellDropCallback: this.emptyCellClick.bind(this),
55 emptyCellDragCallback: this.emptyCellClick.bind(this),
56 ignoreContentClass: 'gridster-item-content',
57 enableOccupiedCellDrop : true,
58 ignoreMarginInRow: false,
67 disablePushOnDrag: false,
68 disablePushOnResize: false,
69 pushDirections: {north: true, east: true, south: true, west: true},
70 pushResizeItems: true,
71 disableWindowResize: true,
72 disableWarnings: false,
73 scrollToNewItems: true,
74 enableDropToAdd : true,
75 enableEmptyCellDrop : true,
80 this._dashboardReportGridService.getReportList()
81 .subscribe((responseReportList) => {
84 while(responseReportList["rows"][0][i])
90 while(responseReportList["rows"][0][i][j])
92 if(responseReportList["rows"][0][i][j]["columnId"] === "rep_id")
94 id = responseReportList["rows"][0][i][j]["searchresultField"]["displayValue"];
97 if(responseReportList["rows"][0][i][j]["columnId"] === "rep_name")
99 name = responseReportList["rows"][0][i][j]["searchresultField"]["displayValue"];
105 this.reportDataList.push({name : name, id : "Data#" + id});
106 this.reportChartList.push({name : name, id : "Chart#" + id});
109 // console.log(responseReportList["rows"][0]);
111 this.showSpinner = false;
115 // this.reportDataList = [
116 // {name : "E911 report - PointClickTool - 911 Contacts", id : "Data#1972"}
119 // this.reportChartList = [
120 // {name : "E911 report - PointClickTool - 911 Contacts", id : "Chart#1972"}
128 if (this.options.api && this.options.api.optionsChanged) {
129 this.options.api.optionsChanged();
135 this.filteredItemsData = Object.assign([], this.reportDataList);
136 this.filteredItemsChart = Object.assign([], this.reportChartList);
144 } // when nothing has typed
145 this.filteredItemsData = Object.assign([], this.reportDataList).filter(
146 item => (item["name"].toLowerCase().indexOf(value.toLowerCase()) > -1 || item["id"].toLowerCase().indexOf(value.toLowerCase()) > -1)
148 this.filteredItemsChart = Object.assign([], this.reportChartList).filter(
149 item => (item["name"].toLowerCase().indexOf(value.toLowerCase()) > -1 || item["id"].toLowerCase().indexOf(value.toLowerCase()) > -1)
153 emptyCellClick(event: MouseEvent, item: GridsterItem) {
154 // console.info('empty cell click', event, item);
155 console.log(this.dashboard);
156 this.dashboard.push(item);
159 removeItem($event, item) {
160 $event.preventDefault();
161 $event.stopPropagation();
162 this.dashboard.splice(this.dashboard.indexOf(item), 1);
163 console.log(item.hasContent["id"].split("#")[0]);
164 if(item.hasContent["id"].split("#")[0] === "Data")
166 this.reportDataList.push(item.hasContent);
170 if(item.hasContent["id"].split("#")[0] === "Chart")
172 this.reportChartList.push(item.hasContent);
179 this.dashboard.push({x: 0, y: 0, cols: 1, rows: 1, dragEnabled: true, resizeEnabled: true, label: 'Drag&Resize Enabled', hasContent:'Hey'});
182 dragStartHandler(ev, report : {}) {
184 this.originalDashboardLength = this.dashboard.length;
185 ev.dataTransfer.setData('text/plain', 'Drag Me Button');
186 ev.dataTransfer.dropEffect = 'copy';
187 this.reportNo = report;
188 console.log(this.reportNo);
191 console.log(this.dashboard.length);
198 if(this.dashboard.length > this.originalDashboardLength)
200 console.log(this.reportNo);
201 this.dashboard[this.dashboard.length-1]["hasContent"]= this.reportNo;
204 for(let i=0; i<this.reportDataList.length; i++)
206 if(this.reportDataList[i]["id"] === this.reportNo["id"])
208 this.reportDataList.splice(i, 1);
213 for(let i=0; i<this.reportChartList.length; i++)
215 if(this.reportChartList[i]["id"] === this.reportNo["id"])
217 this.reportChartList.splice(i, 1);
224 this.transferDashboardObj.emit(this.dashboard);