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