Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 1 | import { ChangeDetectorRef, Component, ViewEncapsulation } from '@angular/core'; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 2 | import { MatDialog } from '@angular/material'; |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 3 | import { ActivatedRoute, Router } from '@angular/router'; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 4 | import { ToastrService } from 'ngx-toastr'; |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 5 | import { RestApiService } from '../api/rest-api.service'; |
| 6 | import { HostService } from '../host/host.service'; |
| 7 | import { ConfirmPopupComponent } from '../rule-engine/confirm-popup/confirm-popup.component'; |
Manor, Yanir (ym903w) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 8 | // import { PluginPubSub } from '../sdc/plugin-pubsub'; |
| 9 | import { PluginPubSub } from 'sdc-pubsub'; |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 10 | import { Store } from '../store/store'; |
| 11 | import { NgxDatatableModule } from '@swimlane/ngx-datatable'; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 12 | |
| 13 | @Component({ |
| 14 | selector: 'app-home', |
| 15 | templateUrl: './home.component.html', |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 16 | styleUrls: ['./home.component.scss'], |
| 17 | encapsulation: ViewEncapsulation.None |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 18 | }) |
| 19 | export class HomeComponent { |
| 20 | linkToMain: string; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 21 | showTable = true; |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 22 | selectedLine = []; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 23 | monitoringComponents = new Array(); |
| 24 | unavailableMonitoringComponents = new Array(); |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 25 | hoveredIndex = 1; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 26 | dialogRef; |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 27 | deleteRow: number; |
| 28 | |
| 29 | loadingIndicator = true; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 30 | |
| 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) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 44 | |
| 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) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 85 | this.linkToMain = `/main/${params.contextType}/${params.uuid}/${ |
| 86 | params.version |
| 87 | }/`; |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 88 | this.loadingIndicator = true; |
| 89 | |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 90 | 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) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 95 | this.loadingIndicator = false; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 96 | } |
| 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) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 124 | return ( |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 125 | JSON.parse(this.store.sdcParmas.isOwner) && |
| 126 | this.store.sdcParmas.lifecycleState === 'NOT_CERTIFIED_CHECKOUT' |
Manor, Yanir (ym903w) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 127 | ); |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 128 | } |
| 129 | |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 130 | // Monitoring Table logic |
| 131 | |
| 132 | checkTableItemHoverCondition(item: any): boolean { |
Manor, Yanir (ym903w) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 133 | return ( |
| 134 | this.checkCanCreate() && |
| 135 | (this.store.sdcParmas.userId === item.lastUpdaterUserId || |
| 136 | item['lifecycleState'] !== 'NOT_CERTIFIED_CHECKOUT') |
| 137 | ); |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 138 | } |
| 139 | |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 140 | onTableActivate(event: any): void { |
| 141 | this.hoveredIndex = this.monitoringComponents.findIndex( |
Manor, Yanir (ym903w) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 142 | s => s === event.row |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 143 | ); |
| 144 | console.log('selected : '); |
| 145 | } |
| 146 | |
| 147 | editTableItem(item: any): void { |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 148 | this.store.vfiName = item.vfiName; |
| 149 | this.route.navigate([this.linkToMain + '/' + item.uuid]); |
| 150 | } |
| 151 | |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 152 | onTableSelectItem(item: any): void { |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 153 | this.selectedLine = item; |
| 154 | console.log('selected : ', item); |
| 155 | } |
| 156 | |
Stone, Avi (as206k) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 157 | deleteTableItem(item: any, index: any): void { |
| 158 | this.deleteRow = index; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 159 | 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) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 166 | if (item.status === 'Submitted') { |
Manor, Yanir (ym903w) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 167 | this.store.loader = true; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 168 | 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) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 177 | this.itemDeletedRemoveAndNotify(item.uuid, this.deleteRow); |
| 178 | this.store.loader = false; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 179 | }, |
| 180 | error => { |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 181 | const errorMsg = Object.values(error.requestError) as any; |
Manor, Yanir (ym903w) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 182 | 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) | 548c5a2 | 2018-06-03 13:12:12 +0300 | [diff] [blame] | 190 | this.toastr.error('', errorMsg[0].formattedErrorMessage); |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 191 | } |
| 192 | ); |
| 193 | } else { |
Manor, Yanir (ym903w) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 194 | this.store.loader = true; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 195 | this._restApi |
| 196 | .deleteMonitoringComponent( |
| 197 | this.store.sdcParmas, |
| 198 | item.uuid, |
| 199 | item.vfiName |
| 200 | ) |
| 201 | .subscribe( |
| 202 | response => { |
Manor, Yanir (ym903w) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 203 | this.itemDeletedRemoveAndNotify(item.uuid, this.deleteRow); |
| 204 | this.store.loader = false; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 205 | }, |
| 206 | error => { |
| 207 | const errorMsg = Object.values(error.requestError) as any; |
Manor, Yanir (ym903w) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 208 | this.store.loader = false; |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 209 | this.toastr.error('', errorMsg[0]); |
| 210 | } |
| 211 | ); |
| 212 | } |
| 213 | } |
| 214 | }); |
| 215 | } |
| 216 | |
Manor, Yanir (ym903w) | 22eda03 | 2018-09-20 14:18:38 +0300 | [diff] [blame^] | 217 | itemDeletedRemoveAndNotify(uuid, deletedRow: number): void { |
| 218 | this.monitoringComponents = this.monitoringComponents.filter(comp => { |
| 219 | return comp.uuid !== uuid; |
| 220 | }); |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 221 | this.toastr.success( |
| 222 | '', |
| 223 | 'Monitoring Configuration was successfully deleted' |
| 224 | ); |
| 225 | } |
Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 226 | } |