Skip to content

Commit

Permalink
remove some unused generator-angular methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcharl committed Sep 15, 2024
1 parent d722fa4 commit e125204
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 283 deletions.
146 changes: 9 additions & 137 deletions generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { camelCase } from 'lodash-es';
import chalk from 'chalk';
import { isFileStateModified } from 'mem-fs-editor/state';

Expand All @@ -33,7 +32,6 @@ import {
} from '../client/support/index.js';
import { createNeedleCallback, mutateData } from '../base/support/index.js';
import { writeEslintClientRootConfigFile } from '../javascript/generators/eslint/support/tasks.js';
import type { PostWritingEntitiesTaskParam } from '../../lib/types/application/tasks.js';
import { cleanupEntitiesFiles, postWriteEntitiesFiles, writeEntitiesFiles } from './entity-files-angular.js';
import { writeFiles } from './files-angular.js';
import cleanupOldFilesTask from './cleanup.js';
Expand Down Expand Up @@ -100,8 +98,15 @@ export default class AngularGenerator extends BaseApplicationGenerator {
},
addNeedles({ source, application }) {
source.addEntitiesToClient = param => {
this.addEntitiesToModule(param);
this.addEntitiesToMenu(param);
const routeTemplatePath = `${param.application.clientSrcDir}app/entities/entity.routes.ts`;
const ignoreNonExistingRoute = chalk.yellow(`Route(s) not added to ${routeTemplatePath}.`);
const addRouteCallback = addEntitiesRoute(param);
this.editFile(routeTemplatePath, { ignoreNonExisting: ignoreNonExistingRoute }, addRouteCallback);

const filePath = `${application.clientSrcDir}app/layouts/navbar/navbar.component.html`;
const ignoreNonExisting = chalk.yellow('Reference to entities not added to menu.');
const editCallback = addToEntitiesMenu(param);
this.editFile(filePath, { ignoreNonExisting }, editCallback);
};

source.addAdminRoute = (args: Omit<Parameters<typeof addRoute>[0], 'needle'>) =>
Expand Down Expand Up @@ -196,7 +201,6 @@ export default class AngularGenerator extends BaseApplicationGenerator {
returnValue = fieldDefaultValue;
}
}

