Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / cds-ui / designer-client / src / app / modules / feature-modules / packages / packages-dashboard / package-list / package-list.component.ts
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.ngxLoader.start();
43         this.packagesStore.getAll();
44     }
45
46     view(id) {
47         this.router.navigate(['/packages/package', id]);
48     }
49
50     testDispatch(bluePrint: BlueprintModel) {
51         console.log(bluePrint.id);
52     }
53
54     downloadPackage(artifactName: string, artifactVersion: string) {
55         this.configurationDashboardService.downloadResource(artifactName + '/' + artifactVersion).subscribe(response => {
56             const blob = new Blob([response], {type: 'application/octet-stream'});
57             saveAs(blob, artifactName + '-' + artifactVersion + '-CBA.zip');
58         });
59     }
60
61     viewDesigner(id: string) {
62         this.router.navigate(['/packages/designer', id, {actionName: ''}]);
63     }
64
65     deletePackage(id: string) {
66         this.configurationDashboardService.deletePackage(id).subscribe(res => {
67             this.toastService.success('Package Deleted Successfully ');
68             this.router.navigate(['/packages']);
69             this.packagesStore.getAll();
70         }, err => {
71             this.toastService.error('Error has occured during deleting package ' + err.message);
72         });
73
74     }
75 }