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 @Input ("reportMode") reportMode : string;
14 options: GridsterConfig;
15 originalDashboardLength: number;
19 filteredItemsData: any;
20 filteredItemsChart: any;
26 @Input('fetchedDashboardObj') dashboard: Array<GridsterItem> = [];
27 // @Input("fetchedDashboardObj") fetchedDashboardObj : any;
30 @Output() transferDashboardObj = new EventEmitter<any>();
32 constructor(private _dashboardReportGridService: DashboardReportGridService) {
33 this.reportDataList = [];
34 this.reportChartList = [];
40 this.showSpinner = true;
41 // this.dashboard = this.fetchedDashboardObj;
45 gridType: GridType.Fixed,
50 outerMarginBottom: 700,
52 scrollSensitivity: 10,
54 emptyCellDragMaxCols: null,
55 emptyCellDragMaxRows: null,
56 emptyCellDropCallback: this.emptyCellClick.bind(this),
57 emptyCellDragCallback: this.emptyCellClick.bind(this),
58 ignoreContentClass: 'gridster-item-content',
59 enableOccupiedCellDrop: true,
60 ignoreMarginInRow: false,
69 disablePushOnDrag: false,
70 disablePushOnResize: false,
71 pushDirections: {north: true, east: true, south: true, west: true},
72 pushResizeItems: true,
73 disableWindowResize: true,
74 disableWarnings: false,
75 scrollToNewItems: true,
76 enableDropToAdd: true,
77 enableEmptyCellDrop: true,
83 if(this.reportMode !== 'Copy'){
84 this._dashboardReportGridService.getReportList()
85 .subscribe((responseReportList) => {
88 while (responseReportList['rows'][0][i]) {
93 while (responseReportList['rows'][0][i][j]) {
94 if (responseReportList['rows'][0][i][j]['columnId'] === 'rep_id') {
95 id = responseReportList['rows'][0][i][j]['searchresultField']['displayValue'];
98 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, hideDisplay: false});
106 this.reportChartList.push({name: name, id: 'Chart#' + id, hideDisplay: false});
110 this.showSpinner = false;
119 if (this.options.api && this.options.api.optionsChanged) {
120 this.options.api.optionsChanged();
126 this.filteredItemsData = Object.assign([], this.reportDataList);
127 this.filteredItemsChart = Object.assign([], this.reportChartList);
135 } // when nothing has typed
136 this.filteredItemsData = Object.assign([], this.reportDataList).filter(
137 item => (item['name'].toLowerCase().indexOf(value.toLowerCase()) > -1 || item['id'].toLowerCase().indexOf(value.toLowerCase()) > -1)
139 this.filteredItemsChart = Object.assign([], this.reportChartList).filter(
140 item => (item['name'].toLowerCase().indexOf(value.toLowerCase()) > -1 || item['id'].toLowerCase().indexOf(value.toLowerCase()) > -1)
144 emptyCellClick(event: MouseEvent, item: GridsterItem) {
145 console.log(this.dashboard);
146 this.dashboard.push(item);
149 removeItem($event, item) {
150 $event.preventDefault();
151 $event.stopPropagation();
152 this.dashboard.splice(this.dashboard.indexOf(item), 1);
153 console.log(item.hasContent['id'].split('#')[0]);
154 if (item.hasContent['id'].split('#')[0] === 'Data') {
155 this.reportDataList.push(item.hasContent);
159 if (item.hasContent['id'].split('#')[0] === 'Chart') {
160 this.reportChartList.push(item.hasContent);
167 this.dashboard.push({
174 label: 'Drag&Resize Enabled',
179 dragStartHandler(ev, report: {}) {
181 this.originalDashboardLength = this.dashboard.length;
182 ev.dataTransfer.setData('text/plain', 'Drag Me Button');
183 ev.dataTransfer.dropEffect = 'copy';
184 this.reportNo = report;
185 console.log(this.reportNo);
188 console.log(this.dashboard.length);
194 if (this.dashboard.length > this.originalDashboardLength) {
195 console.log(this.reportNo);
196 this.dashboard[this.dashboard.length - 1]['hasContent'] = this.reportNo;
199 for (let i = 0; i < this.reportDataList.length; i++) {
200 if (this.reportDataList[i]['id'] === this.reportNo['id']) {
201 this.reportDataList.splice(i, 1);
206 for (let i = 0; i < this.reportChartList.length; i++) {
207 if (this.reportChartList[i]['id'] === this.reportNo['id']) {
208 this.reportChartList.splice(i, 1);
214 if (this.dashboard.length == this.originalDashboardLength) {
215 console.log('hello');
218 this.transferDashboardObj.emit(this.dashboard);
221 setHideDisplay(item: GridsterItem) {
222 this.transferDashboardObj.emit(this.dashboard);