From df98563e2104b82b119c00a3cd83cd0dc1242d25 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jun 2017 14:32:15 +0200 Subject: Use typescript standard and lint all files --- client/src/app/shared/rest/index.ts | 8 +-- client/src/app/shared/rest/rest-data-source.ts | 60 +++++++++++----------- .../src/app/shared/rest/rest-extractor.service.ts | 48 ++++++++--------- client/src/app/shared/rest/rest-pagination.ts | 8 +-- client/src/app/shared/rest/rest.service.ts | 22 ++++---- 5 files changed, 73 insertions(+), 73 deletions(-) (limited to 'client/src/app/shared/rest') diff --git a/client/src/app/shared/rest/index.ts b/client/src/app/shared/rest/index.ts index 3cb123c3b..e0be155cf 100644 --- a/client/src/app/shared/rest/index.ts +++ b/client/src/app/shared/rest/index.ts @@ -1,4 +1,4 @@ -export * from './rest-data-source'; -export * from './rest-extractor.service'; -export * from './rest-pagination'; -export * from './rest.service'; +export * from './rest-data-source' +export * from './rest-extractor.service' +export * from './rest-pagination' +export * from './rest.service' diff --git a/client/src/app/shared/rest/rest-data-source.ts b/client/src/app/shared/rest/rest-data-source.ts index 1def38c73..2ef5d38da 100644 --- a/client/src/app/shared/rest/rest-data-source.ts +++ b/client/src/app/shared/rest/rest-data-source.ts @@ -1,51 +1,51 @@ -import { Http, RequestOptionsArgs, URLSearchParams, } from '@angular/http'; +import { Http, RequestOptionsArgs, URLSearchParams, Response } from '@angular/http' -import { ServerDataSource } from 'ng2-smart-table'; +import { ServerDataSource } from 'ng2-smart-table' export class RestDataSource extends ServerDataSource { - constructor(http: Http, endpoint: string) { - const options = { - endPoint: endpoint, - sortFieldKey: 'sort', - dataKey: 'data' - }; - - super(http, options); - } - - protected extractTotalFromResponse(res) { - const rawData = res.json(); - return rawData ? parseInt(rawData.total) : 0; + constructor (http: Http, endpoint: string) { + const options = { + endPoint: endpoint, + sortFieldKey: 'sort', + dataKey: 'data' + } + + super(http, options) + } + + protected extractTotalFromResponse (res: Response) { + const rawData = res.json() + return rawData ? parseInt(rawData.total, 10) : 0 } - protected addSortRequestOptions(requestOptions: RequestOptionsArgs) { - let searchParams: URLSearchParams = requestOptions.search; + protected addSortRequestOptions (requestOptions: RequestOptionsArgs) { + const searchParams = requestOptions.search as URLSearchParams if (this.sortConf) { this.sortConf.forEach((fieldConf) => { - const sortPrefix = fieldConf.direction === 'desc' ? '-' : ''; + const sortPrefix = fieldConf.direction === 'desc' ? '-' : '' - searchParams.set(this.conf.sortFieldKey, sortPrefix + fieldConf.field); - }); + searchParams.set(this.conf.sortFieldKey, sortPrefix + fieldConf.field) + }) } - return requestOptions; + return requestOptions } - protected addPagerRequestOptions(requestOptions: RequestOptionsArgs) { - let searchParams: URLSearchParams = requestOptions.search; + protected addPagerRequestOptions (requestOptions: RequestOptionsArgs) { + const searchParams = requestOptions.search as URLSearchParams if (this.pagingConf && this.pagingConf['page'] && this.pagingConf['perPage']) { - const perPage = this.pagingConf['perPage']; - const page = this.pagingConf['page']; + const perPage = this.pagingConf['perPage'] + const page = this.pagingConf['page'] - const start = (page - 1) * perPage; - const count = perPage; + const start = (page - 1) * perPage + const count = perPage - searchParams.set('start', start.toString()); - searchParams.set('count', count.toString()); + searchParams.set('start', start.toString()) + searchParams.set('count', count.toString()) } - return requestOptions; + return requestOptions } } diff --git a/client/src/app/shared/rest/rest-extractor.service.ts b/client/src/app/shared/rest/rest-extractor.service.ts index fcb1598f4..f6a818ec8 100644 --- a/client/src/app/shared/rest/rest-extractor.service.ts +++ b/client/src/app/shared/rest/rest-extractor.service.ts @@ -1,52 +1,52 @@ -import { Injectable } from '@angular/core'; -import { Response } from '@angular/http'; -import { Observable } from 'rxjs/Observable'; +import { Injectable } from '@angular/core' +import { Response } from '@angular/http' +import { Observable } from 'rxjs/Observable' export interface ResultList { - data: any[]; - total: number; + data: any[] + total: number } @Injectable() export class RestExtractor { - constructor () { ; } - - extractDataBool(res: Response) { - return true; + extractDataBool (res: Response) { + return true } - extractDataList(res: Response) { - const body = res.json(); + extractDataList (res: Response) { + const body = res.json() const ret: ResultList = { data: body.data, total: body.total - }; + } - return ret; + return ret } - extractDataGet(res: Response) { - return res.json(); + extractDataGet (res: Response) { + return res.json() } - handleError(res: Response) { - let text = 'Server error: '; - text += res.text(); - let json = ''; + handleError (res: Response) { + let text = 'Server error: ' + text += res.text() + let json = '' try { - json = res.json(); - } catch (err) { ; } + json = res.json() + } catch (err) { + console.error('Cannot get JSON from response.') + } const error = { json, text - }; + } - console.error(error); + console.error(error) - return Observable.throw(error); + return Observable.throw(error) } } diff --git a/client/src/app/shared/rest/rest-pagination.ts b/client/src/app/shared/rest/rest-pagination.ts index 0cfa4f468..766e7a9e5 100644 --- a/client/src/app/shared/rest/rest-pagination.ts +++ b/client/src/app/shared/rest/rest-pagination.ts @@ -1,5 +1,5 @@ export interface RestPagination { - currentPage: number; - itemsPerPage: number; - totalItems: number; -}; + currentPage: number + itemsPerPage: number + totalItems: number +} diff --git a/client/src/app/shared/rest/rest.service.ts b/client/src/app/shared/rest/rest.service.ts index 16b47e957..43dc20b34 100644 --- a/client/src/app/shared/rest/rest.service.ts +++ b/client/src/app/shared/rest/rest.service.ts @@ -1,27 +1,27 @@ -import { Injectable } from '@angular/core'; -import { URLSearchParams } from '@angular/http'; +import { Injectable } from '@angular/core' +import { URLSearchParams } from '@angular/http' -import { RestPagination } from './rest-pagination'; +import { RestPagination } from './rest-pagination' @Injectable() export class RestService { - buildRestGetParams(pagination?: RestPagination, sort?: string) { - const params = new URLSearchParams(); + buildRestGetParams (pagination?: RestPagination, sort?: string) { + const params = new URLSearchParams() if (pagination) { - const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage; - const count: number = pagination.itemsPerPage; + const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage + const count: number = pagination.itemsPerPage - params.set('start', start.toString()); - params.set('count', count.toString()); + params.set('start', start.toString()) + params.set('count', count.toString()) } if (sort) { - params.set('sort', sort); + params.set('sort', sort) } - return params; + return params } } -- cgit v1.2.3