69401928f7fd27cc6efb3f7c25cd562da68a0f8d
[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
26     constructor(
27         private store: DesignerStore,
28         private packageCreationUtils: PackageCreationUtils,
29         private router: Router,
30         private route: ActivatedRoute,
31         private sourceViewService: SourceViewService) {
32         this.controllerSideBar = true;
33     }
34     private _toggleSidebar1() {
35         this.controllerSideBar = !this.controllerSideBar;
36         if (this.controllerSideBar === false) {
37           this.cl = 'editBar2';
38        }
39         if (this.controllerSideBar === true) {
40         this.cl = 'editBar';
41        }
42       }
43
44     ngOnInit() {
45         this.store.state$.subscribe(
46             state => {
47                 console.log(state);
48                 this.content = this.packageCreationUtils.transformToJson(state.template);
49             });
50
51         const id = this.route.snapshot.paramMap.get('id');
52         this.sourceViewService.getPagedPackages(id).subscribe(
53             (bluePrintDetailModels) => {
54                 if (bluePrintDetailModels) {
55                     this.viewedPackage = bluePrintDetailModels[0];
56                 }
57             });
58     }
59
60     convertAndOpenInDesingerView(id) {
61         // TODO validate json against scheme
62         console.log('convertAndOpenInDesingerView ...', this.content);
63         this.store.saveSourceContent(this.content);
64         this.router.navigate(['/packages/designer', id, { actionName: this.customActionName }]);
65     }
66
67     ngOnDestroy() {
68         this.ngUnsubscribe.next();
69         this.ngUnsubscribe.complete();
70     }
71 }