Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / workspace / disribution / distribution-component-table / distribution-component-artifact-table / distribution-component-artifact-table.component.ts
1 import { Component, Input, OnInit, ViewChild } from '@angular/core';
2 import * as _ from 'lodash';
3 import { DistributionService } from '../../distribution.service';
4
5 // tslint:disable:no-string-literal
6
7 @Component({
8     selector: 'app-distribution-component-artifact-table',
9     templateUrl: './distribution-component-artifact-table.component.html',
10     styleUrls: ['./distribution-component-artifact-table.component.less']
11 })
12 export class DistributionComponentArtifactTableComponent implements OnInit {
13
14     @ViewChild('statusTable', {}) table: any;
15
16     @Input() componentName: string;
17     @Input() rowDistributionID: string;
18     @Input() statusFilter: string;
19
20     public artifacts = [];
21
22     constructor(private distributionService: DistributionService) {
23     }
24
25     ngOnInit() {
26         this.artifacts = this.distributionService.getArtifactstByDistributionIDAndComponentsName(this.rowDistributionID, this.componentName);
27         if (this.statusFilter) {
28             this.artifacts.forEach(
29             (artifact) => {
30                 artifact.statuses = _.filter(artifact.statuses, {status: this.statusFilter});
31             });
32         }
33     }
34
35     public getLatestArtifact(artifactName: string) {
36         const selectedArtifact = this.artifacts.filter((artifact) => artifact.name === artifactName);
37         if (selectedArtifact && selectedArtifact[0] && selectedArtifact[0]['statuses'] && selectedArtifact[0]['statuses'][0]) {
38             return selectedArtifact[0]['statuses'][0];
39         } else {
40             return null;
41         }
42     }
43
44     private copyToClipboard(urlToCopy: any) {
45
46         const inputForCopyToClipboard = document.getElementById('inputForCopyToClipboard') as HTMLInputElement;
47         inputForCopyToClipboard.value = urlToCopy;
48         /* Select the text field */
49         inputForCopyToClipboard.select();
50
51         /* Copy the text inside the text field */
52         document.execCommand('copy');
53
54     }
55
56     private generateDataTestID(preFix: string, componentName: string, artifactName: string, status?: string) {
57         if (!status) {
58             return preFix + componentName + '_' + artifactName;
59         } else {
60             return preFix + status + '_' + componentName + '_' + artifactName;
61         }
62     }
63
64     private expandRow(row: any) {
65         this.table.rowDetail.toggleExpandRow(row);
66     }
67
68 }