diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
commit | 88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch) | |
tree | b242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /client/src/app/shared/rest | |
parent | 53a94c7cfa8368da4cd248d65df8346905938f0c (diff) | |
parent | 9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff) | |
download | PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip |
Merge branch 'develop' into pr/1217
Diffstat (limited to 'client/src/app/shared/rest')
-rw-r--r-- | client/src/app/shared/rest/component-pagination.model.ts | 11 | ||||
-rw-r--r-- | client/src/app/shared/rest/rest-extractor.service.ts | 5 | ||||
-rw-r--r-- | client/src/app/shared/rest/rest-table.ts | 29 | ||||
-rw-r--r-- | client/src/app/shared/rest/rest.service.ts | 2 |
4 files changed, 42 insertions, 5 deletions
diff --git a/client/src/app/shared/rest/component-pagination.model.ts b/client/src/app/shared/rest/component-pagination.model.ts index 0b8ecc318..85160d445 100644 --- a/client/src/app/shared/rest/component-pagination.model.ts +++ b/client/src/app/shared/rest/component-pagination.model.ts | |||
@@ -3,3 +3,14 @@ export interface ComponentPagination { | |||
3 | itemsPerPage: number | 3 | itemsPerPage: number |
4 | totalItems?: number | 4 | totalItems?: number |
5 | } | 5 | } |
6 | |||
7 | export function hasMoreItems (componentPagination: ComponentPagination) { | ||
8 | // No results | ||
9 | if (componentPagination.totalItems === 0) return false | ||
10 | |||
11 | // Not loaded yet | ||
12 | if (!componentPagination.totalItems) return true | ||
13 | |||
14 | const maxPage = componentPagination.totalItems / componentPagination.itemsPerPage | ||
15 | return maxPage > componentPagination.currentPage | ||
16 | } | ||
diff --git a/client/src/app/shared/rest/rest-extractor.service.ts b/client/src/app/shared/rest/rest-extractor.service.ts index 6492aa66d..e6518dd1d 100644 --- a/client/src/app/shared/rest/rest-extractor.service.ts +++ b/client/src/app/shared/rest/rest-extractor.service.ts | |||
@@ -33,7 +33,7 @@ export class RestExtractor { | |||
33 | return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert ]) | 33 | return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert ]) |
34 | } | 34 | } |
35 | 35 | ||
36 | convertDateToHuman (target: object, fieldsToConvert: string[]) { | 36 | convertDateToHuman (target: { [ id: string ]: string }, fieldsToConvert: string[]) { |
37 | fieldsToConvert.forEach(field => target[field] = dateToHuman(target[field])) | 37 | fieldsToConvert.forEach(field => target[field] = dateToHuman(target[field])) |
38 | 38 | ||
39 | return target | 39 | return target |
@@ -80,10 +80,11 @@ export class RestExtractor { | |||
80 | errorMessage = errorMessage ? errorMessage : 'Unknown error.' | 80 | errorMessage = errorMessage ? errorMessage : 'Unknown error.' |
81 | console.error(`Backend returned code ${err.status}, errorMessage is: ${errorMessage}`) | 81 | console.error(`Backend returned code ${err.status}, errorMessage is: ${errorMessage}`) |
82 | } else { | 82 | } else { |
83 | console.error(err) | ||
83 | errorMessage = err | 84 | errorMessage = err |
84 | } | 85 | } |
85 | 86 | ||
86 | const errorObj = { | 87 | const errorObj: { message: string, status: string, body: string } = { |
87 | message: errorMessage, | 88 | message: errorMessage, |
88 | status: undefined, | 89 | status: undefined, |
89 | body: undefined | 90 | body: undefined |
diff --git a/client/src/app/shared/rest/rest-table.ts b/client/src/app/shared/rest/rest-table.ts index fe1a91d2d..884588207 100644 --- a/client/src/app/shared/rest/rest-table.ts +++ b/client/src/app/shared/rest/rest-table.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' | 1 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' |
2 | import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent' | 2 | import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent' |
3 | import { SortMeta } from 'primeng/components/common/sortmeta' | 3 | import { SortMeta } from 'primeng/components/common/sortmeta' |
4 | |||
5 | import { RestPagination } from './rest-pagination' | 4 | import { RestPagination } from './rest-pagination' |
5 | import { Subject } from 'rxjs' | ||
6 | import { debounceTime, distinctUntilChanged } from 'rxjs/operators' | ||
6 | 7 | ||
7 | export abstract class RestTable { | 8 | export abstract class RestTable { |
8 | 9 | ||
@@ -11,9 +12,14 @@ export abstract class RestTable { | |||
11 | abstract sort: SortMeta | 12 | abstract sort: SortMeta |
12 | abstract pagination: RestPagination | 13 | abstract pagination: RestPagination |
13 | 14 | ||
15 | protected search: string | ||
16 | private searchStream: Subject<string> | ||
14 | private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name | 17 | private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name |
15 | 18 | ||
16 | protected abstract loadData (): void | 19 | initialize () { |
20 | this.loadSort() | ||
21 | this.initSearch() | ||
22 | } | ||
17 | 23 | ||
18 | loadSort () { | 24 | loadSort () { |
19 | const result = peertubeLocalStorage.getItem(this.sortLocalStorageKey) | 25 | const result = peertubeLocalStorage.getItem(this.sortLocalStorageKey) |
@@ -46,4 +52,23 @@ export abstract class RestTable { | |||
46 | peertubeLocalStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort)) | 52 | peertubeLocalStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort)) |
47 | } | 53 | } |
48 | 54 | ||
55 | initSearch () { | ||
56 | this.searchStream = new Subject() | ||
57 | |||
58 | this.searchStream | ||
59 | .pipe( | ||
60 | debounceTime(400), | ||
61 | distinctUntilChanged() | ||
62 | ) | ||
63 | .subscribe(search => { | ||
64 | this.search = search | ||
65 | this.loadData() | ||
66 | }) | ||
67 | } | ||
68 | |||
69 | onSearch (search: string) { | ||
70 | this.searchStream.next(search) | ||
71 | } | ||
72 | |||
73 | protected abstract loadData (): void | ||
49 | } | 74 | } |
diff --git a/client/src/app/shared/rest/rest.service.ts b/client/src/app/shared/rest/rest.service.ts index 4560c2024..e6d4e6e5e 100644 --- a/client/src/app/shared/rest/rest.service.ts +++ b/client/src/app/shared/rest/rest.service.ts | |||
@@ -32,7 +32,7 @@ export class RestService { | |||
32 | return newParams | 32 | return newParams |
33 | } | 33 | } |
34 | 34 | ||
35 | addObjectParams (params: HttpParams, object: object) { | 35 | addObjectParams (params: HttpParams, object: { [ name: string ]: any }) { |
36 | for (const name of Object.keys(object)) { | 36 | for (const name of Object.keys(object)) { |
37 | const value = object[name] | 37 | const value = object[name] |
38 | if (!value) continue | 38 | if (!value) continue |