1
- import { AfterViewInit , ChangeDetectorRef , Component , OnDestroy , OnInit } from '@angular/core' ;
2
- import { ActivatedRoute } from '@angular/router' ;
3
- import { NgbModal } from '@ng-bootstrap/ng-bootstrap' ;
1
+ import { AfterViewInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , OnDestroy , OnInit } from '@angular/core' ;
2
+ import { ActivatedRoute , Router } from '@angular/router' ;
4
3
import { CompactType , GridsterConfig , GridsterItem , GridType } from 'angular-gridster2' ;
5
4
import { UUID } from 'angular2-uuid' ;
5
+ import { NgxSpinnerService } from 'ngx-spinner' ;
6
+ import { Observable } from 'rxjs' ;
7
+ import { map , tap } from 'rxjs/operators' ;
6
8
import { IComponent } from '../../graphic-builder/dashboard-builder/shared/services/layout.service' ;
7
9
import { rebuildVisualizationFilterTime } from '../../graphic-builder/shared/util/chart-filter/chart-filter.util' ;
8
10
import { DashboardBehavior } from '../../shared/behaviors/dashboard.behavior' ;
@@ -11,20 +13,20 @@ import {UtmDashboardVisualizationType} from '../../shared/chart/types/dashboard/
11
13
import { UtmDashboardType } from '../../shared/chart/types/dashboard/utm-dashboard.type' ;
12
14
import { VisualizationType } from '../../shared/chart/types/visualization.type' ;
13
15
import { ChartTypeEnum } from '../../shared/enums/chart-type.enum' ;
16
+ import { ExportPdfService } from '../../shared/services/util/export-pdf.service' ;
17
+ import { RefreshService } from '../../shared/services/util/refresh.service' ;
14
18
import { DashboardFilterType } from '../../shared/types/filter/dashboard-filter.type' ;
15
19
import { ElasticFilterType } from '../../shared/types/filter/elastic-filter.type' ;
16
20
import { mergeParams , sanitizeFilters } from '../../shared/util/elastic-filter.util' ;
17
21
import { filtersToStringParam } from '../../shared/util/query-params-to-filter.util' ;
18
22
import { normalizeString } from '../../shared/util/string-util' ;
19
23
import { RenderLayoutService } from '../shared/services/render-layout.service' ;
20
- import { UtmRenderVisualization } from '../shared/services/utm-render-visualization.service' ;
21
- import { ExportPdfService } from "../../shared/services/util/export-pdf.service" ;
22
- import { NgxSpinnerService } from "ngx-spinner" ;
23
24
24
25
@Component ( {
25
26
selector : 'app-dashboard-render' ,
26
27
templateUrl : './dashboard-render.component.html' ,
27
- styleUrls : [ './dashboard-render.component.scss' ]
28
+ styleUrls : [ './dashboard-render.component.scss' ] ,
29
+ changeDetection : ChangeDetectionStrategy . OnPush
28
30
} )
29
31
export class DashboardRenderComponent implements OnInit , OnDestroy , AfterViewInit {
30
32
dashboardId : number ;
@@ -59,25 +61,37 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
59
61
swap : false
60
62
} ;
61
63
filtersValues : ElasticFilterType [ ] = [ ] ;
62
- timeEnable : number [ ] = [ ] ;
64
+ layout$ : Observable < { grid : GridsterItem , visualization : VisualizationType } [ ] > ;
63
65
64
66
constructor ( private activatedRoute : ActivatedRoute ,
65
67
private layoutService : RenderLayoutService ,
66
68
private cdr : ChangeDetectorRef ,
67
- private modalService : NgbModal ,
68
69
private dashboardBehavior : DashboardBehavior ,
69
70
private timeFilterBehavior : TimeFilterBehavior ,
70
- private utmRenderVisualization : UtmRenderVisualization ,
71
71
private exportPdfService : ExportPdfService ,
72
- private spinner : NgxSpinnerService ) {
72
+ private spinner : NgxSpinnerService ,
73
+ private refreshService : RefreshService ,
74
+ private router : Router ) {
73
75
}
74
76
75
77
ngOnInit ( ) {
76
- console . log ( 'Init dashboard' ) ;
77
-
78
78
document . body . classList . add ( 'overflow-hidden' ) ;
79
79
this . loadingVisualizations = true ;
80
- this . activatedRoute . params . subscribe ( params => {
80
+ this . layout$ = this . activatedRoute . data
81
+ . pipe (
82
+ tap ( ( visualizations ) => {
83
+ this . dashboard = this . layoutService . dashboard ;
84
+ this . filters = this . dashboard && this . dashboard . filters ? JSON . parse ( this . dashboard . filters ) : [ ] ;
85
+ /* if (this.dashboard.refreshTime) {
86
+ console.log(this.dashboard.refreshTime);
87
+ this.onRefreshTime(this.dashboard.refreshTime);
88
+ }*/
89
+ this . loadingVisualizations = false ;
90
+ } ) ,
91
+ map ( data => data . response )
92
+ ) ;
93
+
94
+ /*this.activatedRoute.params.subscribe(params => {
81
95
this.dashboardId = params.id;
82
96
if (this.dashboardId) {
83
97
const request = {
@@ -105,14 +119,15 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
105
119
this.loadingVisualizations = false;
106
120
});
107
121
}
108
- } ) ;
122
+ });*/
109
123
this . dashboardBehavior . $filterDashboard . subscribe ( dashboardFilter => {
110
124
if ( dashboardFilter ) {
111
125
mergeParams ( dashboardFilter . filter , this . filtersValues ) . then ( newFilters => {
112
126
this . filtersValues = sanitizeFilters ( newFilters ) ;
113
127
} ) ;
114
128
}
115
129
} ) ;
130
+
116
131
this . timeFilterBehavior . $time . subscribe ( time => {
117
132
if ( time ) {
118
133
rebuildVisualizationFilterTime ( { timeFrom : time . from , timeTo : time . to } , this . filtersValues ) . then ( filters => {
@@ -146,9 +161,7 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
146
161
ngOnDestroy ( ) : void {
147
162
document . body . classList . remove ( 'overflow-hidden' ) ;
148
163
clearInterval ( this . interval ) ;
149
- this . visualizationRender = [ ] ;
150
- this . layoutService . layout = [ ] ;
151
- this . timeEnable = [ ] ;
164
+ this . layoutService . clearLayout ( ) ;
152
165
this . dashboardBehavior . $filterDashboard . next ( null ) ;
153
166
}
154
167
@@ -164,7 +177,7 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
164
177
exportToPdf ( ) {
165
178
filtersToStringParam ( this . filtersValues ) . then ( queryParams => {
166
179
this . spinner . show ( 'buildPrintPDF' ) ;
167
- const url = '/dashboard/export/' + this . dashboardId + '/' + normalizeString ( this . dashboard . name ) + '?' + queryParams ;
180
+ const url = '/dashboard/export/' + this . dashboard . id + '/' + normalizeString ( this . dashboard . name ) + '?' + queryParams ;
168
181
// window.open('/dashboard/export/' + this.dashboardId + '/' + normalizeString(this.dashboard.name) + '?' + queryParams, '_blank');
169
182
this . exportPdfService . getPdf ( url , this . dashboard . name , 'PDF_TYPE_TOKEN' ) . subscribe ( response => {
170
183
this . spinner . hide ( 'buildPrintPDF' ) . then ( ( ) =>
@@ -175,5 +188,9 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
175
188
} ) ;
176
189
} ) ;
177
190
}
191
+
192
+ trackByFn ( index : number , item : { grid : GridsterItem , visualization : VisualizationType } ) {
193
+ return item . visualization . id ;
194
+ }
178
195
}
179
196
0 commit comments