aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/app.component.ts10
-rw-r--r--client/src/app/core/config/config.service.ts26
-rw-r--r--client/src/app/core/config/index.ts1
-rw-r--r--client/src/app/core/core.module.ts4
-rw-r--r--client/src/app/core/index.ts2
-rw-r--r--client/src/app/core/menu/menu.component.ts6
-rw-r--r--client/src/app/core/server/index.ts1
-rw-r--r--client/src/app/core/server/server.service.ts67
-rw-r--r--client/src/app/videos/+video-edit/video-add.component.ts12
-rw-r--r--client/src/app/videos/+video-edit/video-update.component.ts13
-rw-r--r--client/src/app/videos/shared/video.service.ts32
-rw-r--r--client/src/app/videos/video-list/video-miniature.component.ts15
-rw-r--r--client/src/app/videos/videos.component.ts14
13 files changed, 99 insertions, 104 deletions
diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts
index 82e647c98..68719f73d 100644
--- a/client/src/app/app.component.ts
+++ b/client/src/app/app.component.ts
@@ -1,7 +1,7 @@
1import { Component, OnInit, ViewContainerRef } from '@angular/core' 1import { Component, OnInit, ViewContainerRef } from '@angular/core'
2import { Router } from '@angular/router' 2import { Router } from '@angular/router'
3 3
4import { AuthService, ConfigService } from './core' 4import { AuthService, ServerService } from './core'
5import { UserService } from './shared' 5import { UserService } from './shared'
6 6
7@Component({ 7@Component({
@@ -28,7 +28,7 @@ export class AppComponent implements OnInit {
28 constructor ( 28 constructor (
29 private router: Router, 29 private router: Router,
30 private authService: AuthService, 30 private authService: AuthService,
31 private configService: ConfigService, 31 private serverService: ServerService,
32 private userService: UserService 32 private userService: UserService
33 ) {} 33 ) {}
34 34
@@ -40,7 +40,11 @@ export class AppComponent implements OnInit {
40 this.userService.checkTokenValidity() 40 this.userService.checkTokenValidity()
41 } 41 }
42 42
43 this.configService.loadConfig() 43 // Load custom data from server
44 this.serverService.loadConfig()
45 this.serverService.loadVideoCategories()
46 this.serverService.loadVideoLanguages()
47 this.serverService.loadVideoLicences()
44 48
45 // Do not display menu on small screens 49 // Do not display menu on small screens
46 if (window.innerWidth < 600) { 50 if (window.innerWidth < 600) {
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 @@
1import { Injectable } from '@angular/core'
2import { HttpClient } from '@angular/common/http'
3
4import { ServerConfig } from '../../../../../shared'
5
6@Injectable()
7export 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 @@
1export * 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'
8import { ModalModule } from 'ngx-bootstrap/modal' 8import { ModalModule } from 'ngx-bootstrap/modal'
9 9
10import { AuthService } from './auth' 10import { AuthService } from './auth'
11import { ConfigService } from './config' 11import { ServerService } from './server'
12import { ConfirmComponent, ConfirmService } from './confirm' 12import { ConfirmComponent, ConfirmService } from './confirm'
13import { MenuComponent, MenuAdminComponent } from './menu' 13import { MenuComponent, MenuAdminComponent } from './menu'
14import { throwIfAlreadyLoaded } from './module-import-guard' 14import { 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})
47export class CoreModule { 47export 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 @@
1export * from './auth' 1export * from './auth'
2export * from './config' 2export * from './server'
3export * from './confirm' 3export * from './confirm'
4export * from './menu' 4export * from './menu'
5export * from './routing' 5export * 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'
2import { Router } from '@angular/router' 2import { Router } from '@angular/router'
3 3
4import { AuthService, AuthStatus } from '../auth' 4import { AuthService, AuthStatus } from '../auth'
5import { ConfigService } from '../config' 5import { 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 @@
1import { Injectable } from '@angular/core'
2import { HttpClient } from '@angular/common/http'
3
4import { ServerConfig } from '../../../../../shared'
5
6@Injectable()
7export 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}
diff --git a/client/src/app/videos/+video-edit/video-add.component.ts b/client/src/app/videos/+video-edit/video-add.component.ts
index 21311b184..d930423c2 100644
--- a/client/src/app/videos/+video-edit/video-add.component.ts
+++ b/client/src/app/videos/+video-edit/video-add.component.ts
@@ -11,12 +11,13 @@ import {
11 VIDEO_LICENCE, 11 VIDEO_LICENCE,
12 VIDEO_LANGUAGE, 12 VIDEO_LANGUAGE,
13 VIDEO_DESCRIPTION, 13 VIDEO_DESCRIPTION,
14 VIDEO_TAGS 14 VIDEO_TAGS,
15 VIDEO_FILE
15} from '../../shared' 16} from '../../shared'
17import { ServerService} from '../../core'
16import { VideoService } from '../shared' 18import { VideoService } from '../shared'
17import { VideoCreate } from '../../../../../shared' 19import { VideoCreate } from '../../../../../shared'
18import { HttpEventType, HttpResponse } from '@angular/common/http' 20import { HttpEventType, HttpResponse } from '@angular/common/http'
19import { VIDEO_FILE } from '../../shared/forms/form-validators/video'
20 21
21@Component({ 22@Component({
22 selector: 'my-videos-add', 23 selector: 'my-videos-add',
@@ -59,6 +60,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
59 private formBuilder: FormBuilder, 60 private formBuilder: FormBuilder,
60 private router: Router, 61 private router: Router,
61 private notificationsService: NotificationsService, 62 private notificationsService: NotificationsService,
63 private serverService: ServerService,
62 private videoService: VideoService 64 private videoService: VideoService
63 ) { 65 ) {
64 super() 66 super()
@@ -84,9 +86,9 @@ export class VideoAddComponent extends FormReactive implements OnInit {
84 } 86 }
85 87
86 ngOnInit () { 88 ngOnInit () {
87 this.videoCategories = this.videoService.videoCategories 89 this.videoCategories = this.serverService.getVideoCategories()
88 this.videoLicences = this.videoService.videoLicences 90 this.videoLicences = this.serverService.getVideoLicences()
89 this.videoLanguages = this.videoService.videoLanguages 91 this.videoLanguages = this.serverService.getVideoLanguages()
90 92
91 this.buildForm() 93 this.buildForm()
92 } 94 }
diff --git a/client/src/app/videos/+video-edit/video-update.component.ts b/client/src/app/videos/+video-edit/video-update.component.ts
index 141ed3522..6d45265e7 100644
--- a/client/src/app/videos/+video-edit/video-update.component.ts
+++ b/client/src/app/videos/+video-edit/video-update.component.ts
@@ -1,10 +1,10 @@
1import { Component, ElementRef, OnInit } from '@angular/core' 1import { Component, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms' 2import { FormBuilder, FormGroup } from '@angular/forms'
3import { ActivatedRoute, Router } from '@angular/router' 3import { ActivatedRoute, Router } from '@angular/router'
4 4
5import { NotificationsService } from 'angular2-notifications' 5import { NotificationsService } from 'angular2-notifications'
6 6
7import { AuthService } from '../../core' 7import { ServerService } from '../../core'
8import { 8import {
9 FormReactive, 9 FormReactive,
10 VIDEO_NAME, 10 VIDEO_NAME,
@@ -52,12 +52,11 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
52 fileError = '' 52 fileError = ''
53 53
54 constructor ( 54 constructor (
55 private authService: AuthService,
56 private elementRef: ElementRef,
57 private formBuilder: FormBuilder, 55 private formBuilder: FormBuilder,
58 private route: ActivatedRoute, 56 private route: ActivatedRoute,
59 private router: Router, 57 private router: Router,
60 private notificationsService: NotificationsService, 58 private notificationsService: NotificationsService,
59 private serverService: ServerService,
61 private videoService: VideoService 60 private videoService: VideoService
62 ) { 61 ) {
63 super() 62 super()
@@ -80,9 +79,9 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
80 ngOnInit () { 79 ngOnInit () {
81 this.buildForm() 80 this.buildForm()
82 81
83 this.videoCategories = this.videoService.videoCategories 82 this.videoCategories = this.serverService.getVideoCategories()
84 this.videoLicences = this.videoService.videoLicences 83 this.videoLicences = this.serverService.getVideoLicences()
85 this.videoLanguages = this.videoService.videoLanguages 84 this.videoLanguages = this.serverService.getVideoLanguages()
86 85
87 const uuid: string = this.route.snapshot.params['uuid'] 86 const uuid: string = this.route.snapshot.params['uuid']
88 this.videoService.getVideo(uuid) 87 this.videoService.getVideo(uuid)
diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts
index cfce4cb16..037c20416 100644
--- a/client/src/app/videos/shared/video.service.ts
+++ b/client/src/app/videos/shared/video.service.ts
@@ -14,7 +14,6 @@ import {
14import { Video } from './video.model' 14import { Video } from './video.model'
15import { VideoPagination } from './video-pagination.model' 15import { VideoPagination } from './video-pagination.model'
16import { 16import {
17 VideoCreate,
18 UserVideoRate, 17 UserVideoRate,
19 VideoRateType, 18 VideoRateType,
20 VideoUpdate, 19 VideoUpdate,
@@ -28,28 +27,12 @@ import {
28export class VideoService { 27export class VideoService {
29 private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/' 28 private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
30 29
31 videoCategories: Array<{ id: number, label: string }> = []
32 videoLicences: Array<{ id: number, label: string }> = []
33 videoLanguages: Array<{ id: number, label: string }> = []
34
35 constructor ( 30 constructor (
36 private authHttp: HttpClient, 31 private authHttp: HttpClient,
37 private restExtractor: RestExtractor, 32 private restExtractor: RestExtractor,
38 private restService: RestService 33 private restService: RestService
39 ) {} 34 ) {}
40 35
41 loadVideoCategories () {
42 return this.loadVideoAttributeEnum('categories', this.videoCategories)
43 }
44
45 loadVideoLicences () {
46 return this.loadVideoAttributeEnum('licences', this.videoLicences)
47 }
48
49 loadVideoLanguages () {
50 return this.loadVideoAttributeEnum('languages', this.videoLanguages)
51 }
52
53 getVideo (uuid: string) { 36 getVideo (uuid: string) {
54 return this.authHttp.get<VideoServerModel>(VideoService.BASE_VIDEO_URL + uuid) 37 return this.authHttp.get<VideoServerModel>(VideoService.BASE_VIDEO_URL + uuid)
55 .map(videoHash => new Video(videoHash)) 38 .map(videoHash => new Video(videoHash))
@@ -74,8 +57,7 @@ export class VideoService {
74 .catch(this.restExtractor.handleError) 57 .catch(this.restExtractor.handleError)
75 } 58 }
76 59
77 // uploadVideo (video: VideoCreate) { 60 uploadVideo (video: FormData) {
78 uploadVideo (video: any) {
79 const req = new HttpRequest('POST', `${VideoService.BASE_VIDEO_URL}/upload`, video, { reportProgress: true }) 61 const req = new HttpRequest('POST', `${VideoService.BASE_VIDEO_URL}/upload`, video, { reportProgress: true })
80 62
81 return this.authHttp.request(req) 63 return this.authHttp.request(req)
@@ -175,16 +157,4 @@ export class VideoService {
175 157
176 return { videos, totalVideos } 158 return { videos, totalVideos }
177 } 159 }
178
179 private loadVideoAttributeEnum (attributeName: 'categories' | 'licences' | 'languages', hashToPopulate: { id: number, label: string }[]) {
180 return this.authHttp.get(VideoService.BASE_VIDEO_URL + attributeName)
181 .subscribe(data => {
182 Object.keys(data).forEach(dataKey => {
183 hashToPopulate.push({
184 id: parseInt(dataKey, 10),
185 label: data[dataKey]
186 })
187 })
188 })
189 }
190} 160}
diff --git a/client/src/app/videos/video-list/video-miniature.component.ts b/client/src/app/videos/video-list/video-miniature.component.ts
index 1cfeacf36..8d8b817ee 100644
--- a/client/src/app/videos/video-list/video-miniature.component.ts
+++ b/client/src/app/videos/video-list/video-miniature.component.ts
@@ -1,9 +1,6 @@
1import { Component, Input, Output, EventEmitter } from '@angular/core' 1import { Component, Input } from '@angular/core'
2 2
3import { NotificationsService } from 'angular2-notifications' 3import { SortField, Video } from '../shared'
4
5import { ConfirmService, ConfigService } from '../../core'
6import { SortField, Video, VideoService } from '../shared'
7import { User } from '../../shared' 4import { User } from '../../shared'
8 5
9@Component({ 6@Component({
@@ -11,19 +8,11 @@ import { User } from '../../shared'
11 styleUrls: [ './video-miniature.component.scss' ], 8 styleUrls: [ './video-miniature.component.scss' ],
12 templateUrl: './video-miniature.component.html' 9 templateUrl: './video-miniature.component.html'
13}) 10})
14
15export class VideoMiniatureComponent { 11export class VideoMiniatureComponent {
16 @Input() currentSort: SortField 12 @Input() currentSort: SortField
17 @Input() user: User 13 @Input() user: User
18 @Input() video: Video 14 @Input() video: Video
19 15
20 constructor (
21 private notificationsService: NotificationsService,
22 private confirmService: ConfirmService,
23 private configService: ConfigService,
24 private videoService: VideoService
25 ) {}
26
27 getVideoName () { 16 getVideoName () {
28 if (this.isVideoNSFWForThisUser()) { 17 if (this.isVideoNSFWForThisUser()) {
29 return 'NSFW' 18 return 'NSFW'
diff --git a/client/src/app/videos/videos.component.ts b/client/src/app/videos/videos.component.ts
index 80ff46a0a..585a3ad9a 100644
--- a/client/src/app/videos/videos.component.ts
+++ b/client/src/app/videos/videos.component.ts
@@ -1,16 +1,6 @@
1import { Component, OnInit } from '@angular/core' 1import { Component } from '@angular/core'
2
3import { VideoService } from './shared'
4 2
5@Component({ 3@Component({
6 template: '<router-outlet></router-outlet>' 4 template: '<router-outlet></router-outlet>'
7}) 5})
8export class VideosComponent implements OnInit { 6export class VideosComponent {}
9 constructor (private videoService: VideoService) {}
10
11 ngOnInit () {
12 this.videoService.loadVideoCategories()
13 this.videoService.loadVideoLicences()
14 this.videoService.loadVideoLanguages()
15 }
16}