This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
/
dataservices.component.ts
698 lines (619 loc) · 22.7 KB
/
dataservices.component.ts
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/**
* @license
* Copyright 2017 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, OnInit, ViewChild } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { ConnectionService } from "@connections/shared/connection.service";
import { ConnectionsConstants } from "@connections/shared/connections-constants";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { Dataservice } from "@dataservices/shared/dataservice.model";
import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { DataservicesConstants } from "@dataservices/shared/dataservices-constants";
import { DeploymentState } from "@dataservices/shared/deployment-state.enum";
import { NotifierService } from "@dataservices/shared/notifier.service";
import { Table } from "@dataservices/shared/table.model";
import { VdbService } from "@dataservices/shared/vdb.service";
import { WizardService } from "@dataservices/shared/wizard.service";
import { SqlControlComponent } from "@dataservices/sql-control/sql-control.component";
import { AbstractPageComponent } from "@shared/abstract-page.component";
import { ConfirmDeleteComponent } from "@shared/confirm-delete/confirm-delete.component";
import { LayoutType } from "@shared/layout-type.enum";
import { SortDirection } from "@shared/sort-direction.enum";
import {
ActionConfig,
EmptyStateConfig,
Filter,
FilterConfig,
FilterEvent,
FilterField,
FilterType,
NotificationType,
SortConfig,
SortEvent,
SortField
} from "patternfly-ng";
import { Subscription } from "rxjs/Subscription";
@Component({
moduleId: module.id,
selector: "app-dataservices",
templateUrl: "./dataservices.component.html",
styleUrls: ["./dataservices.component.css"]
})
export class DataservicesComponent extends AbstractPageComponent implements OnInit {
public readonly exportInProgressHeader: string = "Publishing: ";
public readonly exportSuccessHeader: string = "Publish Succeeded: ";
public readonly exportFailedHeader: string = "Publish Failed: ";
public readonly connectionsLoadedTag = "connections";
public readonly downloadInProgressHeader: string = "Downloading: ";
public readonly downloadSuccessHeader: string = "Download Succeeded: ";
public readonly downloadFailedHeader: string = "Download Failed: ";
public filterConfig: FilterConfig;
public filtersText = "";
public items: Dataservice[];
public sortConfig: SortConfig;
public currentSortField: SortField;
public isAscendingSort = true;
private connectionsExist = false;
private noConnectionsConfig: EmptyStateConfig;
private noDataservicesConfig: EmptyStateConfig;
private cardListAreaCss = "dataservice-summary-top-area-no-results";
private resultsAreaCss = "dataservice-summary-bottom-area-no-results";
private resultsShowing = false;
private quickLookSvcName: string;
private quickLookQueryText: string;
private allServices: Dataservice[] = [];
private connectionService: ConnectionService;
private filteredServices: Dataservice[] = [];
private selectedServices: Dataservice[] = [];
private dataserviceNameForDelete: string;
private router: Router;
private appSettingsService: AppSettingsService;
private dataserviceService: DataserviceService;
private vdbService: VdbService;
private sortDirection: SortDirection = SortDirection.ASC;
private exportNotificationHeader: string;
private exportNotificationMessage: string;
private exportNotificationType = NotificationType.SUCCESS;
private exportNotificationVisible = false;
private dataserviceStateSubscription: Subscription;
private notifierService: NotifierService;
private wizardService: WizardService;
private selectedSvcViews: Table[] = [];
private allSvcViews: Table[] = [];
@ViewChild(ConfirmDeleteComponent) private confirmDeleteDialog: ConfirmDeleteComponent;
@ViewChild(SqlControlComponent) private sqlControlComponent: SqlControlComponent;
constructor(router: Router, route: ActivatedRoute, dataserviceService: DataserviceService,
logger: LoggerService, appSettingsService: AppSettingsService, wizardService: WizardService,
notifierService: NotifierService, vdbService: VdbService, connectionService: ConnectionService ) {
super(route, logger);
this.router = router;
this.appSettingsService = appSettingsService;
this.dataserviceService = dataserviceService;
this.vdbService = vdbService;
this.notifierService = notifierService;
this.wizardService = wizardService;
// Register for dataservice state changes
this.dataserviceStateSubscription = this.notifierService.getDataserviceStateMap().subscribe((serviceStateMap) => {
this.onDataserviceStateChanged(serviceStateMap);
});
this.connectionService = connectionService;
}
public ngOnInit(): void {
super.ngOnInit();
this.filterConfig = {
fields: [{
id: "name",
title: "Name",
placeholder: "Filter by Name...",
type: FilterType.TEXT
}, {
id: "description",
title: "Description",
placeholder: "Filter by Description...",
type: FilterType.TEXT
}] as FilterField[],
resultsCount: this.filteredDataservices.length,
appliedFilters: []
} as FilterConfig;
this.sortConfig = {
fields: [{
id: "name",
title: "Name",
sortType: "alpha"
}, {
id: "description",
title: "Description",
sortType: "alpha"
}],
isAscending: this.isAscendingSort
} as SortConfig;
}
public get noConnectionsEmptyConfig(): EmptyStateConfig {
if ( !this.noConnectionsConfig ) {
const actionConfig = {
primaryActions: [
{
id: "createConnectionActionId",
title: "Add Connection",
tooltip: "Add a connection"
}
]
} as ActionConfig;
this.noConnectionsConfig = {
actions: actionConfig,
iconStyleClass: "pficon-warning-triangle-o",
info: "No dataservices were found. In order to create a dataservice, you must first create a connection. "
+ "Please click below to create a connection.",
title: "No Dataservices Available"
} as EmptyStateConfig;
}
return this.noConnectionsConfig;
}
public get noDataservicesEmptyConfig(): EmptyStateConfig {
if ( !this.noDataservicesConfig ) {
const actionConfig = {
primaryActions: [
{
id: "createDataserviceActionId",
title: "Add Dataservice",
tooltip: "Add a dataservice"
}
]
} as ActionConfig;
this.noDataservicesConfig = {
actions: actionConfig,
iconStyleClass: "pficon-warning-triangle-o",
info: "No dataservices were found. Please click below to create a dataservice.",
title: "No Dataservices Available"
} as EmptyStateConfig;
}
return this.noDataservicesConfig;
}
public get hasConnections(): boolean {
return this.isLoaded( this.connectionsLoadedTag ) && this.connectionsExist;
}
public onNewConnection(): void {
// TODO ask Mark if this will work
this.wizardService.setEdit(false);
const link: string[] = [ ConnectionsConstants.addConnectionPath ];
this.logger.log( "[DataservicesPageComponent] Navigating to: %o", link );
this.router.navigate( link ).then(() => {
// nothing to do
} );
}
public loadAsyncPageData(): void {
const self = this;
this.dataserviceService
.getAllDataservices()
.subscribe(
(dataservices) => {
self.allServices = dataservices;
self.filteredServices = dataservices;
self.dataserviceService.updateDataserviceStates(); // trigger refresh in event of new deployment
self.loaded("dataservices");
},
(error) => {
self.error(error, "Error getting dataservices");
}
);
this.connectionService
.getAllConnections()
.subscribe(
( connections ) => {
self.connectionsExist = connections.length !== 0;
self.loaded( self.connectionsLoadedTag );
},
( error ) => {
self.error( error, "Error getting connections" );
}
);
}
/**
* Sets the open state of the quick look panel
* @param {boolean} openState true if quick look panel is to be shown
*/
public setQuickLookPanelOpenState(openState: boolean): void {
if (openState) {
this.cardListAreaCss = "dataservice-summary-top-area-with-results";
this.resultsAreaCss = "dataservice-summary-bottom-area-with-results";
this.resultsShowing = true;
} else {
this.cardListAreaCss = "dataservice-summary-top-area-no-results";
this.resultsAreaCss = "dataservice-summary-bottom-area-no-results";
this.resultsShowing = false;
}
}
/**
* @returns {boolean} true if dataservice results panel is to be shown
*/
public get showResults(): boolean {
return this.resultsShowing;
}
/**
* @returns {boolean} true if dataservice export notification is to be shown
*/
public get showExportNotification(): boolean {
return this.exportNotificationVisible;
}
/**
* @returns {boolean} true if dataservices are being represented by cards
*/
public get isCardLayout(): boolean {
return this.appSettingsService.dataservicesPageLayout === LayoutType.CARD;
}
/**
* @returns {boolean} true if dataservices are being represented by items in a list
*/
public get isListLayout(): boolean {
return this.appSettingsService.dataservicesPageLayout === LayoutType.LIST;
}
/**
* @returns {boolean} true if sorting dataservice names in ascending order
*/
public get isSortAscending(): boolean {
return this.sortDirection === SortDirection.ASC;
}
/**
* @returns {boolean} true if sorting dataservice names in descending order
*/
public get isSortDescending(): boolean {
return this.sortDirection === SortDirection.DESC;
}
/**
* @returns {Dataservice[]} the array of all dataservices
*/
public get allDataservices(): Dataservice[] {
return this.allServices;
}
/**
* @returns {Dataservice[]} the array of filtered dataservices
*/
public get filteredDataservices(): Dataservice[] {
return this.filteredServices;
}
/**
* @returns {Dataservice[]} the array of selected dataservices
*/
public get selectedDataservices(): Dataservice[] {
return this.selectedServices;
}
/**
* Accessor for all available service views
*/
public get allServiceViews( ): Table[] {
return this.allSvcViews;
}
/**
* Accessor for selected service view
*/
public get selectedViews( ): Table[] {
return this.selectedSvcViews;
}
/**
* @returns {string} the quick look service name
*/
public get quickLookServiceName(): string {
return this.quickLookSvcName;
}
/**
* @returns {string} the quick look service name
*/
public get quickLookSql(): string {
return this.quickLookQueryText;
}
public onSelected(dataservice: Dataservice): void {
// Only allow one item to be selected
this.selectedServices.shift();
this.selectedServices.push(dataservice);
}
public onDeselected(dataservice: Dataservice): void {
// Only one item is selected at a time
this.selectedServices.shift();
// this.selectedServices.splice(this.selectedServices.indexOf(dataservice), 1);
}
public onCloseExportNotification(): void {
this.exportNotificationVisible = false;
}
public onActivate(svcName: string): void {
const selectedService = this.filteredDataservices.find((x) => x.getId() === svcName);
selectedService.setServiceDeploymentState(DeploymentState.LOADING);
this.setQuickLookPanelOpenState(false);
const self = this;
// Start the deployment and then redirect to the dataservice summary page
this.dataserviceService
.deployDataservice(svcName)
.subscribe(
(wasSuccess) => {
self.dataserviceService.updateDataserviceStates();
},
(error) => {
self.dataserviceService.updateDataserviceStates();
}
);
}
public onTest(svcName: string): void {
const selectedService = this.filteredDataservices.find((x) => x.getId() === svcName);
this.dataserviceService.setSelectedDataservice(selectedService);
this.allSvcViews = this.dataserviceService.getSelectedDataserviceViews();
this.selectedSvcViews = [];
this.selectedSvcViews.push(this.allServiceViews[0]);
this.setQuickLookPanelOpenState(false);
const link: string[] = [ DataservicesConstants.testDataservicePath ];
this.logger.debug("[DataservicesPageComponent] Navigating to: %o", link);
this.router.navigate(link).then(() => {
// nothing to do
});
}
/**
* Handle Download of the specified Dataservice
* @param {string} svcName
*/
public onDownload(svcName: string): void {
this.setQuickLookPanelOpenState(false);
this.exportNotificationHeader = this.exportInProgressHeader;
this.exportNotificationMessage = "Downloading " + svcName + "...";
this.exportNotificationType = NotificationType.INFO;
this.exportNotificationVisible = true;
this.logger.log("[DataservicesPageComponent] Downloading Dataservice: " + svcName);
const self = this;
this.dataserviceService
.downloadDataservice(svcName)
.subscribe(
(wasSuccess) => {
self.exportNotificationHeader = this.downloadSuccessHeader;
self.exportNotificationMessage = " " + svcName + " was downloaded successfully!";
self.exportNotificationType = NotificationType.SUCCESS;
this.logger.log("[DataservicesPageComponent] Download Dataservice was successful");
},
(error) => {
self.exportNotificationHeader = this.downloadFailedHeader;
self.exportNotificationMessage = " Failed to downlaod dataservice " + svcName;
self.exportNotificationType = NotificationType.DANGER;
this.logger.error("[DataservicesPageComponent] Download dataservice " + svcName + " failed.");
}
);
}
public onPublish(svcName: string): void {
this.setQuickLookPanelOpenState(false);
this.exportNotificationHeader = this.exportInProgressHeader;
this.exportNotificationMessage = "Publishing " + svcName + "...";
this.exportNotificationType = NotificationType.INFO;
this.exportNotificationVisible = true;
this.logger.log("[DataservicesPageComponent] Publishing Dataservice: " + svcName);
const self = this;
this.dataserviceService
.publishDataservice(svcName)
.subscribe(
(wasSuccess) => {
self.exportNotificationHeader = this.exportSuccessHeader;
self.exportNotificationMessage = " " + svcName + " publishing successfully initiated!";
self.exportNotificationType = NotificationType.SUCCESS;
this.logger.log("[DataservicesPageComponent] Dataservice publishing initiation was successful");
},
(error) => {
self.exportNotificationHeader = this.exportFailedHeader;
self.exportNotificationMessage = " Failed to publish dataservice " + svcName + "!";
self.exportNotificationType = NotificationType.DANGER;
this.logger.log("[DataservicesPageComponent] Publish dataservice " + svcName + " failed.");
}
);
}
/**
* Handle Delete of the specified Dataservice
* @param {string} svcName
*/
public onDelete(svcName: string): void {
this.setQuickLookPanelOpenState(false);
this.dataserviceNameForDelete = svcName;
this.confirmDeleteDialog.open();
}
/**
* Handle request for new Dataservice
*/
public onNew(): void {
this.wizardService.setEdit(false);
this.wizardService.clearWizardSelectedTables();
const link: string[] = [ DataservicesConstants.addDataservicePath ];
this.logger.log("[DataservicesPageComponent] Navigating to: %o", link);
this.router.navigate(link).then(() => {
// nothing to do
});
}
/**
* Handle Edit of the specified Dataservice
* @param {string} svcName
*/
public onEdit(svcName: string): void {
const selectedService = this.filteredDataservices.find((x) => x.getId() === svcName);
this.dataserviceService.setSelectedDataservice(selectedService);
this.setQuickLookPanelOpenState(false);
// Sets the selected dataservice and edit mode before transferring
this.wizardService.setSelectedDataservice(selectedService);
this.wizardService.setEdit(true);
const link: string[] = [ DataservicesConstants.addDataservicePath ];
this.logger.log("[DataservicesPageComponent] Navigating to: %o", link);
this.router.navigate(link).then(() => {
// nothing to do
});
}
/*
* Handle showing the QuickLook panel for the specified Dataservice
*/
public onQuickLook(svcName: string): void {
const selectedService = this.filteredDataservices.find((x) => x.getId() === svcName);
this.dataserviceService.setSelectedDataservice(selectedService);
this.allSvcViews = this.dataserviceService.getSelectedDataserviceViews();
this.selectedSvcViews = [];
this.selectedSvcViews.push(this.allServiceViews[0]);
const viewName = this.selectedSvcViews[0].getName();
this.quickLookQueryText = "SELECT * FROM " + viewName + ";";
if (!this.resultsShowing) {
this.setQuickLookPanelOpenState(true);
}
this.setQuickLookResults(svcName);
this.sqlControlComponent.queryText = this.quickLookQueryText;
this.sqlControlComponent.submitCurrentQuery();
}
/**
* Set the layout to list type
*/
public setListLayout(): void {
this.setQuickLookPanelOpenState(false);
this.appSettingsService.dataservicesPageLayout = LayoutType.LIST;
}
/**
* Set the layout to card type
*/
public setCardLayout(): void {
this.setQuickLookPanelOpenState(false);
this.appSettingsService.dataservicesPageLayout = LayoutType.CARD;
}
/**
* Called to doDelete all selected APIs.
*/
public onDeleteDataservice(): void {
const selectedService = this.filteredDataservices.find((x) => x.getId() === this.dataserviceNameForDelete);
// const itemsToDelete: Dataservice[] = ArrayUtils.intersect(this.selectedServices, this.filteredServices);
// const selectedService = itemsToDelete[0];
// Note: we can only doDelete selected items that we can see in the UI.
this.logger.log("[DataservicesPageComponent] Deleting selected Dataservice.");
const self = this;
this.dataserviceService
.deleteDataservice(selectedService.getId())
.subscribe(
(wasSuccess) => {
self.undeployVdb(selectedService.getServiceVdbName());
self.removeDataserviceFromList(selectedService);
},
(error) => {
self.error(error, "Error deleting the dataservice");
}
);
}
/**
* Called to submit the quick look query
*/
public onSubmitQuickLookQuery(): void {
this.sqlControlComponent.submitCurrentQuery();
}
/**
* Filter functions
*/
public applyFilters(filters: Filter[]): void {
this.items = [];
if (filters && filters.length > 0) {
this.allDataservices.forEach((item) => {
if (this.matchesFilters(item, filters)) {
this.items.push(item);
}
});
} else {
this.items = this.allDataservices;
}
this.filteredServices = this.items;
this.filterConfig.resultsCount = this.items.length;
}
public filterChanged($event: FilterEvent): void {
this.filtersText = "";
$event.appliedFilters.forEach((filter) => {
this.filtersText += filter.field.title + " : " + filter.value + "\n";
});
this.applyFilters($event.appliedFilters);
}
public matchesFilter(item: any, filter: Filter): boolean {
let match = true;
if (filter.field.id === "name") {
match = item.getId().match(filter.value) !== null;
} else if (filter.field.id === "description") {
match = item.getDescription().match(filter.value) !== null;
} else if (filter.field.id === "view") {
match = item.getViews() === filter.value;
}
return match;
}
public matchesFilters(item: any, filters: Filter[]): boolean {
let matches = true;
filters.forEach((filter) => {
if (!this.matchesFilter(item, filter)) {
matches = false;
return matches;
}
});
return matches;
}
/**
* Sort functions
*/
public compare(item1: any, item2: any): number {
let compValue = 0;
if (this.currentSortField.id === "name") {
compValue = item1.getId().localeCompare(item2.getId());
} else if (this.currentSortField.id === "description") {
compValue = item1.getDescription().localeCompare(item2.getDescription());
}
if (!this.isAscendingSort) {
compValue = compValue * -1;
}
return compValue;
}
public sortChange($event: SortEvent): void {
this.currentSortField = $event.field;
this.isAscendingSort = $event.isAscending;
this.filteredServices.sort((item1: any, item2: any) => this.compare(item1, item2));
}
/*
* Undeploy the Vdb with the specified name
* @param {string} vdbName the name of the Vdb
*/
private undeployVdb(vdbName: string): void {
this.vdbService
.undeployVdb(vdbName)
.subscribe(
(wasSuccess) => {
// nothing to do
},
(error) => {
// nothing to do
}
);
}
/*
* Remove the specified Dataservice from the list of dataservices
*/
private removeDataserviceFromList(dataservice: Dataservice): void {
this.allServices.splice(this.allServices.indexOf(dataservice), 1);
}
/*
* Update the displayed dataservice states using the provided states
*/
private onDataserviceStateChanged(stateMap: Map<string, DeploymentState>): void {
// For displayed dataservices, update the State using supplied services
for ( const dService of this.filteredDataservices ) {
const serviceId = dService.getId();
if (stateMap && stateMap.has(serviceId)) {
dService.setServiceDeploymentState(stateMap.get(serviceId));
}
}
}
/*
* Update quick look results using the supplied dataservice
* @param {string} svcName the dataservice name
*/
private setQuickLookResults(svcName): void {
this.quickLookSvcName = svcName;
}
}