New Angular UI from 1806
[vid.git] / vid-webpack-master / src / app / instantiationStatus / instantiationStatus.component.ts
1 import {AfterViewChecked, Component, ViewChild} from '@angular/core';
2 import {ServiceInfoService} from '../shared/server/serviceInfo/serviceInfo.service';
3 import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model';
4 import {InstantiationStatusComponentService} from './instantiationStatus.component.service';
5 import {ContextMenuComponent, ContextMenuService} from 'ngx-contextmenu';
6 import {AuditInfoModalComponent} from "./auditInfoModal/auditInfoModal.component";
7 import * as _ from 'lodash';
8 import {ScrollToConfigOptions, ScrollToService} from '@nicky-lenaers/ngx-scroll-to';
9 import {ConfigurationService} from "../services/configuration.service";
10 import {LogService} from '../shared/utils/log/log.service';
11
12
13 @Component({
14   selector : 'instantiation-status',
15   templateUrl : './instantiationStatus.component.html',
16   styleUrls : ['./instantiationStatus.component.scss']
17 })
18 export class InstantiationStatusComponent implements AfterViewChecked{
19
20
21   TIMER_TIME_IN_SECONDS : number = 0;
22   timer = null;
23   dataIsReady : boolean = false;
24   scroll : boolean = false;
25   lastUpdatedDate: Date = null;
26   currentJobId: string = null;
27   instantiationStatusComponentService: InstantiationStatusComponentService;
28   configurationService : ConfigurationService;
29   serviceInfoData: Array<ServiceInfoModel> = null;
30   @ViewChild(ContextMenuComponent) public contextMenu: ContextMenuComponent;
31
32   constructor(private _serviceInfoService: ServiceInfoService,
33               private _instantiationStatusComponentService : InstantiationStatusComponentService,
34               private _contextMenuService: ContextMenuService,
35               private _configurationService : ConfigurationService,
36               private _scrollToService: ScrollToService,
37               private _logService : LogService) {
38     this.instantiationStatusComponentService = _instantiationStatusComponentService;
39     this.configurationService = this._configurationService;
40     this.configurationService.getConfiguration("refreshTimeInstantiationDashboard").subscribe(response => {
41       this.TIMER_TIME_IN_SECONDS = _.isNumber(response) ? response : 0;
42       this.activateInterval();
43       this.refreshData();
44     });
45   }
46
47   activateInterval() {
48     if (this.TIMER_TIME_IN_SECONDS > 0) {
49       this.timer = setInterval(() => {
50         this.refreshData();
51       }, this.TIMER_TIME_IN_SECONDS * 1000);
52     }
53   }
54
55   deactivateInterval() {
56     clearInterval(this.timer);
57   }
58
59   refreshData(): void {
60     this.dataIsReady = false;
61     this._serviceInfoService.getServicesJobInfo(true)
62       .subscribe((res: Array<ServiceInfoModel>) => {
63         this._instantiationStatusComponentService.convertObjectToArray(res).subscribe((res) => {
64           this._logService.info('refresh instantiation status table', res);
65           this.dataIsReady = true;
66           this.lastUpdatedDate = new Date();
67           if (!_.isEqual(this.serviceInfoData, res)) {
68             this.serviceInfoData = res;
69             this.scroll = true;
70           }
71         });
72       })
73   }
74
75   ngAfterViewChecked(){
76     if (this.scroll) {
77       this.scrollToElement();
78       this.scroll = false;
79     }
80   }
81
82
83
84   isDeleteEnabled(item):boolean {
85     return _.includes(['PENDING', 'STOPPED'], item.jobStatus);
86   }
87
88   deleteItem(item): void {
89     this._serviceInfoService.deleteJob(item.jobId).subscribe(() => {
90       this.refreshData();
91     });
92   }
93
94   hideItem(item): void {
95     this._serviceInfoService.hideJob(item.jobId).subscribe(() => {
96       this.refreshData();
97     });
98   }
99
100   auditInfo(jobData : ServiceInfoModel): void {
101     AuditInfoModalComponent.openModal.next(jobData);
102
103   }
104
105   isOpenVisible(item):boolean {
106     return _.includes(['COMPLETED', 'PAUSE'], item.jobStatus);
107   }
108
109   open(item): void {
110     let query =
111       `subscriberId=${item['subscriberName']}&` +
112       `serviceType=${item['serviceType']}&` +
113       `serviceInstanceId=${item['serviceInstanceId']}`;
114
115     window.parent.location.assign('../../serviceModels.htm#/instantiate?' + query);
116   }
117
118   public onContextMenu($event: MouseEvent, item: any): void {
119     this._contextMenuService.show.next({
120       contextMenu: this.contextMenu,
121       event: $event,
122       item: item,
123     });
124     $event.preventDefault();
125     $event.stopPropagation();
126   }
127
128   getImagesSrc(imageName : string) : string {
129     return './' + imageName + '.svg';
130   }
131
132   isHideEnabled(item: any):boolean {
133     return _.includes(['COMPLETED', 'FAILED', 'STOPPED'], item.jobStatus);
134   }
135   scrollToElement() {
136     if(this.currentJobId){
137       const config: ScrollToConfigOptions = {
138         target: this.currentJobId,
139         duration: 50,
140         offset: -35 //header height
141       };
142       this._scrollToService.scrollTo(config);
143     }
144   }
145 }