From 73e8273f7d3e273e10e35d4bc4142f6c7e94eb04 Mon Sep 17 00:00:00 2001 From: Kaido Hallik Date: Thu, 17 Dec 2020 12:50:28 +0200 Subject: [PATCH] [angular] Polish entity modules and update component --- .../client/needle-api/needle-client-angular.js | 6 +++--- .../app/entities/entity-management.module.ts.ejs | 11 ++--------- .../route/entity-management-routing.module.ts.ejs | 7 ++----- .../entity-management-update.component.ts.ejs | 13 ++----------- test/needle-api/needle-client-angular.spec.js | 2 +- 5 files changed, 10 insertions(+), 29 deletions(-) diff --git a/generators/client/needle-api/needle-client-angular.js b/generators/client/needle-api/needle-client-angular.js index 01057427daa8..c02012843731 100644 --- a/generators/client/needle-api/needle-client-angular.js +++ b/generators/client/needle-api/needle-client-angular.js @@ -231,10 +231,10 @@ module.exports = class extends needleClientBase { ); if (!isSpecificEntityAlreadyGenerated) { - const modulePath = `./${entityFolderName}/route/${entityFileName}-routing.module`; + const modulePath = `./${entityFolderName}/${entityFileName}.module`; const moduleName = microserviceName - ? `${this.generator.upperFirstCamelCase(microserviceName)}${entityAngularName}RoutingModule` - : `${entityAngularName}RoutingModule`; + ? `${this.generator.upperFirstCamelCase(microserviceName)}${entityAngularName}Module` + : `${entityAngularName}Module`; this._addRoute(entityUrl, modulePath, moduleName, 'jhipster-needle-add-entity-route', entityModulePath, pageTitle); } diff --git a/generators/entity-client/templates/angular/src/main/webapp/app/entities/entity-management.module.ts.ejs b/generators/entity-client/templates/angular/src/main/webapp/app/entities/entity-management.module.ts.ejs index 429f7f8f0ba8..c28d4d8b4741 100644 --- a/generators/entity-client/templates/angular/src/main/webapp/app/entities/entity-management.module.ts.ejs +++ b/generators/entity-client/templates/angular/src/main/webapp/app/entities/entity-management.module.ts.ejs @@ -17,7 +17,6 @@ limitations under the License. -%> import { NgModule } from '@angular/core'; -import { RouterModule } from '@angular/router'; import { SharedModule } from 'app/shared/shared.module'; import { <%= entityAngularName %>Component } from './list/<%= entityFileName %>.component'; @@ -26,11 +25,12 @@ import { <%= entityAngularName %>DetailComponent } from './detail/<%= entityFile import { <%= entityAngularName %>UpdateComponent } from './update/<%= entityFileName %>-update.component'; import { <%= entityAngularName %>DeleteDialogComponent } from './delete/<%= entityFileName %>-delete-dialog.component'; <%_ } _%> +import { <%= entityAngularName %>RoutingModule } from './route/<%= entityFileName %>-routing.module'; @NgModule({ imports: [ SharedModule, - RouterModule, + <%= entityAngularName %>RoutingModule, ], declarations: [ <%= entityAngularName %>Component, @@ -40,13 +40,6 @@ import { <%= entityAngularName %>DeleteDialogComponent } from './delete/<%= enti <%= entityAngularName %>DeleteDialogComponent, <%_ } %> ], - exports: [ - <%= entityAngularName %>DetailComponent, - <%_ if (!readOnly) { _%> - <%= entityAngularName %>UpdateComponent, - <%= entityAngularName %>DeleteDialogComponent, - <%_ } %> - ], <%_ if (!readOnly) { _%> entryComponents: [ <%= entityAngularName %>DeleteDialogComponent diff --git a/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing.module.ts.ejs b/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing.module.ts.ejs index 31a19fe45eef..6d7f7a03e528 100644 --- a/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing.module.ts.ejs +++ b/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing.module.ts.ejs @@ -27,7 +27,6 @@ import { <%= entityAngularName %>DetailComponent } from '../detail/<%= entityFil import { <%= entityAngularName %>UpdateComponent } from '../update/<%= entityFileName %>-update.component'; <%_ } _%> import { <%= entityAngularName %>RoutingResolveService } from './<%= entityFileName %>-routing-resolve.service'; -import { <%= microservicePrefix %><%= entityAngularName %>Module } from '../<%= entityFileName %>.module'; const <%= entityInstance %>Route: Routes = [ { @@ -69,9 +68,7 @@ const <%= entityInstance %>Route: Routes = [ ]; @NgModule({ - imports: [ - RouterModule.forChild(<%= entityInstance %>Route), - <%= microservicePrefix %><%= entityAngularName %>Module, - ], + imports: [RouterModule.forChild(<%= entityInstance %>Route)], + exports: [RouterModule], }) export class <%= microservicePrefix %><%= entityAngularName %>RoutingModule {} diff --git a/generators/entity-client/templates/angular/src/main/webapp/app/entities/update/entity-management-update.component.ts.ejs b/generators/entity-client/templates/angular/src/main/webapp/app/entities/update/entity-management-update.component.ts.ejs index dae1a39312c3..ca69a2e04c5a 100644 --- a/generators/entity-client/templates/angular/src/main/webapp/app/entities/update/entity-management-update.component.ts.ejs +++ b/generators/entity-client/templates/angular/src/main/webapp/app/entities/update/entity-management-update.component.ts.ejs @@ -36,7 +36,7 @@ const hasValidationRule = fields.some(field => const hasRequiredRelationship = relationships.some(relationship => relationship.relationshipRequired); const isValidatorsRequired = hasValidationRule || hasRequiredRelationship; _%> -import { Component, OnInit<% if (fieldsContainImageBlob) { %>, ElementRef<% } %>, Optional } from '@angular/core'; +import { Component, OnInit<% if (fieldsContainImageBlob) { %>, ElementRef<% } %> } from '@angular/core'; import { HttpResponse } from '@angular/common/http'; import { FormBuilder,<%_ if (isValidatorsRequired) { _%> Validators<%_ } _%> } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; @@ -44,7 +44,6 @@ import { Observable } from 'rxjs'; <%_ if ( rxjsMapIsUsed ) { _%> import { map } from 'rxjs/operators'; <%_ } _%> -import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; <%_ if (fieldsContainInstant || fieldsContainZonedDateTime) { _%> import * as dayjs from 'dayjs'; import { DATE_TIME_FORMAT } from 'app/config/input.constants'; @@ -137,13 +136,9 @@ _%> <%_ } _%> protected activatedRoute: ActivatedRoute, private fb: FormBuilder, - @Optional() public activeModal?: NgbActiveModal, ) {} ngOnInit(): void { - if (this.activeModal) { - return; - } this.activatedRoute.data.subscribe(({ <%= entityInstance %> }) => { <%_ if (fieldsContainInstant || fieldsContainZonedDateTime) { _%> if (<%= entityInstance %>.<%= primaryKey.name %> == null) { @@ -233,11 +228,7 @@ _%> <%_ } _%> previousState(): void { - if (this.activeModal) { - this.activeModal.close(); - } else { - window.history.back(); - } + window.history.back(); } save(): void { diff --git a/test/needle-api/needle-client-angular.spec.js b/test/needle-api/needle-client-angular.spec.js index 47487b632406..ef853ad96fb8 100644 --- a/test/needle-api/needle-client-angular.spec.js +++ b/test/needle-api/needle-client-angular.spec.js @@ -179,7 +179,7 @@ describe('needle API Angular: JHipster client generator with blueprint', () => { ' {\n' + " path: 'entityUrl',\n" + " data: { pageTitle: 'entity.home.title' },\n" + - " loadChildren: () => import('./entityFolderName/route/entityFileName-routing.module').then(m => m.MicroserviceNameentityNameRoutingModule),\n" + + " loadChildren: () => import('./entityFolderName/entityFileName.module').then(m => m.MicroserviceNameentityNameModule),\n" + ' }' ); });