Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / workspace / disribution / distribution-component-table / distribution-component-table.component.ts
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';
6
7 @Component({
8   selector: 'app-distribution-component-table',
9   templateUrl: './distribution-component-table.component.html',
10   styleUrls: ['./distribution-component-table.component.less']
11 })
12 export class DistributionComponentTableComponent implements OnInit {
13
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) {
22   }
23
24   ngOnInit() {
25     this.initComponents();
26   }
27
28   private generateTotalComponentArtifactsLabel(componentName: any, status: string): string {
29     return 'total' + componentName + status + 'ArtifactsLabel';
30   }
31
32   private generateExpandDataTestID(componentName: string) {
33     return 'expandIcon_' + componentName;
34   }
35
36   private initComponents() {
37     this.components = this.distributionService.getComponentsByDistributionID(this.rowDistributionID);
38     this.components.map((component) => this.expanded.push({componentName: component, expanded: false}));
39   }
40
41   private getTotalArtifactsForDistributionID(distributionID: string, componentName?: string): number {
42     return this.distributionService.getArtifactstByDistributionIDAndComponentsName(distributionID, componentName).length;
43   }
44
45   private getLengthArtifactsForDistributionIDByStatus(distributionID: string, statusToSerach: string, componentName?: string): number {
46     if (componentName) {
47       return this.distributionService.getArtifactsForDistributionIDAndComponentByStatus(distributionID, statusToSerach, componentName).length;
48     } else {
49       return this.distributionService.getArtifactsForDistributionIDAndComponentByStatus(distributionID, statusToSerach).length;
50     }
51   }
52
53   private openModal(rowDistributionID: string, statusFilter: string) {
54
55     const title: string = 'Distribution by Status';
56     const attributeModalConfig = {
57       title,
58       size: 'sdc-xl',
59       type: SdcUiCommon.ModalType.custom,
60       buttons: [
61         {
62           id: 'close',
63           text: 'Close',
64           size: 'sm',
65           closeModal: true,
66           disabled: false,
67         }
68       ] as SdcUiCommon.IModalButtonComponent[]
69     };
70
71     this.customModalInstance = this.modalService.openCustomModal(attributeModalConfig, DistributionComponent, {
72         // inputs
73         rowDistributionID,
74         statusFilter,
75         isModal: true,
76     });
77   }
78
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!
89       }
90     }
91     const selectedComponentAfter = this.expanded.find((component) => component.componentName === componentName);
92     const selectedComponentExpandedValAfter = selectedComponentAfter['expanded'];
93   }
94
95   private isExpanded(componentName: string) {
96     const selectedComponent = this.expanded.find((component) => component.componentName === componentName);
97     return selectedComponent['expanded'];
98   }
99
100
101     private getMSOStatus(rowDistributionID: string, componentName: string): string {
102         return this.distributionService.getMSOStatus(rowDistributionID, componentName);
103     }
104 }