@hpcc-js/marshaller 2.28.5 → 2.28.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +43 -43
  2. package/dist/index.es6.js +22 -22
  3. package/dist/index.es6.js.map +1 -1
  4. package/dist/index.js +20 -20
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.min.js +2 -2
  7. package/dist/index.min.js.map +1 -1
  8. package/package.json +16 -16
  9. package/src/__package__.ts +3 -3
  10. package/src/dashy.css +239 -239
  11. package/src/dashy.ts +521 -521
  12. package/src/ddl1/DDLApi.ts +229 -229
  13. package/src/ddl1/FlyoutButton.ts +120 -120
  14. package/src/ddl1/Graph.ts +93 -93
  15. package/src/ddl1/HTML.ts +77 -77
  16. package/src/ddl1/HipieDDL.ts +2437 -2437
  17. package/src/ddl1/HipieDDLMixin.ts +380 -380
  18. package/src/ddl1/Tabbed.ts +91 -91
  19. package/src/ddl1/TargetMarshaller.ts +57 -57
  20. package/src/ddl2/PopupManager.ts +89 -89
  21. package/src/ddl2/activities/activity.ts +431 -431
  22. package/src/ddl2/activities/databomb.ts +237 -237
  23. package/src/ddl2/activities/datasource.ts +52 -52
  24. package/src/ddl2/activities/dspicker.ts +106 -106
  25. package/src/ddl2/activities/filter.ts +542 -542
  26. package/src/ddl2/activities/form.ts +153 -153
  27. package/src/ddl2/activities/groupby.ts +439 -439
  28. package/src/ddl2/activities/hipiepipeline.ts +114 -114
  29. package/src/ddl2/activities/limit.ts +49 -49
  30. package/src/ddl2/activities/logicalfile.ts +62 -62
  31. package/src/ddl2/activities/nullview.ts +12 -12
  32. package/src/ddl2/activities/project.ts +764 -764
  33. package/src/ddl2/activities/rest.ts +568 -568
  34. package/src/ddl2/activities/roxie.ts +490 -490
  35. package/src/ddl2/activities/sampledata.json +16264 -16264
  36. package/src/ddl2/activities/sort.ts +176 -176
  37. package/src/ddl2/activities/wuresult.ts +395 -395
  38. package/src/ddl2/dashboard.css +13 -13
  39. package/src/ddl2/dashboard.ts +330 -330
  40. package/src/ddl2/dashboardDockPanel.ts +123 -123
  41. package/src/ddl2/dashboardGrid.ts +202 -202
  42. package/src/ddl2/ddl.ts +410 -410
  43. package/src/ddl2/ddleditor.ts +60 -60
  44. package/src/ddl2/dsTable.ts +238 -238
  45. package/src/ddl2/dvTable.ts +31 -31
  46. package/src/ddl2/graphadapter.ts +297 -297
  47. package/src/ddl2/javascriptadapter.ts +354 -354
  48. package/src/ddl2/model/element.ts +398 -398
  49. package/src/ddl2/model/visualization.ts +351 -351
  50. package/src/ddl2/model/vizChartPanel.ts +149 -149
  51. package/src/ddl2/pipelinePanel.css +4 -4
  52. package/src/ddl2/pipelinePanel.ts +465 -465
  53. package/src/index.ts +26 -26
  54. package/types/__package__.d.ts +2 -2
  55. package/types-3.4/__package__.d.ts +2 -2
