Merge "Refactoring Resource Resolution Service"
[ccsdk/cds.git] / cds-ui / designer-client / src / app / modules / feature-modules / packages / package-creation / package-creation.component.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2019 Orange. All rights reserved.
5 ===================================================================
6
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
11
12     http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END============================================
20 */
21
22 import {Component, OnInit} from '@angular/core';
23 import {FilesContent, FolderNodeElement, MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model';
24
25 import * as JSZip from 'jszip';
26 import {PackageCreationStore} from './package-creation.store';
27 import {Definition} from './mapping-models/CBAPacakge.model';
28 import {PackageCreationModes} from './creationModes/PackageCreationModes';
29 import {PackageCreationBuilder} from './creationModes/PackageCreationBuilder';
30 import {PackageCreationUtils} from './package-creation.utils';
31
32
33 @Component({
34     selector: 'app-package-creation',
35     templateUrl: './package-creation.component.html',
36     styleUrls: ['./package-creation.component.css']
37 })
38 export class PackageCreationComponent implements OnInit {
39     counter = 0;
40     modes: object[] = [
41         {name: 'Designer Mode', style: 'mode-icon icon-designer-mode'},
42         {name: 'Scripting Mode', style: 'mode-icon icon-scripting-mode'}];
43     private metaDataTab: MetaDataTabModel = new MetaDataTabModel();
44     private folder: FolderNodeElement = new FolderNodeElement();
45     private zipFile: JSZip = new JSZip();
46     private filesData: any = [];
47     private definition: Definition = new Definition();
48
49     // adding initial referencing to designer mode
50
51
52     constructor(private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils) {
53     }
54
55     ngOnInit() {
56
57     }
58
59     saveBluePrint() {
60         this.packageCreationStore.state$.subscribe(
61             cbaPackage => {
62                 console.log(cbaPackage);
63                 FilesContent.clear();
64                 let packageCreationModes: PackageCreationModes;
65                 cbaPackage = PackageCreationModes.mapModeType(cbaPackage);
66                 cbaPackage.metaData = PackageCreationModes.setEntryPoint(cbaPackage.metaData);
67                 packageCreationModes = PackageCreationBuilder.getCreationMode(cbaPackage);
68                 packageCreationModes.execute(cbaPackage, this.packageCreationUtils);
69                 this.filesData.push(this.folder.TREE_DATA);
70                 this.saveBluePrintToDataBase();
71             });
72
73
74     }
75
76
77     saveBluePrintToDataBase() {
78         this.create();
79         this.zipFile.generateAsync({type: 'blob'})
80             .then(blob => {
81                 this.packageCreationStore.saveBluePrint(blob);
82             });
83     }
84
85
86     create() {
87         FilesContent.getMapOfFilesNamesAndContent().forEach((key, value) => {
88             this.zipFile.folder(key.split('/')[0]);
89             this.zipFile.file(key, value);
90         });
91         /*this.folder.TREE_DATA.forEach((path) => {
92             const name = path.name;
93             if (path.children) {
94                 this.zipFile.folder(name);
95                 path.children.forEach(children => {
96                     const name2 = children.name;
97                     if (FilesContent.getMapOfFilesNamesAndContent().has(name2)) {
98                         this.zipFile.file(name + '/' + name2, FilesContent.getMapOfFilesNamesAndContent().get(name2));
99                     } else {
100                         // this.zipFile.file(name2, FilesContent.getMapOfFilesNamesAndContent().get(name2));
101                     }
102
103                 });
104
105             }
106         });*/
107     }
108
109
110 }