Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1935800

Browse files
Paging refactored
1 parent 47f91bb commit 1935800

File tree

4 files changed

+53
-64
lines changed

4 files changed

+53
-64
lines changed

‎src/AspnetRun.Web/src/app/core/core.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
1818
import { TabsModule } from 'ngx-bootstrap/tabs';
1919
import { RouterModule } from '@angular/router';
2020
import { CustomerDataService } from './services/customer-data.services';
21+
import { PageService } from './services/page.service';
2122
import { ToastrModule } from 'ngx-toastr';
2223
import { NgWizardModule, NgWizardConfig, THEME } from 'ng-wizard';
2324

@@ -61,6 +62,7 @@ const ngWizardConfig: NgWizardConfig = {
6162
AuthService,
6263
AuthGuardService,
6364
ValidationService,
65+
PageService,
6466
SpinnerService,
6567
{
6668
provide: HTTP_INTERCEPTORS,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Injectable } from '@angular/core';
2+
import { AngularGridInstance } from 'angular-slickgrid';
3+
4+
@Injectable()
5+
export class PageService {
6+
getPageArgs(angularGrid: AngularGridInstance): any {
7+
if (angularGrid) {
8+
var filteringOptions = angularGrid.backendService.options.filteringOptions;
9+
var sortingOptions = angularGrid.backendService.options.sortingOptions;
10+
var paginationOptions = angularGrid.backendService.getCurrentPagination();
11+
12+
return {
13+
pageIndex: paginationOptions ? paginationOptions.pageNumber : 1,
14+
pageSize: paginationOptions ? paginationOptions.pageSize : 10,
15+
filteringOptions: filteringOptions,
16+
sortingOptions: sortingOptions
17+
};
18+
}
19+
else {
20+
return {
21+
pageIndex: 1,
22+
pageSize: 10
23+
};
24+
}
25+
}
26+
}
Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Component, OnInit } from '@angular/core';
22
import { Router } from '@angular/router';
3+
import { Observable } from 'rxjs';
4+
import { map } from 'rxjs/operators';
35

46
import { AngularGridInstance, Column, GridOption, GraphqlService, GraphqlResult, Filters, Formatters, OnEventArgs, FieldType } from 'angular-slickgrid';
57

68
import { CategoryDataService } from 'src/app/core/services/category-data.service';
9+
import { PageService } from 'src/app/core/services/page.service';
710

811

912
const GRAPHQL_QUERY_DATASET_NAME = 'categories';
@@ -19,7 +22,7 @@ export class CategoryListComponent implements OnInit {
1922
gridOptions: GridOption;
2023
dataset = [];
2124

22-
constructor(private dataService: CategoryDataService, private router: Router) {
25+
constructor(private dataService: CategoryDataService, private router: Router,privatepageService: PageService) {
2326
}
2427

2528
ngOnInit(): void {
@@ -58,49 +61,25 @@ export class CategoryListComponent implements OnInit {
5861
this.angularGrid = angularGrid;
5962
}
6063

61-
getCategories(): Promise<GraphqlResult> {
62-
return new Promise((resolve) => {
63-
64-
var args: {};
65-
66-
if (this.angularGrid) {
67-
var filteringOptions = this.angularGrid.backendService.options.filteringOptions;
68-
var sortingOptions = this.angularGrid.backendService.options.sortingOptions;
69-
var paginationOptions = this.angularGrid.backendService.getCurrentPagination();
70-
71-
args = {
72-
pageIndex: paginationOptions.pageNumber,
73-
pageSize: paginationOptions.pageSize,
74-
filteringOptions: filteringOptions,
75-
sortingOptions: sortingOptions
76-
};
77-
}
78-
else {
79-
args = {
80-
pageIndex: 1,
81-
pageSize: 10
82-
};
83-
}
84-
85-
this.dataService.searchCategories(args)
86-
.toPromise()
87-
.then(
88-
page => {
89-
var result: GraphqlResult = {
90-
data: {
91-
[GRAPHQL_QUERY_DATASET_NAME]: {
92-
nodes: page.items,
93-
pageInfo: {
94-
hasNextPage: page.hasNextPage
95-
},
96-
totalCount: page.totalCount
97-
}
64+
getCategories(): Observable<GraphqlResult> {
65+
var args = this.pageService.getPageArgs(this.angularGrid);
66+
67+
return this.dataService.searchCategories(args)
68+
.pipe(map(
69+
page => {
70+
var result: GraphqlResult = {
71+
data: {
72+
[GRAPHQL_QUERY_DATASET_NAME]: {
73+
nodes: page.items,
74+
pageInfo: {
75+
hasNextPage: page.hasNextPage
76+
},
77+
totalCount: page.totalCount
9878
}
99-
};
79+
}
80+
};
10081

101-
resolve(result);
102-
}
103-
);
104-
});
82+
return result;
83+
}));
10584
}
10685
}

‎src/AspnetRun.Web/src/app/views/product/product-list/product-list.component.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { map } from 'rxjs/operators';
66
import { AngularGridInstance, Column, GridOption, GraphqlService, GraphqlResult, Filters, Formatters, OnEventArgs, FieldType } from 'angular-slickgrid';
77

88
import { ProductDataService } from 'src/app/core/services/product-data.service';
9+
import { PageService } from 'src/app/core/services/page.service';
910

1011

1112
const GRAPHQL_QUERY_DATASET_NAME = 'products';
@@ -21,7 +22,7 @@ export class ProductListComponent implements OnInit {
2122
gridOptions: GridOption;
2223
dataset = [];
2324

24-
constructor(private dataService: ProductDataService, private router: Router) {
25+
constructor(private dataService: ProductDataService, private router: Router,privatepageService: PageService) {
2526
}
2627

2728
ngOnInit(): void {
@@ -62,26 +63,7 @@ export class ProductListComponent implements OnInit {
6263
}
6364

6465
getProducts(): Observable<GraphqlResult> {
65-
var args: {};
66-
67-
if (this.angularGrid) {
68-
var filteringOptions = this.angularGrid.backendService.options.filteringOptions;
69-
var sortingOptions = this.angularGrid.backendService.options.sortingOptions;
70-
var paginationOptions = this.angularGrid.backendService.getCurrentPagination();
71-
72-
args = {
73-
pageIndex: paginationOptions ? paginationOptions.pageNumber : 1,
74-
pageSize: paginationOptions ? paginationOptions.pageSize : 10,
75-
filteringOptions: filteringOptions,
76-
sortingOptions: sortingOptions
77-
};
78-
}
79-
else {
80-
args = {
81-
pageIndex: 1,
82-
pageSize: 10
83-
};
84-
}
66+
var args = this.pageService.getPageArgs(this.angularGrid);
8567

8668
return this.dataService.searchProducts(args)
8769
.pipe(map(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /