You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2020/03/01 17:05:54 UTC

[incubator-streampipes] branch STREAMPIPES-79 updated: Store and load widgets in dashboard views

This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch STREAMPIPES-79
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/STREAMPIPES-79 by this push:
     new fa2b84a  Store and load widgets in dashboard views
fa2b84a is described below

commit fa2b84a7393cba6a9d0534e8843e38afd3f0870c
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Sun Mar 1 18:03:23 2020 +0100

    Store and load widgets in dashboard views
---
 .../data-explorer-dashboard-panel.component.ts     |  23 +--
 .../data-explorer-dashboard-widget.component.ts    |   4 +-
 .../services/data-view-data-explorer.service.ts    | 185 ++++++++++-----------
 .../platform-services/tsonld-serializer.service.ts |   9 +-
 ui/src/app/platform-services/tsonld/tsonld.ts      |  13 ++
 5 files changed, 122 insertions(+), 112 deletions(-)

diff --git a/ui/src/app/data-explorer-v2/components/panel/data-explorer-dashboard-panel.component.ts b/ui/src/app/data-explorer-v2/components/panel/data-explorer-dashboard-panel.component.ts
index bbcf4f0..eb1a024 100644
--- a/ui/src/app/data-explorer-v2/components/panel/data-explorer-dashboard-panel.component.ts
+++ b/ui/src/app/data-explorer-v2/components/panel/data-explorer-dashboard-panel.component.ts
@@ -24,6 +24,7 @@ import { DataExplorerAddVisualizationDialogComponent } from '../../dialogs/add-w
 import { IDataViewDashboard, IDataViewDashboardItem } from '../../models/dataview-dashboard.model';
 import { DataViewDataExplorerService } from '../../services/data-view-data-explorer.service';
 import { RefreshDashboardService } from '../../services/refresh-dashboard.service';
