From e70a0e413947cc3e5e21d041f0ed3d7582b44d7a Mon Sep 17 00:00:00 2001 From: Ahmed Date: Mon, 24 Feb 2020 20:10:40 +0200 Subject: import maaping from CSV file or the current template Issue-ID: CCSDK-2065 Signed-off-by: ahmedeldeeb50 Change-Id: Idc5b1deccf2966438aed13329290df6d9b3f0da7 --- cds-ui/designer-client/angular.json | 24 ++-- cds-ui/designer-client/package.json | 8 +- .../creationModes/DesignerCreationMode.ts | 13 ++ .../mapping-models/CBAPacakge.model.ts | 22 ++- .../mapping-models/ResourceDictionary.model.ts | 23 ++++ .../mapping-models/definitions/VlbDefinition.ts | 2 +- .../mapping-models/mappingAdapter.model.ts | 38 ++++++ .../package-creation/package-creation.service.ts | 3 +- .../package-creation/package-creation.store.ts | 23 ++-- .../templ-mapp-creation.component.html | 106 ++++++++++----- .../templ-mapp-creation.component.ts | 150 ++++++++++++++++++--- .../feature-modules/packages/packages.module.ts | 60 +++++---- 12 files changed, 366 insertions(+), 106 deletions(-) create mode 100644 cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ResourceDictionary.model.ts create mode 100644 cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/mappingAdapter.model.ts (limited to 'cds-ui') diff --git a/cds-ui/designer-client/angular.json b/cds-ui/designer-client/angular.json index 6219bf68a..a84b95e39 100644 --- a/cds-ui/designer-client/angular.json +++ b/cds-ui/designer-client/angular.json @@ -25,21 +25,23 @@ ], "styles": [ "src/styles.css", + "./node_modules/datatables.net-dt/css/jquery.dataTables.css", "./node_modules/bootstrap/dist/css/bootstrap.min.css", "./node_modules/@angular/material/prebuilt-themes/purple-green.css", "./node_modules/font-awesome/css/font-awesome.css", "./node_modules/jointjs/css/layout.css", "./node_modules/jointjs/css/themes/material.css", "./node_modules/jointjs/css/themes/default.css" - ], "scripts": [ + "./node_modules/jquery/dist/jquery.js", + "./node_modules/datatables.net/js/jquery.dataTables.js", + "./node_modules/bootstrap/dist/js/bootstrap.js", "./node_modules/ace-builds/src-min/ace.js", "./node_modules/ace-builds/src-min/theme-eclipse.js", "./node_modules/ace-builds/src-min/theme-tomorrow_night_bright.js", "./node_modules/ace-builds/src-min/mode-json.js", "./node_modules/ace-builds/src-min/mode-javascript.js", - "./node_modules/ace-builds/src-min/mode-python.js", "./node_modules/ace-builds/src-min/mode-xml.js", "./node_modules/ace-builds/src-min/mode-kotlin.js", "./node_modules/ace-builds/src-min/mode-text.js", @@ -52,7 +54,6 @@ "./node_modules/ace-builds/src-min/ext-language_tools.js", "./node_modules/ace-builds/src-min/worker-json.js", "./node_modules/ace-builds/src-min/worker-javascript.js", - "./node_modules/jquery/dist/jquery.js", "./node_modules/lodash/index.js", "./node_modules/backbone/backbone.js", "./node_modules/jointjs/dist/joint.js" @@ -60,12 +61,10 @@ }, "configurations": { "production": { - "fileReplacements": [ - { - "replace": "src/environments/environment.ts", - "with": "src/environments/environment.prod.ts" - } - ], + "fileReplacements": [{ + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.prod.ts" + }], "optimization": true, "outputHashing": "all", "sourceMap": false, @@ -75,8 +74,7 @@ "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, - "budgets": [ - { + "budgets": [{ "type": "initial", "maximumWarning": "2mb", "maximumError": "5mb" @@ -126,7 +124,7 @@ ], "scripts": [ - + ] } }, @@ -159,4 +157,4 @@ } }, "defaultProject": "designer-client" -} +} \ No newline at end of file diff --git a/cds-ui/designer-client/package.json b/cds-ui/designer-client/package.json index 22defe502..5149300d1 100644 --- a/cds-ui/designer-client/package.json +++ b/cds-ui/designer-client/package.json @@ -24,14 +24,17 @@ "@angular/router": "~8.2.9", "@ng-bootstrap/ng-bootstrap": "^5.1.1", "angular-animations": "0.0.10", + "angular-datatables": "^8.0.0", "angular-font-awesome": "^3.1.2", "angular-material-expansion-panel": "^0.7.2", "backbone": "^1.4.0", "bootstrap": "^4.3.1", + "datatables.net": "^1.10.20", + "datatables.net-dt": "^1.10.20", "file-saver": "^2.0.2", "font-awesome": "^4.7.0", "jointjs": "^3.0.4", - "jquery": "^3.1.1", + "jquery": "^3.4.1", "json2typescript": "^1.2.3", "lodash": "^4.17.15", "ng-sidebar": "^9.1.1", @@ -48,10 +51,11 @@ "@angular/compiler-cli": "~8.2.9", "@angular/language-service": "~8.2.9", "@types/backbone": "^1.4.1", + "@types/datatables.net": "^1.10.18", "@types/jasmine": "~3.3.8", "@types/jasminewd2": "~2.0.3", "@types/jointjs": "^2.0.0", - "@types/jquery": "^3.3.31", + "@types/jquery": "^3.3.33", "@types/lodash": "^3.10.1", "@types/node": "~8.9.4", "codelyzer": "^5.0.0", diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts index db6d0420b..162efff9e 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts @@ -7,6 +7,7 @@ import { PackageCreationUtils } from '../package-creation.utils'; export class DesignerCreationMode extends PackageCreationModes { + // Refactor methods params to be in constructor level constructor() { super(); } @@ -15,6 +16,7 @@ export class DesignerCreationMode extends PackageCreationModes { this.addToscaMetaDataFile(cbaPackage.metaData); this.createDefinitionsFolder(cbaPackage, packageCreationUtils); this.addScriptsFolder(cbaPackage.scripts); + this.addTemplateFolder(cbaPackage); } private addScriptsFolder(scripts: Scripts) { @@ -23,6 +25,17 @@ export class DesignerCreationMode extends PackageCreationModes { }); } + private addTemplateFolder(cbaPackage: CBAPackage) { + // Create Template Files Folder + cbaPackage.templates.files.forEach((value, key) => { + FilesContent.putData(key, value); + }); + // Create Mapping Files Folder + cbaPackage.mapping.files.forEach((value, key) => { + FilesContent.putData(key, value); + }); + } + private createDefinitionsFolder(cbaPackage: CBAPackage, packageCreationUtils: PackageCreationUtils) { cbaPackage.definitions.imports.forEach((valueOfFile, key) => { FilesContent.putData(key, valueOfFile); diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts index 3595f7872..45a00ff06 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts @@ -1,4 +1,4 @@ -import {MetaDataTabModel} from './metadata/MetaDataTab.model'; +import { MetaDataTabModel } from './metadata/MetaDataTab.model'; export class Definition { @@ -34,6 +34,22 @@ export class DslDefinition { content: string; } +export class Base { + public files: Map; + + constructor() { + this.files = new Map(); + } + + public setContent(key: string, value: string) { + this.files.set(key, value); + return this; + } + + public getValue(key: string): string { + return this.files.get(key); + } +} export class Scripts { public files: Map; @@ -65,12 +81,15 @@ export class Template { } } +export class Mapping extends Base { +} export class CBAPackage { public metaData: MetaDataTabModel; public definitions: Definition; public scripts: Scripts; public templates: Template; + public mapping: Mapping; constructor() { @@ -78,6 +97,7 @@ export class CBAPackage { this.scripts = new Scripts(); this.metaData = new MetaDataTabModel(); this.templates = new Template(); + this.mapping = new Mapping(); } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ResourceDictionary.model.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ResourceDictionary.model.ts new file mode 100644 index 000000000..558d1c7d0 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ResourceDictionary.model.ts @@ -0,0 +1,23 @@ +import { JsonObject, JsonProperty } from 'json2typescript'; + +@JsonObject('ResourceDictionary') +export class ResourceDictionary { + @JsonProperty() + name: string; + @JsonProperty('creation_date') + creationDate: string; + @JsonProperty('data_type') + dataType: string; + @JsonObject('definition') + definition?: any | null; + @JsonProperty('description') + description: string; + @JsonProperty('entry_schema') + entrySchema: string; + @JsonProperty('esource_dictionary_group') + resourceDictionaryGroup: string; + @JsonProperty('tags') + tags: string; + @JsonProperty('upadted_by') + updatedBy: string; +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts index b797050dd..8e2ff475e 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts @@ -17,7 +17,7 @@ export class VlbDefinition { export class DslContent { } - +// Refactor varaibles name and use JsonConverteri @JsonObject('metadata') export class Metadata { @JsonProperty('template_author') diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/mappingAdapter.model.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/mappingAdapter.model.ts new file mode 100644 index 000000000..638654a95 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/mappingAdapter.model.ts @@ -0,0 +1,38 @@ +import { ResourceDictionary } from './ResourceDictionary.model'; +import { JsonObject, JsonProperty, JsonConvert } from 'json2typescript'; + +// Convert ResourceDictionary object to store Mapping +export class MappingAdapter { + + constructor(private resourceDictionary: ResourceDictionary) { } + + ToMapping(): Mapping { + const mapping = new Mapping(); + mapping.name = this.resourceDictionary.name; + mapping.dictionaryName = this.resourceDictionary.name; + mapping.property = this.resourceDictionary.definition.property; + mapping.inputParam = false; + mapping.dictionarySource = 'sdnc'; + mapping.dependencies = []; + mapping.version = 0; + return mapping; + } +} + +@JsonObject('Mapping') +export class Mapping { + @JsonProperty('name') + name: string; + @JsonProperty() + property: any; + @JsonProperty('input-param', Boolean) + inputParam: boolean; + @JsonProperty('dictionary-name') + dictionaryName: string; + @JsonProperty('dictionary-source') + dictionarySource: string; + @JsonProperty() + dependencies: []; + @JsonProperty() + version: number; +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts index cac27120f..494c9e555 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts @@ -26,6 +26,7 @@ import {ApiService} from '../../../../common/core/services/api.service'; import {BlueprintURLs, ResourceDictionaryURLs} from '../../../../common/constants/app-constants'; import {PackagesApiService} from '../packages-api.service'; import {PackagesStore} from '../packages.store'; +import { ResourceDictionary } from './mapping-models/ResourceDictionary.model'; @Injectable({ providedIn: 'root' @@ -62,7 +63,7 @@ export class PackageCreationService { }); } - getTemplateAndMapping(variables: string[]): Observable { + getTemplateAndMapping(variables: string[]): Observable { return this.api.post(ResourceDictionaryURLs.searchResourceDictionaryByNames, variables); } } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts index 565603ad1..6a9d9c4b3 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts @@ -19,14 +19,16 @@ limitations under the License. ============LICENSE_END============================================ */ -import {Injectable} from '@angular/core'; +import { Injectable } from '@angular/core'; -import {Store} from '../../../../common/core/stores/Store'; +import { Store } from '../../../../common/core/stores/Store'; -import {CBAPackage, DslDefinition} from './mapping-models/CBAPacakge.model'; -import {PackageCreationService} from './package-creation.service'; -import {FolderNodeElement, MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model'; +import { CBAPackage, DslDefinition } from './mapping-models/CBAPacakge.model'; +import { PackageCreationService } from './package-creation.service'; +import { FolderNodeElement, MetaDataTabModel } from './mapping-models/metadata/MetaDataTab.model'; import * as JSZip from 'jszip'; +import { Observable } from 'rxjs'; +import { ResourceDictionary } from './mapping-models/ResourceDictionary.model'; @Injectable({ @@ -94,9 +96,14 @@ export class PackageCreationStore extends Store { }); } - getTemplateAndMapping(variables: string[]) { - this.packageCreationService.getTemplateAndMapping(variables).subscribe(element => { - console.log('the element is ' + element); + addMapping(filePath: string, fileContent: string) { + this.setState({ + ...this.state, + mapping: this.state.mapping.setContent(filePath, fileContent) }); } + + getTemplateAndMapping(variables: string[]): Observable { + return this.packageCreationService.getTemplateAndMapping(variables); + } } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html index c3a36c9cb..d08ada98d 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html @@ -17,7 +17,7 @@
@@ -29,25 +29,24 @@
-
Use the editor to add parameters or you can also Import - File
+ data-toggle="modal" data-target="#exampleModal">Import + File
- +
@@ -70,7 +68,7 @@
@@ -79,14 +77,15 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
RequiredParameter NameDictionary NameDictionary SourceDependanciesDefaultData TypeEntry Schema
{{ dict.definition?.property?.required }}{{ dict.name }}{{ dict.name }} + + + + + {{ dict.definition?.property?.default }}{{ dict.dataType }}{{ dict.entrySchema }}
+
-
- +