Skip to content

Commit

Permalink
Update form component template and update package.json version
Browse files Browse the repository at this point in the history
  • Loading branch information
saiat3 committed Aug 20, 2019
1 parent 5671512 commit 18da149
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
31 changes: 27 additions & 4 deletions src/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions src/templates/form.component.template
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
locales: i18nHelper.getAvailableLocales(),
fields: [],
translatableFields: {{serviceName}}.getGeneralFields().translatableFields,
{{objectVariableName}}: {
key: ''
{{objectVariableName}}: {{{formDataFields}}
}
};

Expand All @@ -57,10 +56,7 @@
return data
},
validations() {
let validators = {
key: {
required
}
let validators = {{{formValidatorFields}}
};

this.translatableFields.forEach((field) => {
Expand Down

0 comments on commit 18da149

Please sign in to comment.