1 import {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 "../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";
15 export interface MenuAction{
20 click(item: ServiceInfoModel): void;
21 enabled (item?: ServiceInfoModel): boolean;
22 visible (item?: ServiceInfoModel): boolean;
26 selector : 'instantiation-status',
27 templateUrl : './instantiationStatus.component.html',
28 styleUrls : ['./instantiationStatus.component.scss']
30 export class InstantiationStatusComponent {
32 TIMER_TIME_IN_SECONDS : number = 0;
34 dataIsReady : boolean = false;
35 scroll : boolean = false;
36 lastUpdatedDate: Date = null;
37 instantiationStatusComponentService: InstantiationStatusComponentService;
38 configurationService : ConfigurationService;
39 serviceInfoData: ServiceInfoModel[] = null;
40 @ViewChild(ContextMenuComponent) public contextMenu: ContextMenuComponent;
42 public contextMenuActions: Array<MenuAction> = [
45 dataTestId: "context-menu-retry",
46 className: "fa-repeat",
47 click: (item: ServiceInfoModel) => this.retryItem(item),
49 visible: (item: ServiceInfoModel) => item.isRetryEnabled,
53 dataTestId: "context-menu-open",
54 className: "fa-external-link",
55 click: (item: ServiceInfoModel) => this.instantiationStatusComponentService.open(item),
56 enabled: (item: ServiceInfoModel) => this.isOpenEnabled(item),
61 dataTestId: "context-menu-audit-info",
62 className: "fa-info-circle",
63 click: (item: ServiceInfoModel) => this.auditInfo(item),
64 enabled: (item: ServiceInfoModel) => this.isAuditInfoEnabled(item),
69 dataTestId: "context-menu-remove",
70 className: "fa-trash-o",
71 click: (item: ServiceInfoModel) => this.deleteItem(item),
72 enabled: (item: ServiceInfoModel) => this.isDeleteEnabled(item),
77 dataTestId: "context-menu-hide",
78 className: "fa-eye-slash",
79 tooltip: "Hide this service from this table",
80 click: (item: ServiceInfoModel) => this.hideItem(item),
81 enabled: (item: ServiceInfoModel) => this.isHideEnabled(item),
87 constructor(private _serviceInfoService: ServiceInfoService,
88 private _instantiationStatusComponentService : InstantiationStatusComponentService,
89 private _contextMenuService: ContextMenuService,
90 private _configurationService : ConfigurationService,
91 private _scrollToService: ScrollToService,
92 private _logService : LogService,
93 private _store: NgRedux<AppState>) {
94 this.instantiationStatusComponentService = _instantiationStatusComponentService;
95 this.configurationService = this._configurationService;
96 this.configurationService.getConfiguration("refreshTimeInstantiationDashboard").subscribe(response => {
97 this.TIMER_TIME_IN_SECONDS = _.isNumber(response) ? response : 0;
98 this.activateInterval();
104 if (this.TIMER_TIME_IN_SECONDS > 0) {
105 this.timer = setInterval(() => {
107 }, this.TIMER_TIME_IN_SECONDS * 1000);
111 deactivateInterval() {
112 clearInterval(this.timer);
115 refreshData(): void {
116 this.dataIsReady = false;
117 this._serviceInfoService.getServicesJobInfo(this.lastUpdatedDate === null)
118 .subscribe((res: ServiceInfoModel[]) => {
119 this._instantiationStatusComponentService.convertObjectToArray(res).subscribe((res) => {
120 this._logService.info('refresh instantiation status table', res);
121 this.dataIsReady = true;
122 this.lastUpdatedDate = new Date();
123 if (!_.isEqual(this.serviceInfoData, res)) {
124 this.serviceInfoData = res;
125 this.scrollToElement(this.findFirstVisibleJob());
131 trackByFn(index: number, item: ServiceInfoModel){
132 return _.isNil(item) ? null : item.jobId;
135 deleteItem(item: ServiceInfoModel): void {
136 this._serviceInfoService.deleteJob(item.jobId).subscribe(() => {
141 hideItem(item: ServiceInfoModel): void {
142 this._serviceInfoService.hideJob(item.jobId).subscribe(() => {
147 retryItem(item: ServiceInfoModel) : void {
148 if (item.isRetryEnabled) {
149 this._instantiationStatusComponentService.retry(item);
153 auditInfo(jobData : ServiceInfoModel): void {
154 AuditInfoModalComponent.openModal.next(jobData);
157 isOpenEnabled(item: ServiceInfoModel):boolean {
158 switch(item.action) {
159 case ServiceAction.DELETE:
160 return _.includes([ JobStatus.PENDING, JobStatus.COMPLETED_WITH_ERRORS, JobStatus.FAILED], item.jobStatus);
161 case ServiceAction.UPDATE:
162 return _.includes([JobStatus.PENDING, JobStatus.PAUSE, JobStatus.COMPLETED_WITH_ERRORS, JobStatus.COMPLETED, JobStatus.FAILED], item.jobStatus);
164 return _.includes([JobStatus.COMPLETED, JobStatus.PAUSE, JobStatus.COMPLETED_WITH_ERRORS], item.jobStatus);
168 isAuditInfoEnabled(item: ServiceInfoModel): boolean {
169 if(item.action === ServiceAction.DELETE || item.action=== ServiceAction.UPDATE) {
170 return _.includes([JobStatus.FAILED, JobStatus.IN_PROGRESS, JobStatus.COMPLETED_WITH_ERRORS, JobStatus.PAUSE, JobStatus.COMPLETED], item.jobStatus);
172 return true;// ServiceAction.INSTANTIATE
175 isDeleteEnabled(item: ServiceInfoModel):boolean {
176 if( item.action === ServiceAction.DELETE || item.action === ServiceAction.UPDATE){
177 return _.includes([JobStatus.PENDING], item.jobStatus);
179 return _.includes([JobStatus.PENDING, JobStatus.STOPPED], item.jobStatus);
182 isHideEnabled(item: ServiceInfoModel):boolean {
183 return _.includes([JobStatus.COMPLETED, JobStatus.FAILED, JobStatus.STOPPED, JobStatus.COMPLETED_WITH_ERRORS], item.jobStatus);
186 public onContextMenu($event: MouseEvent, item: any): void {
187 this._contextMenuService.show.next({
188 contextMenu: this.contextMenu,
192 $event.preventDefault();
193 $event.stopPropagation();
196 getImagesSrc(imageName : string) : string {
197 return './' + imageName + '.svg';
200 private getHeaderHeaderClientRect(): ClientRect {
201 const element = document.querySelector("#instantiation-status thead") as HTMLElement;
202 return element.getBoundingClientRect();
205 findFirstVisibleJob(): HTMLElement {
206 const elements : any = document.querySelectorAll('#instantiation-status tr');
207 const headerRect = this.getHeaderHeaderClientRect();
209 const topEdge = headerRect.bottom;
210 for (let i = 0; i < elements.length; i++) {
211 if (elements[i].getBoundingClientRect().top >= topEdge)
218 scrollToElement(currentJob: HTMLElement) {
220 const config: ScrollToConfigOptions = {
223 offset: -1 * (this.getHeaderHeaderClientRect().height + 2),
228 this._scrollToService.scrollTo(config);