aboutsummaryrefslogtreecommitdiffstats
path: root/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/package-list/package-list.component.ts
blob: 2f151d1bf186a8e9fa83baf572e3f54361888759 (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
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';
import {NgxUiLoaderService} from 'ngx-ui-loader';
import {TourService} from 'ngx-tour-md-menu';
import {ToastrService} from 'ngx-toastr';

@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,
        private ngxLoader: NgxUiLoaderService,
        private tourService: TourService,
        private toastService: ToastrService
    ) {
        console.log('PackageListComponent');


        this.packagesStore.state$.subscribe(state => {
            console.log(state);
            if (state.filteredPackages) {
                this.viewedPackages = state.filteredPackages.content;
            }
        });
    }


    ngOnInit() {
        this.ngxLoader.start();
        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');
        });
    }

    viewDesigner(id: string) {
        this.router.navigate(['/packages/designer', id, {actionName: ''}]);
    }

    deletePackage(id: string) {
        this.configurationDashboardService.deletePackage(id).subscribe(res => {
            this.toastService.success('Package Deleted Successfully ');
            this.router.navigate(['/packages']);
            this.packagesStore.getAll();
        }, err => {
            this.toastService.error('Error has occured during deleting package ' + err.message);
        });

    }
}