Skip to content

Commit cb8a0bf

Browse files
authored
angular: convert more fields to signal (#31727)
1 parent 240809d commit cb8a0bf

File tree

4 files changed

+30
-44
lines changed

4 files changed

+30
-44
lines changed

generators/angular/templates/src/main/webapp/app/admin/user-management/list/user-management.html.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@
137137
138138
<div>
139139
<div class="d-flex justify-content-center">
140-
<<%= jhiPrefixDashed %>-item-count [params]="{ page, totalItems: totalItems(), itemsPerPage }" />
140+
<<%= jhiPrefixDashed %>-item-count [params]="{ page: page(), totalItems: totalItems(), itemsPerPage: itemsPerPage() }" />
141141
</div>
142142
143143
<div class="d-flex justify-content-center">
144144
<ngb-pagination
145145
[collectionSize]="totalItems()"
146146
[(page)]="page"
147-
[pageSize]="itemsPerPage"
147+
[pageSize]="itemsPerPage()"
148148
[maxSize]="5"
149149
[rotate]="true"
150150
[boundaryLinks]="true"

generators/angular/templates/src/main/webapp/app/admin/user-management/list/user-management.ts.ejs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ export default class UserManagement implements OnInit {
7272
isLoading = signal(false);
7373
<%_ if (!databaseTypeCassandra) { _%>
7474
totalItems = signal(0);
75-
itemsPerPage = ITEMS_PER_PAGE;
76-
page!: number;
75+
itemsPerPage = signal(ITEMS_PER_PAGE);
76+
page = signal(0);
7777
sortState = sortStateSignal({});
7878
<%_ } _%>
7979

@@ -116,8 +116,8 @@ export default class UserManagement implements OnInit {
116116
this.isLoading.set(true);
117117
this.userService
118118
.query(<% if (!databaseTypeCassandra) { %>{
119-
page: this.page - 1,
120-
size: this.itemsPerPage,
119+
page: this.page() - 1,
120+
size: this.itemsPerPage(),
121121
sort: this.sortService.buildSortParam(this.sortState(), 'id'),
122122
}<% } %>)
123123
.subscribe({
@@ -134,7 +134,7 @@ export default class UserManagement implements OnInit {
134134
this.router.navigate(['./'], {
135135
relativeTo: this.activatedRoute.parent,
136136
queryParams: {
137-
page: this.page,
137+
page: this.page(),
138138
sort: this.sortService.buildSortParam(sortState ?? this.sortState()),
139139
},
140140
});
@@ -143,7 +143,7 @@ export default class UserManagement implements OnInit {
143143
private handleNavigation(): void {
144144
combineLatest([this.activatedRoute.data, this.activatedRoute.queryParamMap]).subscribe(([data, params]) => {
145145
const page = params.get('page');
146-
this.page = +(page ?? 1);
146+
this.page.set(+(page ?? 1));
147147
this.sortState.set(this.sortService.parseSortParam(params.get(SORT) ?? data.defaultSort));
148148
this.loadAll();
149149
});

generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.html.ejs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
<label class="visually-hidden" for="currentSearch">__jhiTranslateTag__('<%- i18nKeyPrefix %>.home.search')</label>
4747
<input type="text" class="form-control" [(ngModel)]="currentSearch" id="currentSearch" name="currentSearch" placeholder="__jhiTranslatePipe__('<%= i18nKeyPrefix %>.home.search')">
4848
49-
<button class="btn btn-info" (click)="search(currentSearch)">
49+
<button class="btn btn-info" (click)="search(currentSearch())">
5050
<fa-icon icon="search" />
5151
</button>
5252
53-
@if (currentSearch) {
53+
@if (currentSearch()) {
5454
<button class="btn btn-danger" (click)="search('')">
5555
<fa-icon icon="trash-alt" />
5656
</button>
@@ -226,11 +226,11 @@ _%>
226226
@if (<%= entityInstancePlural %>().length > 0) {
227227
<div>
228228
<div class="d-flex justify-content-center">
229-
<<%= jhiPrefixDashed %>-item-count [params]="{ page, totalItems, itemsPerPage }" />
229+
<<%= jhiPrefixDashed %>-item-count [params]="{ page: page(), totalItems: totalItems(), itemsPerPage: itemsPerPage() }" />
230230
</div>
231231
232232
<div class="d-flex justify-content-center">
233-
<ngb-pagination [collectionSize]="totalItems" [page]="page" [pageSize]="itemsPerPage" [maxSize]="5" [rotate]="true" [boundaryLinks]="true" (pageChange)="navigateToPage($event)" />
233+
<ngb-pagination [collectionSize]="totalItems()" [page]="page()" [pageSize]="itemsPerPage()" [maxSize]="5" [rotate]="true" [boundaryLinks]="true" (pageChange)="navigateToPage($event)" />
234234
</div>
235235
</div>
236236
}

generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.ts.ejs

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,18 @@ export class <%= componentName %> implements OnInit {
141141

142142
sortState = sortStateSignal({});
143143
<%_ if (searchEngineAny) { _%>
144-
currentSearch = '';
144+
currentSearch = signal('');
145145
<%_ } _%>
146146
<%_ if (jpaMetamodelFiltering && paginationPagination) { _%>
147147
filters: IFilterOptions = new FilterOptions();
148148
<%_ } _%>
149149

150150
<%_ if (paginationPagination) { _%>
151-
itemsPerPage = ITEMS_PER_PAGE;
152-
totalItems = 0;
153-
page = 1;
151+
itemsPerPage = signal(ITEMS_PER_PAGE);
152+
totalItems = signal(0);
153+
page = signal(1);
154154
<%_ } else if (paginationInfiniteScroll) { _%>
155-
itemsPerPage = ITEMS_PER_PAGE;
155+
itemsPerPage = signal(ITEMS_PER_PAGE);
156156
links: WritableSignal<Record<string, undefined | Record<string, string | undefined>>> = signal({});
157157
hasMorePage = computed(() => !!this.links().next);
158158
isFirstFetch = computed(() => Object.keys(this.links()).length === 0);
@@ -213,9 +213,9 @@ export class <%= componentName %> implements OnInit {
213213
<%_ if (searchEngineAny) { _%>
214214
search(query: string): void {
215215
<%_ if (paginationPagination) { _%>
216-
this.page = 1;
216+
this.page.set(1);
217217
<%_ } _%>
218-
this.currentSearch = query;
218+
this.currentSearch.set(query);
219219
<%_ if (notSortableFieldsAfterSearch) { _%>
220220
const { predicate } = this.sortState();
221221
if (query && predicate && <%= componentName %>.NOT_SORTABLE_FIELDS_AFTER_SEARCH.includes(predicate)) {
@@ -263,27 +263,27 @@ export class <%= componentName %> implements OnInit {
263263
}
264264

265265
navigateToWithComponentValues(event: SortState): void {
266-
this.handleNavigation(<% if (paginationPagination) { %>this.page, <% } %>event<% if (jpaMetamodelFiltering && paginationPagination) { %>, this.filters.filterOptions<% } %><% if (searchEngineAny) { %>, this.currentSearch<% } %>);
266+
this.handleNavigation(<% if (paginationPagination) { %>this.page(), <% } %>event<% if (jpaMetamodelFiltering && paginationPagination) { %>, this.filters.filterOptions<% } %><% if (searchEngineAny) { %>, this.currentSearch()<% } %>);
267267
}
268268

269269
<%_ if (paginationPagination) { _%>
270270
navigateToPage(page: number): void {
271-
this.handleNavigation(page, this.sortState()<% if (jpaMetamodelFiltering && paginationPagination) { %>, this.filters.filterOptions<% } %><% if (searchEngineAny) { %>, this.currentSearch<% } %>);
271+
this.handleNavigation(page, this.sortState()<% if (jpaMetamodelFiltering && paginationPagination) { %>, this.filters.filterOptions<% } %><% if (searchEngineAny) { %>, this.currentSearch()<% } %>);
272272
}
273273
274274
<%_ } _%>
275275
protected fillComponentAttributeFromRoute(params: ParamMap, data: Data): void {
276276
<%_ if (paginationPagination) { _%>
277277
const page = params.get(PAGE_HEADER);
278-
this.page = +(page ?? 1);
278+
this.page.set(+ (page ?? 1));
279279
<%_ } _%>
280280
this.sortState.set(this.sortService.parseSortParam(params.get(SORT) ?? data[DEFAULT_SORT_DATA]));
281281
<%_ if (jpaMetamodelFiltering && paginationPagination) { _%>
282282
this.filters.initializeFromParams(params);
283283
<%_ } _%>
284284
<%_ if (searchEngineAny) { _%>
285285
if (params.has('search') && params.get('search') !== '') {
286-
this.currentSearch = params.get('search') as string;
286+
this.currentSearch.set(params.get('search') as string);
287287
<%_ if (notSortableFieldsAfterSearch) { _%>
288288
const { predicate } = this.sortState();
289289
if (predicate && <%= componentName %>.NOT_SORTABLE_FIELDS_AFTER_SEARCH.includes(predicate)) {
@@ -338,7 +338,7 @@ export class <%= componentName %> implements OnInit {
338338
<%_ if (!paginationNo) { _%>
339339
protected fillComponentAttributesFromResponseHeader(headers: HttpHeaders): void {
340340
<%_ if (paginationPagination) { _%>
341-
this.totalItems = Number(headers.get(TOTAL_COUNT_RESPONSE_HEADER));
341+
this.totalItems.set(Number(headers.get(TOTAL_COUNT_RESPONSE_HEADER)));
342342
<%_ } else if (paginationInfiniteScroll) { _%>
343343
const linkHeader = headers.get('link');
344344
if (linkHeader) {
@@ -351,43 +351,29 @@ export class <%= componentName %> implements OnInit {
351351
352352
<%_ } _%>
353353
protected queryBackend(): Observable<EntityArrayResponseType> {
354-
<%_ if (paginationPagination || searchEngineAny) { _%>
355-
const {
356-
<%_ if (paginationPagination) { _%>
357-
page,
358-
<%_ } _%>
359-
<%_ if (jpaMetamodelFiltering && paginationPagination) { _%>
360-
filters,
361-
<%_ } _%>
362-
<%_ if (searchEngineAny) { _%>
363-
currentSearch,
364-
<%_ } _%>
365-
} = this;
366-
<%_ } _%>
367-
368354
this.isLoading.set(true);
369355
<%_ if (paginationPagination) { _%>
370-
const pageToLoad: number = page;
356+
const pageToLoad: number = this.page();
371357
<%_ } _%>
372358
const queryObject<% if ((jpaMetamodelFiltering && paginationPagination) || searchEngine) { %>: any <% } %> = {
373359
<%_ if (paginationPagination) { _%>
374360
page: pageToLoad - 1,
375361
<%_ } _%>
376362
<%_ if (!paginationNo) { _%>
377-
size: this.itemsPerPage,
363+
size: this.itemsPerPage(),
378364
<%_ } _%>
379365
<%_ if(implementsEagerLoadApis || containsBagRelationships) { _%>
380366
eagerload: true,
381367
<%_ } _%>
382368
<%_ if (searchEngineAny) { _%>
383-
query: currentSearch,
369+
query: this.currentSearch(),
384370
<%_ } _%>
385371
<%_ if (!paginationInfiniteScroll) { _%>
386372
sort: this.sortService.buildSortParam(this.sortState()),
387373
<%_ } _%>
388374
};
389375
<%_ if (jpaMetamodelFiltering && paginationPagination) { _%>
390-
for (const filterOption of filters.filterOptions) {
376+
for (const filterOption of this.filters.filterOptions) {
391377
queryObject[filterOption.name] = filterOption.values;
392378
}
393379
<%_ } _%>
@@ -400,7 +386,7 @@ export class <%= componentName %> implements OnInit {
400386
401387
<%_ } _%>
402388
<%_ if (searchEngineAny) { _%>
403-
if (this.currentSearch && this.currentSearch !== '') {
389+
if (this.currentSearch() && this.currentSearch() !== '') {
404390
return this.<%= entityInstance %>Service.search(queryObject)
405391
.pipe(
406392
finalize(() => this.isLoading.set(false))
@@ -427,7 +413,7 @@ export class <%= componentName %> implements OnInit {
427413
<%_ } _%>
428414
<%_ if (paginationPagination) { _%>
429415
page,
430-
size: this.itemsPerPage,
416+
size: this.itemsPerPage(),
431417
<%_ } _%>
432418
sort: this.sortService.buildSortParam(sortState),
433419
};

0 commit comments

Comments
 (0)