1 import { Component, Input, OnInit } from '@angular/core';
2 import { SdcUiCommon, SdcUiComponents, SdcUiServices } from 'onap-ui-angular';
3 import { ModalComponent } from 'onap-ui-angular/dist/modals/modal.component';
4 import { DistributionComponent } from '../distribution.component';
5 import { DistributionService } from '../distribution.service';
8 selector: 'app-distribution-component-table',
9 templateUrl: './distribution-component-table.component.html',
10 styleUrls: ['./distribution-component-table.component.less']
12 export class DistributionComponentTableComponent implements OnInit {
14 @Input() rowDistributionID: string;
15 @Input() isModal: boolean = false;
16 @Input() statusFilter: string;
17 public components = [];
18 private customModalInstance: ModalComponent;
19 private expanded = [];
20 constructor(private distributionService: DistributionService,
21 private modalService: SdcUiServices.ModalService) {
25 this.initComponents();
28 private generateTotalComponentArtifactsLabel(componentName: any, status: string): string {
29 return 'total' + componentName + status + 'ArtifactsLabel';
32 private generateExpandDataTestID(componentName: string) {
33 return 'expandIcon_' + componentName;
36 private initComponents() {
37 this.components = this.distributionService.getComponentsByDistributionID(this.rowDistributionID);
38 this.components.map((component) => this.expanded.push({componentName: component, expanded: false}));
41 private getTotalArtifactsForDistributionID(distributionID: string, componentName?: string): number {
42 return this.distributionService.getArtifactstByDistributionIDAndComponentsName(distributionID, componentName).length;
45 private getLengthArtifactsForDistributionIDByStatus(distributionID: string, statusToSerach: string, componentName?: string): number {
47 return this.distributionService.getArtifactsForDistributionIDAndComponentByStatus(distributionID, statusToSerach, componentName).length;
49 return this.distributionService.getArtifactsForDistributionIDAndComponentByStatus(distributionID, statusToSerach).length;
53 private openModal(rowDistributionID: string, statusFilter: string) {
55 const title: string = 'Distribution by Status';
56 const attributeModalConfig = {
59 type: SdcUiCommon.ModalType.custom,
68 ] as SdcUiCommon.IModalButtonComponent[]
71 this.customModalInstance = this.modalService.openCustomModal(attributeModalConfig, DistributionComponent, {
79 private expandRow(componentName: string) {
80 console.log('Should expand componentSummary for componentName = ' + componentName);
81 const selectedComponent = this.expanded.find((component) => component.componentName === componentName);
82 // tslint:disable:no-string-literal
83 const selectedComponentExpandedVal = selectedComponent['expanded'];
84 // this.expanded = !this.expanded;
85 for (const i in this.expanded) {
86 if (this.expanded[i].componentName === componentName) {
87 this.expanded[i].expanded = !this.expanded[i].expanded;
88 break; //Stop this loop, we found it!
91 const selectedComponentAfter = this.expanded.find((component) => component.componentName === componentName);
92 const selectedComponentExpandedValAfter = selectedComponentAfter['expanded'];
95 private isExpanded(componentName: string) {
96 const selectedComponent = this.expanded.find((component) => component.componentName === componentName);
97 return selectedComponent['expanded'];
101 private getMSOStatus(rowDistributionID: string, componentName: string): string {
102 return this.distributionService.getMSOStatus(rowDistributionID, componentName);