blob: ed45ce43cda801d0e94f8a40da3764749bb90994 [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import {AfterViewChecked, Component, ViewChild} from '@angular/core';
2import {ServiceInfoService} from '../shared/server/serviceInfo/serviceInfo.service';
3import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model';
4import {InstantiationStatusComponentService} from './instantiationStatus.component.service';
5import {ContextMenuComponent, ContextMenuService} from 'ngx-contextmenu';
6import {AuditInfoModalComponent} from "./auditInfoModal/auditInfoModal.component";
7import * as _ from 'lodash';
8import {ScrollToConfigOptions, ScrollToService} from '@nicky-lenaers/ngx-scroll-to';
9import {ConfigurationService} from "../services/configuration.service";
10import {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})
18export 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}