Skip to content

Commit 281f4d0

Browse files
committed
angular: convert entity-navbar-items.ts to needles
1 parent fbf1542 commit 281f4d0

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

generators/angular/generator.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,29 @@ export default class AngularGenerator extends BaseApplicationGenerator<DefaultTa
109109
const ignoreNonExisting = chalk.yellow('Reference to entities not added to menu.');
110110
const editCallback = addToEntitiesMenu(param);
111111
this.editFile(filePath, { ignoreNonExisting }, editCallback);
112+
113+
this.editFile(
114+
`${application.clientSrcDir}app/entities/entity-navbar-items.ts`,
115+
createNeedleCallback({
116+
needle: 'add-entity-navbar',
117+
contentToAdd: param.entities
118+
.filter(e => !e.adminEntity)
119+
.map(entity => ({
120+
contentToCheck: `name: '${entity.entityAngularName}',`,
121+
content: `{
122+
name: '${entity.entityAngularName}',
123+
route: '/${entity.entityPage}',${
124+
application.enableTranslation
125+
? `
126+
translationKey: 'global.menu.entities.${entity.entityTranslationKey}',`
127+
: ''
128+
}
129+
},`,
130+
})),
131+
}),
132+
);
112133
};
134+
113135
source.addAdminRoute = (args: Omit<Parameters<typeof addRoute>[0], 'needle'>) =>
114136
this.editFile(
115137
`${application.srcMainWebapp}app/admin/admin.routes.ts`,
@@ -250,9 +272,6 @@ export default class AngularGenerator extends BaseApplicationGenerator<DefaultTa
250272

251273
get default() {
252274
return this.asDefaultTaskGroup({
253-
loadEntities({ application, entities }) {
254-
application.angularEntities = entities.filter(entity => !entity.builtIn && !entity.skipClient) as AngularEntity[];
255-
},
256275
queueTranslateTransform({ application }) {
257276
const { enableTranslation, jhiPrefix } = application;
258277
this.queueTransformStream(

generators/angular/templates/src/main/webapp/app/entities/entity-navbar-items.ts.ejs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,5 @@
1919
import NavbarItem from 'app/layouts/navbar/navbar-item.model';
2020

2121
export const EntityNavbarItems: NavbarItem[] = [
22-
<%_ for (const entity of angularEntities) { _%>
23-
{
24-
name: '<%= entity.entityAngularName %>',
25-
route: '/<%= entity.entityPage %>',
26-
<%_ if (enableTranslation) { _%>
27-
translationKey: 'global.menu.entities.<%= entity.entityTranslationKey %>',
28-
<%_ } _%>
29-
},
30-
<%_ } _%>
22+
/* jhipster-needle-add-entity-navbar - JHipster will add entity navbar items here */
3123
];

generators/angular/types.d.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ export interface AngularEntity extends Entity {
2626
* @param fields returns the import of enums that are referenced by the fields
2727
* @returns {typeImports:Map} the fields that potentially contains some enum types
2828
*/
29-
generateEntityClientEnumImports: (fields: any) => Map<any, any>;
29+
generateEntityClientEnumImports?: (fields: any) => Map<any, any>;
3030
}
3131

32-
export type AngularApplication = {
33-
/** @experimental to be replaced with needles */
34-
angularEntities: AngularEntity[];
35-
} & ApplicationType<AngularEntity>;
32+
export type AngularApplication = ApplicationType<AngularEntity>;

generators/app/__snapshots__/generator.spec.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ exports[`generator - app with default config should match snapshot 1`] = `
218218
"addOpenapiGeneratorPlugin": undefined,
219219
"addPrettierExtensions": [Function],
220220
"addSpringMilestoneRepository": false,
221-
"angularEntities": [],
222221
"angularLocaleId": "en",
223222
"anyEntityHasRelationshipWithUser": false,
224223
"applicationType": "monolith",
@@ -896,7 +895,6 @@ exports[`generator - app with gateway should match snapshot 1`] = `
896895
"addOpenapiGeneratorPlugin": undefined,
897896
"addPrettierExtensions": [Function],
898897
"addSpringMilestoneRepository": false,
899-
"angularEntities": [],
900898
"angularLocaleId": "en",
901899
"anyEntityHasRelationshipWithUser": false,
902900
"applicationType": "gateway",

0 commit comments

Comments
 (0)