summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/definition/dashboard-report-grid/dashboard-report-grid.component.ts
blob: 25137322c189e184bac94278e88f820eec6a79e3 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import {Component, OnInit, EventEmitter, Output, Input} from '@angular/core';
import {CompactType, DisplayGrid, GridsterConfig, GridsterItem, GridType} from 'angular-gridster2';
import {DashboardReportGridService} from './dashboard-report-grid.service';


@Component({
    selector: 'app-dashboard-report-grid',
    templateUrl: './dashboard-report-grid.component.html',
    styleUrls: ['./dashboard-report-grid.component.css']
})
export class DashboardReportGridComponent implements OnInit {

    @Input ("reportMode") reportMode : string;
    options: GridsterConfig;
    originalDashboardLength: number;
    reportNo: {};
    reportDataList: any;
    reportChartList: any;
    filteredItemsData: any;
    filteredItemsChart: any;
    // dashboard : {}[];
    reportList: {}[];
    showSpinner: boolean;
    hideChart: true;

    @Input('fetchedDashboardObj') dashboard: Array<GridsterItem> = [];
    // @Input("fetchedDashboardObj") fetchedDashboardObj : any;


    @Output() transferDashboardObj = new EventEmitter<any>();
    name: any;

    constructor(private _dashboardReportGridService: DashboardReportGridService) {
        this.reportDataList = [];
        this.reportChartList = [];
        this.reportList = [];
    }

    ngOnInit() {

        this.showSpinner = true;
        // this.dashboard = this.fetchedDashboardObj;


        this.options = {
            gridType: GridType.Fixed,
            margin: 10,
            outerMargin: true,
            outerMarginTop: 10,
            outerMarginRight: 10,
            outerMarginBottom: 700,
            outerMarginLeft: 10,
            scrollSensitivity: 10,
            scrollSpeed: 20,
            emptyCellDragMaxCols: null,
            emptyCellDragMaxRows: null,
            emptyCellDropCallback: this.emptyCellClick.bind(this),
            emptyCellDragCallback: this.emptyCellClick.bind(this),
            ignoreContentClass: 'gridster-item-content',
            enableOccupiedCellDrop: true,
            ignoreMarginInRow: false,
            draggable: {
                enabled: true,
            },
            resizable: {
                enabled: true,
            },
            swap: false,
            pushItems: true,
            disablePushOnDrag: false,
            disablePushOnResize: false,
            pushDirections: {north: true, east: true, south: true, west: true},
            pushResizeItems: true,
            disableWindowResize: true,
            disableWarnings: false,
            scrollToNewItems: true,
            enableDropToAdd: true,
            enableEmptyCellDrop: true,
            minCols: 2,
            minRows: 2,
        };


        if(this.reportMode !== 'Copy'){
        this._dashboardReportGridService.getReportList()
            .subscribe((responseReportList) => {
                let i = 0;

                while (responseReportList['rows'][0][i]) {
                    let j = 0;
                    let name = '';
                    let id = '';

                    while (responseReportList['rows'][0][i][j]) {
                        if (responseReportList['rows'][0][i][j]['columnId'] === 'rep_id') {
                            id = responseReportList['rows'][0][i][j]['searchresultField']['displayValue'];
                        }

                        if (responseReportList['rows'][0][i][j]['columnId'] === 'rep_name') {
                            name = responseReportList['rows'][0][i][j]['searchresultField']['displayValue'];
                        }


                        j++;
                    }
                    this.reportDataList.push({name: name, id: 'Data#' + id, hideDisplay: false});
                    this.reportChartList.push({name: name, id: 'Chart#' + id, hideDisplay: false});
                    i++;
                }
                this.assignCopy();
                this.showSpinner = false;
            });

        }
       
        this.assignCopy();
    }

    changedOptions() {
        if (this.options.api && this.options.api.optionsChanged) {
            this.options.api.optionsChanged();
        }
    }

    assignCopy() {

        this.filteredItemsData = Object.assign([], this.reportDataList);
        this.filteredItemsChart = Object.assign([], this.reportChartList);


    }

    filterItem(value) {
        if (!value) {
            this.assignCopy();
        } // when nothing has typed
        this.filteredItemsData = Object.assign([], this.reportDataList).filter(
            item => (item['name'].toLowerCase().indexOf(value.toLowerCase()) > -1 || item['id'].toLowerCase().indexOf(value.toLowerCase()) > -1)
        );
        this.filteredItemsChart = Object.assign([], this.reportChartList).filter(
            item => (item['name'].toLowerCase().indexOf(value.toLowerCase()) > -1 || item['id'].toLowerCase().indexOf(value.toLowerCase()) > -1)
        );
    }

    emptyCellClick(event: MouseEvent, item: GridsterItem) {
        console.log(this.dashboard);
        this.dashboard.push(item);
    }

    removeItem($event, item) {
        $event.preventDefault();
        $event.stopPropagation();
        this.dashboard.splice(this.dashboard.indexOf(item), 1);
        console.log(item.hasContent['id'].split('#')[0]);
        if (item.hasContent['id'].split('#')[0] === 'Data') {
            this.reportDataList.push(item.hasContent);
            this.assignCopy();
        }

        if (item.hasContent['id'].split('#')[0] === 'Chart') {
            this.reportChartList.push(item.hasContent);
            this.assignCopy();
        }

    }

    addItem() {
        this.dashboard.push({
            x: 0,
            y: 0,
            cols: 1,
            rows: 1,
            dragEnabled: true,
            resizeEnabled: true,
            label: 'Drag&Resize Enabled',
            hasContent: 'Hey'
        });
    }

    dragStartHandler(ev, report: {}) {

        this.originalDashboardLength = this.dashboard.length;
        ev.dataTransfer.setData('text/plain', 'Drag Me Button');
        ev.dataTransfer.dropEffect = 'copy';
        this.reportNo = report;
        console.log(this.reportNo);


        console.log(this.dashboard.length);


    }

    ngDoCheck() {
        if (this.dashboard.length > this.originalDashboardLength) {
            console.log(this.reportNo);
            this.dashboard[this.dashboard.length - 1]['hasContent'] = this.reportNo;


            for (let i = 0; i < this.reportDataList.length; i++) {
                if (this.reportDataList[i]['id'] === this.reportNo['id']) {
                    this.reportDataList.splice(i, 1);
                    this.assignCopy();
                }
            }

            for (let i = 0; i < this.reportChartList.length; i++) {
                if (this.reportChartList[i]['id'] === this.reportNo['id']) {
                    this.reportChartList.splice(i, 1);
                    this.assignCopy();
                }
            }

        }
        if (this.dashboard.length == this.originalDashboardLength) {
            console.log('hello');
        }

        this.transferDashboardObj.emit(this.dashboard);
    }

    setHideDisplay(item: GridsterItem) {
        this.transferDashboardObj.emit(this.dashboard);
    }
}