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 | |
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')
-rw-r--r-- | client/src/app/core/config/config.service.ts | 26 | ||||
-rw-r--r-- | client/src/app/core/config/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/core.module.ts | 4 | ||||
-rw-r--r-- | client/src/app/core/index.ts | 2 | ||||
-rw-r--r-- | client/src/app/core/menu/menu.component.ts | 6 | ||||
-rw-r--r-- | client/src/app/core/server/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/server/server.service.ts | 67 |
7 files changed, 74 insertions, 33 deletions
diff --git a/client/src/app/core/config/config.service.ts b/client/src/app/core/config/config.service.ts deleted file mode 100644 index 3c479bcb8..000000000 --- a/client/src/app/core/config/config.service.ts +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
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 ConfigService { | ||
8 | private static BASE_CONFIG_URL = API_URL + '/api/v1/config/' | ||
9 | |||
10 | private config: ServerConfig = { | ||
11 | signup: { | ||
12 | allowed: false | ||
13 | } | ||
14 | } | ||
15 | |||
16 | constructor (private http: HttpClient) {} | ||
17 | |||
18 | loadConfig () { | ||
19 | this.http.get<ServerConfig>(ConfigService.BASE_CONFIG_URL) | ||
20 | .subscribe(data => this.config = data) | ||
21 | } | ||
22 | |||
23 | getConfig () { | ||
24 | return this.config | ||
25 | } | ||
26 | } | ||
diff --git a/client/src/app/core/config/index.ts b/client/src/app/core/config/index.ts deleted file mode 100644 index 3724e12f2..000000000 --- a/client/src/app/core/config/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './config.service' | ||
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index 9ca94dd0e..fd1586f8e 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts | |||
@@ -8,7 +8,7 @@ import { SimpleNotificationsModule } from 'angular2-notifications' | |||
8 | import { ModalModule } from 'ngx-bootstrap/modal' | 8 | import { ModalModule } from 'ngx-bootstrap/modal' |
9 | 9 | ||
10 | import { AuthService } from './auth' | 10 | import { AuthService } from './auth' |
11 | import { ConfigService } from './config' | 11 | import { ServerService } from './server' |
12 | import { ConfirmComponent, ConfirmService } from './confirm' | 12 | import { ConfirmComponent, ConfirmService } from './confirm' |
13 | import { MenuComponent, MenuAdminComponent } from './menu' | 13 | import { MenuComponent, MenuAdminComponent } from './menu' |
14 | import { throwIfAlreadyLoaded } from './module-import-guard' | 14 | import { throwIfAlreadyLoaded } from './module-import-guard' |
@@ -41,7 +41,7 @@ import { throwIfAlreadyLoaded } from './module-import-guard' | |||
41 | providers: [ | 41 | providers: [ |
42 | AuthService, | 42 | AuthService, |
43 | ConfirmService, | 43 | ConfirmService, |
44 | ConfigService | 44 | ServerService |
45 | ] | 45 | ] |
46 | }) | 46 | }) |
47 | export class CoreModule { | 47 | export class CoreModule { |
diff --git a/client/src/app/core/index.ts b/client/src/app/core/index.ts index 31322138f..8358261ae 100644 --- a/client/src/app/core/index.ts +++ b/client/src/app/core/index.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | export * from './auth' | 1 | export * from './auth' |
2 | export * from './config' | 2 | export * from './server' |
3 | export * from './confirm' | 3 | export * from './confirm' |
4 | export * from './menu' | 4 | export * from './menu' |
5 | export * from './routing' | 5 | export * from './routing' |
diff --git a/client/src/app/core/menu/menu.component.ts b/client/src/app/core/menu/menu.component.ts index 669fc6572..8f15d8838 100644 --- a/client/src/app/core/menu/menu.component.ts +++ b/client/src/app/core/menu/menu.component.ts | |||
@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core' | |||
2 | import { Router } from '@angular/router' | 2 | import { Router } from '@angular/router' |
3 | 3 | ||
4 | import { AuthService, AuthStatus } from '../auth' | 4 | import { AuthService, AuthStatus } from '../auth' |
5 | import { ConfigService } from '../config' | 5 | import { ServerService } from '../server' |
6 | 6 | ||
7 | @Component({ | 7 | @Component({ |
8 | selector: 'my-menu', | 8 | selector: 'my-menu', |
@@ -14,7 +14,7 @@ export class MenuComponent implements OnInit { | |||
14 | 14 | ||
15 | constructor ( | 15 | constructor ( |
16 | private authService: AuthService, | 16 | private authService: AuthService, |
17 | private configService: ConfigService, | 17 | private serverService: ServerService, |
18 | private router: Router | 18 | private router: Router |
19 | ) {} | 19 | ) {} |
20 | 20 | ||
@@ -37,7 +37,7 @@ export class MenuComponent implements OnInit { | |||
37 | } | 37 | } |
38 | 38 | ||
39 | isRegistrationAllowed () { | 39 | isRegistrationAllowed () { |
40 | return this.configService.getConfig().signup.allowed | 40 | return this.serverService.getConfig().signup.allowed |
41 | } | 41 | } |
42 | 42 | ||
43 | isUserAdmin () { | 43 | isUserAdmin () { |
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 | } | ||