Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / cds-ui / designer-client / src / app / modules / feature-modules / packages / designer / source-view / source-view.component.ts
1 import { Component, OnInit, OnDestroy } from '@angular/core';
2 import { DesignerStore } from '../designer.store';
3 import { PackageCreationUtils } from '../../package-creation/package-creation.utils';
4 import { RouterLink, Router, ActivatedRoute } from '@angular/router';
5 import { Subject } from 'rxjs';
6 import { BluePrintDetailModel } from '../../model/BluePrint.detail.model';
7 import { viewClassName } from '@angular/compiler';
8 import { SourceViewService } from './source-view.service';
9
10 @Component({
11     selector: 'app-designer-source-view',
12     templateUrl: './source-view.component.html',
13     // styleUrls: ['./source-view.component.css']
14     styleUrls: ['../designer.component.css']
15 })
16 export class DesignerSourceViewComponent implements OnInit, OnDestroy {
17
18     content = '';
19     lang = 'json';
20     controllerSideBar: boolean;
21     ngUnsubscribe = new Subject();
22     viewedPackage: BluePrintDetailModel = new BluePrintDetailModel();
23     public customActionName = '';
24     cl = 'editBar';
25     packageId: string;
26
27     constructor(
28         private store: DesignerStore,
29         private packageCreationUtils: PackageCreationUtils,
30         private router: Router,
31         private route: ActivatedRoute,
32         private sourceViewService: SourceViewService) {
33         this.controllerSideBar = true;
34     }
35     _toggleSidebar1() {
36         this.controllerSideBar = !this.controllerSideBar;
37         if (this.controllerSideBar === false) {
38             this.cl = 'editBar2';
39         }
40         if (this.controllerSideBar === true) {
41             this.cl = 'editBar';
42         }
43     }
44
45     ngOnInit() {
46         this.store.state$.subscribe(
47             state => {
48                 console.log(state);
49                 this.content = this.packageCreationUtils.transformToJson(state.template);
50             });
51
52         const id = this.route.snapshot.paramMap.get('id');
53         this.sourceViewService.getPagedPackages(id).subscribe(
54             (bluePrintDetailModels) => {
55                 if (bluePrintDetailModels) {
56                     this.viewedPackage = bluePrintDetailModels[0];
57                 }
58             });
59
60         this.route.paramMap.subscribe(res => {
61             this.packageId = res.get('id');
62         });
63     }
64
65     convertAndOpenInDesingerView(id) {
66         // TODO validate json against scheme
67         console.log('convertAndOpenInDesingerView ...', this.content);
68         this.store.saveSourceContent(this.content);
69         this.router.navigate(['/packages/designer', this.packageId, { actionName: this.customActionName }]);
70     }
71
72     ngOnDestroy() {
73         this.ngUnsubscribe.next();
74         this.ngUnsubscribe.complete();
75     }
76 }