+import forkJoin = module
 
 @Component({
   selector: 'sp-data-explorer-dashboard-panel',
@@ -43,7 +44,7 @@ export class DataExplorerDashboardPanelComponent implements OnInit {
   widgetIdsToRemove: string[] = [];
   widgetsToUpdate: Map<string, DataExplorerWidgetModel> = new Map<string, DataExplorerWidgetModel>();
 
-  constructor(private dashboardService: DataViewDataExplorerService,
+  constructor(private dataViewDataExplorerService: DataViewDataExplorerService,
               public dialog: MatDialog,
               private refreshDashboardService: RefreshDashboardService) {
   }
@@ -79,16 +80,16 @@ export class DataExplorerDashboardPanelComponent implements OnInit {
   }
 
   updateDashboardAndCloseEditMode() {
-    // this.dashboardService.updateDashboard(this.dashboard).subscribe(result => {
-    //     if (this.widgetsToUpdate.size > 0) {
-    //         forkJoin(this.prepareWidgetUpdates()).subscribe(result => {
-    //             this.closeEditModeAndReloadDashboard();
-    //         });
-    //     } else {
-    //         this.deleteWidgets();
-    //         this.closeEditModeAndReloadDashboard();
-    //     }
-    // });
+    this.dataViewDataExplorerService.updateDashboard(this.dashboard).subscribe(result => {
+        if (this.widgetsToUpdate.size > 0) {
+            forkJoin(this.prepareWidgetUpdates()).subscribe(result => {
+                this.closeEditModeAndReloadDashboard();
+            });
+        } else {
+            this.deleteWidgets();
+            this.closeEditModeAndReloadDashboard();
+        }
+    });
 
     this.editModeChange.emit(!(this.editMode));
     this.refreshDashboardService.notify(this.dashboard._id);
diff --git a/ui/src/app/data-explorer-v2/components/widget/data-explorer-dashboard-widget.component.ts b/ui/src/app/data-explorer-v2/components/widget/data-explorer-dashboard-widget.component.ts
index a945174..2f2bc3f 100644
--- a/ui/src/app/data-explorer-v2/components/widget/data-explorer-dashboard-widget.component.ts
+++ b/ui/src/app/data-explorer-v2/components/widget/data-explorer-dashboard-widget.component.ts
@@ -42,12 +42,12 @@ export class DataExplorerDashboardWidgetComponent implements OnInit {
     widgetLoaded = false;
     configuredWidget: DataExplorerWidgetModel;
 
-    constructor(private dashboardService: DataViewDataExplorerService,
+    constructor(private dataViewDataExplorerService: DataViewDataExplorerService,
                 private dialog: MatDialog) {
     }
 
     ngOnInit(): void {
-        this.dashboardService.getWidget(this.widget.id).subscribe(response => {
+        this.dataViewDataExplorerService.getWidget(this.widget.id).subscribe(response => {
             this.configuredWidget = response;
             this.widgetLoaded = true;
         });
diff --git a/ui/src/app/data-explorer-v2/services/data-view-data-explorer.service.ts b/ui/src/app/data-explorer-v2/services/data-view-data-explorer.service.ts
index d10d4ea..065a300 100644
--- a/ui/src/app/data-explorer-v2/services/data-view-data-explorer.service.ts
+++ b/ui/src/app/data-explorer-v2/services/data-view-data-explorer.service.ts
@@ -33,102 +33,95 @@ import { IDataViewDashboard } from '../models/dataview-dashboard.model';
 @Injectable()
 export class DataViewDataExplorerService {
 
-    localDashboards: IDataViewDashboard[] = [];
-
-    constructor(private http: HttpClient,
-                private authStatusService: AuthStatusService,
-                private tsonLdSerializerService: TsonLdSerializerService,
-                private dataLakeRestService: DatalakeRestService,
-                private sharedDatalakeRestService: SharedDatalakeRestService) {
-    }
-
-    getVisualizableData(): Observable<InfoResult[]> {
-        return this.dataLakeRestService.getAllInfos();
-    }
-
-    getDataViews(): Observable<IDataViewDashboard[]> {
-      return this.sharedDatalakeRestService.getDashboards(this.getDashboardUrl());
-    }
-
-    updateDashboard(dashboard: IDataViewDashboard): Observable<IDataViewDashboard> {
-      return this.sharedDatalakeRestService.updateDashboard(this.getDashboardUrl(), dashboard);
-    }
-
-    deleteDashboard(dashboard: IDataViewDashboard): Observable<any> {
-      return this.sharedDatalakeRestService.deleteDashboard(this.getDashboardUrl(), dashboard);
-    }
-
-    saveDataView(dataViewDashboard: IDataViewDashboard): Observable<any> {
-      return this.sharedDatalakeRestService.saveDashboard(this.getDashboardUrl(), dataViewDashboard);
-    }
-
-    private getbaseUrl() {
-        return '/streampipes-backend';
-    }
-
-    private getDashboardUrl() {
-        return this.getbaseUrl() + '/api/v3/users/' + this.authStatusService.email + '/datalake/dashboard';
-    }
-
-    private getDashboardWidgetUrl() {
-        return this.getbaseUrl() + '/api/v3/users/' + this.authStatusService.email + '/datalake/dashboard/widgets';
-    }
-
-    getWidget(widgetId: string): Observable<DataExplorerWidgetModel> {
-        const promise = new Promise<DataExplorerWidgetModel>((resolve, reject) => {
-            this.http.get(this.getDashboardWidgetUrl() + '/' + widgetId).subscribe(response => {
-                const dashboardWidget: DataExplorerWidgetModel =
-                  this.tsonLdSerializerService.fromJsonLd(response, 'sp:DataLakeWidgetModel');
-                resolve(dashboardWidget);
-            });
+  localDashboards: IDataViewDashboard[] = [];
+
+  constructor(private http: HttpClient,
+              private authStatusService: AuthStatusService,
+              private tsonLdSerializerService: TsonLdSerializerService,
+              private dataLakeRestService: DatalakeRestService,
+              private sharedDatalakeRestService: SharedDatalakeRestService) {
+  }
+
+  getVisualizableData(): Observable<InfoResult[]> {
+    return this.dataLakeRestService.getAllInfos();
+  }
+
+  getDataViews(): Observable<IDataViewDashboard[]> {
+    return this.sharedDatalakeRestService.getDashboards(this.getDashboardUrl());
+  }
+
+  updateDashboard(dashboard: IDataViewDashboard): Observable<IDataViewDashboard> {
+    return this.sharedDatalakeRestService.updateDashboard(this.getDashboardUrl(), dashboard);
+  }
+
+  deleteDashboard(dashboard: IDataViewDashboard): Observable<any> {
+    return this.sharedDatalakeRestService.deleteDashboard(this.getDashboardUrl(), dashboard);
+  }
+
+  saveDataView(dataViewDashboard: IDataViewDashboard): Observable<any> {
+    return this.sharedDatalakeRestService.saveDashboard(this.getDashboardUrl(), dataViewDashboard);
+  }
+
+  private getbaseUrl() {
+    return '/streampipes-backend';
+  }
+
+  private getDashboardUrl() {
+    return this.getbaseUrl() + '/api/v3/users/' + this.authStatusService.email + '/datalake/dashboard';
+  }
+
+  private getDashboardWidgetUrl() {
+    return this.getbaseUrl() + '/api/v3/users/' + this.authStatusService.email + '/datalake/dashboard/widgets';
+  }
+
+  getWidget(widgetId: string): Observable<DataExplorerWidgetModel> {
+    const promise = new Promise<DataExplorerWidgetModel>((resolve, reject) => {
+      this.http.get(this.getDashboardWidgetUrl() + '/' + widgetId).subscribe(response => {
+        this.tsonLdSerializerService.jsonLdToFlattenJsonLd(response).subscribe(res => {
+          const dashboardWidget: DataExplorerWidgetModel =
+            this.tsonLdSerializerService.fromJsonLd(res, 'sp:DataExplorerWidgetModel');
+          resolve(dashboardWidget);
         });
-        return from(promise);
-    }
-
-    saveWidget(widget: DataExplorerWidgetModel): Observable<DataExplorerWidgetModel> {
-        const promise = new Promise<DataExplorerWidgetModel>((resolve, reject) => {
-            this.tsonLdSerializerService.toJsonLd(widget).subscribe(serialized => {
-                  this.http.post(this.getDashboardWidgetUrl(), serialized, this.jsonLdHeaders()).pipe(map(response => {
-                    resolve(this.tsonLdSerializerService.fromJsonLd(response, 'sp:DataLakeWidgetModel'));
-                })).subscribe();
-            });
+      });
+    });
+    return from(promise);
+  }
+
+  saveWidget(widget: DataExplorerWidgetModel): Observable<DataExplorerWidgetModel> {
+    const promise = new Promise<DataExplorerWidgetModel>((resolve, reject) => {
+      this.tsonLdSerializerService.toJsonLd(widget).subscribe(serialized => {
+        this.http.post(this.getDashboardWidgetUrl(), serialized, this.jsonLdHeaders()).pipe(map(response => {
+
+          this.tsonLdSerializerService.jsonLdToFlattenJsonLd(response).subscribe(res => {
+            resolve(this.tsonLdSerializerService.fromJsonLd(res, 'sp:DataExplorerWidgetModel'));
+          });
+
+        })).subscribe();
+      });
+    });
+    return from(promise);
+  }
+
+  deleteWidget(widgetId: string): Observable<any> {
+    return this.http.delete(this.getDashboardWidgetUrl() + '/' + widgetId);
+  }
+
+  updateWidget(widget: DataExplorerWidgetModel): Observable<any> {
+    const promise = new Promise<DataExplorerWidgetModel>((resolve, reject) => {
+      this.tsonLdSerializerService.toJsonLd(widget).subscribe(serialized => {
+        this.http.put(this.getDashboardWidgetUrl() + '/' + widget._id, serialized, this.jsonLdHeaders()).subscribe(result => {
+          resolve();
         });
-        return from(promise);
-    }
-
-    deleteWidget(widgetId: string): Observable<any> {
-        return this.http.delete(this.getDashboardWidgetUrl() + '/' + widgetId);
-    }
-
-    updateWidget(widget: DataExplorerWidgetModel): Observable<any> {
-        const promise = new Promise<DataExplorerWidgetModel>((resolve, reject) => {
-            this.tsonLdSerializerService.toJsonLd(widget).subscribe(serialized => {
-                this.http.put(this.getDashboardWidgetUrl() + '/' + widget._id, serialized, this.jsonLdHeaders()).subscribe(result => {
-                    resolve();
-                });
-            });
-        });
-        return from(promise);
-    }
-
-    serializeAndPost(url: string, object: any): Observable<DataExplorerWidgetModel> {
-        const promise = new Promise<DataExplorerWidgetModel>((resolve, reject) => {
-            this.tsonLdSerializerService.toJsonLd(object).subscribe(serialized => {
-              console.log(serialized);
-                // this.http.post(url, serialized, this.jsonLdHeaders()).pipe(map(response => {
-                //     resolve(this.tsonLdSerializerService.fromJsonLd(response, 'sp:DataLakeWidgetModel'));
-                // })).subscribe();
-            });
-        });
-        return from(promise);
-    }
-
-    jsonLdHeaders(): any {
-        console.log('asdfad')
-        return {
-            headers: new HttpHeaders({
-                'Content-Type': 'application/ld+json',
-            }),
-        };
-    }
+      });
+    });
+    return from(promise);
+  }
+
+  jsonLdHeaders(): any {
+    return {
+      headers: new HttpHeaders({
+        'Content-Type': 'application/ld+json',
+      }),
+    };
+  }
 }
diff --git a/ui/src/app/platform-services/tsonld-serializer.service.ts b/ui/src/app/platform-services/tsonld-serializer.service.ts
index 62b4be0..b60bce7 100644
--- a/ui/src/app/platform-services/tsonld-serializer.service.ts
+++ b/ui/src/app/platform-services/tsonld-serializer.service.ts
@@ -210,9 +210,12 @@ export class TsonLdSerializerService {
         return this.getTsonLd().fromJsonLdType(o, type);
     }
 
-    public fromJsonLdContainer(o: any, type:string): any {
-        console.log(o);
+    public fromJsonLdContainer(o: any, type: string): any {
         return this.getTsonLd().fromJsonLdContainer(o, type);
     }
 
-}
\ No newline at end of file
+    public jsonLdToFlattenJsonLd(object: any): any {
+        return this.getTsonLd().jsonLdToFlattenJsonLd(object);
+    }
+
+}
diff --git a/ui/src/app/platform-services/tsonld/tsonld.ts b/ui/src/app/platform-services/tsonld/tsonld.ts
index c72a6b1..3ec7995 100644
--- a/ui/src/app/platform-services/tsonld/tsonld.ts
+++ b/ui/src/app/platform-services/tsonld/tsonld.ts
@@ -65,6 +65,19 @@ export class TsonLd {
     return from(promise);
   }
 
+  public jsonLdToFlattenJsonLd(object: any) {
+     const context = object['@context'];
+    delete object['@context'];
+
+    let promise = new Promise(function(resolve, reject) {
+      (jsonld as any).flatten(object, context, function (err, data) {
+        resolve(data);
+      });
+    });
+
+    return from(promise);
+  }
+
   /**
    *
    * @param object the object to serialize