summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/workspace/disribution/distribution-component-table/distribution-component-table.component.ts
blob: e3aaf9d6391a7b118c9064bb33a317b4ab5adc73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { Component, Input, OnInit } from '@angular/core';
import { SdcUiCommon, SdcUiComponents, SdcUiServices } from 'onap-ui-angular';
import { ModalComponent } from 'onap-ui-angular/dist/modals/modal.component';
import { DistributionComponent } from '../distribution.component';
import { DistributionService } from '../distribution.service';

@Component({
  selector: 'app-distribution-component-table',
  templateUrl: './distribution-component-table.component.html',
  styleUrls: ['./distribution-component-table.component.less']
})
export class DistributionComponentTableComponent implements OnInit {

  @Input() rowDistributionID: string;
  @Input() isModal: boolean = false;
  @Input() statusFilter: string;
  public components = [];
  private customModalInstance: ModalComponent;
  private expanded = [];
  constructor(private distributionService: DistributionService,
              private modalService: SdcUiServices.ModalService) {
  }

  ngOnInit() {
    this.initComponents();
  }

  private generateTotalComponentArtifactsLabel(componentName: any, status: string): string {
    return 'total' + componentName + status + 'ArtifactsLabel';
  }

  private generateExpandDataTestID(componentName: string) {
    return 'expandIcon_' + componentName;
  }

  private initComponents() {
    this.components = this.distributionService.getComponentsByDistributionID(this.rowDistributionID);
    this.components.map((component) => this.expanded.push({componentName: component, expanded: false}));
  }

  private getTotalArtifactsForDistributionID(distributionID: string, componentName?: string): number {
    return this.distributionService.getArtifactstByDistributionIDAndComponentsName(distributionID, componentName).length;
  }

  private getLengthArtifactsForDistributionIDByStatus(distributionID: string, statusToSerach: string, componentName?: string): number {
    if (componentName) {
      return this.distributionService.getArtifactsForDistributionIDAndComponentByStatus(distributionID, statusToSerach, componentName).length;
    } else {
      return this.distributionService.getArtifactsForDistributionIDAndComponentByStatus(distributionID, statusToSerach).length;
    }
  }

  private openModal(rowDistributionID: string, statusFilter: string) {

    const title: string = 'Distribution by Status';
    const attributeModalConfig = {
      title,
      size: 'sdc-xl',
      type: SdcUiCommon.ModalType.custom,
      buttons: [
        {
          id: 'close',
          text: 'Close',
          size: 'sm',
          closeModal: true,
          disabled: false,
        }
      ] as SdcUiCommon.IModalButtonComponent[]
    };

    this.customModalInstance = this.modalService.openCustomModal(attributeModalConfig, DistributionComponent, {
        // inputs
        rowDistributionID,
        statusFilter,
        isModal: true,
    });
  }

  private expandRow(componentName: string) {
    console.log('Should expand componentSummary for componentName = ' + componentName);
    const selectedComponent = this.expanded.find((component) => component.componentName === componentName);
    // tslint:disable:no-string-literal
    const selectedComponentExpandedVal = selectedComponent['expanded'];
    // this.expanded = !this.expanded;
    for (const i in this.expanded) {
      if (this.expanded[i].componentName === componentName) {
        this.expanded[i].expanded = !this.expanded[i].expanded;
        break; //Stop this loop, we found it!
      }
    }
    const selectedComponentAfter = this.expanded.find((component) => component.componentName === componentName);
    const selectedComponentExpandedValAfter = selectedComponentAfter['expanded'];
  }

  private isExpanded(componentName: string) {
    const selectedComponent = this.expanded.find((component) => component.componentName === componentName);
    return selectedComponent['expanded'];
  }


    private getMSOStatus(rowDistributionID: string, componentName: string): string {
        return this.distributionService.getMSOStatus(rowDistributionID, componentName);
    }
}