44c4a71680ac883c7de0b479f6c2d8041c02b3b2
[ccsdk/cds.git] /
1 import {Component, OnInit} from '@angular/core';
2 import {BlueprintModel} from '../../model/BluePrint.model';
3 import {PackagesStore} from '../../packages.store';
4 import {Router} from '@angular/router';
5 import {ConfigurationDashboardService} from '../../configuration-dashboard/configuration-dashboard.service';
6 import {saveAs} from 'file-saver';
7 import {NgxUiLoaderService} from 'ngx-ui-loader';
8 import {TourService} from 'ngx-tour-md-menu';
9 import {ToastrService} from 'ngx-toastr';
10
11 @Component({
12     selector: 'app-packages-list',
13     templateUrl: './package-list.component.html',
14     styleUrls: ['./package-list.component.css']
15 })
16 export class PackageListComponent implements OnInit {
17
18     viewedPackages: BlueprintModel[] = [];
19
20
21     constructor(
22         private packagesStore: PackagesStore,
23         private router: Router,
24         private configurationDashboardService: ConfigurationDashboardService,
25         private ngxLoader: NgxUiLoaderService,
26         private tourService: TourService,
27         private toastService: ToastrService
28     ) {
29         console.log('PackageListComponent');
30
31
32         this.packagesStore.state$.subscribe(state => {
33             console.log(state);
34             if (state.filteredPackages) {
35                 this.viewedPackages = state.filteredPackages.content;
36             }
37         });
38     }
39
40
41     ngOnInit() {
42         this.packagesStore.getAll();
43     }
44
45     view(id) {
46         this.router.navigate(['/packages/package', id]);
47     }
48
49     testDispatch(bluePrint: BlueprintModel) {
50         console.log(bluePrint.id);
51     }
52
53     downloadPackage(artifactName: string, artifactVersion: string) {
54         this.configurationDashboardService.downloadResource(artifactName + '/' + artifactVersion).subscribe(response => {
55             const blob = new Blob([response], {type: 'application/octet-stream'});
56             saveAs(blob, artifactName + '-' + artifactVersion + '-CBA.zip');
57         });
58     }
59
60     viewDesigner(id: string) {
61         this.router.navigate(['/packages/designer', id]);
62     }
63
64     deletePackage(id: string) {
65         this.configurationDashboardService.deletePackage(id).subscribe(res => {
66             this.toastService.info('package deleted successfully ');
67             this.router.navigate(['/packages']);
68             this.packagesStore.getAll();
69         }, err => {
70             this.toastService.error('error deleting package' + err.message);
71         });
72
73     }
74 }