Skip to content

Commit 485e085

Browse files
authored
Merge pull request #26 from netgrif/NAE-1612
[NAE-1612] Optimize Tree Case View performance with many children
2 parents 4ef7b12 + 2436384 commit 485e085

File tree

20 files changed

+137
-34
lines changed

20 files changed

+137
-34
lines changed

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* [Introduction](/)
22
* [Get Started](get_started.md)
33
* [Configuration](configuration/configuration.md)
4+
* [Tree case view](views/tree_case_view.md)
45
* Compodoc
56
* [Components](https://components.netgrif.com/compodoc/components)
67
* Typedoc

docs/views/tree_case_view.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Tree case view
2+
3+
##Configure case paging
4+
5+
By default, the Tree case view uses a page size of 50 cases when it loads the tree nodes.
6+
7+
If you want to configure this value you can do this by providing the `NAE_TREE_CASE_VIEW_CONFIGURATION` injection token.
8+
9+
If you provide this token directly in the Component that houses the Tree case view, you will configure the page size of this view only. By providing the token higher in the provider tree you will affect all Tree case views in the respective subtree. By providing the token at the application root, all Tree case views in the application will be affected by this configuration.
10+
11+
An example code snippet, for setting the page size to 100, note that other providers may be present in a real application:
12+
```typescript
13+
providers: [
14+
{provide: NAE_TREE_CASE_VIEW_CONFIGURATION, useValue: {pageSize: 100}}
15+
]
16+
```

projects/nae-example-app/src/app/doc/tree-view-example/tree-view-example.component.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
import {Component} from '@angular/core';
2-
import {CaseResourceService, Filter, FilterType,
3-
ProcessService, SimpleFilter, TreeCaseViewService, CreateCaseEventOutcome} from '@netgrif/components-core';
2+
import {
3+
CaseResourceService,
4+
ChangedFieldsService,
5+
CreateCaseEventOutcome,
6+
createSortParam,
7+
Filter,
8+
FilterType,
9+
NAE_TREE_CASE_VIEW_CONFIGURATION,
10+
PaginationParams,
11+
PaginationSort,
12+
ProcessService,
13+
SimpleFilter,
14+
TreeCaseViewService,
15+
} from '@netgrif/components-core';
416
import {HttpParams} from '@angular/common/http';
517

618
@Component({
719
selector: 'nae-app-tree-view-example',
820
templateUrl: './tree-view-example.component.html',
921
styleUrls: ['./tree-view-example.component.scss'],
10-
providers: [TreeCaseViewService]
22+
providers: [
23+
ChangedFieldsService,
24+
TreeCaseViewService,
25+
{provide: NAE_TREE_CASE_VIEW_CONFIGURATION, useValue: {pageSize: 100}}
26+
]
1127
})
1228
export class TreeViewExampleComponent {
1329

@@ -21,7 +37,7 @@ export class TreeViewExampleComponent {
2137
private _processService: ProcessService) {
2238
this.loading = true;
2339
let params: HttpParams = new HttpParams();
24-
params = params.set('sort', 'creationDateSortable,asc');
40+
params = params.set(PaginationParams.PAGE_SORT, createSortParam('creationDateSortable', PaginationSort.ASCENDING));
2541
this._caseResource.searchCases(
2642
new SimpleFilter('', FilterType.CASE, {process: {identifier: 'tree_test'}, query: '(title:root)'}), params)
2743
.subscribe(page => {

projects/netgrif-components-core/src/lib/groups/services/next-group.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {HttpParams} from '@angular/common/http';
66
import {map, switchMap} from 'rxjs/operators';
77
import {Case} from '../../resources/interface/case';
88
import {BehaviorSubject, Observable, of, Subscription} from 'rxjs';
9+
import {PaginationParams} from '../../utility/pagination/pagination-params';
910

1011
/**
1112
* This service allows access to information about the groups of the currently logged user.
@@ -37,7 +38,7 @@ export class NextGroupService implements OnDestroy {
3738
}
3839

3940
const params = new HttpParams();
40-
params.set('size', `${(user as any).nextGroups.length}`);
41+
params.set(PaginationParams.PAGE_SIZE, `${(user as any).nextGroups.length}`);
4142

4243
return this._caseResourceService.searchCases(SimpleFilter.fromCaseQuery({stringId: (user as any).nextGroups}), params)
4344
.pipe(

projects/netgrif-components-core/src/lib/resources/abstract-endpoint/abstract-resource.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {ResourceProvider} from '../resource-provider.service';
22
import {ConfigurationService} from '../../configuration/configuration.service';
33
import {Page} from '../interface/page';
44
import {Pagination} from '../interface/pagination';
5+
import {PaginationParams} from '../../utility/pagination/pagination-params';
56

67
/**
78
* The class that contains behavior common to all resource services.
@@ -69,7 +70,7 @@ export abstract class AbstractResourceService {
6970

7071
return {
7172
content: this.changeType<Array<T>>(r, propertiesParams),
72-
pagination: r.hasOwnProperty('page') ? r.page : defaultPage
73+
pagination: r.hasOwnProperty(PaginationParams.PAGE_NUMBER) ? r.page : defaultPage
7374
};
7475
}
7576

projects/netgrif-components-core/src/lib/user/services/user-list.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {HttpParams} from '@angular/common/http';
1111
import {MessageResource} from '../../resources/interface/message-resource';
1212
import {Page} from '../../resources/interface/page';
1313
import {UserResource} from '../../resources/interface/user-resource';
14+
import {PaginationParams} from '../../utility/pagination/pagination-params';
1415

1516
export interface UserListItem extends UserResource {
1617
selected: boolean;
@@ -249,9 +250,9 @@ export class UserListService implements OnDestroy {
249250
* @param page Page number that is requested. / Next page users list.
250251
*/
251252
private addPageParams(params: HttpParams, page?: number): HttpParams {
252-
params = params.set('size', this._pagination.size + '');
253+
params = params.set(PaginationParams.PAGE_SIZE, `${this._pagination.size}`);
253254
page = page !== null ? page : this._pagination.number;
254-
params = params.set('page', page + '');
255+
params = params.set(PaginationParams.PAGE_NUMBER, `${page}`);
255256
return params;
256257
}
257258

projects/netgrif-components-core/src/lib/utility/pagination/load-all-pages.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Pagination} from '../../resources/interface/pagination';
55
import {HttpParams} from '@angular/common/http';
66
import {concatMap, map} from 'rxjs/operators';
77
import {hasContent} from './page-has-content';
8+
import {PaginationParams} from './pagination-params';
89

910
/**
1011
* Loads all pages from the given endpoint and returns their content as one array
@@ -43,8 +44,8 @@ export function loadAllPages<T>(source: (filter: any, params: Params) => Observa
4344

4445
function paginationParams(basePagination: Pagination, pageNumber?: number): HttpParams {
4546
let params = new HttpParams();
46-
params = params.set('size', basePagination.size + '');
47-
params = params.set('page', (pageNumber !== undefined ? pageNumber : basePagination.number) + '');
47+
params = params.set(PaginationParams.PAGE_SIZE, `${basePagination.size}`);
48+
params = params.set(PaginationParams.PAGE_NUMBER, (pageNumber !== undefined ? pageNumber : basePagination.number) + '');
4849
return params;
4950
}
5051

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Constants for pagination configuration of HTTP requests.
3+
*/
4+
export enum PaginationParams {
5+
/**
6+
* Size of page - maximal number of elements per page.
7+
*/
8+
PAGE_SIZE = 'size',
9+
/**
10+
* Requested page index. 0 based.
11+
*/
12+
PAGE_NUMBER = 'page',
13+
/**
14+
* Sort configuration of the requested page. Use the {@link createSortParam} function to generate the value for this attribute.
15+
*/
16+
PAGE_SORT = 'sort'
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Constants for use with the
3+
*/
4+
export enum PaginationSort {
5+
ASCENDING = 'asc',
6+
DESCENDING = 'desc'
7+
}
8+
9+
/**
10+
* Creates the configuration string for use with the [PAGE_SORT]{@link PaginationParams#PAGE_SORT} configuration attribute
11+
* @param attribute the name of the attribute that should be used for sorting the results
12+
* @param direction the sorting direction
13+
*/
14+
export function createSortParam(attribute: string, direction: PaginationSort): string {
15+
return `${attribute},${direction}`;
16+
}

projects/netgrif-components-core/src/lib/utility/public-api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export * from './call-chain/call-chain.service';
77
export * from './call-chain/after-action';
88
export * from './pagination/page-has-content';
99
export * from './pagination/load-all-pages';
10+
export * from './pagination/pagination-params';
11+
export * from './pagination/pagination-sort';
1012
export * from './service/spinner-overlay.service';
1113
export * from './service/case-list-font-color.service';
1214
export * from './incrementing-counter';

0 commit comments

Comments
 (0)