summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/workspace/disribution/distribution-component-table/distribution-component-artifact-table/distribution-component-artifact-table.component.ts
blob: af9aef5c641ea37f324960cb69d1b2e5802f5b79 (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
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import * as _ from 'lodash';
import { DistributionService } from '../../distribution.service';

// tslint:disable:no-string-literal

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

    @ViewChild('statusTable', {}) table: any;

    @Input() componentName: string;
    @Input() rowDistributionID: string;
    @Input() statusFilter: string;

    public artifacts = [];

    constructor(private distributionService: DistributionService) {
    }

    ngOnInit() {
        this.artifacts = this.distributionService.getArtifactstByDistributionIDAndComponentsName(this.rowDistributionID, this.componentName);
        if (this.statusFilter) {
            this.artifacts.forEach(
            (artifact) => {
                artifact.statuses = _.filter(artifact.statuses, {status: this.statusFilter});
            });
        }
    }

    public getLatestArtifact(artifactName: string) {
        const selectedArtifact = this.artifacts.filter((artifact) => artifact.name === artifactName);
        if (selectedArtifact && selectedArtifact[0] && selectedArtifact[0]['statuses'] && selectedArtifact[0]['statuses'][0]) {
            return selectedArtifact[0]['statuses'][0];
        } else {
            return null;
        }
    }

    private copyToClipboard(urlToCopy: any) {

        const inputForCopyToClipboard = document.getElementById('inputForCopyToClipboard') as HTMLInputElement;
        inputForCopyToClipboard.value = urlToCopy;
        /* Select the text field */
        inputForCopyToClipboard.select();

        /* Copy the text inside the text field */
        document.execCommand('copy');

    }

    private generateDataTestID(preFix: string, componentName: string, artifactName: string, status?: string) {
        if (!status) {
            return preFix + componentName + '_' + artifactName;
        } else {
            return preFix + status + '_' + componentName + '_' + artifactName;
        }
    }

    private expandRow(row: any) {
        this.table.rowDetail.toggleExpandRow(row);
    }

}