From 08ebb628e04f83cf8aaebc19cf0bcacd080720e8 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Mon, 27 Jun 2022 11:43:50 -0300 Subject: [PATCH] angular: when creating, routing should resolve to null --- .../liquibase/fake-data/table_entity.csv.ejs | 4 +- ...gement-routing-resolve.service.spec.ts.ejs | 6 +- ...-management-routing-resolve.service.ts.ejs | 10 ++-- ...ntity-management-update.component.html.ejs | 2 +- ...ty-management-update.component.spec.ts.ejs | 8 +-- .../entity-management-update.component.ts.ejs | 60 +++++++++---------- 6 files changed, 42 insertions(+), 48 deletions(-) diff --git a/generators/database-changelog-liquibase/templates/src/main/resources/config/liquibase/fake-data/table_entity.csv.ejs b/generators/database-changelog-liquibase/templates/src/main/resources/config/liquibase/fake-data/table_entity.csv.ejs index dbf9fa35a602..84cd915a8abe 100644 --- a/generators/database-changelog-liquibase/templates/src/main/resources/config/liquibase/fake-data/table_entity.csv.ejs +++ b/generators/database-changelog-liquibase/templates/src/main/resources/config/liquibase/fake-data/table_entity.csv.ejs @@ -29,14 +29,14 @@ for (field of fieldsToGenerate) { } } for (relationship of relationships) { - const relationshipType = relationship.relationshipType + const { relationshipType, joinColumnNames } = relationship; if ( (relationshipType === "many-to-one" || (relationshipType === "one-to-one" && relationship.ownerSide === true && (relationship.id == null || relationship.id === false)) ) && (relationship.relationshipValidate === true && relationship.relationshipRequired) ) { - header.push(getColumnName(relationship.relationshipName) + "_id"); + header.push(joinColumnNames[0]); } } table.push(header); diff --git a/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing-resolve.service.spec.ts.ejs b/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing-resolve.service.spec.ts.ejs index cde62a7d1f79..616f73f5e47a 100644 --- a/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing-resolve.service.spec.ts.ejs +++ b/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing-resolve.service.spec.ts.ejs @@ -36,7 +36,7 @@ describe('<%= entityAngularName %> routing resolve service', () => { let mockActivatedRouteSnapshot: ActivatedRouteSnapshot; let routingResolveService: <%= entityAngularName %>RoutingResolveService; let service: <%= entityAngularName %>Service; - let result<%= entityAngularName %>: I<%= entityAngularName %> | undefined; + let result<%= entityAngularName %>: I<%= entityAngularName %> | null | undefined; beforeEach(() => { TestBed.configureTestingModule({ @@ -76,7 +76,7 @@ describe('<%= entityAngularName %> routing resolve service', () => { expect(result<%= entityAngularName %>).toEqual({ <%= primaryKey.name %>: <%- tsKeyId %> }); }); - it('should return new I<%= entityAngularName %> if id is not provided', () => { + it('should return null if id is not provided', () => { // GIVEN service.find = jest.fn(); mockActivatedRouteSnapshot.params = {}; @@ -88,7 +88,7 @@ describe('<%= entityAngularName %> routing resolve service', () => { // THEN expect(service.find).not.toBeCalled(); - expect(result<%= entityAngularName %>).toEqual(new <%= entityAngularName %>()); + expect(result<%= entityAngularName %>).toEqual(null); }); it('should route to 404 page if data not found in server', () => { diff --git a/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing-resolve.service.ts.ejs b/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing-resolve.service.ts.ejs index 5b4125affcab..9515ce96b1ca 100644 --- a/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing-resolve.service.ts.ejs +++ b/generators/entity-client/templates/angular/src/main/webapp/app/entities/route/entity-management-routing-resolve.service.ts.ejs @@ -22,18 +22,18 @@ import { Resolve, ActivatedRouteSnapshot, Router } from '@angular/router'; import { Observable, of, EMPTY } from 'rxjs'; import { mergeMap } from 'rxjs/operators'; -import { I<%= entityAngularName %>, <%= entityAngularName %> } from '../<%= entityFileName %>.model'; +import { I<%= entityAngularName %> } from '../<%= entityFileName %>.model'; import { <%= entityAngularName %>Service } from '../service/<%= entityFileName %>.service'; @Injectable({ providedIn: 'root' }) -export class <%= entityAngularName %>RoutingResolveService implements Resolve> { +export class <%= entityAngularName %>RoutingResolveService implements Resolve | null> { constructor(protected service: <%= entityAngularName %>Service, protected router: Router) {} - resolve(route: ActivatedRouteSnapshot): Observable> | Observable { + resolve(route: ActivatedRouteSnapshot): Observable | null | never> { const id = route.params['<%= primaryKey.name %>']; if (id) { return this.service.find(id).pipe( - mergeMap((<%= entityInstance %>: HttpResponse<<%= entityAngularName %>>) => { + mergeMap((<%= entityInstance %>: HttpResponse>) => { if (<%= entityInstance %>.body) { return of(<%= entityInstance %>.body); } else { @@ -43,6 +43,6 @@ export class <%= entityAngularName %>RoutingResolveService implements Resolve()); + return of(null); } } diff --git a/generators/entity-client/templates/angular/src/main/webapp/app/entities/update/entity-management-update.component.html.ejs b/generators/entity-client/templates/angular/src/main/webapp/app/entities/update/entity-management-update.component.html.ejs index b85f13d96f38..ce441fbd1475 100644 --- a/generators/entity-client/templates/angular/src/main/webapp/app/entities/update/entity-management-update.component.html.ejs +++ b/generators/entity-client/templates/angular/src/main/webapp/app/entities/update/entity-management-update.component.html.ejs @@ -44,7 +44,7 @@ } _%> -
[hidden]="editForm.get('<%= primaryKey.name %>')!.value == null"<% } %>> +
*ngIf="editForm.get('<%= field.fieldName %>')"<% } %>> <%_ if (field.fieldIsEnum) { _%>