aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/instantiationStatus/instantiationStatus.component.ts
blob: ed45ce43cda801d0e94f8a40da3764749bb90994 (plain)
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
import {AfterViewChecked, Component, ViewChild} from '@angular/core';
import {ServiceInfoService} from '../shared/server/serviceInfo/serviceInfo.service';
import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model';
import {InstantiationStatusComponentService} from './instantiationStatus.component.service';
import {ContextMenuComponent, ContextMenuService} from 'ngx-contextmenu';
import {AuditInfoModalComponent} from "./auditInfoModal/auditInfoModal.component";
import * as _ from 'lodash';
import {ScrollToConfigOptions, ScrollToService} from '@nicky-lenaers/ngx-scroll-to';
import {ConfigurationService} from "../services/configuration.service";
import {LogService} from '../shared/utils/log/log.service';


@Component({
  selector : 'instantiation-status',
  templateUrl : './instantiationStatus.component.html',
  styleUrls : ['./instantiationStatus.component.scss']
})
export class InstantiationStatusComponent implements AfterViewChecked{


  TIMER_TIME_IN_SECONDS : number = 0;
  timer = null;
  dataIsReady : boolean = false;
  scroll : boolean = false;
  lastUpdatedDate: Date = null;
  currentJobId: string = null;
  instantiationStatusComponentService: InstantiationStatusComponentService;
  configurationService : ConfigurationService;
  serviceInfoData: Array<ServiceInfoModel> = null;
  @ViewChild(ContextMenuComponent) public contextMenu: ContextMenuComponent;

  constructor(private _serviceInfoService: ServiceInfoService,
              private _instantiationStatusComponentService : InstantiationStatusComponentService,
              private _contextMenuService: ContextMenuService,
              private _configurationService : ConfigurationService,
              private _scrollToService: ScrollToService,
              private _logService : LogService) {
    this.instantiationStatusComponentService = _instantiationStatusComponentService;
    this.configurationService = this._configurationService;
    this.configurationService.getConfiguration("refreshTimeInstantiationDashboard").subscribe(response => {
      this.TIMER_TIME_IN_SECONDS = _.isNumber(response) ? response : 0;
      this.activateInterval();
      this.refreshData();
    });
  }

  activateInterval() {
    if (this.TIMER_TIME_IN_SECONDS > 0) {
      this.timer = setInterval(() => {
        this.refreshData();
      }, this.TIMER_TIME_IN_SECONDS * 1000);
    }
  }

  deactivateInterval() {
    clearInterval(this.timer);
  }

  refreshData(): void {
    this.dataIsReady = false;
    this._serviceInfoService.getServicesJobInfo(true)
      .subscribe((res: Array<ServiceInfoModel>) => {
        this._instantiationStatusComponentService.convertObjectToArray(res).subscribe((res) => {
          this._logService.info('refresh instantiation status table', res);
          this.dataIsReady = true;
          this.lastUpdatedDate = new Date();
          if (!_.isEqual(this.serviceInfoData, res)) {
            this.serviceInfoData = res;
            this.scroll = true;
          }
        });
      })
  }

  ngAfterViewChecked(){
    if (this.scroll) {
      this.scrollToElement();
      this.scroll = false;
    }
  }



  isDeleteEnabled(item):boolean {
    return _.includes(['PENDING', 'STOPPED'], item.jobStatus);
  }

  deleteItem(item): void {
    this._serviceInfoService.deleteJob(item.jobId).subscribe(() => {
      this.refreshData();
    });
  }

  hideItem(item): void {
    this._serviceInfoService.hideJob(item.jobId).subscribe(() => {
      this.refreshData();
    });
  }

  auditInfo(jobData : ServiceInfoModel): void {
    AuditInfoModalComponent.openModal.next(jobData);

  }

  isOpenVisible(item):boolean {
    return _.includes(['COMPLETED', 'PAUSE'], item.jobStatus);
  }

  open(item): void {
    let query =
      `subscriberId=${item['subscriberName']}&` +
      `serviceType=${item['serviceType']}&` +
      `serviceInstanceId=${item['serviceInstanceId']}`;

    window.parent.location.assign('../../serviceModels.htm#/instantiate?' + query);
  }

  public onContextMenu($event: MouseEvent, item: any): void {
    this._contextMenuService.show.next({
      contextMenu: this.contextMenu,
      event: $event,
      item: item,
    });
    $event.preventDefault();
    $event.stopPropagation();
  }

  getImagesSrc(imageName : string) : string {
    return './' + imageName + '.svg';
  }

  isHideEnabled(item: any):boolean {
    return _.includes(['COMPLETED', 'FAILED', 'STOPPED'], item.jobStatus);
  }
  scrollToElement() {
    if(this.currentJobId){
      const config: ScrollToConfigOptions = {
        target: this.currentJobId,
        duration: 50,
        offset: -35 //header height
      };
      this._scrollToService.scrollTo(config);
    }
  }
}