diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-09 19:12:40 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-09 19:12:40 +0200 |
commit | db7af09bd8e9de57cdda88c2e32387551235b3a4 (patch) | |
tree | 8e3cac831be63a2c66e3b6d5e3b22e33492fb726 /client/src/app/core/server | |
parent | bcd1c9e19447a98d605385fab69b5cfa58d0ba4b (diff) | |
download | PeerTube-db7af09bd8e9de57cdda88c2e32387551235b3a4.tar.gz PeerTube-db7af09bd8e9de57cdda88c2e32387551235b3a4.tar.zst PeerTube-db7af09bd8e9de57cdda88c2e32387551235b3a4.zip |
Client: fix loading server configurations
Diffstat (limited to 'client/src/app/core/server')
-rw-r--r-- | client/src/app/core/server/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/server/server.service.ts | 67 |
2 files changed, 68 insertions, 0 deletions
diff --git a/client/src/app/core/server/index.ts b/client/src/app/core/server/index.ts new file mode 100644 index 000000000..224da121a --- /dev/null +++ b/client/src/app/core/server/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './server.service' | |||
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts new file mode 100644 index 000000000..f24df5a89 --- /dev/null +++ b/client/src/app/core/server/server.service.ts | |||
@@ -0,0 +1,67 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { HttpClient } from '@angular/common/http' | ||
3 | |||
4 | import { ServerConfig } from '../../../../../shared' | ||
5 | |||
6 | @Injectable() | ||
7 | export class ServerService { | ||
8 | private static BASE_CONFIG_URL = API_URL + '/api/v1/config/' | ||
9 | private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/' | ||
10 | |||
11 | private config: ServerConfig = { | ||
12 | signup: { | ||
13 | allowed: false | ||
14 | } | ||
15 | } | ||
16 | private videoCategories: Array<{ id: number, label: string }> = [] | ||
17 | private videoLicences: Array<{ id: number, label: string }> = [] | ||
18 | private videoLanguages: Array<{ id: number, label: string }> = [] | ||
19 | |||
20 | constructor (private http: HttpClient) {} | ||
21 | |||
22 | loadConfig () { | ||
23 | this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL) | ||
24 | .subscribe(data => this.config = data) | ||
25 | } | ||
26 | |||
27 | loadVideoCategories () { | ||
28 | return this.loadVideoAttributeEnum('categories', this.videoCategories) | ||
29 | } | ||
30 | |||
31 | loadVideoLicences () { | ||
32 | return this.loadVideoAttributeEnum('licences', this.videoLicences) | ||
33 | } | ||
34 | |||
35 | loadVideoLanguages () { | ||
36 | return this.loadVideoAttributeEnum('languages', this.videoLanguages) | ||
37 | } | ||
38 | |||
39 | getConfig () { | ||
40 | return this.config | ||
41 | } | ||
42 | |||
43 | getVideoCategories () { | ||
44 | return this.videoCategories | ||
45 | } | ||
46 | |||
47 | getVideoLicences () { | ||
48 | return this.videoLicences | ||
49 | } | ||
50 | |||
51 | getVideoLanguages () { | ||
52 | return this.videoLanguages | ||
53 | } | ||
54 | |||
55 | private loadVideoAttributeEnum (attributeName: 'categories' | 'licences' | 'languages', hashToPopulate: { id: number, label: string }[]) { | ||
56 | return this.http.get(ServerService.BASE_VIDEO_URL + attributeName) | ||
57 | .subscribe(data => { | ||
58 | Object.keys(data) | ||
59 | .forEach(dataKey => { | ||
60 | hashToPopulate.push({ | ||
61 | id: parseInt(dataKey, 10), | ||
62 | label: data[dataKey] | ||
63 | }) | ||
64 | }) | ||
65 | }) | ||
66 | } | ||
67 | } | ||