summaryrefslogtreecommitdiffstats
path: root/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/source-view/source-view.component.ts
blob: 34194e42f263c6a5606e692910a16e2511c0cb01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Component, OnInit, OnDestroy } from '@angular/core';
import { DesignerStore } from '../designer.store';
import { PackageCreationUtils } from '../../package-creation/package-creation.utils';
import { RouterLink, Router } from '@angular/router';
import { Subject } from 'rxjs';

@Component({
    selector: 'app-designer-source-view',
    templateUrl: './source-view.component.html',
    styleUrls: ['./source-view.component.css']
})
export class DesignerSourceViewComponent implements OnInit, OnDestroy {

    content = '';
    lang = 'json';
    private controllerSideBar: boolean;
    private ngUnsubscribe = new Subject();

    constructor(private store: DesignerStore,
                private packageCreationUtils: PackageCreationUtils,
                private router: Router) {
        this.controllerSideBar = true;
    }

    ngOnInit() {
        this.store.state$.subscribe(
            state => {
                console.log(state);
                this.content = this.packageCreationUtils.transformToJson(state.template);
            });

    }

    convertAndOpenInDesingerView() {
        // TODO validate json against scheme
        console.log('convertAndOpenInDesingerView ...', this.content);
        this.store.saveSourceContent(this.content);
        this.router.navigateByUrl('/packages/designer');
    }

    ngOnDestroy() {
        this.ngUnsubscribe.next();
        this.ngUnsubscribe.complete();
    }
}