return returnValue;
},
});
Expand Down Expand Up @@ -314,123 +318,6 @@ export default class AngularGenerator extends BaseApplicationGenerator {
get [BaseApplicationGenerator.END]() {
return this.delegateTasksToBlueprint(() => this.end);
}

/**
* @private
* Add new scss style to the angular application in "vendor.scss".
*
* @param {string} style - scss to add in the file
* @param {string} comment - comment to add before css code
*
* example:
*
* style = '.success {\n @extend .message;\n border-color: green;\n}'
* comment = 'Message'
*
* * ==========================================================================
* Message
* ========================================================================== *
* .success {
* @extend .message;
* border-color: green;
* }
*
*/
addVendorSCSSStyle(style, comment?) {
this.needleApi.clientAngular.addVendorSCSSStyle(style, comment);
}

/**
* @private
* Add a new lazy loaded module to admin routing file.
*
* @param {string} route - The route for the module. For example 'entity-audit'.
* @param {string} modulePath - The path to the module file. For example './entity-audit/entity-audit.module'.
* @param {string} moduleName - The name of the module. For example 'EntityAuditModule'.
* @param {string} pageTitle - The translation key if i18n is enabled or the text if i18n is disabled for the page title in the browser.
* For example 'entityAudit.home.title' for i18n enabled or 'Entity audit' for i18n disabled.
* If undefined then application global page title is used in the browser title bar.
*/
addAdminRoute(route, modulePath, moduleName, pageTitle) {
this.needleApi.clientAngular.addAdminRoute(route, modulePath, moduleName, pageTitle);
}

/**
* @private
* Add a new module in the TS modules file.
*
* @param {string} appName - Angular2 application name.
* @param {string} angularName - The name of the new admin item.
* @param {string} folderName - The name of the folder.
* @param {string} fileName - The name of the file.
* @param {boolean} enableTranslation - If translations are enabled or not.
* @param {string} clientFramework - The name of the client framework.
*/
addAngularModule(appName, angularName, folderName, fileName, enableTranslation) {
this.needleApi.clientAngular.addModule(appName, angularName, folderName, fileName, enableTranslation);
}

/**
* @private
* Add a new icon to icon imports.
*
* @param {string} iconName - The name of the Font Awesome icon.
*/
addIcon(iconName) {
this.needleApi.clientAngular.addIcon(iconName);
}

/**
* Add a new menu element to the admin menu.
*
* @param {string} routerName - The name of the Angular router that is added to the admin menu.
* @param {string} iconName - The name of the Font Awesome icon that will be displayed.
* @param {boolean} enableTranslation - If translations are enabled or not
* @param {string} translationKeyMenu - i18n key for entry in the admin menu
*/
addElementToAdminMenu(routerName, iconName, enableTranslation, translationKeyMenu = camelCase(routerName), jhiPrefix?) {
this.needleApi.clientAngular.addElementToAdminMenu(routerName, iconName, enableTranslation, translationKeyMenu, jhiPrefix);
}

addEntitiesToMenu({ application, entities }: Pick<PostWritingEntitiesTaskParam, 'application' | 'entities'>) {
const filePath = `${application.clientSrcDir}app/layouts/navbar/navbar.component.html`;
const ignoreNonExisting = chalk.yellow('Reference to entities not added to menu.');
const editCallback = addToEntitiesMenu({ application, entities });

this.editFile(filePath, { ignoreNonExisting }, editCallback);
}

addEntitiesToModule(param: Pick<PostWritingEntitiesTaskParam, 'application' | 'entities'>) {
const filePath = `${param.application.clientSrcDir}app/entities/entity.routes.ts`;
const ignoreNonExisting = chalk.yellow(`Route(s) not added to ${filePath}.`);
const addRouteCallback = addEntitiesRoute(param);
this.editFile(filePath, { ignoreNonExisting }, addRouteCallback);
}

/**
* @private
* Add new scss style to the angular application in "global.scss
*
* @param {string} style - css to add in the file
* @param {string} comment - comment to add before css code
*
* example:
*
* style = '.jhipster {\n color: #baa186;\n}'
* comment = 'New JHipster color'
*
* * ==========================================================================
* New JHipster color
* ========================================================================== *
* .jhipster {
* color: #baa186;
* }
*
*/
addMainSCSSStyle(style, comment?) {
this.needleApi.clientAngular.addGlobalSCSSStyle(style, comment);
}

/**
* Returns the typescript import section of enums referenced by all fields of the entity.
* @param fields returns the import of enums that are referenced by the fields
Expand Down Expand Up @@ -459,7 +346,6 @@ export default class AngularGenerator extends BaseApplicationGenerator {
generateTestEntityId(primaryKey, index = 0, wrapped = true) {
return getTestEntityId(primaryKey, index, wrapped);
}

/**
* @private
* Generate a test entity, for the PK references (when the PK is a composite, derived key)
Expand Down Expand Up @@ -493,18 +379,4 @@ export default class AngularGenerator extends BaseApplicationGenerator {
buildAngularFormPath(reference, prefix = []) {
return angularFormPath(reference, prefix);
}

/**
* @private
* Add a new menu element, at the root of the menu.
*
* @param {string} routerName - The name of the router that is added to the menu.
* @param {string} iconName - The name of the Font Awesome icon that will be displayed.
* @param {boolean} enableTranslation - If translations are enabled or not
* @param {string} clientFramework - The name of the client framework
* @param {string} translationKeyMenu - i18n key for entry in the menu
*/
addElementToMenu(routerName, iconName, enableTranslation, _clientFramework?, translationKeyMenu = camelCase(routerName)) {
this.needleApi.clientAngular.addElementToMenu(routerName, iconName, enableTranslation, translationKeyMenu);
}
}
4 changes: 3 additions & 1 deletion generators/angular/types.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export type AngularApplication = { angularLocaleId: string };
export type AngularApplication = {
angularLocaleId: string;
};
27 changes: 15 additions & 12 deletions generators/client/support/template-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import path from 'path';