package/src/dashy.ts CHANGED
@@ -1,521 +1,521 @@
1
- import { JSEditor, JSONEditor } from "@hpcc-js/codemirror";
2
- import { Button, PropertyExt, publish, publishProxy, Utility, Widget } from "@hpcc-js/common";
3
- import { DDL1, DDL2, ddl2Schema, isDDL2Schema, upgrade } from "@hpcc-js/ddl-shim";
4
- import { Graph } from "@hpcc-js/graph";
5
- import { ChartPanel } from "@hpcc-js/layout";
6
- import { CommandPalette, CommandRegistry, ContextMenu, SplitPanel, TabPanel, WidgetAdapter } from "@hpcc-js/phosphor";
7
- import { scopedLogger } from "@hpcc-js/util";
8
- import { Activity } from "./ddl2/activities/activity";
9
- import { Databomb } from "./ddl2/activities/databomb";
10
- import { DSPicker } from "./ddl2/activities/dspicker";
11
- import { Dashboard } from "./ddl2/dashboard";
12
- import { DSTable } from "./ddl2/dsTable";
13
- import { DVTable } from "./ddl2/dvTable";
14
- import { GraphAdapter, VertexData } from "./ddl2/graphadapter";
15
- import { Element, ElementContainer, State } from "./ddl2/model/element";
16
- import { Visualization } from "./ddl2/model/visualization";
17
- import { VizChartPanel } from "./ddl2/model/vizChartPanel";
18
- import { PipelineSplitPanel } from "./ddl2/pipelinePanel";
19
-
20
- const logger = scopedLogger("marshaller/dashy");
21
-
22
- import "../src/dashy.css";
23
-
24
- export type FocusType = Element | Activity | Visualization | VizChartPanel | State | undefined;
25
-
26
- class DDLPreview extends ChartPanel {
27
-
28
- private _save = new Button().faChar("fa-save").tooltip("Save")
29
- .on("click", () => {
30
- const obj = JSON.parse(this._jsonEditor.text());
31
- this._dashy.importDDL(obj);
32
- this.updateToolbar();
33
- });
34
-
35
- private _reset = new Button().faChar("fa-undo").tooltip("Reset")
36
- .on("click", () => {
37
- this._jsonEditor
38
- .text(this._ddl)
39
- .lazyRender()
40
- ;
41
- this.updateToolbar();
42
- });
43
-
44
- private _jsonEditor = new JSONEditor()
45
- .on("changes", (changes: object[]) => {
46
- this.updateToolbar();
47
- });
48
-
49
- constructor(private _dashy: Dashy) {
50
- super();
51
- this._titleBar.buttons([this._save, this._reset]);
52
- this.widget(this._jsonEditor);
53
- }
54
-
55
- private _ddl;
56
- ddl(_: DDL2.Schema): this {
57
- this._ddl = JSON.stringify(_, undefined, 4);
58
- return this;
59
- }
60
-
61
- private _prevJson: string;
62
- update(domNode, element) {
63
- super.update(domNode, element);
64
- if (this._prevJson !== this._ddl) {
65
- this._prevJson = this._ddl;
66
- this._jsonEditor.text(this._ddl);
67
- }
68
- this.updateToolbar();
69
- }
70
-
71
- updateToolbar() {
72
- const editorJson = this._jsonEditor.text();
73
- this._save.enabled(this._ddl !== editorJson).lazyRender();
74
- this._reset.enabled(this._ddl !== editorJson).lazyRender();
75
- }
76
- }
77
-
78
- export class Dashy extends SplitPanel {
79
-
80
- private _elementContainer: ElementContainer = new ElementContainer();
81
-
82
- private _lhsSheet = new TabPanel();
83
- private _lhsDashboard: Dashboard = new Dashboard(this._elementContainer)
84
- .on("vizActivation", (elem: Element, wa: WidgetAdapter) => {
85
- this.focus(this._lhsDashboard, elem);
86
- })
87
- .on("vizStateChanged", (elem: Element) => {
88
- for (const filteredViz of this._elementContainer.filteredBy(elem.id())) {
89
- if (this.focus() === filteredViz) {
90
- this._rhsSplitView.refreshPreview();
91
- }
92
- }
93
- })
94
- ;
95
- private _lhsDataviews: DVTable = new DVTable(this._elementContainer)
96
- .on("click", (row: any, col: string, sel: boolean, ext: any) => {
97
- this.focus(this._lhsDataviews, row.__lparam);
98
- this._rhsSplitView.refreshPreview();
99
- })
100
- ;
101
- private _lhsDatasources: DSTable = new DSTable(this._elementContainer)
102
- .on("click", (row: any, col: string, sel: boolean, ext: any) => {
103
- this.focus(this._lhsDatasources, row.__lparam);
104
- this._rhsSplitView.refreshPreview();
105
- })
106
- ;
107
- private _graphAdapter = new GraphAdapter(this._elementContainer);
108
- private _lhsPipeline: Graph = new Graph()
109
- .layout("Hierarchy")
110
- .allowDragging(false)
111
- .applyScaleOnLayout(true)
112
- .on("vertex_click", (row: any, col: string, sel: boolean, ext: any) => {
113
- const obj: VertexData = row.__lparam[0] || {};
114
- this.focus(this._lhsPipeline, obj.state || obj.chartPanel || obj.visualization || obj.activity || obj.view);
115
- })
116
- .on("vertex_contextmenu", (row: any, col: string, sel: boolean, ext: any) => {
117
- })
118
- ;
119
- private _lhsDebugSheet = new TabPanel();
120
- private _lhsDebugDDLEditor = new DDLPreview(this);
121
- private _lhsDebugDDLSchema = new JSONEditor().json(ddl2Schema);
122
- private _lhsDebugJSEditor = new JSEditor();
123
- private _lhsDebugCloneEC: ElementContainer = new ElementContainer();
124
- private _lhsDebugClone: Dashboard = new Dashboard(this._lhsDebugCloneEC).hideSingleTabs(true).titleVisible(false);
125
- private _lhsDebugDDLv1 = new JSONEditor();
126
- private _lhsDebugDDLv2 = new JSONEditor();
127
-
128
- private _rhsSplitView = new PipelineSplitPanel();
129
-
130
- @publishProxy("_rhsSplitView")
131
- disableActivities: publish<this, string[]>;
132
-
133
- private _fileOpen;
134
-
135
- static create(target: string, ddl?: DDL1.DDLSchema | DDL2.Schema, baseUrl?: string, wuid?: string): Promise<Dashy> {
136
- return new Promise((resolve, reject) => {
137
- const dashy = new Dashy()
138
- .target(target)
139
- .render((w: Dashy) => {
140
- if (ddl) {
141
- w.importDDL(ddl, baseUrl, wuid).then(() => {
142
- resolve(dashy);
143
- });
144
- } else {
145
- resolve(dashy);
146
- }
147
- });
148
- });
149
- }
150
-
151
- constructor() {
152
- super("horizontal");
153
- }
154
-
155
- elementContainer(): ElementContainer {
156
- return this._elementContainer;
157
- }
158
-
159
- clear(): Promise<void> {
160
- this._lhsDebugSheet.removeWidget(this._lhsDebugDDLv1);
161
- this._lhsDebugSheet.removeWidget(this._lhsDebugDDLv2);
162
- this._elementContainer.clear();
163
- this._graphAdapter.clear();
164
- this.focus(this._lhsDashboard, undefined);
165
- return this.loadDashboard().then(() => {
166
- return this._elementContainer.refresh();
167
- }).then(ec => {
168
- return;
169
- });
170
- }
171
-
172
- save(): DDL2.Schema {
173
- return this._lhsDashboard.save();
174
- }
175
-
176
- restore(json: DDL2.Schema): Promise<void> {
177
- this._lhsSheet.active(this._lhsDashboard);
178
- return this.clear().then(() => {
179
- this._lhsDashboard.restore(json);
180
- this._lhsDataviews.render();
181
- this._lhsDatasources.render();
182
- return this._lhsDashboard.renderPromise().then(() => {
183
- const elements = this._elementContainer.elements();
184
- if (elements.length) {
185
- this._lhsDashboard.activate(elements[0]);
186
- }
187
- return this._elementContainer.refresh();
188
- }).then(() => {
189
- let hasError = false;
190
- for (const error of this._elementContainer.validate()) {
191
- hasError = true;
192
- logger.warning(error.elementID + " (" + error.source + "): " + error.msg);
193
- }
194
- if (hasError) {
195
- // Re-render to highlight errrors ---
196
- this._lhsDashboard.renderPromise();
197
- }
198
- });
199
- });
200
- }
201
-
202
- importDDL(ddl: DDL1.DDLSchema | DDL2.Schema, baseUrl?: string, wuid?: string, dermatologyJson: object = {}): Promise<void> {
203
- const ddl2: DDL2.Schema = isDDL2Schema(ddl) ? ddl : upgrade(ddl, baseUrl, wuid, true, dermatologyJson);
204
- const retVal = this.restore(ddl2);
205
- if (isDDL2Schema(ddl)) {
206
- this._lhsDebugDDLv2.json(ddl2);
207
- this._lhsDebugSheet
208
- .addWidget(this._lhsDebugDDLv2, "orig v2")
209
- ;
210
- } else {
211
- this._lhsDebugDDLv1.json(ddl);
212
- this._lhsDebugDDLv2.json(ddl2);
213
- this._lhsDebugSheet
214
- .addWidget(this._lhsDebugDDLv1, "v1")
215
- .addWidget(this._lhsDebugDDLv2, "v1 -> v2")
216
- ;
217
- }
218
- return retVal;
219
- }
220
-
221
- activeLHS(): Widget {
222
- let retVal = this._lhsSheet.active();
223
- if (retVal === this._lhsDebugSheet) {
224
- retVal = this._lhsDebugSheet.active();
225
- }
226
- return retVal;
227
- }
228
-
229
- activeRHS(): Widget {
230
- return this._rhsSplitView;
231
- }
232
-
233
- private _currSelection: { [sourceID: string]: FocusType } = {};
234
-
235
- private focusAsElement(): Element | undefined {
236
- const currSelection = this.focus();
237
- return currSelection instanceof Element ? currSelection : undefined;
238
- }
239
-
240
- private focus(): FocusType;
241
- private focus(source: Widget, item: FocusType): this;
242
- private focus(source?: Widget, item?: FocusType): FocusType | this {
243
- if (!arguments.length) return this._currSelection[this.activeLHS().id()];
244
- if (this._currSelection[source.id()] !== item) {
245
- this._currSelection[source.id()] = item;
246
- this.loadRHSSplit();
247
- }
248
- return this;
249
- }
250
-
251
- loadRHSSplit() {
252
- this._rhsSplitView.loadDataProps(this.focus());
253
- }
254
-
255
- loadDataviews(): Promise<Widget | undefined> {
256
- if (this.activeLHS() === this._lhsDataviews) {
257
- return this._lhsDataviews.renderPromise();
258
- }
259
- return Promise.resolve(undefined);
260
- }
261
-
262
- loadDatasources(): Promise<Widget | undefined> {
263
- if (this.activeLHS() === this._lhsDatasources) {
264
- return this._lhsDatasources.renderPromise();
265
- }
266
- return Promise.resolve(undefined);
267
- }
268
-
269
- loadDashboard(): Promise<Widget | undefined> {
270
- if (this.activeLHS() === this._lhsDashboard) {
271
- this._elementContainer.validate();
272
- return this._lhsDashboard.renderPromise();
273
- }
274
- return Promise.resolve(undefined);
275
- }
276
-
277
- loadGraph() {
278
- this._lhsPipeline
279
- .data({ ...this._graphAdapter.createGraph() }, true)
280
- ;
281
- if (this.activeLHS() === this._lhsPipeline) {
282
- this._lhsPipeline
283
- .lazyRender()
284
- ;
285
- }
286
- }
287
-
288
- loadDDL() {
289
- this._lhsDebugDDLEditor
290
- .ddl(this._lhsDashboard.ddl())
291
- ;
292
- if (this.activeLHS() === this._lhsDebugDDLEditor) {
293
- this._lhsDebugDDLEditor
294
- .lazyRender()
295
- ;
296
- }
297
- }
298
-
299
- loadJavaScript() {
300
- this._lhsDebugJSEditor
301
- .javascript(this._lhsDashboard.javascript())
302
- ;
303
- if (this.activeLHS() === this._lhsDebugJSEditor) {
304
- this._lhsDebugJSEditor
305
- .lazyRender()
306
- ;
307
- }
308
- }
309
-
310
- loadClone() {
311
- const json = this.save();
312
- this._lhsDebugCloneEC.clear();
313
- this._lhsDebugClone.renderPromise().then(() => {
314
- this._lhsDebugClone.restore(json);
315
- this._lhsDebugClone.renderPromise().then(() => {
316
- return this._lhsDebugCloneEC.refresh();
317
- }).then(() => {
318
- for (const error of this._lhsDebugCloneEC.validate()) {
319
- logger.warning(error.elementID + " (" + error.source + "): " + error.msg);
320
- }
321
- });
322
- });
323
- }
324
-
325
- initMenu() {
326
- const commands = new CommandRegistry();
327
-
328
- // Dashboard Commands ---
329
- commands.addCommand("dash_add", {
330
- label: "Add View",
331
- execute: () => {
332
- const newElem = new Element(this._elementContainer);
333
- this._elementContainer.append(newElem);
334
- this.loadDashboard().then(() => {
335
- newElem.refresh().then(() => {
336
- this._lhsDashboard.activate(newElem);
337
- });
338
- });
339
- }
340
- });
341
-
342
- commands.addCommand("dash_clear", {
343
- label: "Clear",
344
- execute: () => {
345
- this.clear();
346
- }
347
- });
348
-
349
- commands.addCommand("dash_save", {
350
- label: "Save",
351
- execute: () => {
352
- const text = JSON.stringify(this.save(), null, " ");
353
- Utility.downloadString("JSON", text, "dashy");
354
- }
355
- });
356
-
357
- commands.addCommand("dash_load", {
358
- label: "Open",
359
- execute: () => {
360
- this._fileOpen.property("accept", ".dashy,.json");
361
- this._fileOpen.node().click();
362
- }
363
- });
364
-
365
- // Model Commands ---
366
- const palette = new CommandPalette({ commands });
367
- palette.addItem({ command: "addWUResult", category: "Notebook" });
368
- palette.addItem({ command: "addView", category: "Notebook" });
369
- palette.addItem({ command: "remove", category: "Notebook" });
370
- palette.id = "palette";
371
-
372
- const contextMenu = new ContextMenu({ commands });
373
-
374
- contextMenu.addItem({ command: "dash_add", selector: `#${this._lhsDashboard.id()}` });
375
- contextMenu.addItem({ command: "dash_clear", selector: `#${this._lhsDashboard.id()}` });
376
- contextMenu.addItem({ type: "separator", selector: `#${this._lhsDashboard.id()}` });
377
-
378
- contextMenu.addItem({ command: "dash_load", selector: `#${this.id()}` });
379
- contextMenu.addItem({ command: "dash_save", selector: `#${this.id()}` });
380
-
381
- document.addEventListener("contextmenu", (event: MouseEvent) => {
382
- if (contextMenu.open(event)) {
383
- event.preventDefault();
384
- }
385
- });
386
- }
387
-
388
- addDatabomb(label: string, payload: string, format: "csv" | "tsv" | "json") {
389
- const databomb = new Databomb().id(label).format(format).payload(payload);
390
- this._elementContainer.appendDatasource(databomb);
391
- const newElem = new Element(this._elementContainer);
392
- const ds = newElem.hipiePipeline().datasource();
393
- if (ds instanceof DSPicker) {
394
- ds.datasourceID(databomb.id());
395
- }
396
- this._elementContainer.append(newElem);
397
- this.loadDashboard().then(() => {
398
- newElem.refresh().then(() => {
399
- this._lhsDashboard.activate(newElem);
400
- });
401
- });
402
- }
403
-
404
- enter(domNode, element) {
405
- super.enter(domNode, element);
406
- this
407
- .addWidget(this._lhsSheet)
408
- .addWidget(this._rhsSplitView)
409
- ;
410
- this._lhsSheet
411
- .addWidget(this._lhsDashboard, "Dashboard")
412
- .addWidget(this._lhsDataviews, "Dataviews")
413
- .addWidget(this._lhsDatasources, "Datasources")
414
- .addWidget(this._lhsPipeline, "Pipeline")
415
- .addWidget(this._lhsDebugSheet, "Debug")
416
- .on("childActivation", (w: Widget) => {
417
- switch (w) {
418
- case this._lhsDataviews:
419
- this.loadRHSSplit();
420
- break;
421
- case this._lhsDatasources:
422
- this.loadRHSSplit();
423
- break;
424
- case this._lhsDashboard:
425
- this.loadRHSSplit();
426
- break;
427
- case this._lhsPipeline:
428
- this.loadRHSSplit();
429
- this.loadGraph();
430
- break;
431
- case this._lhsDebugSheet:
432
- this._lhsDebugSheet.childActivation(this._lhsDebugSheet.active());
433
- break;
434
- }
435
- })
436
- ;
437
- this._lhsDebugSheet
438
- .addWidget(this._lhsDebugDDLEditor, "v2")
439
- .addWidget(this._lhsDebugDDLSchema, "Schema")
440
- .addWidget(this._lhsDebugJSEditor, "TS")
441
- .addWidget(this._lhsDebugClone, "Clone")
442
- .on("childActivation", (w: Widget) => {
443
- switch (w) {
444
- case this._lhsDebugDDLEditor:
445
- this.loadRHSSplit();
446
- this.loadDDL();
447
- break;
448
- case this._lhsDebugJSEditor:
449
- this.loadRHSSplit();
450
- this.loadJavaScript();
451
- break;
452
- case this._lhsDebugClone:
453
- this.loadClone();
454
- break;
455
- }
456
- })
457
- ;
458
-
459
- this.initMenu();
460
- this._rhsSplitView.on("propChanged", (id: string, newValue: any, oldValue: any, source: PropertyExt) => {
461
- const currElement = this.focusAsElement();
462
- if (currElement) {
463
- currElement.refresh().then(() => {
464
- this._rhsSplitView.refreshPreview();
465
- });
466
- } else {
467
- this._rhsSplitView.refreshPreview();
468
- }
469
- switch (this.activeLHS()) {
470
- case this._lhsDashboard:
471
- this.loadDashboard();
472
- break;
473
- case this._lhsDatasources:
474
- this._elementContainer.refresh();
475
- break;
476
- case this._lhsPipeline:
477
- this.loadGraph();
478
- break;
479
- case this._lhsDebugDDLEditor:
480
- this.loadDDL();
481
- break;
482
- case this._lhsDebugClone:
483
- this.loadClone();
484
- break;
485
- }
486
- });
487
-
488
- const context = this;
489
- this._fileOpen = element.append("input")
490
- .attr("type", "file")
491
- .property("accept", ".dashy,.json")
492
- .style("display", "none")
493
- .on("change", function () {
494
- let i = 0;
495
- let f = this.files[i];
496
- while (f) {
497
- const reader = new FileReader();
498
- reader.onload = (function (theFile) {
499
- return function (e) {
500
- try {
501
- const result = Array.isArray(e.target.result) ? e.target.result[0] : e.target.result;
502
- const json = JSON.parse(result);
503
- context.importDDL(json);
504
- } catch (ex) {
505
- alert("ex when trying to parse json = " + ex);
506
- }
507
- };
508
- })(f);
509
- reader.readAsText(f);
510
- f = this.files[++i];
511
- break;
512
- }
513
- })
514
- ;
515
- }
516
-
517
- update(domNode, element) {
518
- super.update(domNode, element);
519
- }
520
- }
521
- Dashy.prototype._class += " composite_Dashy";
1
+ import { JSEditor, JSONEditor } from "@hpcc-js/codemirror";
2
+ import { Button, PropertyExt, publish, publishProxy, Utility, Widget } from "@hpcc-js/common";
3
+ import { DDL1, DDL2, ddl2Schema, isDDL2Schema, upgrade } from "@hpcc-js/ddl-shim";
4
+ import { Graph } from "@hpcc-js/graph";
5
+ import { ChartPanel } from "@hpcc-js/layout";
6
+ import { CommandPalette, CommandRegistry, ContextMenu, SplitPanel, TabPanel, WidgetAdapter } from "@hpcc-js/phosphor";
7
+ import { scopedLogger } from "@hpcc-js/util";
8
+ import { Activity } from "./ddl2/activities/activity";
9
+ import { Databomb } from "./ddl2/activities/databomb";
10
+ import { DSPicker } from "./ddl2/activities/dspicker";
11
+ import { Dashboard } from "./ddl2/dashboard";
12
+ import { DSTable } from "./ddl2/dsTable";
13
+ import { DVTable } from "./ddl2/dvTable";
14
+ import { GraphAdapter, VertexData } from "./ddl2/graphadapter";
15
+ import { Element, ElementContainer, State } from "./ddl2/model/element";
16
+ import { Visualization } from "./ddl2/model/visualization";
17
+ import { VizChartPanel } from "./ddl2/model/vizChartPanel";
18
+ import { PipelineSplitPanel } from "./ddl2/pipelinePanel";
19
+
20
+ const logger = scopedLogger("marshaller/dashy");
21
+
22
+ import "../src/dashy.css";
23
+
24
+ export type FocusType = Element | Activity | Visualization | VizChartPanel | State | undefined;
25
+
26
+ class DDLPreview extends ChartPanel {
27
+
28
+ private _save = new Button().faChar("fa-save").tooltip("Save")
29
+ .on("click", () => {
30
+ const obj = JSON.parse(this._jsonEditor.text());
31
+ this._dashy.importDDL(obj);
32
+ this.updateToolbar();
33
+ });
34
+
35
+ private _reset = new Button().faChar("fa-undo").tooltip("Reset")
36
+ .on("click", () => {
37
+ this._jsonEditor
38
+ .text(this._ddl)
39
+ .lazyRender()
40
+ ;
41
+ this.updateToolbar();
42
+ });
43
+
44
+ private _jsonEditor = new JSONEditor()
45
+ .on("changes", (changes: object[]) => {
46
+ this.updateToolbar();
47
+ });
48
+
49
+ constructor(private _dashy: Dashy) {
50
+ super();
51
+ this._titleBar.buttons([this._save, this._reset]);
52
+ this.widget(this._jsonEditor);
53
+ }
54
+
55
+ private _ddl;
56
+ ddl(_: DDL2.Schema): this {
57
+ this._ddl = JSON.stringify(_, undefined, 4);
58
+ return this;
59
+ }
60
+
61
+ private _prevJson: string;
62
+ update(domNode, element) {
63
+ super.update(domNode, element);
64
+ if (this._prevJson !== this._ddl) {
65
+ this._prevJson = this._ddl;
66
+ this._jsonEditor.text(this._ddl);
67
+ }
68
+ this.updateToolbar();
69
+ }
70
+
71
+ updateToolbar() {
72
+ const editorJson = this._jsonEditor.text();
73
+ this._save.enabled(this._ddl !== editorJson).lazyRender();
74
+ this._reset.enabled(this._ddl !== editorJson).lazyRender();
75
+ }
76
+ }
77
+
78
+ export class Dashy extends SplitPanel {
79
+
80
+ private _elementContainer: ElementContainer = new ElementContainer();
81
+
82
+ private _lhsSheet = new TabPanel();
83
+ private _lhsDashboard: Dashboard = new Dashboard(this._elementContainer)
84
+ .on("vizActivation", (elem: Element, wa: WidgetAdapter) => {
85
+ this.focus(this._lhsDashboard, elem);
86
+ })
87
+ .on("vizStateChanged", (elem: Element) => {
88
+ for (const filteredViz of this._elementContainer.filteredBy(elem.id())) {
89
+ if (this.focus() === filteredViz) {
90
+ this._rhsSplitView.refreshPreview();
91
+ }
92
+ }
93
+ })
94
+ ;
95
+ private _lhsDataviews: DVTable = new DVTable(this._elementContainer)
96
+ .on("click", (row: any, col: string, sel: boolean, ext: any) => {
97
+ this.focus(this._lhsDataviews, row.__lparam);
98
+ this._rhsSplitView.refreshPreview();
99
+ })
100
+ ;
101
+ private _lhsDatasources: DSTable = new DSTable(this._elementContainer)
102
+ .on("click", (row: any, col: string, sel: boolean, ext: any) => {
103
+ this.focus(this._lhsDatasources, row.__lparam);
104
+ this._rhsSplitView.refreshPreview();
105
+ })
106
+ ;
107
+ private _graphAdapter = new GraphAdapter(this._elementContainer);
108
+ private _lhsPipeline: Graph = new Graph()
109
+ .layout("Hierarchy")
110
+ .allowDragging(false)
111
+ .applyScaleOnLayout(true)
112
+ .on("vertex_click", (row: any, col: string, sel: boolean, ext: any) => {
113
+ const obj: VertexData = row.__lparam[0] || {};
114
+ this.focus(this._lhsPipeline, obj.state || obj.chartPanel || obj.visualization || obj.activity || obj.view);
115
+ })
116
+ .on("vertex_contextmenu", (row: any, col: string, sel: boolean, ext: any) => {
117
+ })
118
+ ;
119
+ private _lhsDebugSheet = new TabPanel();
120
+ private _lhsDebugDDLEditor = new DDLPreview(this);
121
+ private _lhsDebugDDLSchema = new JSONEditor().json(ddl2Schema);
122
+ private _lhsDebugJSEditor = new JSEditor();
123
+ private _lhsDebugCloneEC: ElementContainer = new ElementContainer();
124
+ private _lhsDebugClone: Dashboard = new Dashboard(this._lhsDebugCloneEC).hideSingleTabs(true).titleVisible(false);
125
+ private _lhsDebugDDLv1 = new JSONEditor();
126
+ private _lhsDebugDDLv2 = new JSONEditor();
127
+
128
+ private _rhsSplitView = new PipelineSplitPanel();
129
+
130
+ @publishProxy("_rhsSplitView")
131
+ disableActivities: publish<this, string[]>;
132
+
133
+ private _fileOpen;
134
+
135
+ static create(target: string, ddl?: DDL1.DDLSchema | DDL2.Schema, baseUrl?: string, wuid?: string): Promise<Dashy> {
136
+ return new Promise((resolve, reject) => {
137
+ const dashy = new Dashy()
138
+ .target(target)
139
+ .render((w: Dashy) => {
140
+ if (ddl) {
141
+ w.importDDL(ddl, baseUrl, wuid).then(() => {
142
+ resolve(dashy);
143
+ });
144
+ } else {
145
+ resolve(dashy);
146
+ }
147
+ });
148
+ });
149
+ }
150
+
151
+ constructor() {
152
+ super("horizontal");
153
+ }
154
+
155
+ elementContainer(): ElementContainer {
156
+ return this._elementContainer;
157
+ }
158
+
159
+ clear(): Promise<void> {
160
+ this._lhsDebugSheet.removeWidget(this._lhsDebugDDLv1);
161
+ this._lhsDebugSheet.removeWidget(this._lhsDebugDDLv2);
162
+ this._elementContainer.clear();
163
+ this._graphAdapter.clear();
164
+ this.focus(this._lhsDashboard, undefined);
165
+ return this.loadDashboard().then(() => {
166
+ return this._elementContainer.refresh();
167
+ }).then(ec => {
168
+ return;
169
+ });
170
+ }
171
+
172
+ save(): DDL2.Schema {
173
+ return this._lhsDashboard.save();
174
+ }
175
+
176
+ restore(json: DDL2.Schema): Promise<void> {
177
+ this._lhsSheet.active(this._lhsDashboard);
178
+ return this.clear().then(() => {
179
+ this._lhsDashboard.restore(json);
180
+ this._lhsDataviews.render();
181
+ this._lhsDatasources.render();
182
+ return this._lhsDashboard.renderPromise().then(() => {
183
+ const elements = this._elementContainer.elements();
184
+ if (elements.length) {
185
+ this._lhsDashboard.activate(elements[0]);
186
+ }
187
+ return this._elementContainer.refresh();
188
+ }).then(() => {
189
+ let hasError = false;
190
+ for (const error of this._elementContainer.validate()) {
191
+ hasError = true;
192
+ logger.warning(error.elementID + " (" + error.source + "): " + error.msg);
193
+ }
194
+ if (hasError) {
195
+ // Re-render to highlight errrors ---
196
+ this._lhsDashboard.renderPromise();
197
+ }
198
+ });
199
+ });
200
+ }
201
+
202
+ importDDL(ddl: DDL1.DDLSchema | DDL2.Schema, baseUrl?: string, wuid?: string, dermatologyJson: object = {}): Promise<void> {
203
+ const ddl2: DDL2.Schema = isDDL2Schema(ddl) ? ddl : upgrade(ddl, baseUrl, wuid, true, dermatologyJson);
204
+ const retVal = this.restore(ddl2);
205
+ if (isDDL2Schema(ddl)) {
206
+ this._lhsDebugDDLv2.json(ddl2);
207
+ this._lhsDebugSheet
208
+ .addWidget(this._lhsDebugDDLv2, "orig v2")
209
+ ;
210
+ } else {
211
+ this._lhsDebugDDLv1.json(ddl);
212
+ this._lhsDebugDDLv2.json(ddl2);
213
+ this._lhsDebugSheet
214
+ .addWidget(this._lhsDebugDDLv1, "v1")
215
+ .addWidget(this._lhsDebugDDLv2, "v1 -> v2")
216
+ ;
217
+ }
218
+ return retVal;
219
+ }
220
+
221
+ activeLHS(): Widget {
222
+ let retVal = this._lhsSheet.active();
223
+ if (retVal === this._lhsDebugSheet) {
224
+ retVal = this._lhsDebugSheet.active();
225
+ }
226
+ return retVal;
227
+ }
228
+
229
+ activeRHS(): Widget {
230
+ return this._rhsSplitView;
231
+ }
232
+
233
+ private _currSelection: { [sourceID: string]: FocusType } = {};
234
+
235
+ private focusAsElement(): Element | undefined {
236
+ const currSelection = this.focus();
237
+ return currSelection instanceof Element ? currSelection : undefined;
238
+ }
239
+
240
+ private focus(): FocusType;
241
+ private focus(source: Widget, item: FocusType): this;
242
+ private focus(source?: Widget, item?: FocusType): FocusType | this {
243
+ if (!arguments.length) return this._currSelection[this.activeLHS().id()];
244
+ if (this._currSelection[source.id()] !== item) {
245
+ this._currSelection[source.id()] = item;
246
+ this.loadRHSSplit();
247
+ }
248
+ return this;
249
+ }
250
+
251
+ loadRHSSplit() {
252
+ this._rhsSplitView.loadDataProps(this.focus());
253
+ }
254
+
255
+ loadDataviews(): Promise<Widget | undefined> {
256
+ if (this.activeLHS() === this._lhsDataviews) {
257
+ return this._lhsDataviews.renderPromise();
258
+ }
259
+ return Promise.resolve(undefined);
260
+ }
261
+
262
+ loadDatasources(): Promise<Widget | undefined> {
263
+ if (this.activeLHS() === this._lhsDatasources) {
264
+ return this._lhsDatasources.renderPromise();
265
+ }
266
+ return Promise.resolve(undefined);
267
+ }
268
+
269
+ loadDashboard(): Promise<Widget | undefined> {
270
+ if (this.activeLHS() === this._lhsDashboard) {
271
+ this._elementContainer.validate();
272
+ return this._lhsDashboard.renderPromise();
273
+ }
274
+ return Promise.resolve(undefined);
275
+ }
276
+
277
+ loadGraph() {
278
+ this._lhsPipeline
279
+ .data({ ...this._graphAdapter.createGraph() }, true)
280
+ ;
281
+ if (this.activeLHS() === this._lhsPipeline) {
282
+ this._lhsPipeline
283
+ .lazyRender()
284
+ ;
285
+ }
286
+ }
287
+
288
+ loadDDL() {
289
+ this._lhsDebugDDLEditor
290
+ .ddl(this._lhsDashboard.ddl())
291
+ ;
292
+ if (this.activeLHS() === this._lhsDebugDDLEditor) {
293
+ this._lhsDebugDDLEditor
294
+ .lazyRender()
295
+ ;
296
+ }
297
+ }
298
+
299
+ loadJavaScript() {
300
+ this._lhsDebugJSEditor
301
+ .javascript(this._lhsDashboard.javascript())
302
+ ;
303
+ if (this.activeLHS() === this._lhsDebugJSEditor) {
304
+ this._lhsDebugJSEditor
305
+ .lazyRender()
306
+ ;
307
+ }
308
+ }
309
+
310
+ loadClone() {
311
+ const json = this.save();
312
+ this._lhsDebugCloneEC.clear();
313
+ this._lhsDebugClone.renderPromise().then(() => {
314
+ this._lhsDebugClone.restore(json);
315
+ this._lhsDebugClone.renderPromise().then(() => {
316
+ return this._lhsDebugCloneEC.refresh();
317
+ }).then(() => {
318
+ for (const error of this._lhsDebugCloneEC.validate()) {
319
+ logger.warning(error.elementID + " (" + error.source + "): " + error.msg);
320
+ }
321
+ });
322
+ });
323
+ }
324
+
325
+ initMenu() {
326
+ const commands = new CommandRegistry();
327
+
328
+ // Dashboard Commands ---
329
+ commands.addCommand("dash_add", {
330
+ label: "Add View",
331
+ execute: () => {
332
+ const newElem = new Element(this._elementContainer);
333
+ this._elementContainer.append(newElem);
334
+ this.loadDashboard().then(() => {
335
+ newElem.refresh().then(() => {
336
+ this._lhsDashboard.activate(newElem);
337
+ });
338
+ });
339
+ }
340
+ });
341
+
342
+ commands.addCommand("dash_clear", {
343
+ label: "Clear",
344
+ execute: () => {
345
+ this.clear();
346
+ }
347
+ });
348
+
349
+ commands.addCommand("dash_save", {
350
+ label: "Save",
351
+ execute: () => {
352
+ const text = JSON.stringify(this.save(), null, " ");
353
+ Utility.downloadString("JSON", text, "dashy");
354
+ }
355
+ });
356
+
357
+ commands.addCommand("dash_load", {
358
+ label: "Open",
359
+ execute: () => {
360
+ this._fileOpen.property("accept", ".dashy,.json");
361
+ this._fileOpen.node().click();
362
+ }
363
+ });
364
+
365
+ // Model Commands ---
366
+ const palette = new CommandPalette({ commands });
367
+ palette.addItem({ command: "addWUResult", category: "Notebook" });
368
+ palette.addItem({ command: "addView", category: "Notebook" });
369
+ palette.addItem({ command: "remove", category: "Notebook" });
370
+ palette.id = "palette";
371
+
372
+ const contextMenu = new ContextMenu({ commands });
373
+
374
+ contextMenu.addItem({ command: "dash_add", selector: `#${this._lhsDashboard.id()}` });
375
+ contextMenu.addItem({ command: "dash_clear", selector: `#${this._lhsDashboard.id()}` });
376
+ contextMenu.addItem({ type: "separator", selector: `#${this._lhsDashboard.id()}` });
377
+
378
+ contextMenu.addItem({ command: "dash_load", selector: `#${this.id()}` });
379
+ contextMenu.addItem({ command: "dash_save", selector: `#${this.id()}` });
380
+
381
+ document.addEventListener("contextmenu", (event: MouseEvent) => {
382
+ if (contextMenu.open(event)) {
383
+ event.preventDefault();
384
+ }
385
+ });
386
+ }
387
+
388
+ addDatabomb(label: string, payload: string, format: "csv" | "tsv" | "json") {
389
+ const databomb = new Databomb().id(label).format(format).payload(payload);
390
+ this._elementContainer.appendDatasource(databomb);
391
+ const newElem = new Element(this._elementContainer);
392
+ const ds = newElem.hipiePipeline().datasource();
393
+ if (ds instanceof DSPicker) {
394
+ ds.datasourceID(databomb.id());
395
+ }
396
+ this._elementContainer.append(newElem);
397
+ this.loadDashboard().then(() => {
398
+ newElem.refresh().then(() => {
399
+ this._lhsDashboard.activate(newElem);
400
+ });
401
+ });
402
+ }
403
+
404
+ enter(domNode, element) {
405
+ super.enter(domNode, element);
406
+ this
407
+ .addWidget(this._lhsSheet)
408
+ .addWidget(this._rhsSplitView)
409
+ ;
410
+ this._lhsSheet
411
+ .addWidget(this._lhsDashboard, "Dashboard")
412
+ .addWidget(this._lhsDataviews, "Dataviews")
413
+ .addWidget(this._lhsDatasources, "Datasources")
414
+ .addWidget(this._lhsPipeline, "Pipeline")
415
+ .addWidget(this._lhsDebugSheet, "Debug")
416
+ .on("childActivation", (w: Widget) => {
417
+ switch (w) {
418
+ case this._lhsDataviews:
419
+ this.loadRHSSplit();
420
+ break;
421
+ case this._lhsDatasources:
422
+ this.loadRHSSplit();
423
+ break;
424
+ case this._lhsDashboard:
425
+ this.loadRHSSplit();
426
+ break;
427
+ case this._lhsPipeline:
428
+ this.loadRHSSplit();
429
+ this.loadGraph();
430
+ break;
431
+ case this._lhsDebugSheet:
432
+ this._lhsDebugSheet.childActivation(this._lhsDebugSheet.active());
433
+ break;
434
+ }
435
+ })
436
+ ;
437
+ this._lhsDebugSheet
438
+ .addWidget(this._lhsDebugDDLEditor, "v2")
439
+ .addWidget(this._lhsDebugDDLSchema, "Schema")
440
+ .addWidget(this._lhsDebugJSEditor, "TS")
441
+ .addWidget(this._lhsDebugClone, "Clone")
442
+ .on("childActivation", (w: Widget) => {
443
+ switch (w) {
444
+ case this._lhsDebugDDLEditor:
445
+ this.loadRHSSplit();
446
+ this.loadDDL();
447
+ break;
448
+ case this._lhsDebugJSEditor:
449
+ this.loadRHSSplit();
450
+ this.loadJavaScript();
451
+ break;
452
+ case this._lhsDebugClone:
453
+ this.loadClone();
454
+ break;
455
+ }
456
+ })
457
+ ;
458
+
459
+ this.initMenu();
460
+ this._rhsSplitView.on("propChanged", (id: string, newValue: any, oldValue: any, source: PropertyExt) => {
461
+ const currElement = this.focusAsElement();
462
+ if (currElement) {
463
+ currElement.refresh().then(() => {
464
+ this._rhsSplitView.refreshPreview();
465
+ });
466
+ } else {
467
+ this._rhsSplitView.refreshPreview();
468
+ }
469
+ switch (this.activeLHS()) {
470
+ case this._lhsDashboard:
471
+ this.loadDashboard();
472
+ break;
473
+ case this._lhsDatasources:
474
+ this._elementContainer.refresh();
475
+ break;
476
+ case this._lhsPipeline:
477
+ this.loadGraph();
478
+ break;
479
+ case this._lhsDebugDDLEditor:
480
+ this.loadDDL();
481
+ break;
482
+ case this._lhsDebugClone:
483
+ this.loadClone();
484
+ break;
485
+ }
486
+ });
487
+
488
+ const context = this;
489
+ this._fileOpen = element.append("input")
490
+ .attr("type", "file")
491
+ .property("accept", ".dashy,.json")
492
+ .style("display", "none")
493
+ .on("change", function () {
494
+ let i = 0;
495
+ let f = this.files[i];
496
+ while (f) {
497
+ const reader = new FileReader();
498
+ reader.onload = (function (theFile) {
499
+ return function (e) {
500
+ try {
501
+ const result = Array.isArray(e.target.result) ? e.target.result[0] : e.target.result;
502
+ const json = JSON.parse(result);
503
+ context.importDDL(json);
504
+ } catch (ex) {
505
+ alert("ex when trying to parse json = " + ex);
506
+ }
507
+ };
508
+ })(f);
509
+ reader.readAsText(f);
510
+ f = this.files[++i];
511
+ break;
512
+ }
513
+ })
514
+ ;
515
+ }
516
+
517
+ update(domNode, element) {
518
+ super.update(domNode, element);
519
+ }
520
+ }
521
+ Dashy.prototype._class += " composite_Dashy";