Merge "Package > Temp&Mapp: View"
[ccsdk/cds.git] / cds-ui / designer-client / src / app / modules / feature-modules / packages / package-creation / package-creation.store.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 { Injectable } from '@angular/core';
23
24 import { Store } from '../../../../common/core/stores/Store';
25
26 import { CBAPackage, DslDefinition } from './mapping-models/CBAPacakge.model';
27 import { PackageCreationService } from './package-creation.service';
28 import { MetaDataTabModel } from './mapping-models/metadata/MetaDataTab.model';
29 import { Observable } from 'rxjs';
30 import { ResourceDictionary } from './mapping-models/ResourceDictionary.model';
31
32
33 @Injectable({
34     providedIn: 'root'
35 })
36 export class PackageCreationStore extends Store<CBAPackage> {
37
38
39     constructor(private packageCreationService: PackageCreationService) {
40         super(new CBAPackage());
41     }
42
43     changeMetaData(metaDataObject: MetaDataTabModel) {
44
45         this.setState({
46             ...this.state,
47             metaData: metaDataObject
48         });
49     }
50
51     setCustomKeys(mapOfCustomKey: Map<string, string>) {
52         this.setState({
53             ...this.state,
54             metaData: this.state.metaData.setCustomKey(mapOfCustomKey)
55         });
56     }
57
58     changeDslDefinition(dslDefinition: DslDefinition) {
59
60         this.setState({
61             ...this.state,
62             definitions: this.state.definitions.setDslDefinition(dslDefinition)
63         });
64     }
65
66
67     addDefinition(name: string, content: string) {
68
69         this.setState({
70             ...this.state,
71             definitions: this.state.definitions.setImports(name, content)
72         });
73     }
74
75     addScripts(name: string, content: string) {
76         this.setState({
77             ...this.state,
78             scripts: this.state.scripts.setScripts(name, content)
79         });
80
81     }
82
83     removeFileFromState(name: string) {
84         this.state.scripts.files.delete(name);
85     }
86
87     fileExist(key: string) {
88         return this.state.templates.files.has(key);
89     }
90
91     removeFileFromDefinition(filename) {
92         this.state.definitions.imports.delete(filename);
93     }
94
95     saveBluePrint(blob) {
96         this.packageCreationService.savePackage(blob);
97     }
98
99     addTemplate(filePath: string, fileContent: string) {
100         this.setState({
101             ...this.state,
102             templates: this.state.templates.setTemplates(filePath, fileContent)
103         });
104     }
105
106     addMapping(filePath: string, fileContent: string) {
107         this.setState({
108             ...this.state,
109             mapping: this.state.mapping.setContent(filePath, fileContent)
110         });
111     }
112
113     getTemplateAndMapping(variables: string[]): Observable<ResourceDictionary[]> {
114         return this.packageCreationService.getTemplateAndMapping(variables);
115     }
116
117     clear() {
118         this.setState(new CBAPackage());
119     }
120 }