1 import { Component, Input, OnInit, ViewChild } from '@angular/core';
2 import { SdcUiCommon, SdcUiServices } from 'onap-ui-angular';
3 import { EventListenerService } from '../../../../services/event-listener-service';
4 import { AuthenticationService } from '../../../services/authentication.service';
5 import { WorkspaceService } from '../workspace.service';
6 import { DistributionService } from './distribution.service';
7 import { EVENTS } from '../../../../utils/constants';
10 selector: 'distribution',
11 templateUrl: './distribution.component.html',
12 styleUrls: ['../../../../../assets/styles/table-style.less', './distribution.component.less']
14 export class DistributionComponent implements OnInit {
16 @ViewChild('distributionTable', { }) table: any;
18 @Input() isModal: boolean = false;
19 @Input() statusFilter: string;
20 @Input() rowDistributionID: string;
21 public componentUuid: string;
22 public distributions = [];
23 private expanded: any = {};
24 private serviceHasDistibutions: boolean = false;
25 private readonly uniqueId: string;
26 private userRole: string;
28 constructor(private workspaceService: WorkspaceService,
29 private distributionService: DistributionService,
30 private loaderService: SdcUiServices.LoaderService,
31 private authService: AuthenticationService,
32 private eventListenerService: EventListenerService) {
33 this.componentUuid = this.workspaceService.metadata.uuid;
34 this.uniqueId = this.workspaceService.metadata.uniqueId;
40 this.userRole = this.authService.getLoggedinUser().role;
41 this.eventListenerService.registerObserverCallback(EVENTS.ON_DISTRIBUTION_SUCCESS, async () => {
42 await this.refreshDistributions();
44 await this.initDistributions(this.componentUuid, this.rowDistributionID);
48 this.eventListenerService.unRegisterObserver(EVENTS.ON_DISTRIBUTION_SUCCESS);
51 async initDistributions(componentUuid: string, specificDistributionID?: string) {
52 this.loaderService.activate();
53 await this.distributionService.initDistributionsList(componentUuid);
54 this.distributions = this.distributionService.getDistributionList();
55 this.distributions.length > 0 ? this.serviceHasDistibutions = true : this.serviceHasDistibutions = false;
56 if (specificDistributionID) {
57 this.distributions = this.distributionService.getDistributionList(specificDistributionID);
59 this.loaderService.deactivate();
62 getIconName(rowStatus: string ) {
63 if (rowStatus === 'Distributed') {
66 if (rowStatus === 'Deployed') {
71 getIconMode(rowStatus: string) {
72 if (rowStatus === 'Distributed') {
75 if (rowStatus === 'Deployed') {
80 private async markDeploy(distributionID: string, status: string) {
81 if (status === 'Distributed') {
82 console.log('Should send MarkDeploy POST Request ServiceID:' + this.uniqueId + ' DISTID:' + distributionID);
83 await this.distributionService.markDeploy(this.uniqueId, distributionID);
84 this.refreshDistributions();
88 private async refreshDistributions() {
89 await this.initDistributions(this.componentUuid);
92 private updateFilter(event) {
93 const val = event.target.value.toLowerCase();
96 this.distributions = this.distributionService.getDistributionList().filter((distribution: any[]) => {
98 // tslint:disable:no-string-literal
99 distribution['distributionID'].toLowerCase().indexOf(val) !== -1;
103 private generateDataTestID(preFix: string, distributionID: string, isModal?: boolean ): string {
105 return preFix + distributionID.substring(0, 5) + '_Modal';
107 return preFix + distributionID.substring(0, 5);
111 private async expandRow(row: any, expanded: boolean) {
113 await this.distributionService.initDistributionsStatusForDistributionID(row.distributionID);
115 this.table.rowDetail.toggleExpandRow(row);