aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/auth/auth-http.service.ts82
-rw-r--r--client/src/app/shared/auth/index.ts2
-rw-r--r--client/src/app/shared/forms/form-reactive.ts30
-rw-r--r--client/src/app/shared/forms/form-validators/host.validator.ts8
-rw-r--r--client/src/app/shared/forms/form-validators/index.ts8
-rw-r--r--client/src/app/shared/forms/form-validators/user.ts12
-rw-r--r--client/src/app/shared/forms/form-validators/video-abuse.ts4
-rw-r--r--client/src/app/shared/forms/form-validators/video.ts14
-rw-r--r--client/src/app/shared/forms/index.ts4
-rw-r--r--client/src/app/shared/index.ts16
-rw-r--r--client/src/app/shared/rest/index.ts8
-rw-r--r--client/src/app/shared/rest/rest-data-source.ts60
-rw-r--r--client/src/app/shared/rest/rest-extractor.service.ts48
-rw-r--r--client/src/app/shared/rest/rest-pagination.ts8
-rw-r--r--client/src/app/shared/rest/rest.service.ts22
-rw-r--r--client/src/app/shared/search/index.ts8
-rw-r--r--client/src/app/shared/search/search-field.type.ts2
-rw-r--r--client/src/app/shared/search/search.component.ts48
-rw-r--r--client/src/app/shared/search/search.model.ts6
-rw-r--r--client/src/app/shared/search/search.service.ts18
-rw-r--r--client/src/app/shared/shared.module.ts36
-rw-r--r--client/src/app/shared/users/index.ts4
-rw-r--r--client/src/app/shared/users/user.model.ts34
-rw-r--r--client/src/app/shared/users/user.service.ts44
-rw-r--r--client/src/app/shared/utils.ts10
-rw-r--r--client/src/app/shared/video-abuse/index.ts4
-rw-r--r--client/src/app/shared/video-abuse/video-abuse.model.ts12
-rw-r--r--client/src/app/shared/video-abuse/video-abuse.service.ts42
28 files changed, 297 insertions, 297 deletions
diff --git a/client/src/app/shared/auth/auth-http.service.ts b/client/src/app/shared/auth/auth-http.service.ts
index c4114aa02..0fbaab0a8 100644
--- a/client/src/app/shared/auth/auth-http.service.ts
+++ b/client/src/app/shared/auth/auth-http.service.ts
@@ -1,4 +1,4 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { 2import {
3 ConnectionBackend, 3 ConnectionBackend,
4 Headers, 4 Headers,
@@ -9,79 +9,79 @@ import {
9 RequestOptionsArgs, 9 RequestOptionsArgs,
10 Response, 10 Response,
11 XHRBackend 11 XHRBackend
12} from '@angular/http'; 12} from '@angular/http'
13import { Observable } from 'rxjs/Observable'; 13import { Observable } from 'rxjs/Observable'
14 14
15import { AuthService } from '../../core'; 15import { AuthService } from '../../core'
16 16
17@Injectable() 17@Injectable()
18export class AuthHttp extends Http { 18export class AuthHttp extends Http {
19 constructor(backend: ConnectionBackend, defaultOptions: RequestOptions, private authService: AuthService) { 19 constructor (backend: ConnectionBackend, defaultOptions: RequestOptions, private authService: AuthService) {
20 super(backend, defaultOptions); 20 super(backend, defaultOptions)
21 } 21 }
22 22
23 request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> { 23 request (url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
24 if (!options) options = {}; 24 if (!options) options = {}
25 25
26 options.headers = new Headers(); 26 options.headers = new Headers()
27 this.setAuthorizationHeader(options.headers); 27 this.setAuthorizationHeader(options.headers)
28 28
29 return super.request(url, options) 29 return super.request(url, options)
30 .catch((err) => { 30 .catch((err) => {
31 if (err.status === 401) { 31 if (err.status === 401) {
32 return this.handleTokenExpired(url, options); 32 return this.handleTokenExpired(url, options)
33 } 33 }
34 34
35 return Observable.throw(err); 35 return Observable.throw(err)
36 }); 36 })
37 } 37 }
38 38
39 delete(url: string, options?: RequestOptionsArgs): Observable<Response> { 39 delete (url: string, options?: RequestOptionsArgs): Observable<Response> {
40 if (!options) options = {}; 40 if (!options) options = {}
41 options.method = RequestMethod.Delete; 41 options.method = RequestMethod.Delete
42 42
43 return this.request(url, options); 43 return this.request(url, options)
44 } 44 }
45 45
46 get(url: string, options?: RequestOptionsArgs): Observable<Response> { 46 get (url: string, options?: RequestOptionsArgs): Observable<Response> {
47 if (!options) options = {}; 47 if (!options) options = {}
48 options.method = RequestMethod.Get; 48 options.method = RequestMethod.Get
49 49
50 return this.request(url, options); 50 return this.request(url, options)
51 } 51 }
52 52
53 post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> { 53 post (url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
54 if (!options) options = {}; 54 if (!options) options = {}
55 options.method = RequestMethod.Post; 55 options.method = RequestMethod.Post
56 options.body = body; 56 options.body = body
57 57
58 return this.request(url, options); 58 return this.request(url, options)
59 } 59 }
60 60
61 put(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> { 61 put (url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
62 if (!options) options = {}; 62 if (!options) options = {}
63 options.method = RequestMethod.Put; 63 options.method = RequestMethod.Put
64 options.body = body; 64 options.body = body
65 65
66 return this.request(url, options); 66 return this.request(url, options)
67 } 67 }
68 68
69 private handleTokenExpired(url: string | Request, options: RequestOptionsArgs) { 69 private handleTokenExpired (url: string | Request, options: RequestOptionsArgs) {
70 return this.authService.refreshAccessToken() 70 return this.authService.refreshAccessToken()
71 .flatMap(() => { 71 .flatMap(() => {
72 this.setAuthorizationHeader(options.headers); 72 this.setAuthorizationHeader(options.headers)
73 73
74 return super.request(url, options); 74 return super.request(url, options)
75 }); 75 })
76 } 76 }
77 77
78 private setAuthorizationHeader(headers: Headers) { 78 private setAuthorizationHeader (headers: Headers) {
79 headers.set('Authorization', this.authService.getRequestHeaderValue()); 79 headers.set('Authorization', this.authService.getRequestHeaderValue())
80 } 80 }
81} 81}
82 82
83export function useFactory(backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) { 83export function useFactory (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) {
84 return new AuthHttp(backend, defaultOptions, authService); 84 return new AuthHttp(backend, defaultOptions, authService)
85} 85}
86 86
87export const AUTH_HTTP_PROVIDERS = [ 87export const AUTH_HTTP_PROVIDERS = [
@@ -89,5 +89,5 @@ export const AUTH_HTTP_PROVIDERS = [
89 provide: AuthHttp, 89 provide: AuthHttp,
90 useFactory, 90 useFactory,
91 deps: [ XHRBackend, RequestOptions, AuthService ] 91 deps: [ XHRBackend, RequestOptions, AuthService ]
92 }, 92 }
93]; 93]
diff --git a/client/src/app/shared/auth/index.ts b/client/src/app/shared/auth/index.ts
index c488aed69..0f2bfb0d6 100644
--- a/client/src/app/shared/auth/index.ts
+++ b/client/src/app/shared/auth/index.ts
@@ -1 +1 @@
export * from './auth-http.service'; export * from './auth-http.service'
diff --git a/client/src/app/shared/forms/form-reactive.ts b/client/src/app/shared/forms/form-reactive.ts
index a5732e083..e7764d069 100644
--- a/client/src/app/shared/forms/form-reactive.ts
+++ b/client/src/app/shared/forms/form-reactive.ts
@@ -1,38 +1,38 @@
1import { FormGroup } from '@angular/forms'; 1import { FormGroup } from '@angular/forms'
2 2
3export abstract class FormReactive { 3export abstract class FormReactive {
4 abstract form: FormGroup; 4 abstract form: FormGroup
5 abstract formErrors: Object; 5 abstract formErrors: Object
6 abstract validationMessages: Object; 6 abstract validationMessages: Object
7 7
8 abstract buildForm(): void; 8 abstract buildForm (): void
9 9
10 protected onValueChanged(data?: any) { 10 protected onValueChanged (data?: any) {
11 for (const field in this.formErrors) { 11 for (const field in this.formErrors) {
12 // clear previous error message (if any) 12 // clear previous error message (if any)
13 this.formErrors[field] = ''; 13 this.formErrors[field] = ''
14 const control = this.form.get(field); 14 const control = this.form.get(field)
15 15
16 if (control && control.dirty && !control.valid) { 16 if (control && control.dirty && !control.valid) {
17 const messages = this.validationMessages[field]; 17 const messages = this.validationMessages[field]
18 for (const key in control.errors) { 18 for (const key in control.errors) {
19 this.formErrors[field] += messages[key] + ' '; 19 this.formErrors[field] += messages[key] + ' '
20 } 20 }
21 } 21 }
22 } 22 }
23 } 23 }
24 24
25 // Same as onValueChanged but force checking even if the field is not dirty 25 // Same as onValueChanged but force checking even if the field is not dirty
26 protected forceCheck() { 26 protected forceCheck () {
27 for (const field in this.formErrors) { 27 for (const field in this.formErrors) {
28 // clear previous error message (if any) 28 // clear previous error message (if any)
29 this.formErrors[field] = ''; 29 this.formErrors[field] = ''
30 const control = this.form.get(field); 30 const control = this.form.get(field)
31 31
32 if (control && !control.valid) { 32 if (control && !control.valid) {
33 const messages = this.validationMessages[field]; 33 const messages = this.validationMessages[field]
34 for (const key in control.errors) { 34 for (const key in control.errors) {
35 this.formErrors[field] += messages[key] + ' '; 35 this.formErrors[field] += messages[key] + ' '
36 } 36 }
37 } 37 }
38 } 38 }
diff --git a/client/src/app/shared/forms/form-validators/host.validator.ts b/client/src/app/shared/forms/form-validators/host.validator.ts
index ec417e079..03e810fdb 100644
--- a/client/src/app/shared/forms/form-validators/host.validator.ts
+++ b/client/src/app/shared/forms/form-validators/host.validator.ts
@@ -1,14 +1,14 @@
1import { FormControl } from '@angular/forms'; 1import { FormControl } from '@angular/forms'
2 2
3export function validateHost(c: FormControl) { 3export function validateHost (c: FormControl) {
4 // Thanks to http://stackoverflow.com/a/106223 4 // Thanks to http://stackoverflow.com/a/106223
5 const HOST_REGEXP = new RegExp( 5 const HOST_REGEXP = new RegExp(
6 '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$' 6 '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$'
7 ); 7 )
8 8
9 return HOST_REGEXP.test(c.value) ? null : { 9 return HOST_REGEXP.test(c.value) ? null : {
10 validateHost: { 10 validateHost: {
11 valid: false 11 valid: false
12 } 12 }
13 }; 13 }
14} 14}
diff --git a/client/src/app/shared/forms/form-validators/index.ts b/client/src/app/shared/forms/form-validators/index.ts
index ab7c2df31..efe77d4ae 100644
--- a/client/src/app/shared/forms/form-validators/index.ts
+++ b/client/src/app/shared/forms/form-validators/index.ts
@@ -1,4 +1,4 @@
1export * from './host.validator'; 1export * from './host.validator'
2export * from './user'; 2export * from './user'
3export * from './video-abuse'; 3export * from './video-abuse'
4export * from './video'; 4export * from './video'
diff --git a/client/src/app/shared/forms/form-validators/user.ts b/client/src/app/shared/forms/form-validators/user.ts
index 259d2b868..fd316583e 100644
--- a/client/src/app/shared/forms/form-validators/user.ts
+++ b/client/src/app/shared/forms/form-validators/user.ts
@@ -1,4 +1,4 @@
1import { Validators } from '@angular/forms'; 1import { Validators } from '@angular/forms'
2 2
3export const USER_USERNAME = { 3export const USER_USERNAME = {
4 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(20) ], 4 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(20) ],
@@ -7,18 +7,18 @@ export const USER_USERNAME = {
7 'minlength': 'Username must be at least 3 characters long.', 7 'minlength': 'Username must be at least 3 characters long.',
8 'maxlength': 'Username cannot be more than 20 characters long.' 8 'maxlength': 'Username cannot be more than 20 characters long.'
9 } 9 }
10}; 10}
11export const USER_EMAIL = { 11export const USER_EMAIL = {
12 VALIDATORS: [ Validators.required, Validators.email ], 12 VALIDATORS: [ Validators.required, Validators.email ],
13 MESSAGES: { 13 MESSAGES: {
14 'required': 'Email is required.', 14 'required': 'Email is required.',
15 'email': 'Email must be valid.', 15 'email': 'Email must be valid.'
16 } 16 }
17}; 17}
18export const USER_PASSWORD = { 18export const USER_PASSWORD = {
19 VALIDATORS: [ Validators.required, Validators.minLength(6) ], 19 VALIDATORS: [ Validators.required, Validators.minLength(6) ],
20 MESSAGES: { 20 MESSAGES: {
21 'required': 'Password is required.', 21 'required': 'Password is required.',
22 'minlength': 'Password must be at least 6 characters long.', 22 'minlength': 'Password must be at least 6 characters long.'
23 } 23 }
24}; 24}
diff --git a/client/src/app/shared/forms/form-validators/video-abuse.ts b/client/src/app/shared/forms/form-validators/video-abuse.ts
index 94a29a3b7..3c7f26205 100644
--- a/client/src/app/shared/forms/form-validators/video-abuse.ts
+++ b/client/src/app/shared/forms/form-validators/video-abuse.ts
@@ -1,4 +1,4 @@
1import { Validators } from '@angular/forms'; 1import { Validators } from '@angular/forms'
2 2
3export const VIDEO_ABUSE_REASON = { 3export const VIDEO_ABUSE_REASON = {
4 VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(300) ], 4 VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(300) ],
@@ -7,4 +7,4 @@ export const VIDEO_ABUSE_REASON = {
7 'minlength': 'Report reson must be at least 2 characters long.', 7 'minlength': 'Report reson must be at least 2 characters long.',
8 'maxlength': 'Report reson cannot be more than 300 characters long.' 8 'maxlength': 'Report reson cannot be more than 300 characters long.'
9 } 9 }
10}; 10}
diff --git a/client/src/app/shared/forms/form-validators/video.ts b/client/src/app/shared/forms/form-validators/video.ts
index f7e4e5e4b..6542cf8f6 100644
--- a/client/src/app/shared/forms/form-validators/video.ts
+++ b/client/src/app/shared/forms/form-validators/video.ts
@@ -1,4 +1,4 @@
1import { Validators } from '@angular/forms'; 1import { Validators } from '@angular/forms'
2 2
3export const VIDEO_NAME = { 3export const VIDEO_NAME = {
4 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(50) ], 4 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(50) ],
@@ -7,26 +7,26 @@ export const VIDEO_NAME = {
7 'minlength': 'Video name must be at least 3 characters long.', 7 'minlength': 'Video name must be at least 3 characters long.',
8 'maxlength': 'Video name cannot be more than 50 characters long.' 8 'maxlength': 'Video name cannot be more than 50 characters long.'
9 } 9 }
10}; 10}
11 11
12export const VIDEO_CATEGORY = { 12export const VIDEO_CATEGORY = {
13 VALIDATORS: [ Validators.required ], 13 VALIDATORS: [ Validators.required ],
14 MESSAGES: { 14 MESSAGES: {
15 'required': 'Video category is required.' 15 'required': 'Video category is required.'
16 } 16 }
17}; 17}
18 18
19export const VIDEO_LICENCE = { 19export const VIDEO_LICENCE = {
20 VALIDATORS: [ Validators.required ], 20 VALIDATORS: [ Validators.required ],
21 MESSAGES: { 21 MESSAGES: {
22 'required': 'Video licence is required.' 22 'required': 'Video licence is required.'
23 } 23 }
24}; 24}
25 25
26export const VIDEO_LANGUAGE = { 26export const VIDEO_LANGUAGE = {
27 VALIDATORS: [ ], 27 VALIDATORS: [ ],
28 MESSAGES: {} 28 MESSAGES: {}
29}; 29}
30 30
31export const VIDEO_DESCRIPTION = { 31export const VIDEO_DESCRIPTION = {
32 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ], 32 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ],
@@ -35,7 +35,7 @@ export const VIDEO_DESCRIPTION = {
35 'minlength': 'Video description must be at least 3 characters long.', 35 'minlength': 'Video description must be at least 3 characters long.',
36 'maxlength': 'Video description cannot be more than 250 characters long.' 36 'maxlength': 'Video description cannot be more than 250 characters long.'
37 } 37 }
38}; 38}
39 39
40export const VIDEO_TAGS = { 40export const VIDEO_TAGS = {
41 VALIDATORS: [ Validators.minLength(2), Validators.maxLength(10) ], 41 VALIDATORS: [ Validators.minLength(2), Validators.maxLength(10) ],
@@ -43,4 +43,4 @@ export const VIDEO_TAGS = {
43 'minlength': 'A tag should be more than 2 characters long.', 43 'minlength': 'A tag should be more than 2 characters long.',
44 'maxlength': 'A tag should be less than 10 characters long.' 44 'maxlength': 'A tag should be less than 10 characters long.'
45 } 45 }
46}; 46}
diff --git a/client/src/app/shared/forms/index.ts b/client/src/app/shared/forms/index.ts
index 588ebb4be..7464bb022 100644
--- a/client/src/app/shared/forms/index.ts
+++ b/client/src/app/shared/forms/index.ts
@@ -1,2 +1,2 @@
1export * from './form-validators'; 1export * from './form-validators'
2export * from './form-reactive'; 2export * from './form-reactive'
diff --git a/client/src/app/shared/index.ts b/client/src/app/shared/index.ts
index 61e8ed523..212645c51 100644
--- a/client/src/app/shared/index.ts
+++ b/client/src/app/shared/index.ts
@@ -1,8 +1,8 @@
1export * from './auth'; 1export * from './auth'
2export * from './forms'; 2export * from './forms'
3export * from './rest'; 3export * from './rest'
4export * from './search'; 4export * 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'; 8export * from './utils'
diff --git a/client/src/app/shared/rest/index.ts b/client/src/app/shared/rest/index.ts
index 3cb123c3b..e0be155cf 100644
--- a/client/src/app/shared/rest/index.ts
+++ b/client/src/app/shared/rest/index.ts
@@ -1,4 +1,4 @@
1export * from './rest-data-source'; 1export * from './rest-data-source'
2export * from './rest-extractor.service'; 2export * from './rest-extractor.service'
3export * from './rest-pagination'; 3export * from './rest-pagination'
4export * 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
index 1def38c73..2ef5d38da 100644
--- a/client/src/app/shared/rest/rest-data-source.ts
+++ b/client/src/app/shared/rest/rest-data-source.ts
@@ -1,51 +1,51 @@
1import { Http, RequestOptionsArgs, URLSearchParams, } from '@angular/http'; 1import { Http, RequestOptionsArgs, URLSearchParams, Response } from '@angular/http'
2 2
3import { ServerDataSource } from 'ng2-smart-table'; 3import { ServerDataSource } from 'ng2-smart-table'
4 4
5export class RestDataSource extends ServerDataSource { 5export class RestDataSource extends ServerDataSource {
6 constructor(http: Http, endpoint: string) { 6 constructor (http: Http, endpoint: string) {
7 const options = { 7 const options = {
8 endPoint: endpoint, 8 endPoint: endpoint,
9 sortFieldKey: 'sort', 9 sortFieldKey: 'sort',
10 dataKey: 'data' 10 dataKey: 'data'
11 }; 11 }
12 12
13 super(http, options); 13 super(http, options)
14 } 14 }
15 15
16 protected extractTotalFromResponse(res) { 16 protected extractTotalFromResponse (res: Response) {
17 const rawData = res.json(); 17 const rawData = res.json()
18 return rawData ? parseInt(rawData.total) : 0; 18 return rawData ? parseInt(rawData.total, 10) : 0
19 } 19 }
20 20
21 protected addSortRequestOptions(requestOptions: RequestOptionsArgs) { 21 protected addSortRequestOptions (requestOptions: RequestOptionsArgs) {
22 let searchParams: URLSearchParams = <URLSearchParams> requestOptions.search; 22 const searchParams = requestOptions.search as URLSearchParams
23 23
24 if (this.sortConf) { 24 if (this.sortConf) {
25 this.sortConf.forEach((fieldConf) => { 25 this.sortConf.forEach((fieldConf) => {
26 const sortPrefix = fieldConf.direction === 'desc' ? '-' : ''; 26 const sortPrefix = fieldConf.direction === 'desc' ? '-' : ''
27 27
28 searchParams.set(this.conf.sortFieldKey, sortPrefix + fieldConf.field); 28 searchParams.set(this.conf.sortFieldKey, sortPrefix + fieldConf.field)
29 }); 29 })
30 } 30 }
31 31
32 return requestOptions; 32 return requestOptions
33 } 33 }
34 34
35 protected addPagerRequestOptions(requestOptions: RequestOptionsArgs) { 35 protected addPagerRequestOptions (requestOptions: RequestOptionsArgs) {
36 let searchParams: URLSearchParams = <URLSearchParams> requestOptions.search; 36 const searchParams = requestOptions.search as URLSearchParams
37 37
38 if (this.pagingConf && this.pagingConf['page'] && this.pagingConf['perPage']) { 38 if (this.pagingConf && this.pagingConf['page'] && this.pagingConf['perPage']) {
39 const perPage = this.pagingConf['perPage']; 39 const perPage = this.pagingConf['perPage']
40 const page = this.pagingConf['page']; 40 const page = this.pagingConf['page']
41 41
42 const start = (page - 1) * perPage; 42 const start = (page - 1) * perPage
43 const count = perPage; 43 const count = perPage
44 44
45 searchParams.set('start', start.toString()); 45 searchParams.set('start', start.toString())
46 searchParams.set('count', count.toString()); 46 searchParams.set('count', count.toString())
47 } 47 }
48 48
49 return requestOptions; 49 return requestOptions
50 } 50 }
51} 51}
diff --git a/client/src/app/shared/rest/rest-extractor.service.ts b/client/src/app/shared/rest/rest-extractor.service.ts
index fcb1598f4..f6a818ec8 100644
--- a/client/src/app/shared/rest/rest-extractor.service.ts
+++ b/client/src/app/shared/rest/rest-extractor.service.ts
@@ -1,52 +1,52 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { Response } from '@angular/http'; 2import { Response } from '@angular/http'
3import { Observable } from 'rxjs/Observable'; 3import { Observable } from 'rxjs/Observable'
4 4
5export interface ResultList { 5export interface ResultList {
6 data: any[]; 6 data: any[]
7 total: number; 7 total: number
8} 8}
9 9
10@Injectable() 10@Injectable()
11export class RestExtractor { 11export class RestExtractor {
12 12
13 constructor () { ; } 13 extractDataBool (res: Response) {
14 14 return true
15 extractDataBool(res: Response) {
16 return true;
17 } 15 }
18 16
19 extractDataList(res: Response) { 17 extractDataList (res: Response) {
20 const body = res.json(); 18 const body = res.json()
21 19
22 const ret: ResultList = { 20 const ret: ResultList = {
23 data: body.data, 21 data: body.data,
24 total: body.total 22 total: body.total
25 }; 23 }
26 24
27 return ret; 25 return ret
28 } 26 }
29 27
30 extractDataGet(res: Response) { 28 extractDataGet (res: Response) {
31 return res.json(); 29 return res.json()
32 } 30 }
33 31
34 handleError(res: Response) { 32 handleError (res: Response) {
35 let text = 'Server error: '; 33 let text = 'Server error: '
36 text += res.text(); 34 text += res.text()
37 let json = ''; 35 let json = ''
38 36
39 try { 37 try {
40 json = res.json(); 38 json = res.json()
41 } catch (err) { ; } 39 } catch (err) {
40 console.error('Cannot get JSON from response.')
41 }
42 42
43 const error = { 43 const error = {
44 json, 44 json,
45 text 45 text
46 }; 46 }
47 47
48 console.error(error); 48 console.error(error)
49 49
50 return Observable.throw(error); 50 return Observable.throw(error)
51 } 51 }
52} 52}
diff --git a/client/src/app/shared/rest/rest-pagination.ts b/client/src/app/shared/rest/rest-pagination.ts
index 0cfa4f468..766e7a9e5 100644
--- a/client/src/app/shared/rest/rest-pagination.ts
+++ b/client/src/app/shared/rest/rest-pagination.ts
@@ -1,5 +1,5 @@
1export interface RestPagination { 1export interface RestPagination {
2 currentPage: number; 2 currentPage: number
3 itemsPerPage: number; 3 itemsPerPage: number
4 totalItems: number; 4 totalItems: number
5}; 5}
diff --git a/client/src/app/shared/rest/rest.service.ts b/client/src/app/shared/rest/rest.service.ts
index 16b47e957..43dc20b34 100644
--- a/client/src/app/shared/rest/rest.service.ts
+++ b/client/src/app/shared/rest/rest.service.ts
@@ -1,27 +1,27 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { URLSearchParams } from '@angular/http'; 2import { URLSearchParams } from '@angular/http'
3 3
4import { RestPagination } from './rest-pagination'; 4import { RestPagination } from './rest-pagination'
5 5
6@Injectable() 6@Injectable()
7export class RestService { 7export class RestService {
8 8
9 buildRestGetParams(pagination?: RestPagination, sort?: string) { 9 buildRestGetParams (pagination?: RestPagination, sort?: string) {
10 const params = new URLSearchParams(); 10 const params = new URLSearchParams()
11 11
12 if (pagination) { 12 if (pagination) {
13 const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage; 13 const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage
14 const count: number = pagination.itemsPerPage; 14 const count: number = pagination.itemsPerPage
15 15
16 params.set('start', start.toString()); 16 params.set('start', start.toString())
17 params.set('count', count.toString()); 17 params.set('count', count.toString())
18 } 18 }
19 19
20 if (sort) { 20 if (sort) {
21 params.set('sort', sort); 21 params.set('sort', sort)
22 } 22 }
23 23
24 return params; 24 return params
25 } 25 }
26 26
27} 27}
diff --git a/client/src/app/shared/search/index.ts b/client/src/app/shared/search/index.ts
index a897ed099..d4016cf89 100644
--- a/client/src/app/shared/search/index.ts
+++ b/client/src/app/shared/search/index.ts
@@ -1,4 +1,4 @@
1export * from './search-field.type'; 1export * from './search-field.type'
2export * from './search.component'; 2export * from './search.component'
3export * from './search.model'; 3export * from './search.model'
4export * from './search.service'; 4export * from './search.service'
diff --git a/client/src/app/shared/search/search-field.type.ts b/client/src/app/shared/search/search-field.type.ts
index 6be584ed1..63557898a 100644
--- a/client/src/app/shared/search/search-field.type.ts
+++ b/client/src/app/shared/search/search-field.type.ts
@@ -1 +1 @@
export type SearchField = "name" | "author" | "host" | "magnetUri" | "tags"; export type SearchField = 'name' | 'author' | 'host' | 'magnetUri' | 'tags'
diff --git a/client/src/app/shared/search/search.component.ts b/client/src/app/shared/search/search.component.ts
index 48413b4f2..ecce20666 100644
--- a/client/src/app/shared/search/search.component.ts
+++ b/client/src/app/shared/search/search.component.ts
@@ -1,9 +1,9 @@
1import { Component, OnInit } from '@angular/core'; 1import { Component, OnInit } from '@angular/core'
2import { Router } from '@angular/router'; 2import { Router } from '@angular/router'
3 3
4import { Search } from './search.model'; 4import { Search } from './search.model'
5import { SearchField } from './search-field.type'; 5import { SearchField } from './search-field.type'
6import { SearchService } from './search.service'; 6import { SearchService } from './search.service'
7 7
8@Component({ 8@Component({
9 selector: 'my-search', 9 selector: 'my-search',
@@ -18,53 +18,53 @@ export class SearchComponent implements OnInit {
18 host: 'Pod Host', 18 host: 'Pod Host',
19 magnetUri: 'Magnet URI', 19 magnetUri: 'Magnet URI',
20 tags: 'Tags' 20 tags: 'Tags'
21 }; 21 }
22 searchCriterias: Search = { 22 searchCriterias: Search = {
23 field: 'name', 23 field: 'name',
24 value: '' 24 value: ''
25 }; 25 }
26 26
27 constructor(private searchService: SearchService, private router: Router) {} 27 constructor (private searchService: SearchService, private router: Router) {}
28 28
29 ngOnInit() { 29 ngOnInit () {
30 // Subscribe if the search changed 30 // Subscribe if the search changed
31 // Usually changed by videos list component 31 // Usually changed by videos list component
32 this.searchService.updateSearch.subscribe( 32 this.searchService.updateSearch.subscribe(
33 newSearchCriterias => { 33 newSearchCriterias => {
34 // Put a field by default 34 // Put a field by default
35 if (!newSearchCriterias.field) { 35 if (!newSearchCriterias.field) {
36 newSearchCriterias.field = 'name'; 36 newSearchCriterias.field = 'name'
37 } 37 }
38 38
39 this.searchCriterias = newSearchCriterias; 39 this.searchCriterias = newSearchCriterias
40 } 40 }
41 ); 41 )
42 } 42 }
43 43
44 get choiceKeys() { 44 get choiceKeys () {
45 return Object.keys(this.fieldChoices); 45 return Object.keys(this.fieldChoices)
46 } 46 }
47 47
48 choose($event: MouseEvent, choice: SearchField) { 48 choose ($event: MouseEvent, choice: SearchField) {
49 $event.preventDefault(); 49 $event.preventDefault()
50 $event.stopPropagation(); 50 $event.stopPropagation()
51 51
52 this.searchCriterias.field = choice; 52 this.searchCriterias.field = choice
53 53
54 if (this.searchCriterias.value) { 54 if (this.searchCriterias.value) {
55 this.doSearch(); 55 this.doSearch()
56 } 56 }
57 } 57 }
58 58
59 doSearch() { 59 doSearch () {
60 if (this.router.url.indexOf('/videos/list') === -1) { 60 if (this.router.url.indexOf('/videos/list') === -1) {
61 this.router.navigate([ '/videos/list' ]); 61 this.router.navigate([ '/videos/list' ])
62 } 62 }
63 63
64 this.searchService.searchUpdated.next(this.searchCriterias); 64 this.searchService.searchUpdated.next(this.searchCriterias)
65 } 65 }
66 66
67 getStringChoice(choiceKey: SearchField) { 67 getStringChoice (choiceKey: SearchField) {
68 return this.fieldChoices[choiceKey]; 68 return this.fieldChoices[choiceKey]
69 } 69 }
70} 70}
diff --git a/client/src/app/shared/search/search.model.ts b/client/src/app/shared/search/search.model.ts
index 932a6566c..174adf2c6 100644
--- a/client/src/app/shared/search/search.model.ts
+++ b/client/src/app/shared/search/search.model.ts
@@ -1,6 +1,6 @@
1import { SearchField } from './search-field.type'; 1import { SearchField } from './search-field.type'
2 2
3export interface Search { 3export interface Search {
4 field: SearchField; 4 field: SearchField
5 value: string; 5 value: string
6} 6}
diff --git a/client/src/app/shared/search/search.service.ts b/client/src/app/shared/search/search.service.ts
index 717a7fa50..0480b46bd 100644
--- a/client/src/app/shared/search/search.service.ts
+++ b/client/src/app/shared/search/search.service.ts
@@ -1,18 +1,18 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { Subject } from 'rxjs/Subject'; 2import { Subject } from 'rxjs/Subject'
3import { ReplaySubject } from 'rxjs/ReplaySubject'; 3import { ReplaySubject } from 'rxjs/ReplaySubject'
4 4
5import { Search } from './search.model'; 5import { Search } from './search.model'
6 6
7// This class is needed to communicate between videos/ and search component 7// This class is needed to communicate between videos/ and search component
8// Remove it when we'll be able to subscribe to router changes 8// Remove it when we'll be able to subscribe to router changes
9@Injectable() 9@Injectable()
10export class SearchService { 10export class SearchService {
11 searchUpdated: Subject<Search>; 11 searchUpdated: Subject<Search>
12 updateSearch: Subject<Search>; 12 updateSearch: Subject<Search>
13 13
14 constructor() { 14 constructor () {
15 this.updateSearch = new Subject<Search>(); 15 this.updateSearch = new Subject<Search>()
16 this.searchUpdated = new ReplaySubject<Search>(1); 16 this.searchUpdated = new ReplaySubject<Search>(1)
17 } 17 }
18} 18}
diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts
index 8ffaf964b..99b51aa4e 100644
--- a/client/src/app/shared/shared.module.ts
+++ b/client/src/app/shared/shared.module.ts
@@ -1,23 +1,23 @@
1import { NgModule } from '@angular/core'; 1import { NgModule } from '@angular/core'
2import { CommonModule } from '@angular/common'; 2import { CommonModule } from '@angular/common'
3import { HttpModule } from '@angular/http'; 3import { HttpModule } from '@angular/http'
4import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 4import { FormsModule, ReactiveFormsModule } from '@angular/forms'
5import { RouterModule } from '@angular/router'; 5import { RouterModule } from '@angular/router'
6 6
7import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; 7import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'
8import { KeysPipe } from 'angular-pipes/src/object/keys.pipe'; 8import { KeysPipe } from 'angular-pipes/src/object/keys.pipe'
9import { BsDropdownModule } from 'ngx-bootstrap/dropdown'; 9import { BsDropdownModule } from 'ngx-bootstrap/dropdown'
10import { ProgressbarModule } from 'ngx-bootstrap/progressbar'; 10import { ProgressbarModule } from 'ngx-bootstrap/progressbar'
11import { PaginationModule } from 'ngx-bootstrap/pagination'; 11import { PaginationModule } from 'ngx-bootstrap/pagination'
12import { ModalModule } from 'ngx-bootstrap/modal'; 12import { ModalModule } from 'ngx-bootstrap/modal'
13import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload'; 13import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload'
14import { Ng2SmartTableModule } from 'ng2-smart-table'; 14import { Ng2SmartTableModule } from 'ng2-smart-table'
15 15
16import { AUTH_HTTP_PROVIDERS } from './auth'; 16import { AUTH_HTTP_PROVIDERS } from './auth'
17import { RestExtractor, RestService } from './rest'; 17import { RestExtractor, RestService } from './rest'
18import { SearchComponent, SearchService } from './search'; 18import { SearchComponent, SearchService } from './search'
19import { UserService } from './users'; 19import { UserService } from './users'
20import { VideoAbuseService } from './video-abuse'; 20import { VideoAbuseService } from './video-abuse'
21 21
22@NgModule({ 22@NgModule({
23 imports: [ 23 imports: [
diff --git a/client/src/app/shared/users/index.ts b/client/src/app/shared/users/index.ts
index ff009e89b..7b5a67bc7 100644
--- a/client/src/app/shared/users/index.ts
+++ b/client/src/app/shared/users/index.ts
@@ -1,2 +1,2 @@
1export * from './user.model'; 1export * from './user.model'
2export * from './user.service'; 2export * from './user.service'
diff --git a/client/src/app/shared/users/user.model.ts b/client/src/app/shared/users/user.model.ts
index d4695ab67..1c2b481e3 100644
--- a/client/src/app/shared/users/user.model.ts
+++ b/client/src/app/shared/users/user.model.ts
@@ -1,33 +1,33 @@
1import { User as UserServerModel, UserRole } from '../../../../../shared'; 1import { User as UserServerModel, UserRole } from '../../../../../shared'
2 2
3export class User implements UserServerModel { 3export class User implements UserServerModel {
4 id: number; 4 id: number
5 username: string; 5 username: string
6 email: string; 6 email: string
7 role: UserRole; 7 role: UserRole
8 displayNSFW: boolean; 8 displayNSFW: boolean
9 createdAt: Date; 9 createdAt: Date
10 10
11 constructor(hash: { 11 constructor (hash: {
12 id: number, 12 id: number,
13 username: string, 13 username: string,
14 email: string, 14 email: string,
15 role: UserRole, 15 role: UserRole,
16 displayNSFW?: boolean, 16 displayNSFW?: boolean,
17 createdAt?: Date, 17 createdAt?: Date
18 }) { 18 }) {
19 this.id = hash.id; 19 this.id = hash.id
20 this.username = hash.username; 20 this.username = hash.username
21 this.email = hash.email; 21 this.email = hash.email
22 this.role = hash.role; 22 this.role = hash.role
23 this.displayNSFW = hash.displayNSFW; 23 this.displayNSFW = hash.displayNSFW
24 24
25 if (hash.createdAt) { 25 if (hash.createdAt) {
26 this.createdAt = hash.createdAt; 26 this.createdAt = hash.createdAt
27 } 27 }
28 } 28 }
29 29
30 isAdmin() { 30 isAdmin () {
31 return this.role === 'admin'; 31 return this.role === 'admin'
32 } 32 }
33} 33}
diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts
index f1265be0a..e956df5b1 100644
--- a/client/src/app/shared/users/user.service.ts
+++ b/client/src/app/shared/users/user.service.ts
@@ -1,58 +1,58 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { Http } from '@angular/http'; 2import { Http } from '@angular/http'
3import 'rxjs/add/operator/catch'; 3import 'rxjs/add/operator/catch'
4import 'rxjs/add/operator/map'; 4import 'rxjs/add/operator/map'
5 5
6import { AuthService } from '../../core'; 6import { AuthService } from '../../core'
7import { AuthHttp } from '../auth'; 7import { AuthHttp } from '../auth'
8import { RestExtractor } from '../rest'; 8import { RestExtractor } from '../rest'
9 9
10@Injectable() 10@Injectable()
11export class UserService { 11export class UserService {
12 static BASE_USERS_URL = API_URL + '/api/v1/users/'; 12 static BASE_USERS_URL = API_URL + '/api/v1/users/'
13 13
14 constructor( 14 constructor (
15 private http: Http, 15 private http: Http,
16 private authHttp: AuthHttp, 16 private authHttp: AuthHttp,
17 private authService: AuthService, 17 private authService: AuthService,
18 private restExtractor: RestExtractor 18 private restExtractor: RestExtractor
19 ) {} 19 ) {}
20 20
21 checkTokenValidity() { 21 checkTokenValidity () {
22 const url = UserService.BASE_USERS_URL + 'me'; 22 const url = UserService.BASE_USERS_URL + 'me'
23 23
24 // AuthHttp will redirect us to the login page if the oken is not valid anymore 24 // AuthHttp will redirect us to the login page if the oken is not valid anymore
25 this.authHttp.get(url).subscribe(() => { ; }); 25 this.authHttp.get(url).subscribe()
26 } 26 }
27 27
28 changePassword(newPassword: string) { 28 changePassword (newPassword: string) {
29 const url = UserService.BASE_USERS_URL + this.authService.getUser().id; 29 const url = UserService.BASE_USERS_URL + this.authService.getUser().id
30 const body = { 30 const body = {
31 password: newPassword 31 password: newPassword
32 }; 32 }
33 33
34 return this.authHttp.put(url, body) 34 return this.authHttp.put(url, body)
35 .map(this.restExtractor.extractDataBool) 35 .map(this.restExtractor.extractDataBool)
36 .catch((res) => this.restExtractor.handleError(res)); 36 .catch((res) => this.restExtractor.handleError(res))
37 } 37 }
38 38
39 updateDetails(details: { displayNSFW: boolean }) { 39 updateDetails (details: { displayNSFW: boolean }) {
40 const url = UserService.BASE_USERS_URL + this.authService.getUser().id; 40 const url = UserService.BASE_USERS_URL + this.authService.getUser().id
41 41
42 return this.authHttp.put(url, details) 42 return this.authHttp.put(url, details)
43 .map(this.restExtractor.extractDataBool) 43 .map(this.restExtractor.extractDataBool)
44 .catch((res) => this.restExtractor.handleError(res)); 44 .catch((res) => this.restExtractor.handleError(res))
45 } 45 }
46 46
47 signup(username: string, password: string, email: string) { 47 signup (username: string, password: string, email: string) {
48 const body = { 48 const body = {
49 username, 49 username,
50 email, 50 email,
51 password 51 password
52 }; 52 }
53 53
54 return this.http.post(UserService.BASE_USERS_URL + 'register', body) 54 return this.http.post(UserService.BASE_USERS_URL + 'register', body)
55 .map(this.restExtractor.extractDataBool) 55 .map(this.restExtractor.extractDataBool)
56 .catch(this.restExtractor.handleError); 56 .catch(this.restExtractor.handleError)
57 } 57 }
58} 58}
diff --git a/client/src/app/shared/utils.ts b/client/src/app/shared/utils.ts
index 5ab41fe5a..832311f89 100644
--- a/client/src/app/shared/utils.ts
+++ b/client/src/app/shared/utils.ts
@@ -1,12 +1,12 @@
1import { DatePipe } from '@angular/common'; 1import { DatePipe } from '@angular/common'
2 2
3export class Utils { 3export class Utils {
4 4
5 static dateToHuman(date: String) { 5 static dateToHuman (date: String) {
6 return new DatePipe('en').transform(date, 'medium'); 6 return new DatePipe('en').transform(date, 'medium')
7 } 7 }
8 8
9 static getRowDeleteButton() { 9 static getRowDeleteButton () {
10 return '<span class="glyphicon glyphicon-remove glyphicon-black"></span>'; 10 return '<span class="glyphicon glyphicon-remove glyphicon-black"></span>'
11 } 11 }
12} 12}
diff --git a/client/src/app/shared/video-abuse/index.ts b/client/src/app/shared/video-abuse/index.ts
index 563533ba5..7cf24c87d 100644
--- a/client/src/app/shared/video-abuse/index.ts
+++ b/client/src/app/shared/video-abuse/index.ts
@@ -1,2 +1,2 @@
1export * from './video-abuse.service'; 1export * from './video-abuse.service'
2export * from './video-abuse.model'; 2export * from './video-abuse.model'
diff --git a/client/src/app/shared/video-abuse/video-abuse.model.ts b/client/src/app/shared/video-abuse/video-abuse.model.ts
index bb0373027..49c87d6b8 100644
--- a/client/src/app/shared/video-abuse/video-abuse.model.ts
+++ b/client/src/app/shared/video-abuse/video-abuse.model.ts
@@ -1,8 +1,8 @@
1export interface VideoAbuse { 1export interface VideoAbuse {
2 id: string; 2 id: string
3 reason: string; 3 reason: string
4 reporterPodHost: string; 4 reporterPodHost: string
5 reporterUsername: string; 5 reporterUsername: string
6 videoId: string; 6 videoId: string
7 createdAt: Date; 7 createdAt: Date
8} 8}
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 da7b2ef8a..4317f9353 100644
--- a/client/src/app/shared/video-abuse/video-abuse.service.ts
+++ b/client/src/app/shared/video-abuse/video-abuse.service.ts
@@ -1,42 +1,42 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { Http } from '@angular/http'; 2import { Http } from '@angular/http'
3import { Observable } from 'rxjs/Observable'; 3import { Observable } from 'rxjs/Observable'
4import 'rxjs/add/operator/catch'; 4import 'rxjs/add/operator/catch'
5import 'rxjs/add/operator/map'; 5import 'rxjs/add/operator/map'
6 6
7import { AuthService } from '../core'; 7import { AuthService } from '../core'
8import { AuthHttp } from '../auth'; 8import { AuthHttp } from '../auth'
9import { RestDataSource, 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()
13export class VideoAbuseService { 13export class VideoAbuseService {
14 private static BASE_VIDEO_ABUSE_URL = API_URL + '/api/v1/videos/'; 14 private static BASE_VIDEO_ABUSE_URL = API_URL + '/api/v1/videos/'
15 15
16 constructor( 16 constructor (
17 private authHttp: AuthHttp, 17 private authHttp: AuthHttp,
18 private restExtractor: RestExtractor 18 private restExtractor: RestExtractor
19 ) {} 19 ) {}
20 20
21 getDataSource() { 21 getDataSource () {
22 return new RestDataSource(this.authHttp, VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'); 22 return new RestDataSource(this.authHttp, VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse')
23 } 23 }
24 24
25 reportVideo(id: string, reason: string) { 25 reportVideo (id: string, reason: string) {
26 const body = { 26 const body = {
27 reason 27 reason
28 }; 28 }
29 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'; 29 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
30 30
31 return this.authHttp.post(url, body) 31 return this.authHttp.post(url, body)
32 .map(this.restExtractor.extractDataBool) 32 .map(this.restExtractor.extractDataBool)
33 .catch((res) => this.restExtractor.handleError(res)); 33 .catch((res) => this.restExtractor.handleError(res))
34 } 34 }
35 35
36 private extractVideoAbuses(result: ResultList) { 36 private extractVideoAbuses (result: ResultList) {
37 const videoAbuses: VideoAbuse[] = result.data; 37 const videoAbuses: VideoAbuse[] = result.data
38 const totalVideoAbuses = result.total; 38 const totalVideoAbuses = result.total
39 39
40 return { videoAbuses, totalVideoAbuses }; 40 return { videoAbuses, totalVideoAbuses }
41 } 41 }
42} 42}