Skip to content

Commit

Permalink
remove not necessary ActivatedRoute usages
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jan 17, 2024
1 parent bd2db11 commit 9918839
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { Component, inject, OnInit } from '@angular/core';
import { ActivatedRoute, RouterModule } from '@angular/router';
import { Component, Input } from '@angular/core';
import { RouterModule } from '@angular/router';
import SharedModule from 'app/shared/shared.module';

import { User } from '../user-management.model';
Expand All @@ -28,14 +28,6 @@ import { User } from '../user-management.model';
templateUrl: './user-management-detail.component.html',
imports: [RouterModule, SharedModule],
})
export default class UserManagementDetailComponent implements OnInit {
user: User | null = null;

private route = inject(ActivatedRoute);

ngOnInit(): void {
this.route.data.subscribe(({ user }) => {
this.user = user;
});
}
export default class UserManagementDetailComponent {
@Input() user: User | null = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { Component, inject, OnInit, signal } from '@angular/core';
import { Component, inject, Input, OnInit, signal } from '@angular/core';
import { FormGroup, FormControl, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';

import SharedModule from 'app/shared/shared.module';
<%_ if (enableTranslation) { _%>
Expand Down Expand Up @@ -48,6 +47,7 @@ export default class UserManagementUpdateComponent implements OnInit {
<%_ } _%>
authorities: string[] = [];
isSaving = signal(false);
@Input() user: IUser | null = null;

editForm = new FormGroup({
id: new FormControl(userTemplate.id),
Expand All @@ -74,16 +74,13 @@ export default class UserManagementUpdateComponent implements OnInit {
});

private userService = inject(UserManagementService);
private route = inject(ActivatedRoute);

ngOnInit(): void {
this.route.data.subscribe(({ user }) => {
if (user) {
this.editForm.reset(user);
} else {
this.editForm.reset(newUser);
}
});
if (this.user) {
this.editForm.reset(this.user);
} else {
this.editForm.reset(newUser);
}
this.userService.authorities().subscribe(authorities => (this.authorities = authorities));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { Component, inject, Input } from '@angular/core';
import { ActivatedRoute, RouterModule } from '@angular/router';
import { Component, <% if (anyFieldIsBlobDerived) { %>inject, <% } %>Input } from '@angular/core';
import { RouterModule } from '@angular/router';

import SharedModule from 'app/shared/shared.module';
import { DurationPipe, FormatMediumDatetimePipe, FormatMediumDatePipe } from 'app/shared/date';
Expand All @@ -38,7 +38,6 @@ export class <%= entityAngularName %>DetailComponent {
<%_ if (anyFieldIsBlobDerived) { _%>
protected dataUtils = inject(DataUtils);
<%_ } _%>
protected activatedRoute = inject(ActivatedRoute);

<%_ if (anyFieldIsBlobDerived) { _%>
byteSize(base64String: string): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
.map(relationships => relationships.filter(rel => rel.persistableRelationship))
.filter(relationships => relationships.length > 0);
_%>
import { Component, inject, OnInit<% if (anyFieldHasImageContentType) { %>, ElementRef<% } %> } from '@angular/core';
import { Component, inject, Input, OnInit<% if (anyFieldHasImageContentType) { %>, ElementRef<% } %> } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { finalize<% if (relationships.some(rel => rel.persistableRelationship)) { %>, map<% } %> } from 'rxjs/operators';

Expand Down Expand Up @@ -72,7 +71,7 @@ import { <%- importedType %> } from '<%- importedPath %>';
})
export class <%= entityAngularName %>UpdateComponent implements OnInit {
isSaving = false;
<%= entityInstance %>: I<%= entityAngularName %> | null = null;
@Input() <%= entityInstance %>: I<%= entityAngularName %> | null = null;
<%_ enumImports.forEach( (importedPath, importedType) => { _%>
<%- this._.lowerFirst(importedType) %>Values = Object.keys(<%- importedType %>);
<%_ }); _%>
Expand Down Expand Up @@ -109,7 +108,6 @@ _%>
<%_ if (anyFieldHasImageContentType) { _%>
protected elementRef = inject(ElementRef);
<%_ } _%>
protected activatedRoute = inject(ActivatedRoute);

// eslint-disable-next-line @typescript-eslint/member-ordering
editForm: <%= entityAngularName %>FormGroup = this.<%= entityInstance %>FormService.create<%= entityAngularName %>FormGroup();
Expand All @@ -123,16 +121,12 @@ _%>
<%_ } _%>

ngOnInit(): void {
this.activatedRoute.data.subscribe(({ <%= entityInstance %> }) => {
this.<%= entityInstance %> = <%= entityInstance %>;
if (<%= entityInstance %>) {
this.updateForm(<%= entityInstance %>);
}

if (this.<%= entityInstance %>) {
this.updateForm(this.<%= entityInstance %>);
}
<%_ if (relationships.filter(rel => rel.persistableRelationship && !rel.otherEntityIsEmbedded).length > 0) { _%>
this.loadRelationshipsOptions();
this.loadRelationshipsOptions();
<%_ } _%>
});
}

<%_ if (anyFieldIsBlobDerived) { _%>
Expand Down

0 comments on commit 9918839

Please sign in to comment.