blob: aa783d4dfa5dd4ce4427ed5340bae8df67db54e0 [file] [log] [blame]
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +03001import { ChangeDetectorRef, Component, ViewEncapsulation } from '@angular/core';
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +03002import { MatDialog } from '@angular/material';
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +03003import { ActivatedRoute, Router } from '@angular/router';
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +03004import { ToastrService } from 'ngx-toastr';
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +03005import { RestApiService } from '../api/rest-api.service';
6import { HostService } from '../host/host.service';
7import { ConfirmPopupComponent } from '../rule-engine/confirm-popup/confirm-popup.component';
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +03008// import { PluginPubSub } from '../sdc/plugin-pubsub';
9import { PluginPubSub } from 'sdc-pubsub';
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030010import { Store } from '../store/store';
11import { NgxDatatableModule } from '@swimlane/ngx-datatable';
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030012
13@Component({
14 selector: 'app-home',
15 templateUrl: './home.component.html',
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030016 styleUrls: ['./home.component.scss'],
17 encapsulation: ViewEncapsulation.None
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030018})
19export class HomeComponent {
20 linkToMain: string;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030021 showTable = true;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030022 selectedLine = [];
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030023 monitoringComponents = new Array();
24 unavailableMonitoringComponents = new Array();
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030025 hoveredIndex = 1;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030026 dialogRef;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030027 deleteRow: number;
28
29 loadingIndicator = true;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030030
31 constructor(
32 private activeRoute: ActivatedRoute,
33 private route: Router,
34 private _restApi: RestApiService,
35 private dialog: MatDialog,
36 public store: Store,
37 private toastr: ToastrService,
38 private changeDetectorRef: ChangeDetectorRef
39 ) {
40 this.store.loader = true;
41 this.activeRoute.queryParams.subscribe(params => {
42 console.log('params: %o', params);
43 this.store.sdcParmas = params;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030044
45 console.log('init comunication with sdc');
46 const eventsToWaitFor = [
47 'WINDOW_OUT',
48 'VERSION_CHANGE',
49 'CHECK_IN',
50 'CHECK_OUT',
51 'SUBMIT_FOR_TESTING',
52 'UNDO_CHECK_OUT'
53 ];
54 this.store.ifrmaeMessenger = new PluginPubSub(
55 this.store.sdcParmas.eventsClientId,
56 this.store.sdcParmas.parentUrl,
57 eventsToWaitFor
58 );
59 console.log('send ready to sdc');
60 this.store.ifrmaeMessenger.notify('READY');
61
62 this.store.ifrmaeMessenger.on((eventData, event) => {
63 console.log('eventData', eventData);
64 console.log('event', event);
65 if (
66 eventData.type === 'WINDOW_OUT' ||
67 eventData.type === 'CHECK_IN' ||
68 eventData.type === 'SUBMIT_FOR_TESTING'
69 ) {
70 const currentUrl = this.route.url;
71 if (currentUrl.includes('main')) {
72 if (this.store.cdumpIsDirty) {
73 this.store.displaySDCDialog = true;
74 } else {
75 this.store.ifrmaeMessenger.notify('ACTION_COMPLETED');
76 }
77 } else {
78 this.store.ifrmaeMessenger.notify('ACTION_COMPLETED');
79 }
80 } else {
81 this.store.ifrmaeMessenger.notify('ACTION_COMPLETED');
82 }
83 });
84
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030085 this.linkToMain = `/main/${params.contextType}/${params.uuid}/${
86 params.version
87 }/`;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030088 this.loadingIndicator = true;
89
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030090 this._restApi.getMonitoringComponents(params).subscribe(
91 response => {
92 console.log('response: ', response);
93 if (response.hasOwnProperty('monitoringComponents')) {
94 this.monitoringComponents = response.monitoringComponents;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030095 this.loadingIndicator = false;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030096 }
97 if (response.hasOwnProperty('unavailable')) {
98 this.unavailableMonitoringComponents = response.unavailable;
99 }
100 this.showTable = this.monitoringComponents.length > 0;
101 this.store.loader = false;
102 },
103 response => {
104 this.showTable = false;
105 this.store.loader = false;
106 console.log('ERROR: ', response);
107 }
108 );
109 HostService.disableLoader();
110 });
111 }
112
113 createScreen() {
114 this.store.isEditMode = false;
115 this.route.navigate([this.linkToMain + 'new']);
116 }
117
118 importScreen() {
119 this.store.isEditMode = false;
120 this.route.navigate([this.linkToMain + 'import']);
121 }
122
123 checkCanCreate() {
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300124 return (
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300125 JSON.parse(this.store.sdcParmas.isOwner) &&
126 this.store.sdcParmas.lifecycleState === 'NOT_CERTIFIED_CHECKOUT'
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300127 );
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300128 }
129
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300130 // Monitoring Table logic
131
132 checkTableItemHoverCondition(item: any): boolean {
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300133 return (
134 this.checkCanCreate() &&
135 (this.store.sdcParmas.userId === item.lastUpdaterUserId ||
136 item['lifecycleState'] !== 'NOT_CERTIFIED_CHECKOUT')
137 );
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300138 }
139
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300140 onTableActivate(event: any): void {
141 this.hoveredIndex = this.monitoringComponents.findIndex(
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300142 s => s === event.row
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300143 );
144 console.log('selected : ');
145 }
146
147 editTableItem(item: any): void {
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300148 this.store.vfiName = item.vfiName;
149 this.route.navigate([this.linkToMain + '/' + item.uuid]);
150 }
151
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300152 onTableSelectItem(item: any): void {
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300153 this.selectedLine = item;
154 console.log('selected : ', item);
155 }
156
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300157 deleteTableItem(item: any, index: any): void {
158 this.deleteRow = index;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300159 this.dialogRef = this.dialog.open(ConfirmPopupComponent, {
160 panelClass: 'my-confrim-dialog',
161 disableClose: true
162 });
163 this.dialogRef.afterClosed().subscribe(result => {
164 // if the user want to delete
165 if (result) {
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300166 if (item.status === 'Submitted') {
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300167 this.store.loader = true;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300168 this._restApi
169 .deleteMonitoringComponentWithBlueprint(
170 this.store.sdcParmas,
171 item.name,
172 item.uuid,
173 item.vfiName
174 )
175 .subscribe(
176 response => {
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300177 this.itemDeletedRemoveAndNotify(item.uuid, this.deleteRow);
178 this.store.loader = false;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300179 },
180 error => {
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300181 const errorMsg = Object.values(error.requestError) as any;
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300182 if (errorMsg[0].messageId === 'SVC6118') {
183 this.monitoringComponents = this.monitoringComponents.filter(
184 comp => {
185 return comp.uuid !== item.uuid;
186 }
187 );
188 }
189 this.store.loader = false;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300190 this.toastr.error('', errorMsg[0].formattedErrorMessage);
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300191 }
192 );
193 } else {
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300194 this.store.loader = true;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300195 this._restApi
196 .deleteMonitoringComponent(
197 this.store.sdcParmas,
198 item.uuid,
199 item.vfiName
200 )
201 .subscribe(
202 response => {
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300203 this.itemDeletedRemoveAndNotify(item.uuid, this.deleteRow);
204 this.store.loader = false;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300205 },
206 error => {
207 const errorMsg = Object.values(error.requestError) as any;
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300208 this.store.loader = false;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300209 this.toastr.error('', errorMsg[0]);
210 }
211 );
212 }
213 }
214 });
215 }
216
Manor, Yanir (ym903w)22eda032018-09-20 14:18:38 +0300217 itemDeletedRemoveAndNotify(uuid, deletedRow: number): void {
218 this.monitoringComponents = this.monitoringComponents.filter(comp => {
219 return comp.uuid !== uuid;
220 });
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300221 this.toastr.success(
222 '',
223 'Monitoring Configuration was successfully deleted'
224 );
225 }
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300226}