Do not prefix private attributes
authorChocobozzz <florian.bigard@gmail.com>
Fri, 27 May 2016 15:25:52 +0000 (17:25 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 27 May 2016 15:25:52 +0000 (17:25 +0200)
15 files changed:
client/app/app.component.ts
client/app/friends/friend.service.ts
client/app/shared/search.component.ts
client/app/users/login/login.component.ts
client/app/users/shared/auth.service.ts
client/app/users/shared/token.model.ts
client/app/users/shared/user.model.ts
client/app/videos/shared/video.model.ts
client/app/videos/shared/video.service.ts
client/app/videos/video-add/video-add.component.ts
client/app/videos/video-list/video-list.component.ts
client/app/videos/video-list/video-miniature.component.ts
client/app/videos/video-list/video-sort.component.ts
client/app/videos/video-watch/video-watch.component.ts
client/tslint.json

index c94ff79a79cfef34b69f38ea41af9bddc9d344b4..20c8c8724ff352cdab75eebd2f82946ff4a0f65a 100644 (file)
@@ -51,16 +51,15 @@ import {
 export class AppComponent {
   isLoggedIn: boolean;
   search_field: string = name;
-  choices = [ ];
-
-  constructor(private _friendService: FriendService,
-              private _authService: AuthService,
-              private _router: Router
+  choices = [];
 
+  constructor(private friendService: FriendService,
+              private authService: AuthService,
+              private router: Router
   ) {
-    this.isLoggedIn = this._authService.isLoggedIn();
+    this.isLoggedIn = this.authService.isLoggedIn();
 
-    this._authService.loginChanged$.subscribe(
+    this.authService.loginChangedSource.subscribe(
       status => {
         if (status === AuthStatus.LoggedIn) {
           this.isLoggedIn = true;
@@ -75,9 +74,9 @@ export class AppComponent {
         search: search.value,
         field: search.field
       };
-      this._router.navigate(['VideosList', params]);
+      this.router.navigate(['VideosList', params]);
     } else {
-      this._router.navigate(['VideosList']);
+      this.router.navigate(['VideosList']);
     }
   }
 
@@ -86,7 +85,7 @@ export class AppComponent {
   }
 
   makeFriends() {
-    this._friendService.makeFriends().subscribe(
+    this.friendService.makeFriends().subscribe(
       status => {
         if (status === 409) {
           alert('Already made friends!');
@@ -99,7 +98,7 @@ export class AppComponent {
   }
 
   quitFriends() {
-    this._friendService.quitFriends().subscribe(
+    this.friendService.quitFriends().subscribe(
       status => {
           alert('Quit friends!');
       },
index d143ec40d07b83282a9d0f8db0ea20dc8a4281fa..bdfa7baeca1622057838874035e0655354adcaed 100644 (file)
@@ -4,23 +4,23 @@ import { Observable } from 'rxjs/Rx';
 
 @Injectable()
 export class FriendService {
-  private _baseFriendsUrl = '/api/v1/pods/';
+  private static BASE_FRIEND_URL: string = '/api/v1/pods/';
 
   constructor (private http: Http) {}
 
   makeFriends() {
-    return this.http.get(this._baseFriendsUrl + 'makefriends')
-                    .map(res => <number> res.status)
+    return this.http.get(FriendService.BASE_FRIEND_URL + 'makefriends')
+                    .map(res => res.status)
                     .catch(this.handleError);
   }
 
   quitFriends() {
-    return this.http.get(this._baseFriendsUrl + 'quitfriends')
-                    .map(res => <number> res.status)
+    return this.http.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
+                    .map(res => res.status)
                     .catch(this.handleError);
   }
 
-  private handleError (error: Response) {
+  private handleError (error: Response): Observable<number> {
     console.error(error);
     return Observable.throw(error.json().error || 'Server error');
   }
index 519810f9b9c107a70654bb64a705087746a54458..674518aba81004268550d98d2ceb3634acd7413b 100644 (file)
@@ -12,12 +12,13 @@ import { SearchField } from './search-field.type';
 })
 
 export class SearchComponent {
-  @Output() search: EventEmitter<Search> = new EventEmitter<Search>();
+  @Output() search = new EventEmitter<Search>();
 
   searchCriterias: Search = {
     field: 'name',
     value: ''
   };
+
   fieldChoices = {
     name: 'Name',
     author: 'Author',
@@ -29,18 +30,18 @@ export class SearchComponent {
     return Object.keys(this.fieldChoices);
   }
 
-  getStringChoice(choiceKey: SearchField): string {
+  getStringChoice(choiceKey: SearchField) {
     return this.fieldChoices[choiceKey];
   }
 
-  choose($event:MouseEvent, choice: SearchField) {
+  choose($event: MouseEvent, choice: SearchField) {
     $event.preventDefault();
     $event.stopPropagation();
 
     this.searchCriterias.field = choice;
   }
 
-  doSearch(): void {
+  doSearch() {
     this.search.emit(this.searchCriterias);
   }
 
index 33590ad4c570ab6ecdf6ae60c602ad99fc4d9ce1..8e369541d2912f0d0680b093cecfcb7693387cd4 100644 (file)
@@ -10,17 +10,17 @@ import { AuthService, AuthStatus, User } from '../shared/index';
 })
 
 export class UserLoginComponent {
-  constructor(private _authService: AuthService, private _router: Router) {}
+  constructor(private authService: AuthService, private router: Router) {}
 
   login(username: string, password: string) {
-    this._authService.login(username, password).subscribe(
+    this.authService.login(username, password).subscribe(
       result => {
         const user = new User(username, result);
         user.save();
 
-        this._authService.setStatus(AuthStatus.LoggedIn);
+        this.authService.setStatus(AuthStatus.LoggedIn);
 
-        this._router.navigate(['VideosList']);
+        this.router.navigate(['VideosList']);
       },
       error => {
         if (error.error === 'invalid_grant') {
index 1cb042db57d9fa62ac27ffd78b57affaefd7751a..b1da94436396670e74471993dac65738fbcd147d 100644 (file)
@@ -7,27 +7,28 @@ import { User } from './user.model';
 
 @Injectable()
 export class AuthService {
-  loginChanged$;
+  private static BASE_LOGIN_URL = '/api/v1/users/token';
+  private static BASE_CLIENT_URL = '/api/v1/users/client';
 
-  private _loginChanged;
-  private _baseLoginUrl = '/api/v1/users/token';
-  private _baseClientUrl = '/api/v1/users/client';
-  private _clientId = '';
-  private _clientSecret = '';
+  loginChangedSource: Observable<AuthStatus>;
 
-  constructor (private http: Http) {
-    this._loginChanged = new Subject<AuthStatus>();
-    this.loginChanged$ = this._loginChanged.asObservable();
+  private loginChanged: Subject<AuthStatus>;
+  private clientId: string;
+  private clientSecret: string;
+
+  constructor(private http: Http) {
+    this.loginChanged = new Subject<AuthStatus>();
+    this.loginChangedSource = this.loginChanged.asObservable();
 
     // Fetch the client_id/client_secret
     // FIXME: save in local storage?
-    this.http.get(this._baseClientUrl)
+    this.http.get(AuthService.BASE_CLIENT_URL)
       .map(res => res.json())
       .catch(this.handleError)
       .subscribe(
         result => {
-          this._clientId = result.client_id;
-          this._clientSecret = result.client_secret;
+          this.clientId = result.client_id;
+          this.clientSecret = result.client_secret;
           console.log('Client credentials loaded.');
         },
         error => {
@@ -38,8 +39,8 @@ export class AuthService {
 
   login(username: string, password: string) {
     let body = new URLSearchParams();
-    body.set('client_id', this._clientId);
-    body.set('client_secret', this._clientSecret);
+    body.set('client_id', this.clientId);
+    body.set('client_secret', this.clientSecret);
     body.set('response_type', 'code');
     body.set('grant_type', 'password');
     body.set('scope', 'upload');
@@ -53,7 +54,7 @@ export class AuthService {
       headers: headers
     };
 
-    return this.http.post(this._baseLoginUrl, body.toString(), options)
+    return this.http.post(AuthService.BASE_LOGIN_URL, body.toString(), options)
                     .map(res => res.json())
                     .catch(this.handleError);
   }
@@ -62,7 +63,7 @@ export class AuthService {
     // TODO make HTTP request
   }
 
-  getRequestHeader(): Headers {
+  getRequestHeader() {
     return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` });
   }
 
@@ -70,11 +71,11 @@ export class AuthService {
     return new RequestOptions({ headers: this.getRequestHeader() });
   }
 
-  getToken(): string {
+  getToken() {
     return localStorage.getItem('access_token');
   }
 
-  getTokenType(): string {
+  getTokenType() {
     return localStorage.getItem('token_type');
   }
 
@@ -88,7 +89,7 @@ export class AuthService {
     return user;
   }
 
-  isLoggedIn(): boolean {
+  isLoggedIn() {
     if (this.getToken()) {
       return true;
     } else {
@@ -97,7 +98,7 @@ export class AuthService {
   }
 
   setStatus(status: AuthStatus) {
-    this._loginChanged.next(status);
+    this.loginChanged.next(status);
   }
 
   private handleError (error: Response) {
index b7872e74a1fe69583ce796e919518ec5b26c0a69..021c83fadee41295a248e779df2dac51d7765bf5 100644 (file)
@@ -3,7 +3,7 @@ export class Token {
   refresh_token: string;
   token_type: string;
 
-  static load(): Token {
+  static load() {
     return new Token({
       access_token: localStorage.getItem('access_token'),
       refresh_token: localStorage.getItem('refresh_token'),
@@ -11,10 +11,11 @@ export class Token {
     });
   }
 
-  constructor (hash?: any) {
+  constructor(hash?: any) {
     if (hash) {
       this.access_token = hash.access_token;
       this.refresh_token = hash.refresh_token;
+
       if (hash.token_type === 'bearer') {
         this.token_type = 'Bearer';
       } else {
@@ -23,7 +24,7 @@ export class Token {
     }
   }
 
-  save():void {
+  save() {
     localStorage.setItem('access_token', this.access_token);
     localStorage.setItem('refresh_token', this.refresh_token);
     localStorage.setItem('token_type', this.token_type);
index 73fd4ddc05fb515d7db53270b92e1da17e006a0c..ca0a5f26ca01213471b2ec263c6cbbc0fe6dc3f2 100644 (file)
@@ -4,16 +4,16 @@ export class User {
   username: string;
   token: Token;
 
-  static load(): User {
+  static load() {
     return new User(localStorage.getItem('username'), Token.load());
   }
 
-  constructor (username: string, hash_token: any) {
+  constructor(username: string, hash_token: any) {
     this.username = username;
     this.token = new Token(hash_token);
   }
 
-  save(): void {
+  save() {
     localStorage.setItem('username', this.username);
     this.token.save();
   }
index eec537c9e8b8e67996a8fe1c536d5ba038f97896..2b018ad864f676cdf9e3495f4c154bd642de8ea8 100644 (file)
@@ -11,7 +11,7 @@ export class Video {
   by: string;
   duration: string;
 
-  private static createDurationString(duration: number): string {
+  private static createDurationString(duration: number) {
     const minutes = Math.floor(duration / 60);
     const seconds = duration % 60;
     const minutes_padding = minutes >= 10 ? '' : '0';
@@ -20,7 +20,7 @@ export class Video {
     return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
   }
 
-  private static createByString(author: string, podUrl: string): string {
+  private static createByString(author: string, podUrl: string) {
     let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
 
     if (port === '80' || port === '443') {
@@ -57,7 +57,7 @@ export class Video {
     this.by = Video.createByString(hash.author, hash.podUrl);
   }
 
-  isRemovableBy(user): boolean {
+  isRemovableBy(user) {
     return this.isLocal === true && user && this.author === user.username;
   }
 }
index 78789c3cc95543f6e7405388d2b758948ac83613..b6e0800a073f3f91eb9c518ea1c4268b720652f3 100644 (file)
@@ -10,30 +10,30 @@ import { Video } from './video.model';
 
 @Injectable()
 export class VideoService {
-  private _baseVideoUrl = '/api/v1/videos/';
+  private static BASE_VIDEO_URL = '/api/v1/videos/';
 
-  constructor (private http: Http, private _authService: AuthService) {}
+  constructor(private http: Http, private authService: AuthService) {}
 
   getVideos(pagination: Pagination, sort: SortField) {
     const params = this.createPaginationParams(pagination);
 
     if (sort) params.set('sort', sort);
 
-    return this.http.get(this._baseVideoUrl, { search: params })
+    return this.http.get(VideoService.BASE_VIDEO_URL, { search: params })
                     .map(res => res.json())
                     .map(this.extractVideos)
                     .catch(this.handleError);
   }
 
   getVideo(id: string) {
-    return this.http.get(this._baseVideoUrl + id)
+    return this.http.get(VideoService.BASE_VIDEO_URL + id)
                     .map(res => <Video> res.json())
                     .catch(this.handleError);
   }
 
   removeVideo(id: string) {
-    const options = this._authService.getAuthRequestOptions();
-    return this.http.delete(this._baseVideoUrl + id, options)
+    const options = this.authService.getAuthRequestOptions();
+    return this.http.delete(VideoService.BASE_VIDEO_URL + id, options)
                     .map(res => <number> res.status)
                     .catch(this.handleError);
   }
@@ -44,13 +44,13 @@ export class VideoService {
     if (search.field) params.set('field', search.field);
     if (sort) params.set('sort', sort);
 
-    return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search.value), { search: params })
+    return this.http.get(VideoService.BASE_VIDEO_URL + 'search/' + encodeURIComponent(search.value), { search: params })
                     .map(res => res.json())
                     .map(this.extractVideos)
                     .catch(this.handleError);
   }
 
-  private extractVideos (body: any) {
+  private extractVideos(body: any) {
     const videos_json = body.data;
     const totalVideos = body.total;
     const videos = [];
@@ -61,7 +61,7 @@ export class VideoService {
     return { videos, totalVideos };
   }
 
-  private handleError (error: Response) {
+  private handleError(error: Response) {
     console.error(error);
     return Observable.throw(error.json().error || 'Server error');
   }
index ca583a1036b332c5ed8ce7b73fdb6f175eaccbc3..67a04a2b49217497b0db3658c92515df61fb790c 100644 (file)
@@ -7,7 +7,7 @@ import { PROGRESSBAR_DIRECTIVES } from 'ng2-bootstrap/components/progressbar';
 import { AuthService, User } from '../../users/index';
 
 // TODO: import it with systemjs
-declare var jQuery:any;
+declare var jQuery: any;
 
 @Component({
   selector: 'my-videos-add',
index a88fb379a4513ea79ad448e187e30f7fd2cedf97..3f54c98ceda6ca94e54785865d7360608e2836c9 100644 (file)
@@ -31,26 +31,26 @@ export class VideoListComponent implements OnInit {
     total: 0
   };
   sort: SortField;
-  loading: boolean = false;
+  loading = false;
 
   private search: Search;
 
   constructor(
-    private _authService: AuthService,
-    private _videoService: VideoService,
-    private _routeParams: RouteParams,
-    private _router: Router
+    private authService: AuthService,
+    private videoService: VideoService,
+    private routeParams: RouteParams,
+    private router: Router
   ) {
     this.search = {
-      value: this._routeParams.get('search'),
-      field: <SearchField>this._routeParams.get('field')
+      value: this.routeParams.get('search'),
+      field: <SearchField>this.routeParams.get('field')
     };
 
-    this.sort = <SortField>this._routeParams.get('sort') || '-createdDate';
+    this.sort = <SortField>this.routeParams.get('sort') || '-createdDate';
   }
 
   ngOnInit() {
-    if (this._authService.isLoggedIn()) {
+    if (this.authService.isLoggedIn()) {
       this.user = User.load();
     }
 
@@ -64,9 +64,9 @@ export class VideoListComponent implements OnInit {
     let observable = null;
 
     if (this.search.value !== null) {
-      observable = this._videoService.searchVideos(this.search, this.pagination, this.sort);
+      observable = this.videoService.searchVideos(this.search, this.pagination, this.sort);
     } else {
-      observable = this._videoService.getVideos(this.pagination, this.sort);
+      observable = this.videoService.getVideos(this.pagination, this.sort);
     }
 
     observable.subscribe(
@@ -79,7 +79,7 @@ export class VideoListComponent implements OnInit {
     );
   }
 
-  onRemoved(video: Video): void {
+  onRemoved(video: Video) {
     this.videos.splice(this.videos.indexOf(video), 1);
   }
 
@@ -95,7 +95,7 @@ export class VideoListComponent implements OnInit {
       params.field = this.search.field;
     }
 
-    this._router.navigate(['VideosList', params]);
+    this.router.navigate(['VideosList', params]);
     this.getVideos();
   }
 }
index 817636768cfb8ff2d4367a1bfc1af47d8d96ae89..73416607a8cc11823bba696b65a74109cd785268 100644 (file)
@@ -19,9 +19,9 @@ export class VideoMiniatureComponent {
   @Input() video: Video;
   @Input() user: User;
 
-  hovering: boolean = false;
+  hovering = false;
 
-  constructor(private _videoService: VideoService) {}
+  constructor(private videoService: VideoService) {}
 
   onHover() {
     this.hovering = true;
@@ -31,13 +31,13 @@ export class VideoMiniatureComponent {
     this.hovering = false;
   }
 
-  displayRemoveIcon(): boolean {
+  displayRemoveIcon() {
     return this.hovering && this.video.isRemovableBy(this.user);
   }
 
   removeVideo(id: string) {
     if (confirm('Do you really want to remove this video?')) {
-      this._videoService.removeVideo(id).subscribe(
+      this.videoService.removeVideo(id).subscribe(
         status => this.removed.emit(true),
         error => alert(error)
       );
index d00d7ed4968250af33e16c5fee04a8480d4d1c2e..ed06c75107485222362a04f0be68b7951bfecefa 100644 (file)
@@ -26,7 +26,7 @@ export class VideoSortComponent {
     return Object.keys(this.sortChoices);
   }
 
-  getStringChoice(choiceKey: SortField): string {
+  getStringChoice(choiceKey: SortField) {
     return this.sortChoices[choiceKey];
   }
 
index 891e6563f4f7c253a2df07a2b97c889726eec4be..c159b4004e9fa664b0a1ef3f37768b63a806d7cf 100644 (file)
@@ -23,21 +23,21 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
   numPeers: number;
   loading: boolean = false;
 
-  private _interval: NodeJS.Timer;
+  private interval: NodeJS.Timer;
   private client: any;
 
   constructor(
-    private _videoService: VideoService,
-    private _routeParams: RouteParams,
-    private _elementRef: ElementRef
+    private videoService: VideoService,
+    private routeParams: RouteParams,
+    private elementRef: ElementRef
   ) {
     // TODO: use a service
     this.client = new WebTorrent({ dht: false });
   }
 
   ngOnInit() {
-    let id = this._routeParams.get('id');
-    this._videoService.getVideo(id).subscribe(
+    let id = this.routeParams.get('id');
+    this.videoService.getVideo(id).subscribe(
       video => this.loadVideo(video),
       error => alert(error)
     );
@@ -50,7 +50,7 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
     this.client.add(this.video.magnetUri, (torrent) => {
       this.loading = false;
       console.log('Added ' + this.video.magnetUri + '.');
-      torrent.files[0].appendTo(this._elementRef.nativeElement.querySelector('.embed-responsive'), (err) => {
+      torrent.files[0].appendTo(this.elementRef.nativeElement.querySelector('.embed-responsive'), (err) => {
         if (err) {
           alert('Cannot append the file.');
           console.error(err);
@@ -58,7 +58,7 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
       });
 
       // Refresh each second
-      this._interval = setInterval(() => {
+      this.interval = setInterval(() => {
         this.downloadSpeed = torrent.downloadSpeed;
         this.uploadSpeed = torrent.uploadSpeed;
         this.numPeers = torrent.numPeers;
@@ -66,9 +66,9 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
     });
   }
 
-  routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) : any {
+  routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
     console.log('Removing video from webtorrent.');
-    clearInterval(this._interval);
+    clearInterval(this.interval);
     this.client.remove(this.video.magnetUri);
     return true;
   }
index 8e4e3fca13fc066f2a1b3b89af533393a462e277..9653c965b79ca32e7ff53603e7d783f46f724ba2 100644 (file)
     "use-pipe-transform-interface": true,
     "pipe-naming": [true, "camelCase", "my"],
     "component-class-suffix": true,
-    "directive-class-suffix": true
+    "directive-class-suffix": true,
+
+    "typedef-whitespace": [ true,
+      {
+        "call-signature": "nospace",
+        "index-signature": "nospace",
+        "parameter": "nospace",
+        "property-declaration": "nospace",
+        "variable-declaration": "nospace"
+      }
+    ],
+    "whitespace": [ true,
+      "check-branch",
+      "check-decl",
+      "check-operator",
+      "check-separator",
+      "check-type"
+    ]
   }
 }