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-recreate",
64 className: "fa-clone",
65 click: (item: ServiceInfoModel) => this.instantiationStatusComponentService.recreate(item),
66 enabled: (item: ServiceInfoModel) => this.instantiationStatusComponentService.isRecreateEnabled(item),
67 visible: () => this.instantiationStatusComponentService.isRecreateVisible(),
71 dataTestId: "context-menu-audit-info",
72 className: "fa-info-circle",
73 click: (item: ServiceInfoModel) => this.auditInfo(item),
74 enabled: (item: ServiceInfoModel) => this.isAuditInfoEnabled(item),
79 dataTestId: "context-menu-remove",
80 className: "fa-trash-o",
81 click: (item: ServiceInfoModel) => this.deleteItem(item),
82 enabled: (item: ServiceInfoModel) => this.isDeleteEnabled(item),
87 dataTestId: "context-menu-hide",
88 className: "fa-eye-slash",
89 tooltip: "Hide this service from this table",
90 click: (item: ServiceInfoModel) => this.hideItem(item),
91 enabled: (item: ServiceInfoModel) => this.isHideEnabled(item),
98 constructor(private _serviceInfoService: ServiceInfoService,
99 private _instantiationStatusComponentService : InstantiationStatusComponentService,
100 private _contextMenuService: ContextMenuService,
101 private _configurationService : ConfigurationService,
102 private _scrollToService: ScrollToService,
103 private _logService : LogService,
104 private route: ActivatedRoute,
105 private _store: NgRedux<AppState>) {
106 this.instantiationStatusComponentService = _instantiationStatusComponentService;
107 this.configurationService = this._configurationService;
108 this.configurationService.getConfiguration("refreshTimeInstantiationDashboard").subscribe(response => {
109 this.TIMER_TIME_IN_SECONDS = _.isNumber(response) ? response : 0;
110 this.activateInterval();
116 let filterTextParam = this.route.snapshot.queryParams["filterText"];
117 this.filterText = filterTextParam ? filterTextParam : "" ;
121 if (this.TIMER_TIME_IN_SECONDS > 0) {
122 this.timer = setInterval(() => {
124 }, this.TIMER_TIME_IN_SECONDS * 1000);
128 deactivateInterval() {
129 clearInterval(this.timer);
132 refreshData(): void {
133 this.dataIsReady = false;
134 this._serviceInfoService.getServicesJobInfo(this.lastUpdatedDate === null)
135 .subscribe((res: ServiceInfoModel[]) => {
136 this._instantiationStatusComponentService.convertObjectToArray(res).subscribe((res) => {
137 this._logService.info('refresh instantiation status table', res);
138 this.dataIsReady = true;
139 this.lastUpdatedDate = new Date();
140 if (!_.isEqual(this.serviceInfoData, res)) {
141 this.serviceInfoData = res;
142 this.scrollToElement(this.findFirstVisibleJob());
148 trackByFn(index: number, item: ServiceInfoModel){
149 return _.isNil(item) ? null : item.jobId;
152 deleteItem(item: ServiceInfoModel): void {
153 this._serviceInfoService.deleteJob(item.jobId).subscribe(() => {
158 hideItem(item: ServiceInfoModel): void {
159 this._serviceInfoService.hideJob(item.jobId).subscribe(() => {
164 retryItem(item: ServiceInfoModel) : void {
165 if (item.isRetryEnabled) {
166 this._instantiationStatusComponentService.retry(item);
170 auditInfo(jobData : ServiceInfoModel): void {
171 AuditInfoModalComponent.openModal.next(jobData);
174 isOpenEnabled(item: ServiceInfoModel):boolean {
175 switch(item.action) {
176 case ServiceAction.DELETE:
177 return _.includes([ JobStatus.PENDING, JobStatus.COMPLETED_WITH_ERRORS, JobStatus.FAILED], item.jobStatus);
178 case ServiceAction.UPDATE:
179 return _.includes([JobStatus.PENDING, JobStatus.PAUSE, JobStatus.COMPLETED_WITH_ERRORS, JobStatus.COMPLETED, JobStatus.FAILED], item.jobStatus);
181 return _.includes([JobStatus.COMPLETED, JobStatus.PAUSE, JobStatus.COMPLETED_WITH_ERRORS], item.jobStatus);
185 isAuditInfoEnabled(item: ServiceInfoModel): boolean {
186 if(item.action === ServiceAction.DELETE || item.action=== ServiceAction.UPDATE) {
187 return _.includes([JobStatus.FAILED, JobStatus.IN_PROGRESS, JobStatus.COMPLETED_WITH_ERRORS, JobStatus.PAUSE, JobStatus.COMPLETED], item.jobStatus);
189 return true;// ServiceAction.INSTANTIATE
192 isDeleteEnabled(item: ServiceInfoModel):boolean {
193 if( item.action === ServiceAction.DELETE || item.action === ServiceAction.UPDATE){
194 return _.includes([JobStatus.PENDING], item.jobStatus);
196 return _.includes([JobStatus.PENDING, JobStatus.STOPPED], item.jobStatus);
199 isHideEnabled(item: ServiceInfoModel):boolean {
200 return _.includes([JobStatus.COMPLETED, JobStatus.FAILED, JobStatus.STOPPED, JobStatus.COMPLETED_WITH_ERRORS], item.jobStatus);
203 public onContextMenu($event: MouseEvent, item: any): void {
204 this._contextMenuService.show.next({
205 contextMenu: this.contextMenu,
209 $event.preventDefault();
210 $event.stopPropagation();
213 getImagesSrc(imageName : string) : string {
214 return './' + imageName + '.svg';
217 private getHeaderHeaderClientRect(): ClientRect {
218 const element = document.querySelector("#instantiation-status thead") as HTMLElement;
219 return element.getBoundingClientRect();
222 findFirstVisibleJob(): HTMLElement {
223 const elements : any = document.querySelectorAll('#instantiation-status tr');
224 const headerRect = this.getHeaderHeaderClientRect();
226 const topEdge = headerRect.bottom;
227 for (let i = 0; i < elements.length; i++) {
228 if (elements[i].getBoundingClientRect().top >= topEdge)
235 scrollToElement(currentJob: HTMLElement) {
237 const config: ScrollToConfigOptions = {
240 offset: -1 * (this.getHeaderHeaderClientRect().height + 2),
245 this._scrollToService.scrollTo(config);
250 isInstantiationStatusFilterFlagOn() {
251 return FeatureFlagsService.getFlagState(Features.FLAG_2004_INSTANTIATION_STATUS_FILTER, this._store);