aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/friends
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
commitdf98563e2104b82b119c00a3cd83cd0dc1242d25 (patch)
treea9720bf01bac9ad5646bd3d3c9bc7653617afdad /client/src/app/+admin/friends
parent46757b477c1adb5f98060d15998a3852e18902a6 (diff)
downloadPeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.gz
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.zst
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.zip
Use typescript standard and lint all files
Diffstat (limited to 'client/src/app/+admin/friends')
-rw-r--r--client/src/app/+admin/friends/friend-add/friend-add.component.ts108
-rw-r--r--client/src/app/+admin/friends/friend-add/index.ts2
-rw-r--r--client/src/app/+admin/friends/friend-list/friend-list.component.ts38
-rw-r--r--client/src/app/+admin/friends/friend-list/index.ts2
-rw-r--r--client/src/app/+admin/friends/friends.component.ts5
-rw-r--r--client/src/app/+admin/friends/friends.routes.ts60
-rw-r--r--client/src/app/+admin/friends/index.ts10
-rw-r--r--client/src/app/+admin/friends/shared/friend.model.ts10
-rw-r--r--client/src/app/+admin/friends/shared/friend.service.ts30
-rw-r--r--client/src/app/+admin/friends/shared/index.ts4
10 files changed, 134 insertions, 135 deletions
diff --git a/client/src/app/+admin/friends/friend-add/friend-add.component.ts b/client/src/app/+admin/friends/friend-add/friend-add.component.ts
index 12c46e5cd..35cf4a1f7 100644
--- a/client/src/app/+admin/friends/friend-add/friend-add.component.ts
+++ b/client/src/app/+admin/friends/friend-add/friend-add.component.ts
@@ -1,12 +1,12 @@
1import { Component, OnInit } from '@angular/core'; 1import { Component, OnInit } from '@angular/core'
2import { FormControl, FormGroup } from '@angular/forms'; 2import { FormControl, FormGroup } from '@angular/forms'
3import { Router } from '@angular/router'; 3import { Router } from '@angular/router'
4 4
5import { NotificationsService } from 'angular2-notifications'; 5import { NotificationsService } from 'angular2-notifications'
6 6
7import { ConfirmService } from '../../../core'; 7import { ConfirmService } from '../../../core'
8import { validateHost } from '../../../shared'; 8import { validateHost } from '../../../shared'
9import { FriendService } from '../shared'; 9import { FriendService } from '../shared'
10 10
11@Component({ 11@Component({
12 selector: 'my-friend-add', 12 selector: 'my-friend-add',
@@ -14,107 +14,107 @@ import { FriendService } from '../shared';
14 styleUrls: [ './friend-add.component.scss' ] 14 styleUrls: [ './friend-add.component.scss' ]
15}) 15})
16export class FriendAddComponent implements OnInit { 16export class FriendAddComponent implements OnInit {
17 form: FormGroup; 17 form: FormGroup
18 hosts = [ ]; 18 hosts = [ ]
19 error: string = null; 19 error: string = null
20 20
21 constructor( 21 constructor (
22 private router: Router, 22 private router: Router,
23 private notificationsService: NotificationsService, 23 private notificationsService: NotificationsService,
24 private confirmService: ConfirmService, 24 private confirmService: ConfirmService,
25 private friendService: FriendService 25 private friendService: FriendService
26 ) {} 26 ) {}
27 27
28 ngOnInit() { 28 ngOnInit () {
29 this.form = new FormGroup({}); 29 this.form = new FormGroup({})
30 this.addField(); 30 this.addField()
31 } 31 }
32 32
33 addField() { 33 addField () {
34 this.form.addControl(`host-${this.hosts.length}`, new FormControl('', [ validateHost ])); 34 this.form.addControl(`host-${this.hosts.length}`, new FormControl('', [ validateHost ]))
35 this.hosts.push(''); 35 this.hosts.push('')
36 } 36 }
37 37
38 canMakeFriends() { 38 canMakeFriends () {
39 return window.location.protocol === 'https:'; 39 return window.location.protocol === 'https:'
40 } 40 }
41 41
42 customTrackBy(index: number, obj: any): any { 42 customTrackBy (index: number, obj: any): any {
43 return index; 43 return index
44 } 44 }
45 45
46 displayAddField(index: number) { 46 displayAddField (index: number) {
47 return index === (this.hosts.length - 1); 47 return index === (this.hosts.length - 1)
48 } 48 }
49 49
50 displayRemoveField(index: number) { 50 displayRemoveField (index: number) {
51 return (index !== 0 || this.hosts.length > 1) && index !== (this.hosts.length - 1); 51 return (index !== 0 || this.hosts.length > 1) && index !== (this.hosts.length - 1)
52 } 52 }
53 53
54 isFormValid() { 54 isFormValid () {
55 // Do not check the last input 55 // Do not check the last input
56 for (let i = 0; i < this.hosts.length - 1; i++) { 56 for (let i = 0; i < this.hosts.length - 1; i++) {
57 if (!this.form.controls[`host-${i}`].valid) return false; 57 if (!this.form.controls[`host-${i}`].valid) return false
58 } 58 }
59 59
60 const lastIndex = this.hosts.length - 1; 60 const lastIndex = this.hosts.length - 1
61 // If the last input (which is not the first) is empty, it's ok 61 // If the last input (which is not the first) is empty, it's ok
62 if (this.hosts[lastIndex] === '' && lastIndex !== 0) { 62 if (this.hosts[lastIndex] === '' && lastIndex !== 0) {
63 return true; 63 return true
64 } else { 64 } else {
65 return this.form.controls[`host-${lastIndex}`].valid; 65 return this.form.controls[`host-${lastIndex}`].valid
66 } 66 }
67 } 67 }
68 68
69 removeField(index: number) { 69 removeField (index: number) {
70 // Remove the last control 70 // Remove the last control
71 this.form.removeControl(`host-${this.hosts.length - 1}`); 71 this.form.removeControl(`host-${this.hosts.length - 1}`)
72 this.hosts.splice(index, 1); 72 this.hosts.splice(index, 1)
73 } 73 }
74 74
75 makeFriends() { 75 makeFriends () {
76 this.error = ''; 76 this.error = ''
77 77
78 const notEmptyHosts = this.getNotEmptyHosts(); 78 const notEmptyHosts = this.getNotEmptyHosts()
79 if (notEmptyHosts.length === 0) { 79 if (notEmptyHosts.length === 0) {
80 this.error = 'You need to specify at least 1 host.'; 80 this.error = 'You need to specify at least 1 host.'
81 return; 81 return
82 } 82 }
83 83
84 if (!this.isHostsUnique(notEmptyHosts)) { 84 if (!this.isHostsUnique(notEmptyHosts)) {
85 this.error = 'Hosts need to be unique.'; 85 this.error = 'Hosts need to be unique.'
86 return; 86 return
87 } 87 }
88 88
89 const confirmMessage = 'Are you sure to make friends with:<br /> - ' + notEmptyHosts.join('<br /> - '); 89 const confirmMessage = 'Are you sure to make friends with:<br /> - ' + notEmptyHosts.join('<br /> - ')
90 this.confirmService.confirm(confirmMessage, 'Make friends').subscribe( 90 this.confirmService.confirm(confirmMessage, 'Make friends').subscribe(
91 res => { 91 res => {
92 if (res === false) return; 92 if (res === false) return
93 93
94 this.friendService.makeFriends(notEmptyHosts).subscribe( 94 this.friendService.makeFriends(notEmptyHosts).subscribe(
95 status => { 95 status => {
96 this.notificationsService.success('Sucess', 'Make friends request sent!'); 96 this.notificationsService.success('Sucess', 'Make friends request sent!')
97 this.router.navigate([ '/admin/friends/list' ]); 97 this.router.navigate([ '/admin/friends/list' ])
98 }, 98 },
99 99
100 err => this.notificationsService.error('Error', err.text) 100 err => this.notificationsService.error('Error', err.text)
101 ); 101 )
102 } 102 }
103 ); 103 )
104 } 104 }
105 105
106 private getNotEmptyHosts() { 106 private getNotEmptyHosts () {
107 const notEmptyHosts = []; 107 const notEmptyHosts = []
108 108
109 Object.keys(this.form.value).forEach((hostKey) => { 109 Object.keys(this.form.value).forEach((hostKey) => {
110 const host = this.form.value[hostKey]; 110 const host = this.form.value[hostKey]
111 if (host !== '') notEmptyHosts.push(host); 111 if (host !== '') notEmptyHosts.push(host)
112 }); 112 })
113 113
114 return notEmptyHosts; 114 return notEmptyHosts
115 } 115 }
116 116
117 private isHostsUnique(hosts: string[]) { 117 private isHostsUnique (hosts: string[]) {
118 return hosts.every(host => hosts.indexOf(host) === hosts.lastIndexOf(host)); 118 return hosts.every(host => hosts.indexOf(host) === hosts.lastIndexOf(host))
119 } 119 }
120} 120}
diff --git a/client/src/app/+admin/friends/friend-add/index.ts b/client/src/app/+admin/friends/friend-add/index.ts
index a101b3be5..978ab3d46 100644
--- a/client/src/app/+admin/friends/friend-add/index.ts
+++ b/client/src/app/+admin/friends/friend-add/index.ts
@@ -1 +1 @@
export * from './friend-add.component'; export * from './friend-add.component'
diff --git a/client/src/app/+admin/friends/friend-list/friend-list.component.ts b/client/src/app/+admin/friends/friend-list/friend-list.component.ts
index 525a9fbc3..7bf9d2c6b 100644
--- a/client/src/app/+admin/friends/friend-list/friend-list.component.ts
+++ b/client/src/app/+admin/friends/friend-list/friend-list.component.ts
@@ -1,11 +1,11 @@
1import { Component } from '@angular/core'; 1import { Component } from '@angular/core'
2 2
3import { NotificationsService } from 'angular2-notifications'; 3import { NotificationsService } from 'angular2-notifications'
4import { ServerDataSource } from 'ng2-smart-table'; 4import { ServerDataSource } from 'ng2-smart-table'
5 5
6import { ConfirmService } from '../../../core'; 6import { ConfirmService } from '../../../core'
7import { Utils } from '../../../shared'; 7import { Utils } from '../../../shared'
8import { Friend, FriendService } from '../shared'; 8import { Friend, FriendService } from '../shared'
9 9
10@Component({ 10@Component({
11 selector: 'my-friend-list', 11 selector: 'my-friend-list',
@@ -13,7 +13,7 @@ import { Friend, FriendService } from '../shared';
13 styleUrls: [ './friend-list.component.scss' ] 13 styleUrls: [ './friend-list.component.scss' ]
14}) 14})
15export class FriendListComponent { 15export class FriendListComponent {
16 friendsSource = null; 16 friendsSource = null
17 tableSettings = { 17 tableSettings = {
18 attr: { 18 attr: {
19 class: 'table-hover' 19 class: 'table-hover'
@@ -49,36 +49,36 @@ export class FriendListComponent {
49 valuePrepareFunction: Utils.dateToHuman 49 valuePrepareFunction: Utils.dateToHuman
50 } 50 }
51 } 51 }
52 }; 52 }
53 53
54 constructor( 54 constructor (
55 private notificationsService: NotificationsService, 55 private notificationsService: NotificationsService,
56 private confirmService: ConfirmService, 56 private confirmService: ConfirmService,
57 private friendService: FriendService 57 private friendService: FriendService
58 ) { 58 ) {
59 this.friendsSource = this.friendService.getDataSource(); 59 this.friendsSource = this.friendService.getDataSource()
60 } 60 }
61 61
62 hasFriends() { 62 hasFriends () {
63 return this.friendsSource.count() !== 0; 63 return this.friendsSource.count() !== 0
64 } 64 }
65 65
66 quitFriends() { 66 quitFriends () {
67 const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.'; 67 const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.'
68 this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe( 68 this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe(
69 res => { 69 res => {
70 if (res === false) return; 70 if (res === false) return
71 71
72 this.friendService.quitFriends().subscribe( 72 this.friendService.quitFriends().subscribe(
73 status => { 73 status => {
74 this.notificationsService.success('Sucess', 'Friends left!'); 74 this.notificationsService.success('Sucess', 'Friends left!')
75 75
76 this.friendsSource.refresh(); 76 this.friendsSource.refresh()
77 }, 77 },
78 78
79 err => this.notificationsService.error('Error', err.text) 79 err => this.notificationsService.error('Error', err.text)
80 ); 80 )
81 } 81 }
82 ); 82 )
83 } 83 }
84} 84}
diff --git a/client/src/app/+admin/friends/friend-list/index.ts b/client/src/app/+admin/friends/friend-list/index.ts
index 354c978a4..c9cbd2800 100644
--- a/client/src/app/+admin/friends/friend-list/index.ts
+++ b/client/src/app/+admin/friends/friend-list/index.ts
@@ -1 +1 @@
export * from './friend-list.component'; export * from './friend-list.component'
diff --git a/client/src/app/+admin/friends/friends.component.ts b/client/src/app/+admin/friends/friends.component.ts
index 5ca29111c..5ef0aaa03 100644
--- a/client/src/app/+admin/friends/friends.component.ts
+++ b/client/src/app/+admin/friends/friends.component.ts
@@ -1,8 +1,7 @@
1import { Component } from '@angular/core'; 1import { Component } from '@angular/core'
2 2
3@Component({ 3@Component({
4 template: '<router-outlet></router-outlet>' 4 template: '<router-outlet></router-outlet>'
5}) 5})
6
7export class FriendsComponent { 6export class FriendsComponent {
8} 7}
diff --git a/client/src/app/+admin/friends/friends.routes.ts b/client/src/app/+admin/friends/friends.routes.ts
index 747066d1f..615b6f4f7 100644
--- a/client/src/app/+admin/friends/friends.routes.ts
+++ b/client/src/app/+admin/friends/friends.routes.ts
@@ -1,37 +1,37 @@
1import { Routes } from '@angular/router'; 1import { Routes } from '@angular/router'
2 2
3import { FriendsComponent } from './friends.component'; 3import { FriendsComponent } from './friends.component'
4import { FriendAddComponent } from './friend-add'; 4import { FriendAddComponent } from './friend-add'
5import { FriendListComponent } from './friend-list'; 5import { FriendListComponent } from './friend-list'
6 6
7export const FriendsRoutes: Routes = [ 7export const FriendsRoutes: Routes = [
8 { 8 {
9 path: 'friends', 9 path: 'friends',
10 component: FriendsComponent, 10 component: FriendsComponent,
11 children: [ 11 children: [
12 { 12 {
13 path: '', 13 path: '',
14 redirectTo: 'list', 14 redirectTo: 'list',
15 pathMatch: 'full' 15 pathMatch: 'full'
16 }, 16 },
17 { 17 {
18 path: 'list', 18 path: 'list',
19 component: FriendListComponent, 19 component: FriendListComponent,
20 data: { 20 data: {
21 meta: { 21 meta: {
22 title: 'Friends list' 22 title: 'Friends list'
23 }
24 } 23 }
25 }, 24 }
26 { 25 },
27 path: 'add', 26 {
28 component: FriendAddComponent, 27 path: 'add',
29 data: { 28 component: FriendAddComponent,
30 meta: { 29 data: {
31 title: 'Add friends' 30 meta: {
32 } 31 title: 'Add friends'
33 } 32 }
34 } 33 }
35 ] 34 }
36 } 35 ]
37]; 36 }
37]
diff --git a/client/src/app/+admin/friends/index.ts b/client/src/app/+admin/friends/index.ts
index dd4df2538..356dee8e9 100644
--- a/client/src/app/+admin/friends/index.ts
+++ b/client/src/app/+admin/friends/index.ts
@@ -1,5 +1,5 @@
1export * from './friend-add'; 1export * from './friend-add'
2export * from './friend-list'; 2export * from './friend-list'
3export * from './shared'; 3export * from './shared'
4export * from './friends.component'; 4export * from './friends.component'
5export * from './friends.routes'; 5export * from './friends.routes'
diff --git a/client/src/app/+admin/friends/shared/friend.model.ts b/client/src/app/+admin/friends/shared/friend.model.ts
index f72156d05..6950405b9 100644
--- a/client/src/app/+admin/friends/shared/friend.model.ts
+++ b/client/src/app/+admin/friends/shared/friend.model.ts
@@ -1,7 +1,7 @@
1export interface Friend { 1export interface Friend {
2 id: string; 2 id: string
3 host: string; 3 host: string
4 score: number; 4 score: number
5 email: string; 5 email: string
6 createdAt: Date; 6 createdAt: Date
7} 7}
diff --git a/client/src/app/+admin/friends/shared/friend.service.ts b/client/src/app/+admin/friends/shared/friend.service.ts
index 6e51c954f..f4ecd36ad 100644
--- a/client/src/app/+admin/friends/shared/friend.service.ts
+++ b/client/src/app/+admin/friends/shared/friend.service.ts
@@ -1,39 +1,39 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { Observable } from 'rxjs/Observable'; 2import { Observable } from 'rxjs/Observable'
3import 'rxjs/add/operator/catch'; 3import 'rxjs/add/operator/catch'
4import 'rxjs/add/operator/map'; 4import 'rxjs/add/operator/map'
5 5
6import { ServerDataSource } from 'ng2-smart-table'; 6import { ServerDataSource } from 'ng2-smart-table'
7 7
8import { Friend } from './friend.model'; 8import { Friend } from './friend.model'
9import { AuthHttp, RestExtractor, RestDataSource, ResultList } from '../../../shared'; 9import { AuthHttp, RestExtractor, RestDataSource, ResultList } from '../../../shared'
10 10
11@Injectable() 11@Injectable()
12export class FriendService { 12export class FriendService {
13 private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/'; 13 private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/'
14 14
15 constructor ( 15 constructor (
16 private authHttp: AuthHttp, 16 private authHttp: AuthHttp,
17 private restExtractor: RestExtractor 17 private restExtractor: RestExtractor
18 ) {} 18 ) {}
19 19
20 getDataSource() { 20 getDataSource () {
21 return new RestDataSource(this.authHttp, FriendService.BASE_FRIEND_URL); 21 return new RestDataSource(this.authHttp, FriendService.BASE_FRIEND_URL)
22 } 22 }
23 23
24 makeFriends(notEmptyHosts) { 24 makeFriends (notEmptyHosts) {
25 const body = { 25 const body = {
26 hosts: notEmptyHosts 26 hosts: notEmptyHosts
27 }; 27 }
28 28
29 return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body) 29 return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body)
30 .map(this.restExtractor.extractDataBool) 30 .map(this.restExtractor.extractDataBool)
31 .catch((res) => this.restExtractor.handleError(res)); 31 .catch((res) => this.restExtractor.handleError(res))
32 } 32 }
33 33
34 quitFriends() { 34 quitFriends () {
35 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') 35 return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
36 .map(res => res.status) 36 .map(res => res.status)
37 .catch((res) => this.restExtractor.handleError(res)); 37 .catch((res) => this.restExtractor.handleError(res))
38 } 38 }
39} 39}
diff --git a/client/src/app/+admin/friends/shared/index.ts b/client/src/app/+admin/friends/shared/index.ts
index 0d671637d..41aa6edd6 100644
--- a/client/src/app/+admin/friends/shared/index.ts
+++ b/client/src/app/+admin/friends/shared/index.ts
@@ -1,2 +1,2 @@
1export * from './friend.model'; 1export * from './friend.model'
2export * from './friend.service'; 2export * from './friend.service'