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' ;
43import { CompactType , GridsterConfig , GridsterItem , GridType } from 'angular-gridster2' ;
54import { UUID } from 'angular2-uuid' ;
5+ import { NgxSpinnerService } from 'ngx-spinner' ;
6+ import { Observable } from 'rxjs' ;
7+ import { map , tap } from 'rxjs/operators' ;
68import { IComponent } from '../../graphic-builder/dashboard-builder/shared/services/layout.service' ;
79import { rebuildVisualizationFilterTime } from '../../graphic-builder/shared/util/chart-filter/chart-filter.util' ;
810import { DashboardBehavior } from '../../shared/behaviors/dashboard.behavior' ;
@@ -11,20 +13,20 @@ import {UtmDashboardVisualizationType} from '../../shared/chart/types/dashboard/
1113import { UtmDashboardType } from '../../shared/chart/types/dashboard/utm-dashboard.type' ;
1214import { VisualizationType } from '../../shared/chart/types/visualization.type' ;
1315import { 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' ;
1418import { DashboardFilterType } from '../../shared/types/filter/dashboard-filter.type' ;
1519import { ElasticFilterType } from '../../shared/types/filter/elastic-filter.type' ;
1620import { mergeParams , sanitizeFilters } from '../../shared/util/elastic-filter.util' ;
1721import { filtersToStringParam } from '../../shared/util/query-params-to-filter.util' ;
1822import { normalizeString } from '../../shared/util/string-util' ;
1923import { 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" ;
2324
2425@Component ( {
2526 selector : 'app-dashboard-render' ,
2627 templateUrl : './dashboard-render.component.html' ,
27- styleUrls : [ './dashboard-render.component.scss' ]
28+ styleUrls : [ './dashboard-render.component.scss' ] ,
29+ changeDetection : ChangeDetectionStrategy . OnPush
2830} )
2931export class DashboardRenderComponent implements OnInit , OnDestroy , AfterViewInit {
3032 dashboardId : number ;
@@ -59,25 +61,37 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
5961 swap : false
6062 } ;
6163 filtersValues : ElasticFilterType [ ] = [ ] ;
62- timeEnable : number [ ] = [ ] ;
64+ layout$ : Observable < { grid : GridsterItem , visualization : VisualizationType } [ ] > ;
6365
6466 constructor ( private activatedRoute : ActivatedRoute ,
6567 private layoutService : RenderLayoutService ,
6668 private cdr : ChangeDetectorRef ,
67- private modalService : NgbModal ,
6869 private dashboardBehavior : DashboardBehavior ,
6970 private timeFilterBehavior : TimeFilterBehavior ,
70- private utmRenderVisualization : UtmRenderVisualization ,
7171 private exportPdfService : ExportPdfService ,
72- private spinner : NgxSpinnerService ) {
72+ private spinner : NgxSpinnerService ,
73+ private refreshService : RefreshService ,
74+ private router : Router ) {
7375 }
7476
7577 ngOnInit ( ) {
76- console . log ( 'Init dashboard' ) ;
77-
7878 document . body . classList . add ( 'overflow-hidden' ) ;
7979 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 => {
8195 this.dashboardId = params.id;
8296 if (this.dashboardId) {
8397 const request = {
@@ -105,14 +119,15 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
105119 this.loadingVisualizations = false;
106120 });
107121 }
108- } ) ;
122+ });*/
109123 this . dashboardBehavior . $filterDashboard . subscribe ( dashboardFilter => {
110124 if ( dashboardFilter ) {
111125 mergeParams ( dashboardFilter . filter , this . filtersValues ) . then ( newFilters => {
112126 this . filtersValues = sanitizeFilters ( newFilters ) ;
113127 } ) ;
114128 }
115129 } ) ;
130+
116131 this . timeFilterBehavior . $time . subscribe ( time => {
117132 if ( time ) {
118133 rebuildVisualizationFilterTime ( { timeFrom : time . from , timeTo : time . to } , this . filtersValues ) . then ( filters => {
@@ -146,9 +161,7 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
146161 ngOnDestroy ( ) : void {
147162 document . body . classList . remove ( 'overflow-hidden' ) ;
148163 clearInterval ( this . interval ) ;
149- this . visualizationRender = [ ] ;
150- this . layoutService . layout = [ ] ;
151- this . timeEnable = [ ] ;
164+ this . layoutService . clearLayout ( ) ;
152165 this . dashboardBehavior . $filterDashboard . next ( null ) ;
153166 }
154167
@@ -164,7 +177,7 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
164177 exportToPdf ( ) {
165178 filtersToStringParam ( this . filtersValues ) . then ( queryParams => {
166179 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 ;
168181 // window.open('/dashboard/export/' + this.dashboardId + '/' + normalizeString(this.dashboard.name) + '?' + queryParams, '_blank');
169182 this . exportPdfService . getPdf ( url , this . dashboard . name , 'PDF_TYPE_TOKEN' ) . subscribe ( response => {
170183 this . spinner . hide ( 'buildPrintPDF' ) . then ( ( ) =>
@@ -175,5 +188,9 @@ export class DashboardRenderComponent implements OnInit, OnDestroy, AfterViewIni
175188 } ) ;
176189 } ) ;
177190 }
191+
192+ trackByFn ( index : number , item : { grid : GridsterItem , visualization : VisualizationType } ) {
193+ return item . visualization . id ;
194+ }
178195}
179196
0 commit comments