11/**
2- * Copyright 2013-2021 the original author or authors from the JHipster project.
2+ * Copyright 2013-2022 the original author or authors from the JHipster project.
33 *
44 * This file is part of the JHipster project, see https://www.jhipster.tech/
55 * for more information.
@@ -24,15 +24,25 @@ const needleClientBase = require('./needle-client');
2424module . exports = class extends needleClientBase {
2525 addEntityToMenu ( routerName , enableTranslation , entityTranslationKeyMenu , entityTranslationValue = _ . startCase ( routerName ) ) {
2626 const errorMessage = `${ chalk . yellow ( 'Reference to ' ) + routerName } ${ chalk . yellow ( 'not added to menu.\n' ) } ` ;
27- const filePath = `${ this . CLIENT_MAIN_SRC_DIR } /app/core/jhi-navbar/jhi-navbar.vue` ;
27+ const filePath = `${ this . CLIENT_MAIN_SRC_DIR } /app/entities/entities-menu.vue` ;
28+
29+ const isSpecificEntityAlreadyGenerated = jhipsterUtils . checkStringInFile (
30+ filePath ,
31+ `<b-dropdown-item to="/${ routerName } ">` ,
32+ this . generator
33+ ) ;
34+ if ( isSpecificEntityAlreadyGenerated ) {
35+ return ;
36+ }
37+
2838 const menuI18nTitle = enableTranslation ? ` v-text="$t('global.menu.entities.${ entityTranslationKeyMenu } ')"` : '' ;
2939 const entityEntry =
3040 // prettier-ignore
3141 this . generator . stripMargin (
32- `<b-dropdown-item to="/${ routerName } ">
33- | <font-awesome-icon icon="asterisk" />
34- | <span${ menuI18nTitle } >${ entityTranslationValue } </span>
35- | </b-dropdown-item>` ) ;
42+ `| <b-dropdown-item to="/${ routerName } ">
43+ | <font-awesome-icon icon="asterisk" />
44+ | <span${ menuI18nTitle } >${ entityTranslationValue } </span>
45+ | </b-dropdown-item>` ) ;
3646
3747 const rewriteFileModel = this . generateFileModel ( filePath , 'jhipster-needle-add-entity-to-menu' , entityEntry ) ;
3848 this . addBlockContentToFile ( rewriteFileModel , errorMessage ) ;
@@ -41,6 +51,16 @@ module.exports = class extends needleClientBase {
4151 addEntityToRouterImport ( entityName , fileName , folderName , readOnly ) {
4252 const errorMessage = `${ chalk . yellow ( 'Reference to entity ' ) + entityName } ${ chalk . yellow ( 'not added to router entities import.\n' ) } ` ;
4353 const filePath = `${ this . CLIENT_MAIN_SRC_DIR } /app/router/entities.ts` ;
54+
55+ const isSpecificEntityAlreadyGenerated = jhipsterUtils . checkStringInFile (
56+ filePath ,
57+ `import('@/entities/${ folderName } /${ fileName } .vue');` ,
58+ this . generator
59+ ) ;
60+ if ( isSpecificEntityAlreadyGenerated ) {
61+ return ;
62+ }
63+
4464 let entityEntry ;
4565 if ( ! readOnly ) {
4666 // prettier-ignore
@@ -70,8 +90,7 @@ module.exports = class extends needleClientBase {
7090 const errorMessage = `${ chalk . yellow ( 'Reference to entity ' ) + entityName } ${ chalk . yellow ( 'not added to router entities.\n' ) } ` ;
7191 const filePath = `${ this . CLIENT_MAIN_SRC_DIR } /app/router/entities.ts` ;
7292
73- const isSpecificEntityAlreadyGenerated = jhipsterUtils . checkStringInFile ( filePath , `path: '/${ entityFileName } '` , this . generator ) ;
74-
93+ const isSpecificEntityAlreadyGenerated = jhipsterUtils . checkStringInFile ( filePath , `path: '${ entityFileName } '` , this . generator ) ;
7594 if ( isSpecificEntityAlreadyGenerated ) {
7695 return ;
7796 }
@@ -81,25 +100,25 @@ module.exports = class extends needleClientBase {
81100 // prettier-ignore
82101 entityEntry = this . generator . stripMargin (
83102 `|{
84- | path: '/ ${ entityFileName } ',
103+ | path: '${ entityFileName } ',
85104 | name: '${ entityName } ',
86105 | component: ${ entityName } ,
87106 | meta: { authorities: [Authority.USER] }
88107 | },
89108 | {
90- | path: '/ ${ entityFileName } /new',
109+ | path: '${ entityFileName } /new',
91110 | name: '${ entityName } Create',
92111 | component: ${ entityName } Update,
93112 | meta: { authorities: [Authority.USER] }
94113 | },
95114 | {
96- | path: '/ ${ entityFileName } /:${ entityInstance } Id/edit',
115+ | path: '${ entityFileName } /:${ entityInstance } Id/edit',
97116 | name: '${ entityName } Edit',
98117 | component: ${ entityName } Update,
99118 | meta: { authorities: [Authority.USER] }
100119 | },
101120 | {
102- | path: '/ ${ entityFileName } /:${ entityInstance } Id/view',
121+ | path: '${ entityFileName } /:${ entityInstance } Id/view',
103122 | name: '${ entityName } View',
104123 | component: ${ entityName } Details,
105124 | meta: { authorities: [Authority.USER] }
@@ -124,6 +143,7 @@ module.exports = class extends needleClientBase {
124143 }
125144
126145 const rewriteFileModel = this . generateFileModel ( filePath , 'jhipster-needle-add-entity-to-router' , entityEntry ) ;
146+ rewriteFileModel . prettierAware = true ;
127147 this . addBlockContentToFile ( rewriteFileModel , errorMessage ) ;
128148 }
129149
@@ -152,4 +172,34 @@ module.exports = class extends needleClientBase {
152172 const rewriteFileModel = this . generateFileModel ( filePath , 'jhipster-needle-add-entity-service-to-main' , entityEntry ) ;
153173 this . addBlockContentToFile ( rewriteFileModel , errorMessage ) ;
154174 }
175+
176+ addEntityServiceToEntitiesComponentImport ( entityName , entityClass , entityFileName , entityFolderName ) {
177+ const errorMessage = `${ chalk . yellow ( 'Reference to entity ' ) + entityClass } ${ chalk . yellow (
178+ 'not added to import in entities component.\n'
179+ ) } `;
180+ const filePath = `${ this . CLIENT_MAIN_SRC_DIR } /app/entities/entities.component.ts` ;
181+
182+ // prettier-ignore
183+ const entityEntry = `import ${ entityName } Service from './${ entityFolderName } /${ entityFileName } .service';` ;
184+
185+ const rewriteFileModel = this . generateFileModel (
186+ filePath ,
187+ 'jhipster-needle-add-entity-service-to-entities-component-import' ,
188+ entityEntry
189+ ) ;
190+ this . addBlockContentToFile ( rewriteFileModel , errorMessage ) ;
191+ }
192+
193+ addEntityServiceToEntitiesComponent ( entityInstance , entityName ) {
194+ const errorMessage = `${ chalk . yellow ( 'Reference to entity ' ) + entityName } ${ chalk . yellow (
195+ 'not added to service in entities component.\n'
196+ ) } `;
197+ const filePath = `${ this . CLIENT_MAIN_SRC_DIR } /app/entities/entities.component.ts` ;
198+
199+ // prettier-ignore
200+ const entityEntry = `@Provide('${ entityInstance } Service') private ${ entityInstance } Service = () => new ${ entityName } Service();` ;
201+
202+ const rewriteFileModel = this . generateFileModel ( filePath , 'jhipster-needle-add-entity-service-to-entities-component' , entityEntry ) ;
203+ this . addBlockContentToFile ( rewriteFileModel , errorMessage ) ;
204+ }
155205} ;
0 commit comments