1 import {Component, OnInit, 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 "../shared/components/auditInfoModal/auditInfoModal.component";
7 import * as _ from 'lodash';
8 import {ScrollToConfigOptions, ScrollToService} from '@nicky-lenaers/ngx-scroll-to';
9 import {ConfigurationService} from "../shared/services/configuration.service";
10 import {LogService} from '../shared/utils/log/log.service';
11 import {AppState} from "../shared/store/reducers";
12 import {NgRedux} from '@angular-redux/store';
13 import {JobStatus, ServiceAction} from "../shared/models/serviceInstanceActions";
14 import {ActivatedRoute} from "@angular/router";
15 import {FeatureFlagsService, Features} from "../shared/services/featureFlag/feature-flags.service";
17 export interface MenuAction{
22 click(item: ServiceInfoModel): void;
23 enabled (item?: ServiceInfoModel): boolean;
24 visible (item?: ServiceInfoModel): boolean;
28 selector : 'instantiation-status',
29 templateUrl : './instantiationStatus.component.html',
30 styleUrls : ['./instantiationStatus.component.scss']
32 export class InstantiationStatusComponent implements OnInit {
34 TIMER_TIME_IN_SECONDS : number = 0;
36 dataIsReady : boolean = false;
37 scroll : boolean = false;
38 lastUpdatedDate: Date = null;
39 instantiationStatusComponentService: InstantiationStatusComponentService;
40 configurationService : ConfigurationService;
41 serviceInfoData: ServiceInfoModel[] = null;
42 @ViewChild(ContextMenuComponent) public contextMenu: ContextMenuComponent;
44 public contextMenuActions: Array<MenuAction> = [
47 dataTestId: "context-menu-retry",
48 className: "fa-repeat",
49 click: (item: ServiceInfoModel) => this.retryItem(item),
51 visible: (item: ServiceInfoModel) => item.isRetryEnabled,
55 dataTestId: "context-menu-open",
56 className: "fa-external-link",
57 click: (item: ServiceInfoModel) => this.instantiationStatusComponentService.open(item),
58 enabled: (item: ServiceInfoModel) => this.isOpenEnabled(item),
63 dataTestId: "context-menu-audit-info",
64 className: "fa-info-circle",
65 click: (item: ServiceInfoModel) => this.auditInfo(item),
66 enabled: (item: ServiceInfoModel) => this.isAuditInfoEnabled(item),
71 dataTestId: "context-menu-remove",
72 className: "fa-trash-o",
73 click: (item: ServiceInfoModel) => this.deleteItem(item),
74 enabled: (item: ServiceInfoModel) => this.isDeleteEnabled(item),
79 dataTestId: "context-menu-hide",
80 className: "fa-eye-slash",
81 tooltip: "Hide this service from this table",
82 click: (item: ServiceInfoModel) => this.hideItem(item),
83 enabled: (item: ServiceInfoModel) => this.isHideEnabled(item),
90 constructor(private _serviceInfoService: ServiceInfoService,
91 private _instantiationStatusComponentService : InstantiationStatusComponentService,
92 private _contextMenuService: ContextMenuService,
93 private _configurationService : ConfigurationService,
94 private _scrollToService: ScrollToService,
95 private _logService : LogService,
96 private route: ActivatedRoute,
97 private _store: NgRedux<AppState>) {
98 this.instantiationStatusComponentService = _instantiationStatusComponentService;
99 this.configurationService = this._configurationService;
100 this.configurationService.getConfiguration("refreshTimeInstantiationDashboard").subscribe(response => {
101 this.TIMER_TIME_IN_SECONDS = _.isNumber(response) ? response : 0;
102 this.activateInterval();
108 let filterTextParam = this.route.snapshot.queryParams["filterText"];
109 this.filterText = filterTextParam ? filterTextParam : "" ;
113 if (this.TIMER_TIME_IN_SECONDS > 0) {
114 this.timer = setInterval(() => {
116 }, this.TIMER_TIME_IN_SECONDS * 1000);
120 deactivateInterval() {
121 clearInterval(this.timer);
124 refreshData(): void {
125 this.dataIsReady = false;
126 this._serviceInfoService.getServicesJobInfo(this.lastUpdatedDate === null)
127 .subscribe((res: ServiceInfoModel[]) => {
128 this._instantiationStatusComponentService.convertObjectToArray(res).subscribe((res) => {
129 this._logService.info('refresh instantiation status table', res);
130 this.dataIsReady = true;
131 this.lastUpdatedDate = new Date();
132 if (!_.isEqual(this.serviceInfoData, res)) {
133 this.serviceInfoData = res;
134 this.scrollToElement(this.findFirstVisibleJob());
140 trackByFn(index: number, item: ServiceInfoModel){
141 return _.isNil(item) ? null : item.jobId;
144 deleteItem(item: ServiceInfoModel): void {
145 this._serviceInfoService.deleteJob(item.jobId).subscribe(() => {
150 hideItem(item: ServiceInfoModel): void {
151 this._serviceInfoService.hideJob(item.jobId).subscribe(() => {
156 retryItem(item: ServiceInfoModel) : void {
157 if (item.isRetryEnabled) {
158 this._instantiationStatusComponentService.retry(item);
162 auditInfo(jobData : ServiceInfoModel): void {
163 AuditInfoModalComponent.openModal.next(jobData);
166 isOpenEnabled(item: ServiceInfoModel):boolean {
167 switch(item.action) {
168 case ServiceAction.DELETE:
169 return _.includes([ JobStatus.PENDING, JobStatus.COMPLETED_WITH_ERRORS, JobStatus.FAILED], item.jobStatus);
170 case ServiceAction.UPDATE:
171 return _.includes([JobStatus.PENDING, JobStatus.PAUSE, JobStatus.COMPLETED_WITH_ERRORS, JobStatus.COMPLETED, JobStatus.FAILED], item.jobStatus);
173 return _.includes([JobStatus.COMPLETED, JobStatus.PAUSE, JobStatus.COMPLETED_WITH_ERRORS], item.jobStatus);
177 isAuditInfoEnabled(item: ServiceInfoModel): boolean {
178 if(item.action === ServiceAction.DELETE || item.action=== ServiceAction.UPDATE) {
179 return _.includes([JobStatus.FAILED, JobStatus.IN_PROGRESS, JobStatus.COMPLETED_WITH_ERRORS, JobStatus.PAUSE, JobStatus.COMPLETED], item.jobStatus);
181 return true;// ServiceAction.INSTANTIATE
184 isDeleteEnabled(item: ServiceInfoModel):boolean {
185 if( item.action === ServiceAction.DELETE || item.action === ServiceAction.UPDATE){
186 return _.includes([JobStatus.PENDING], item.jobStatus);
188 return _.includes([JobStatus.PENDING, JobStatus.STOPPED], item.jobStatus);
191 isHideEnabled(item: ServiceInfoModel):boolean {
192 return _.includes([JobStatus.COMPLETED, JobStatus.FAILED, JobStatus.STOPPED, JobStatus.COMPLETED_WITH_ERRORS], item.jobStatus);
195 public onContextMenu($event: MouseEvent, item: any): void {
196 this._contextMenuService.show.next({
197 contextMenu: this.contextMenu,
201 $event.preventDefault();
202 $event.stopPropagation();
205 getImagesSrc(imageName : string) : string {
206 return './' + imageName + '.svg';
209 private getHeaderHeaderClientRect(): ClientRect {
210 const element = document.querySelector("#instantiation-status thead") as HTMLElement;
211 return element.getBoundingClientRect();
214 findFirstVisibleJob(): HTMLElement {
215 const elements : any = document.querySelectorAll('#instantiation-status tr');
216 const headerRect = this.getHeaderHeaderClientRect();
218 const topEdge = headerRect.bottom;
219 for (let i = 0; i < elements.length; i++) {
220 if (elements[i].getBoundingClientRect().top >= topEdge)
227 scrollToElement(currentJob: HTMLElement) {
229 const config: ScrollToConfigOptions = {
232 offset: -1 * (this.getHeaderHeaderClientRect().height + 2),
237 this._scrollToService.scrollTo(config);
242 isInstantiationStatusFilterFlagOn() {
243 return FeatureFlagsService.getFlagState(Features.FLAG_2004_INSTANTIATION_STATUS_FILTER, this._store);