X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Frest%2Frest-data-source.ts;h=57a2efb57bd9f061f9a11901fee78e73f2ab5422;hb=d592e0a9b2931c7c9cbedb27fb8efc9aaacad9bb;hp=5c205d280ce1ecaad453817a09f1d652ffacac44;hpb=91f6f169b1110eeae6ebf5c387f4204b0d07703c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/rest/rest-data-source.ts b/client/src/app/shared/rest/rest-data-source.ts index 5c205d280..57a2efb57 100644 --- a/client/src/app/shared/rest/rest-data-source.ts +++ b/client/src/app/shared/rest/rest-data-source.ts @@ -1,68 +1,32 @@ -import { Http, RequestOptionsArgs, URLSearchParams, Response } from '@angular/http' - -import { ServerDataSource } from 'ng2-smart-table' - -export class RestDataSource extends ServerDataSource { - private updateResponse: (input: any[]) => any[] - - constructor (http: Http, endpoint: string, updateResponse?: (input: any[]) => any[]) { - const options = { - endPoint: endpoint, - sortFieldKey: 'sort', - dataKey: 'data' - } - super(http, options) - - if (updateResponse) { - this.updateResponse = updateResponse - } - } - - protected extractDataFromResponse (res: Response) { - const json = res.json() - if (!json) return [] - let data = json.data - - if (this.updateResponse !== undefined) { - data = this.updateResponse(data) - } - - return data - } - - protected extractTotalFromResponse (res: Response) { - const rawData = res.json() - return rawData ? parseInt(rawData.total, 10) : 0 - } - - protected addSortRequestOptions (requestOptions: RequestOptionsArgs) { - const searchParams = requestOptions.params as URLSearchParams - - if (this.sortConf) { - this.sortConf.forEach((fieldConf) => { - const sortPrefix = fieldConf.direction === 'desc' ? '-' : '' - - searchParams.set(this.conf.sortFieldKey, sortPrefix + fieldConf.field) - }) - } - - return requestOptions - } - - protected addPagerRequestOptions (requestOptions: RequestOptionsArgs) { - const searchParams = requestOptions.params as URLSearchParams - - if (this.pagingConf && this.pagingConf['page'] && this.pagingConf['perPage']) { - const perPage = this.pagingConf['perPage'] - const page = this.pagingConf['page'] - - const start = (page - 1) * perPage - const count = perPage - - searchParams.set('start', start.toString()) - searchParams.set('count', count.toString()) - } - - return requestOptions - } +export class RestDataSource { + // protected addSortRequestOptions (requestOptions: RequestOptionsArgs) { + // const searchParams = requestOptions.params as URLSearchParams + // + // if (this.sortConf) { + // this.sortConf.forEach((fieldConf) => { + // const sortPrefix = fieldConf.direction === 'desc' ? '-' : '' + // + // searchParams.set(this.conf.sortFieldKey, sortPrefix + fieldConf.field) + // }) + // } + // + // return requestOptions + // } + // + // protected addPagerRequestOptions (requestOptions: RequestOptionsArgs) { + // const searchParams = requestOptions.params as URLSearchParams + // + // if (this.pagingConf && this.pagingConf['page'] && this.pagingConf['perPage']) { + // const perPage = this.pagingConf['perPage'] + // const page = this.pagingConf['page'] + // + // const start = (page - 1) * perPage + // const count = perPage + // + // searchParams.set('start', start.toString()) + // searchParams.set('count', count.toString()) + // } + // + // return requestOptions + // } }