From df98563e2104b82b119c00a3cd83cd0dc1242d25 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jun 2017 14:32:15 +0200 Subject: Use typescript standard and lint all files --- .../friends/friend-add/friend-add.component.ts | 108 ++++++++++----------- client/src/app/+admin/friends/friend-add/index.ts | 2 +- .../friends/friend-list/friend-list.component.ts | 38 ++++---- client/src/app/+admin/friends/friend-list/index.ts | 2 +- client/src/app/+admin/friends/friends.component.ts | 5 +- client/src/app/+admin/friends/friends.routes.ts | 60 ++++++------ client/src/app/+admin/friends/index.ts | 10 +- .../src/app/+admin/friends/shared/friend.model.ts | 10 +- .../app/+admin/friends/shared/friend.service.ts | 30 +++--- client/src/app/+admin/friends/shared/index.ts | 4 +- 10 files changed, 134 insertions(+), 135 deletions(-) (limited to 'client/src/app/+admin/friends') 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 @@ -import { Component, OnInit } from '@angular/core'; -import { FormControl, FormGroup } from '@angular/forms'; -import { Router } from '@angular/router'; +import { Component, OnInit } from '@angular/core' +import { FormControl, FormGroup } from '@angular/forms' +import { Router } from '@angular/router' -import { NotificationsService } from 'angular2-notifications'; +import { NotificationsService } from 'angular2-notifications' -import { ConfirmService } from '../../../core'; -import { validateHost } from '../../../shared'; -import { FriendService } from '../shared'; +import { ConfirmService } from '../../../core' +import { validateHost } from '../../../shared' +import { FriendService } from '../shared' @Component({ selector: 'my-friend-add', @@ -14,107 +14,107 @@ import { FriendService } from '../shared'; styleUrls: [ './friend-add.component.scss' ] }) export class FriendAddComponent implements OnInit { - form: FormGroup; - hosts = [ ]; - error: string = null; + form: FormGroup + hosts = [ ] + error: string = null - constructor( + constructor ( private router: Router, private notificationsService: NotificationsService, private confirmService: ConfirmService, private friendService: FriendService ) {} - ngOnInit() { - this.form = new FormGroup({}); - this.addField(); + ngOnInit () { + this.form = new FormGroup({}) + this.addField() } - addField() { - this.form.addControl(`host-${this.hosts.length}`, new FormControl('', [ validateHost ])); - this.hosts.push(''); + addField () { + this.form.addControl(`host-${this.hosts.length}`, new FormControl('', [ validateHost ])) + this.hosts.push('') } - canMakeFriends() { - return window.location.protocol === 'https:'; + canMakeFriends () { + return window.location.protocol === 'https:' } - customTrackBy(index: number, obj: any): any { - return index; + customTrackBy (index: number, obj: any): any { + return index } - displayAddField(index: number) { - return index === (this.hosts.length - 1); + displayAddField (index: number) { + return index === (this.hosts.length - 1) } - displayRemoveField(index: number) { - return (index !== 0 || this.hosts.length > 1) && index !== (this.hosts.length - 1); + displayRemoveField (index: number) { + return (index !== 0 || this.hosts.length > 1) && index !== (this.hosts.length - 1) } - isFormValid() { + isFormValid () { // Do not check the last input for (let i = 0; i < this.hosts.length - 1; i++) { - if (!this.form.controls[`host-${i}`].valid) return false; + if (!this.form.controls[`host-${i}`].valid) return false } - const lastIndex = this.hosts.length - 1; + const lastIndex = this.hosts.length - 1 // If the last input (which is not the first) is empty, it's ok if (this.hosts[lastIndex] === '' && lastIndex !== 0) { - return true; + return true } else { - return this.form.controls[`host-${lastIndex}`].valid; + return this.form.controls[`host-${lastIndex}`].valid } } - removeField(index: number) { + removeField (index: number) { // Remove the last control - this.form.removeControl(`host-${this.hosts.length - 1}`); - this.hosts.splice(index, 1); + this.form.removeControl(`host-${this.hosts.length - 1}`) + this.hosts.splice(index, 1) } - makeFriends() { - this.error = ''; + makeFriends () { + this.error = '' - const notEmptyHosts = this.getNotEmptyHosts(); + const notEmptyHosts = this.getNotEmptyHosts() if (notEmptyHosts.length === 0) { - this.error = 'You need to specify at least 1 host.'; - return; + this.error = 'You need to specify at least 1 host.' + return } if (!this.isHostsUnique(notEmptyHosts)) { - this.error = 'Hosts need to be unique.'; - return; + this.error = 'Hosts need to be unique.' + return } - const confirmMessage = 'Are you sure to make friends with:
- ' + notEmptyHosts.join('
- '); + const confirmMessage = 'Are you sure to make friends with:
- ' + notEmptyHosts.join('
- ') this.confirmService.confirm(confirmMessage, 'Make friends').subscribe( res => { - if (res === false) return; + if (res === false) return this.friendService.makeFriends(notEmptyHosts).subscribe( status => { - this.notificationsService.success('Sucess', 'Make friends request sent!'); - this.router.navigate([ '/admin/friends/list' ]); + this.notificationsService.success('Sucess', 'Make friends request sent!') + this.router.navigate([ '/admin/friends/list' ]) }, err => this.notificationsService.error('Error', err.text) - ); + ) } - ); + ) } - private getNotEmptyHosts() { - const notEmptyHosts = []; + private getNotEmptyHosts () { + const notEmptyHosts = [] Object.keys(this.form.value).forEach((hostKey) => { - const host = this.form.value[hostKey]; - if (host !== '') notEmptyHosts.push(host); - }); + const host = this.form.value[hostKey] + if (host !== '') notEmptyHosts.push(host) + }) - return notEmptyHosts; + return notEmptyHosts } - private isHostsUnique(hosts: string[]) { - return hosts.every(host => hosts.indexOf(host) === hosts.lastIndexOf(host)); + private isHostsUnique (hosts: string[]) { + return hosts.every(host => hosts.indexOf(host) === hosts.lastIndexOf(host)) } } 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 @@ -import { Component } from '@angular/core'; +import { Component } from '@angular/core' -import { NotificationsService } from 'angular2-notifications'; -import { ServerDataSource } from 'ng2-smart-table'; +import { NotificationsService } from 'angular2-notifications' +import { ServerDataSource } from 'ng2-smart-table' -import { ConfirmService } from '../../../core'; -import { Utils } from '../../../shared'; -import { Friend, FriendService } from '../shared'; +import { ConfirmService } from '../../../core' +import { Utils } from '../../../shared' +import { Friend, FriendService } from '../shared' @Component({ selector: 'my-friend-list', @@ -13,7 +13,7 @@ import { Friend, FriendService } from '../shared'; styleUrls: [ './friend-list.component.scss' ] }) export class FriendListComponent { - friendsSource = null; + friendsSource = null tableSettings = { attr: { class: 'table-hover' @@ -49,36 +49,36 @@ export class FriendListComponent { valuePrepareFunction: Utils.dateToHuman } } - }; + } - constructor( + constructor ( private notificationsService: NotificationsService, private confirmService: ConfirmService, private friendService: FriendService ) { - this.friendsSource = this.friendService.getDataSource(); + this.friendsSource = this.friendService.getDataSource() } - hasFriends() { - return this.friendsSource.count() !== 0; + hasFriends () { + return this.friendsSource.count() !== 0 } - quitFriends() { - const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.'; + quitFriends () { + const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.' this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe( res => { - if (res === false) return; + if (res === false) return this.friendService.quitFriends().subscribe( status => { - this.notificationsService.success('Sucess', 'Friends left!'); + this.notificationsService.success('Sucess', 'Friends left!') - this.friendsSource.refresh(); + this.friendsSource.refresh() }, err => this.notificationsService.error('Error', err.text) - ); + ) } - ); + ) } } 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 @@ -import { Component } from '@angular/core'; +import { Component } from '@angular/core' @Component({ - template: '' + template: '' }) - export class FriendsComponent { } 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 @@ -import { Routes } from '@angular/router'; +import { Routes } from '@angular/router' -import { FriendsComponent } from './friends.component'; -import { FriendAddComponent } from './friend-add'; -import { FriendListComponent } from './friend-list'; +import { FriendsComponent } from './friends.component' +import { FriendAddComponent } from './friend-add' +import { FriendListComponent } from './friend-list' export const FriendsRoutes: Routes = [ { - path: 'friends', - component: FriendsComponent, - children: [ - { - path: '', - redirectTo: 'list', - pathMatch: 'full' - }, - { - path: 'list', - component: FriendListComponent, - data: { - meta: { - title: 'Friends list' - } + path: 'friends', + component: FriendsComponent, + children: [ + { + path: '', + redirectTo: 'list', + pathMatch: 'full' + }, + { + path: 'list', + component: FriendListComponent, + data: { + meta: { + title: 'Friends list' } - }, - { - path: 'add', - component: FriendAddComponent, - data: { - meta: { - title: 'Add friends' - } + } + }, + { + path: 'add', + component: FriendAddComponent, + data: { + meta: { + title: 'Add friends' } } - ] - } -]; + } + ] + } +] 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 @@ -export * from './friend-add'; -export * from './friend-list'; -export * from './shared'; -export * from './friends.component'; -export * from './friends.routes'; +export * from './friend-add' +export * from './friend-list' +export * from './shared' +export * from './friends.component' +export * 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 @@ export interface Friend { - id: string; - host: string; - score: number; - email: string; - createdAt: Date; + id: string + host: string + score: number + email: string + createdAt: Date } 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 @@ -import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs/Observable'; -import 'rxjs/add/operator/catch'; -import 'rxjs/add/operator/map'; +import { Injectable } from '@angular/core' +import { Observable } from 'rxjs/Observable' +import 'rxjs/add/operator/catch' +import 'rxjs/add/operator/map' -import { ServerDataSource } from 'ng2-smart-table'; +import { ServerDataSource } from 'ng2-smart-table' -import { Friend } from './friend.model'; -import { AuthHttp, RestExtractor, RestDataSource, ResultList } from '../../../shared'; +import { Friend } from './friend.model' +import { AuthHttp, RestExtractor, RestDataSource, ResultList } from '../../../shared' @Injectable() export class FriendService { - private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/'; + private static BASE_FRIEND_URL = API_URL + '/api/v1/pods/' constructor ( private authHttp: AuthHttp, private restExtractor: RestExtractor ) {} - getDataSource() { - return new RestDataSource(this.authHttp, FriendService.BASE_FRIEND_URL); + getDataSource () { + return new RestDataSource(this.authHttp, FriendService.BASE_FRIEND_URL) } - makeFriends(notEmptyHosts) { + makeFriends (notEmptyHosts) { const body = { hosts: notEmptyHosts - }; + } return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body) .map(this.restExtractor.extractDataBool) - .catch((res) => this.restExtractor.handleError(res)); + .catch((res) => this.restExtractor.handleError(res)) } - quitFriends() { + quitFriends () { return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') .map(res => res.status) - .catch((res) => this.restExtractor.handleError(res)); + .catch((res) => this.restExtractor.handleError(res)) } } 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 @@ -export * from './friend.model'; -export * from './friend.service'; +export * from './friend.model' +export * from './friend.service' -- cgit v1.2.3