diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-30 22:41:14 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-30 22:41:14 +0100 |
commit | 28798b5d949826551740fc893d06e6424b77aa6a (patch) | |
tree | e235a7f49164a06c4b76df49ca61b89998d4ed81 /client/src/app/shared | |
parent | 13fc89f4a4b91b3da10493517de556240fb65463 (diff) | |
download | PeerTube-28798b5d949826551740fc893d06e6424b77aa6a.tar.gz PeerTube-28798b5d949826551740fc893d06e6424b77aa6a.tar.zst PeerTube-28798b5d949826551740fc893d06e6424b77aa6a.zip |
Client: replace simple tables by ng2 smart table component
Diffstat (limited to 'client/src/app/shared')
-rw-r--r-- | client/src/app/shared/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/shared/rest/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/shared/rest/rest-data-source.ts | 51 | ||||
-rw-r--r-- | client/src/app/shared/shared.module.ts | 5 | ||||
-rw-r--r-- | client/src/app/shared/utils.ts | 12 | ||||
-rw-r--r-- | client/src/app/shared/video-abuse/video-abuse.service.ts | 8 |
6 files changed, 72 insertions, 6 deletions
diff --git a/client/src/app/shared/index.ts b/client/src/app/shared/index.ts index 7876e6f14..61e8ed523 100644 --- a/client/src/app/shared/index.ts +++ b/client/src/app/shared/index.ts | |||
@@ -5,3 +5,4 @@ export * from './search'; | |||
5 | export * from './users'; | 5 | export * from './users'; |
6 | export * from './video-abuse'; | 6 | export * from './video-abuse'; |
7 | export * from './shared.module'; | 7 | export * from './shared.module'; |
8 | export * from './utils'; | ||
diff --git a/client/src/app/shared/rest/index.ts b/client/src/app/shared/rest/index.ts index 3c9509dc7..3cb123c3b 100644 --- a/client/src/app/shared/rest/index.ts +++ b/client/src/app/shared/rest/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './rest-data-source'; | ||
1 | export * from './rest-extractor.service'; | 2 | export * from './rest-extractor.service'; |
2 | export * from './rest-pagination'; | 3 | export * from './rest-pagination'; |
3 | export * from './rest.service'; | 4 | 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 new file mode 100644 index 000000000..847dd7c56 --- /dev/null +++ b/client/src/app/shared/rest/rest-data-source.ts | |||
@@ -0,0 +1,51 @@ | |||
1 | import { Http, RequestOptionsArgs, URLSearchParams, } from '@angular/http'; | ||
2 | |||
3 | import { ServerDataSource } from 'ng2-smart-table'; | ||
4 | |||
5 | export class RestDataSource extends ServerDataSource { | ||
6 | constructor(http: Http, endpoint: string) { | ||
7 | const options = { | ||
8 | endPoint: endpoint, | ||
9 | sortFieldKey: 'sort', | ||
10 | dataKey: 'data' | ||
11 | } | ||
12 | |||
13 | super(http, options); | ||
14 | } | ||
15 | |||
16 | protected extractTotalFromResponse(res) { | ||
17 | const rawData = res.json(); | ||
18 | return rawData ? parseInt(rawData.total): 0; | ||
19 | } | ||
20 | |||
21 | protected addSortRequestOptions(requestOptions: RequestOptionsArgs) { | ||
22 | let searchParams: URLSearchParams = <URLSearchParams> requestOptions.search; | ||
23 | |||
24 | if (this.sortConf) { | ||
25 | this.sortConf.forEach((fieldConf) => { | ||
26 | const sortPrefix = fieldConf.direction === 'desc' ? '-' : ''; | ||
27 | |||
28 | searchParams.set(this.conf.sortFieldKey, sortPrefix + fieldConf.field); | ||
29 | }); | ||
30 | } | ||
31 | |||
32 | return requestOptions; | ||
33 | } | ||
34 | |||
35 | protected addPagerRequestOptions(requestOptions: RequestOptionsArgs) { | ||
36 | let searchParams: URLSearchParams = <URLSearchParams> requestOptions.search; | ||
37 | |||
38 | if (this.pagingConf && this.pagingConf['page'] && this.pagingConf['perPage']) { | ||
39 | const perPage = this.pagingConf['perPage']; | ||
40 | const page = this.pagingConf['page']; | ||
41 | |||
42 | const start = (page - 1) * perPage; | ||
43 | const count = perPage; | ||
44 | |||
45 | searchParams.set('start', start.toString()); | ||
46 | searchParams.set('count', count.toString()); | ||
47 | } | ||
48 | |||
49 | return requestOptions; | ||
50 | } | ||
51 | } | ||
diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index 7b2386d6c..99893c8b1 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts | |||
@@ -10,6 +10,7 @@ import { ProgressbarModule } from 'ng2-bootstrap/progressbar'; | |||
10 | import { PaginationModule } from 'ng2-bootstrap/pagination'; | 10 | import { PaginationModule } from 'ng2-bootstrap/pagination'; |
11 | import { ModalModule } from 'ng2-bootstrap/modal'; | 11 | import { ModalModule } from 'ng2-bootstrap/modal'; |
12 | import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload'; | 12 | import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload'; |
13 | import { Ng2SmartTableModule } from 'ng2-smart-table'; | ||
13 | 14 | ||
14 | import { AUTH_HTTP_PROVIDERS } from './auth'; | 15 | import { AUTH_HTTP_PROVIDERS } from './auth'; |
15 | import { RestExtractor, RestService } from './rest'; | 16 | import { RestExtractor, RestService } from './rest'; |
@@ -29,7 +30,8 @@ import { VideoAbuseService } from './video-abuse'; | |||
29 | PaginationModule.forRoot(), | 30 | PaginationModule.forRoot(), |
30 | ProgressbarModule.forRoot(), | 31 | ProgressbarModule.forRoot(), |
31 | 32 | ||
32 | FileUploadModule | 33 | FileUploadModule, |
34 | Ng2SmartTableModule | ||
33 | ], | 35 | ], |
34 | 36 | ||
35 | declarations: [ | 37 | declarations: [ |
@@ -49,6 +51,7 @@ import { VideoAbuseService } from './video-abuse'; | |||
49 | ModalModule, | 51 | ModalModule, |
50 | PaginationModule, | 52 | PaginationModule, |
51 | ProgressbarModule, | 53 | ProgressbarModule, |
54 | Ng2SmartTableModule, | ||
52 | BytesPipe, | 55 | BytesPipe, |
53 | 56 | ||
54 | SearchComponent | 57 | SearchComponent |
diff --git a/client/src/app/shared/utils.ts b/client/src/app/shared/utils.ts new file mode 100644 index 000000000..1dd6f96f0 --- /dev/null +++ b/client/src/app/shared/utils.ts | |||
@@ -0,0 +1,12 @@ | |||
1 | import { DatePipe } from '@angular/common'; | ||
2 | |||
3 | export class Utils { | ||
4 | |||
5 | static dateToHuman(date: String) { | ||
6 | return new DatePipe('en').transform(date, 'medium') | ||
7 | } | ||
8 | |||
9 | static getRowDeleteButton() { | ||
10 | return '<span class="glyphicon glyphicon-remove glyphicon-black"></span>'; | ||
11 | } | ||
12 | } | ||
diff --git a/client/src/app/shared/video-abuse/video-abuse.service.ts b/client/src/app/shared/video-abuse/video-abuse.service.ts index 2750a41c7..f23c36f05 100644 --- a/client/src/app/shared/video-abuse/video-abuse.service.ts +++ b/client/src/app/shared/video-abuse/video-abuse.service.ts | |||
@@ -6,7 +6,7 @@ import 'rxjs/add/operator/map'; | |||
6 | 6 | ||
7 | import { AuthService } from '../core'; | 7 | import { AuthService } from '../core'; |
8 | import { AuthHttp } from '../auth'; | 8 | import { AuthHttp } from '../auth'; |
9 | import { RestExtractor, ResultList } from '../rest'; | 9 | import { RestDataSource, RestExtractor, ResultList } from '../rest'; |
10 | import { VideoAbuse } from './video-abuse.model'; | 10 | import { VideoAbuse } from './video-abuse.model'; |
11 | 11 | ||
12 | @Injectable() | 12 | @Injectable() |
@@ -18,10 +18,8 @@ export class VideoAbuseService { | |||
18 | private restExtractor: RestExtractor | 18 | private restExtractor: RestExtractor |
19 | ) {} | 19 | ) {} |
20 | 20 | ||
21 | getVideoAbuses() { | 21 | getDataSource() { |
22 | return this.authHttp.get(VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse') | 22 | return new RestDataSource(this.authHttp, VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'); |
23 | .map(this.restExtractor.extractDataList) | ||
24 | .map(this.extractVideoAbuses) | ||
25 | } | 23 | } |
26 | 24 | ||
27 | reportVideo(id: string, reason: string) { | 25 | reportVideo(id: string, reason: string) { |