solving continuous saving
[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 import {BluePrintDetailModel} from '../model/BluePrint.detail.model';
32
33
34 @Injectable({
35     providedIn: 'root'
36 })
37 export class PackageCreationStore extends Store<CBAPackage> {
38
39
40     constructor(private packageCreationService: PackageCreationService) {
41         super(new CBAPackage());
42     }
43
44     changeMetaData(metaDataObject: MetaDataTabModel) {
45
46         this.setState({
47             ...this.state,
48             metaData: metaDataObject
49         });
50     }
51
52     setCustomKeys(mapOfCustomKey: Map<string, string>) {
53         this.setState({
54             ...this.state,
55             metaData: this.state.metaData.setCustomKey(mapOfCustomKey)
56         });
57     }
58
59     changeDslDefinition(dslDefinition: DslDefinition) {
60
61         this.setState({
62             ...this.state,
63             definitions: this.state.definitions.setDslDefinition(dslDefinition)
64         });
65     }
66
67
68     addDefinition(name: string, content: string) {
69
70         this.setState({
71             ...this.state,
72             definitions: this.state.definitions.setImports(name, content)
73         });
74     }
75
76     addScripts(name: string, content: string) {
77         this.setState({
78             ...this.state,
79             scripts: this.state.scripts.setScripts(name, content)
80         });
81
82     }
83
84     removeFileFromState(name: string) {
85         this.state.scripts.files.delete(name);
86     }
87
88     fileExist(key: string) {
89         return this.state.templates.files.has(key);
90     }
91
92     removeFileFromDefinition(filename) {
93         this.state.definitions.imports.delete(filename);
94     }
95
96     saveBluePrint(blob): Observable<BluePrintDetailModel> {
97         return this.packageCreationService.savePackage(blob);
98     }
99
100     addTemplate(filePath: string, fileContent: string) {
101         this.setState({
102             ...this.state,
103             templates: this.state.templates.setTemplates(filePath, fileContent)
104         });
105     }
106
107     addMapping(filePath: string, fileContent: string) {
108         this.setState({
109             ...this.state,
110             mapping: this.state.mapping.setContent(filePath, fileContent)
111         });
112     }
113
114     getTemplateAndMapping(variables: string[]): Observable<ResourceDictionary[]> {
115         return this.packageCreationService.getTemplateAndMapping(variables);
116     }
117
118     clear() {
119         this.setState(new CBAPackage());
120     }
121 }