From 18da1491d4a4a16d24ece397361f328577c5ce62 Mon Sep 17 00:00:00 2001 From: Saiat Kalbiev Date: Tue, 20 Aug 2019 13:18:19 +0400 Subject: [PATCH] Update form component template and update package.json version --- package.json | 2 +- src/Generator.js | 31 +++++++++++++++++++++++---- src/templates/form.component.template | 8 ++----- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 3797a27..f1040e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-simple-crud-generator", - "version": "1.0.1", + "version": "1.0.2", "description": "Following package generates simple crud for vue projects", "keywords": [ "vue", diff --git a/src/Generator.js b/src/Generator.js index 2e812fe..8297db4 100644 --- a/src/Generator.js +++ b/src/Generator.js @@ -120,7 +120,9 @@ class Generator { .replace(/{{mainUrl}}/g, this.mainUrl) .replace(/{{inputFields}}/g, this.getFormInputFieldsFileData()) .replace(/{{translatableInputFields}}/g, this.getFormTranslatableInputFieldsFileData()) - .replace(/{{serviceName}}/g, this.serviceName); + .replace(/{{serviceName}}/g, this.serviceName) + .replace(/{{formDataFields}}/g, this.getFormDataFields()) + .replace(/{{formValidatorFields}}/g, this.getFormValidatorsFields()); fs.writeFile(newFile, result, 'utf8', function (err) { if (err) throw new Error(`Error while saving newly updated form component file. Message: ${err.message}`) @@ -230,13 +232,34 @@ class Generator { return returnData.replace('{{innerData}}', innerData); } + getFormDataFields() { + let returnData = ''; + + this.field_names.forEach((fieldName) => { + returnData += ` + ${fieldName}: '',`; + }); + + return returnData; + } + + getFormValidatorsFields() { + let returnData = ''; + + this.field_names.forEach((fieldName) => { + returnData += ` + ${fieldName}: {required},`; + }); + + return returnData; + } + getServiceTranslatableFieldsData() { let returnData = ""; - for (var i = 0; i < this.field_names.length; i++) { + for (var i = 0; i < this.translatable_field_names.length; i++) { returnData += ` { - name: '${this.field_names[i]}', - type: 'text', + name: '${this.translatable_field_names[i]}' },`; } return returnData; diff --git a/src/templates/form.component.template b/src/templates/form.component.template index a4dede8..aa3d625 100644 --- a/src/templates/form.component.template +++ b/src/templates/form.component.template @@ -47,8 +47,7 @@ locales: i18nHelper.getAvailableLocales(), fields: [], translatableFields: {{serviceName}}.getGeneralFields().translatableFields, - {{objectVariableName}}: { - key: '' + {{objectVariableName}}: {{{formDataFields}} } }; @@ -57,10 +56,7 @@ return data }, validations() { - let validators = { - key: { - required - } + let validators = {{{formValidatorFields}} }; this.translatableFields.forEach((field) => {