aboutsummaryrefslogtreecommitdiffstats
path: root/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/package-list/package-list.component.ts
blob: 352f33b910d6ab05c105420ecf9eecb78f20eba3 (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
import {Component, OnInit} from '@angular/core';
import {BlueprintModel} from '../../model/BluePrint.model';
import {PackagesStore} from '../../packages.store';
import {Router} from '@angular/router';
import {ConfigurationDashboardService} from '../../configuration-dashboard/configuration-dashboard.service';
import {saveAs} from 'file-saver';

@Component({
    selector: 'app-packages-list',
    templateUrl: './package-list.component.html',
    styleUrls: ['./package-list.component.css']
})
export class PackageListComponent implements OnInit {

    viewedPackages: BlueprintModel[] = [];


    constructor(private packagesStore: PackagesStore, private router: Router
              , private configurationDashboardService: ConfigurationDashboardService) {
        console.log('PackageListComponent');
        this.packagesStore.state$.subscribe(state => {
            console.log(state);
            if (state.filteredPackages) {
                this.viewedPackages = state.filteredPackages.content;
            }
        });
    }

    ngOnInit() {
        this.packagesStore.getAll();
    }

    view(id) {
        this.router.navigate(['/packages/package', id]);
    }

    testDispatch(bluePrint: BlueprintModel) {
        console.log(bluePrint.id);
    }

    downloadPackage(artifactName: string, artifactVersion: string) {
        this.configurationDashboardService.downloadResource(artifactName + '/' + artifactVersion).subscribe(response => {
            const blob = new Blob([response], {type: 'application/octet-stream'});
            saveAs(blob, artifactName + '-' + artifactVersion + '-CBA.zip');
        });
    }
}