aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-30 22:41:14 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-30 22:41:14 +0100
commit28798b5d949826551740fc893d06e6424b77aa6a (patch)
treee235a7f49164a06c4b76df49ca61b89998d4ed81 /client/src/app/shared
parent13fc89f4a4b91b3da10493517de556240fb65463 (diff)
downloadPeerTube-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.ts1
-rw-r--r--client/src/app/shared/rest/index.ts1
-rw-r--r--client/src/app/shared/rest/rest-data-source.ts51
-rw-r--r--client/src/app/shared/shared.module.ts5
-rw-r--r--client/src/app/shared/utils.ts12
-rw-r--r--client/src/app/shared/video-abuse/video-abuse.service.ts8
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';
5export * from './users'; 5export * from './users';
6export * from './video-abuse'; 6export * from './video-abuse';
7export * from './shared.module'; 7export * from './shared.module';
8export * 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 @@
1export * from './rest-data-source';
1export * from './rest-extractor.service'; 2export * from './rest-extractor.service';
2export * from './rest-pagination'; 3export * from './rest-pagination';
3export * from './rest.service'; 4export * 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 @@
1import { Http, RequestOptionsArgs, URLSearchParams, } from '@angular/http';
2
3import { ServerDataSource } from 'ng2-smart-table';
4
5export 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';
10import { PaginationModule } from 'ng2-bootstrap/pagination'; 10import { PaginationModule } from 'ng2-bootstrap/pagination';
11import { ModalModule } from 'ng2-bootstrap/modal'; 11import { ModalModule } from 'ng2-bootstrap/modal';
12import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload'; 12import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
13import { Ng2SmartTableModule } from 'ng2-smart-table';
13 14
14import { AUTH_HTTP_PROVIDERS } from './auth'; 15import { AUTH_HTTP_PROVIDERS } from './auth';
15import { RestExtractor, RestService } from './rest'; 16import { 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 @@
1import { DatePipe } from '@angular/common';
2
3export 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
7import { AuthService } from '../core'; 7import { AuthService } from '../core';
8import { AuthHttp } from '../auth'; 8import { AuthHttp } from '../auth';
9import { RestExtractor, ResultList } from '../rest'; 9import { RestDataSource, RestExtractor, ResultList } from '../rest';
10import { VideoAbuse } from './video-abuse.model'; 10import { 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) {