487c19ad1eb0777b5d64e3bfb6f462cf3deb5e2f
[ccsdk/cds.git] /
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     private controllerSideBar: boolean;
21     private ngUnsubscribe = new Subject();
22     viewedPackage: BluePrintDetailModel = new BluePrintDetailModel();
23     public customActionName = '';
24
25     constructor(private store: DesignerStore,
26                 private packageCreationUtils: PackageCreationUtils,
27                 private router: Router,
28                 private route: ActivatedRoute,
29                 private sourceViewService: SourceViewService) {
30         this.controllerSideBar = true;
31     }
32
33     ngOnInit() {
34         this.store.state$.subscribe(
35             state => {
36                 console.log(state);
37                 this.content = this.packageCreationUtils.transformToJson(state.template);
38             });
39
40         const id = this.route.snapshot.paramMap.get('id');
41         this.sourceViewService.getPagedPackages(id).subscribe(
42             (bluePrintDetailModels) => {
43                 if (bluePrintDetailModels) {
44                     this.viewedPackage = bluePrintDetailModels[0];
45                 }
46             });
47     }
48
49     convertAndOpenInDesingerView(id) {
50         // TODO validate json against scheme
51         console.log('convertAndOpenInDesingerView ...', this.content);
52         this.store.saveSourceContent(this.content);
53         this.router.navigate(['/packages/designer', id, {actionName: this.customActionName}]);
54     }
55
56     ngOnDestroy() {
57         this.ngUnsubscribe.next();
58         this.ngUnsubscribe.complete();
59     }
60 }