Skip to content

Commit

Permalink
Merge pull request #13318 from kaidohallik/polish-angular-entity-module
Browse files Browse the repository at this point in the history
[angular] Polish entity modules and update component
  • Loading branch information
mshima authored Dec 17, 2020
2 parents 1dc93a5 + 73e8273 commit a6a0f94
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 29 deletions.
6 changes: 3 additions & 3 deletions generators/client/needle-api/needle-client-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ 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';
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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -233,11 +228,7 @@ _%>
<%_ } _%>

previousState(): void {
if (this.activeModal) {
this.activeModal.close();
} else {
window.history.back();
}
window.history.back();
}

save(): void {
Expand Down
2 changes: 1 addition & 1 deletion test/needle-api/needle-client-angular.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
' }'
);
});
Expand Down

0 comments on commit a6a0f94

Please sign in to comment.