From d310c6fa6cdc8774331c5c376bdea5f6d3418bd2 Mon Sep 17 00:00:00 2001 From: swarajsaaj Date: Sun, 3 Oct 2021 19:26:34 +0530 Subject: [PATCH] [vue] Use v-for instead of generation for enums Use v-for instead of generated code for enums for better maintainance Followup of #16475 --- .../webapp/app/entities/entity-update.component.ts.ejs | 7 +++++++ .../src/main/webapp/app/entities/entity-update.vue.ejs | 9 +++------ .../vue/src/main/webapp/app/entities/entity.model.ts.ejs | 2 +- .../spec/app/entities/entity.service.spec.ts.ejs | 2 +- generators/generator-base-private.js | 3 ++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.component.ts.ejs b/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.component.ts.ejs index 14f1d89a3e5..8b8450fc158 100644 --- a/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.component.ts.ejs +++ b/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.component.ts.ejs @@ -78,6 +78,10 @@ import { I<%= otherEntityAngularName %> } from '@/shared/model/<%= otherEntityMo <%_ importEntitiesSeen.push(otherEntityAngularName); } } _%> import { I<%= entityAngularName %>, <%= entityAngularName %> } from '@/shared/model/<%= entityModelFileName %>.model'; import <%= entityAngularName %>Service from './<%= entityFileName %>.service'; +<%_ const enumImports = generateEntityClientEnumImports(fields); _%> +<%_ enumImports.forEach( (importedPath, importedType) => { _%> +import { <%- importedType %> } from '<%- importedPath %>'; +<%_ }); _%> const validations: any = { <%= entityInstance %>: { @@ -148,6 +152,9 @@ export default class <%= entityAngularName %>Update extends <% if (fieldsContain public <%= otherEntityNamePlural %> : <% if (otherEntityAngularName === 'User') { %>Array<%_ } else { _%>I<%= otherEntityAngularName %>[]<%_ } _%> = []; <%_ } _%> <%_ entitiesSeen.push(otherEntityAngularName);entitiesSeen.push(otherEntityNamePlural); } } _%> + <%_ enumImports.forEach( (importedPath, importedType) => { _%> + public <%- _.lowerFirst(importedType) %>Values : string[] = Object.keys(<%- importedType %>); + <%_ }); _%> public isSaving = false; public currentLanguage = ''; diff --git a/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.vue.ejs b/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.vue.ejs index 01d5c379826..defc2d4c8e2 100644 --- a/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.vue.ejs +++ b/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.vue.ejs @@ -34,12 +34,9 @@ _%> <%_ if (field.fieldIsEnum) { _%> <%_ } else { _%> <%_ if (field.fieldTypeBinary && !field.blobContentTypeText) { _%> diff --git a/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity.model.ts.ejs b/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity.model.ts.ejs index ab854150436..011f1fa9f6f 100644 --- a/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity.model.ts.ejs +++ b/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity.model.ts.ejs @@ -32,7 +32,7 @@ import { <%- importedType %> } from '<%- importedPath %>'; <%_ }); _%> <%_ enumImports.forEach( (importedPath, importedType) => { _%> -import { <%- importedType %> } from '<%- importedPath.replace('app/', '@/'); %>'; +import { <%- importedType %> } from '<%- importedPath %>'; <%_ }); _%> export interface I<%= entityAngularName %> { <%_ variablesWithTypes.forEach(variablesWithType => { _%> diff --git a/generators/entity-client/templates/vue/src/test/javascript/spec/app/entities/entity.service.spec.ts.ejs b/generators/entity-client/templates/vue/src/test/javascript/spec/app/entities/entity.service.spec.ts.ejs index 69c3612fc54..1e73d1bbc4d 100644 --- a/generators/entity-client/templates/vue/src/test/javascript/spec/app/entities/entity.service.spec.ts.ejs +++ b/generators/entity-client/templates/vue/src/test/javascript/spec/app/entities/entity.service.spec.ts.ejs @@ -33,7 +33,7 @@ import { <%_ if (fieldsContainLocalDate) { _%>DATE_FORMAT,<%_ } if (fieldsContai import <%= entityAngularName %>Service from '@/entities/<%= entityFolderName %>/<%= entityFileName %>.service'; import { <%= entityAngularName %> } from '@/shared/model/<%= entityModelFileName %>.model'; <%_ enumImports.forEach( (importedPath, importedType) => { _%> -import { <%- importedType %> } from '<%- importedPath.replace('app/', '@/') %>'; +import { <%- importedType %> } from '<%- importedPath %>'; <%_ }); _%> const error = { diff --git a/generators/generator-base-private.js b/generators/generator-base-private.js index 5b63ebaac78..f69944cd6b0 100644 --- a/generators/generator-base-private.js +++ b/generators/generator-base-private.js @@ -995,8 +995,9 @@ module.exports = class JHipsterBasePrivateGenerator extends Generator { const fileName = _.kebabCase(field.fieldType); if (field.fieldIsEnum && (!uniqueEnums[field.fieldType] || (uniqueEnums[field.fieldType] && field.fieldValues.length !== 0))) { const importType = `${field.fieldType}`; + const basePath = clientFramework === VUE ? '@' : 'app'; const modelPath = clientFramework === ANGULAR ? 'entities' : 'shared/model'; - const importPath = `app/${modelPath}/enumerations/${fileName}.model`; + const importPath = `${basePath}/${modelPath}/enumerations/${fileName}.model`; uniqueEnums[field.fieldType] = field.fieldType; typeImports.set(importType, importPath); }