Commit a619dba62f752fd8a626615d6c62917bd237aede

Authored by Yarik
1 parent 41b1d6bc

HZ

src/models/statement.base.ts
@@ -27,23 +27,23 @@ export abstract class StatementBase implements AfterViewInit, OnInit { @@ -27,23 +27,23 @@ export abstract class StatementBase implements AfterViewInit, OnInit {
27 27
28 ngAfterViewInit(): void { 28 ngAfterViewInit(): void {
29 this.gridOptions.api.setDatasource(this.setRowData()); 29 this.gridOptions.api.setDatasource(this.setRowData());
30 - this.data = this.paramsSubject  
31 - .switchMap((params: IGetRowsParams) => {  
32 - return this.service.getData(params);  
33 - }).catch((error: any) => {  
34 - console.log(error);  
35 - return Observable.of<any[]>([]);  
36 - });  
37 - this.data.subscribe((data: any[]) => {  
38 - if (!data.length) {  
39 - data = [this.createModel()];  
40 - }  
41 - let lastRow: number = -1;  
42 - if (data.length < (this.params.endRow - this.params.startRow) && !this.isNew) {  
43 - lastRow = data.length;  
44 - }  
45 - this.params.successCallback(data, lastRow);  
46 - }); 30 + // this.data = this.paramsSubject
  31 + // .switchMap((params: IGetRowsParams) => {
  32 + // return this.service.getData(params);
  33 + // }).catch((error: any) => {
  34 + // console.log(error);
  35 + // return Observable.of<any[]>([]);
  36 + // });
  37 + // this.data.subscribe((data: any[]) => {
  38 + // if (!data.length) {
  39 + // data = [this.createModel()];
  40 + // }
  41 + // let lastRow: number = -1;
  42 + // if (data.length < (this.params.endRow - this.params.startRow) && !this.isNew) {
  43 + // lastRow = data.length;
  44 + // }
  45 + // this.params.successCallback(data, lastRow);
  46 + // });
47 } 47 }
48 48
49 enableLoader(): void { 49 enableLoader(): void {
@@ -77,8 +77,6 @@ export abstract class StatementBase implements AfterViewInit, OnInit { @@ -77,8 +77,6 @@ export abstract class StatementBase implements AfterViewInit, OnInit {
77 this.showGrid = true; 77 this.showGrid = true;
78 this.gridOptions.rowModelType = 'virtual'; 78 this.gridOptions.rowModelType = 'virtual';
79 this.gridOptions.paginationPageSize = 10; 79 this.gridOptions.paginationPageSize = 10;
80 - this.gridOptions.paginationOverflowSize = 2;  
81 - this.gridOptions.maxPagesInCache = 2;  
82 this.gridOptions.getRowNodeId = function(item) { 80 this.gridOptions.getRowNodeId = function(item) {
83 return item.id; 81 return item.id;
84 }; 82 };
@@ -117,17 +115,8 @@ export abstract class StatementBase implements AfterViewInit, OnInit { @@ -117,17 +115,8 @@ export abstract class StatementBase implements AfterViewInit, OnInit {
117 rowCount: null, 115 rowCount: null,
118 getRows: (params: IGetRowsParams) => { 116 getRows: (params: IGetRowsParams) => {
119 this.params = params; 117 this.params = params;
120 - this.paramsSubject.next(params);  
121 - // this.service.getData(params).subscribe((data: any[]) => {  
122 - // if (!data.length) {  
123 - // data = [this.createModel()];  
124 - // }  
125 - // let lastRow: number = -1;  
126 - // if (data.length <= params.endRow) {  
127 - // lastRow = data.length;  
128 - // }  
129 - // params.successCallback(data, lastRow);  
130 - // }); 118 + // this.paramsSubject.next(params);
  119 + this.service.getData(params);
131 }, 120 },
132 }; 121 };
133 return dataSource; 122 return dataSource;
src/services/statement.base.service.ts
@@ -11,36 +11,55 @@ export abstract class StatementBaseService { @@ -11,36 +11,55 @@ export abstract class StatementBaseService {
11 11
12 constructor(protected http: Http) { } 12 constructor(protected http: Http) { }
13 13
14 - // getData2(from: number = 0, to: number = 100, sort: string = null): Promise<any[]> {  
15 - // let url: string = this.url;  
16 - // url += '?from=' + from + '&to=' + to;  
17 - // if (sort) { 14 + getData(params: IGetRowsParams): Promise<any[]> {
  15 + let sort: string = null;
  16 + if (params.sortModel.length) {
  17 + sort = this.parseSort(params.sortModel[0]);
  18 + }
  19 + let url: string = this.url;
  20 + url += '?from=' + params.startRow + '&perPage=' + (params.endRow - params.startRow);
  21 + if (sort) {
  22 + url += '&sort=' + sort;
  23 + }
  24 + let filter: string = this.parseFilter(params.filterModel);
  25 + if (filter) {
  26 + url += '&filter=' + filter;
  27 + }
  28 + return this.http.get(url)
  29 + .toPromise()
  30 + .then((response: Response) => {
  31 + let data: any[] = this.parseModels(response.json());
  32 + if (!data.length) {
  33 + data = [this.createModel()];
  34 + }
  35 + let lastRow: number = -1;
  36 + if (data.length < (params.endRow - params.startRow)) {
  37 + lastRow = data.length;
  38 + }
  39 + params.successCallback(data, lastRow);
  40 + return data;
  41 + })
  42 + .catch(this.handleError);
  43 + }
  44 +
  45 + // getData(params: IGetRowsParams): Observable<any[]> {
  46 + // let sort: string = null;
  47 + // if (params.sortModel.length) {
  48 + // sort = this.parseSort(params.sortModel[0]);
  49 + // }
  50 + // let url: string = this.url;
  51 + // url += '?from=' + params.startRow + '&perPage=' + (params.endRow - params.startRow);
  52 + // if (sort) {
18 // url += '&sort=' + sort; 53 // url += '&sort=' + sort;
19 // } 54 // }
20 - // return this.http.get(url)  
21 - // .toPromise()  
22 - // .then((response: Response) => this.parseModels(response.json()))  
23 - // .catch(this.handleError); 55 + // let filter: string = this.parseFilter(params.filterModel);
  56 + // if (filter) {
  57 + // url += '&filter=' + filter;
  58 + // }
  59 + // return this.http.get(url)
  60 + // .map((response: Response) => this.parseModels(response.json()));
24 // } 61 // }
25 62
26 - getData(params: IGetRowsParams): Observable<any[]> {  
27 - let sort: string = null;  
28 - if (params.sortModel.length) {  
29 - sort = this.parseSort(params.sortModel[0]);  
30 - }  
31 - let url: string = this.url;  
32 - url += '?from=' + params.startRow + '&perPage=' + (params.endRow - params.startRow);  
33 - if (sort) {  
34 - url += '&sort=' + sort;  
35 - }  
36 - let filter: string = this.parseFilter(params.filterModel);  
37 - if (filter) {  
38 - url += '&filter=' + filter;  
39 - }  
40 - return this.http.get(url)  
41 - .map((response: Response) => this.parseModels(response.json()));  
42 - }  
43 -  
44 update(id: number, data: string): Promise<any> { 63 update(id: number, data: string): Promise<any> {
45 return this.http.post(this.url + '/update?id=' + id, data, { headers: this.headers }) 64 return this.http.post(this.url + '/update?id=' + id, data, { headers: this.headers })
46 .toPromise() 65 .toPromise()