import { clientFrameworkTypes, fieldTypes } from '../../../lib/jhipster/index.js';
import type { PrimaryKey } from '../../../lib/types/application/entity.js';
import type { Field } from '../../../lib/types/application/index.js';
import { getEntryIfTypeOrTypeAttribute } from './types-utils.js';

const { STRING: TYPE_STRING, UUID: TYPE_UUID } = fieldTypes.CommonDBTypes;
Expand Down Expand Up @@ -74,20 +75,22 @@ export const generateEntityClientImports = (relationships, dto?, clientFramework
* @param {string} clientFramework the client framework, 'angular' or 'react'.
* @returns typeImports: Map
*/
export const generateEntityClientEnumImports = (fields, clientFramework) => {
export const generateEntityClientEnumImports = (fields: Field[] | undefined, clientFramework: string) => {
const typeImports = new Map();
const uniqueEnums = {};
fields.forEach(field => {
const { enumFileName, fieldType } = field;
if (field.fieldIsEnum && (!uniqueEnums[fieldType] || (uniqueEnums[fieldType] && field.fieldValues.length !== 0))) {
const importType = `${fieldType}`;
const basePath = clientFramework === VUE ? '@' : 'app';
const modelPath = clientFramework === ANGULAR ? 'entities' : 'shared/model';
const importPath = `${basePath}/${modelPath}/enumerations/${enumFileName}.model`;
uniqueEnums[fieldType] = field.fieldType;
typeImports.set(importType, importPath);
}
});
if (fields && fields.forEach) {
fields.forEach(field => {
const { enumFileName, fieldType } = field;
if (field.fieldIsEnum && (!uniqueEnums[fieldType] || (uniqueEnums[fieldType] && field.fieldValues?.length !== 0))) {
const importType = `${fieldType}`;
const basePath = clientFramework === VUE ? '@' : 'app';
const modelPath = clientFramework === ANGULAR ? 'entities' : 'shared/model';
const importPath = `${basePath}/${modelPath}/enumerations/${enumFileName}.model`;
uniqueEnums[fieldType] = field.fieldType;
typeImports.set(importType, importPath);
}
});
}
return typeImports;
};

Expand Down
21 changes: 0 additions & 21 deletions test/needle-api/needle-client-angular-generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const mockAngularBlueprintSubGen = class extends AngularGenerator {

get [BaseApplicationGenerator.POST_WRITING_ENTITIES]() {
return this.asPostWritingEntitiesTaskGroup({
addToMenuStep() {
this.addElementToAdminMenu('routerName2', 'iconName2', true);
},
addToModuleStep({ source, application }) {
source.addEntitiesToClient({
application,
Expand Down Expand Up @@ -66,24 +63,6 @@ describe('needle API Angular angular generator : JHipster with blueprint', () =>
);
});

it('admin menu contains the admin element added by needle api', () => {
runResult.assertFileContent(
`${CLIENT_MAIN_SRC_DIR}app/layouts/navbar/navbar.component.html`,
`
<li>
<a class="dropdown-item" routerLink="/routerName2" routerLinkActive="active" (click)="collapseNavbar()">
<fa-icon icon="iconName2" [fixedWidth]="true"></fa-icon>
<span jhiTranslate="global.menu.admin.routerName2">Router Name 2</span>
</a>
</li>
`,
);
});

it('icon imports contains a new icon added by a new admin menu method of needle api ', () => {
runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}app/config/font-awesome-icons.ts`, ' faIconName2');
});

it('entity module contains the microservice object added by needle api', () => {
runResult.assertFileContent(
`${CLIENT_MAIN_SRC_DIR}app/entities/entity.routes.ts`,
Expand Down
112 changes: 0 additions & 112 deletions test/needle-api/needle-client-angular.spec.ts

This file was deleted.

0 comments on commit e125204

Please sign in to comment.