]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Angular 2 : draft 2
authorChocobozzz <florian.bigard@gmail.com>
Mon, 14 Mar 2016 21:16:43 +0000 (22:16 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 14 Mar 2016 21:16:43 +0000 (22:16 +0100)
13 files changed:
.travis.yml
client/angular/app/app.component.html
client/angular/app/app.component.scss
client/angular/app/app.component.ts
client/angular/videos/components/add/videos-add.component.ts
client/angular/videos/components/list/videos-list.component.ts
client/angular/videos/components/watch/videos-watch.component.ts
client/angular/videos/services/videos.service.ts
client/package.json
client/stylesheets/application.scss
client/stylesheets/index.scss [deleted file]
package.json
server/controllers/api/v1/videos.js

index 2d3d942964b6e933e1767856dcc8c728d555be4c..44d835d2c855dae7059e5dff71f4146fd26896d1 100644 (file)
@@ -21,7 +21,6 @@ services:
 
 before_script:
   - npm install electron-prebuilt -g
-  - npm install grunt-cli -g
 
 after_failure:
   - cat test1/logs/all-logs.log
index 590efa0d6fdf6e4212303c53be43c58e6cdee9d0..af41f86869996ae3e2a0622f927ccdfe8859c0a9 100644 (file)
@@ -1,5 +1,19 @@
 <div class="container">
 
+  <header class="row">
+    <div class="col-md-2">
+      <h4>PeerTube</h4>
+    </div>
+
+    <div class="col-md-8">
+      <input
+        type="text" id="search_video" name="search_video" class="form-control" placeholder="Search a video..."
+        #search (keyup.enter)="doSearch(search.value)"
+      >
+    </div>
+  </header>
+
+
   <div class="row">
 
     <menu class="col-md-2">
index 03ecba8f2244ee34f9707b824c47b709eb5f01be..346460a3128ec16387c0b6f17ee4c7f7b267cd14 100644 (file)
@@ -1,3 +1,9 @@
+header div {
+  height: 50px;
+  line-height: 25px;
+  margin-bottom: 30px;
+}
+
 menu {
   min-height: 300px;
   height: 100%;
index 3d41183f2c4029e71f687293a9d55bbe4b55b656..cb961a3c8157052b0c3f16abb10cebeecc235ec0 100644 (file)
@@ -1,6 +1,6 @@
 import { Component, ElementRef } from 'angular2/core';
-import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router';
-import {HTTP_PROVIDERS} from 'angular2/http';
+import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from 'angular2/router';
+import { HTTP_PROVIDERS } from 'angular2/http';
 
 import { VideosAddComponent } from '../videos/components/add/videos-add.component';
 import { VideosListComponent } from '../videos/components/list/videos-list.component';
@@ -36,15 +36,22 @@ import { FriendsService } from '../friends/services/friends.service';
 })
 
 export class AppComponent {
-  constructor(private _friendsService: FriendsService) {}
+  constructor(private _friendsService: FriendsService, private _router: Router) {}
+
+  doSearch(search: string) {
+    if (search !== '') {
+      this._router.navigate(['VideosList', { search: search }]);
+    } else {
+      this._router.navigate(['VideosList']);
+    }
+  }
 
   makeFriends() {
     this._friendsService.makeFriends().subscribe(
       status => {
         if (status === 409) {
           alert('Already made friends!');
-        }
-        else {
+        } else {
           alert('Made friends!');
         }
       },
index 97e3bb3b544797f968c32df92624e9af370f5ec5..8ff6cfec87db6f350f9ca3e2dd33b761419102b8 100644 (file)
@@ -1,9 +1,10 @@
-import {Component, ElementRef, Inject, OnInit} from 'angular2/core';
-import {Router} from 'angular2/router';
-import {NgForm} from 'angular2/common';
+import { Component, ElementRef, Inject, OnInit } from 'angular2/core';
+import { Router } from 'angular2/router';
+import { NgForm } from 'angular2/common';
 
-import {Video} from '../../models/video';
+import { Video } from '../../models/video';
 
+// TODO: import it with systemjs
 declare var jQuery:any;
 
 @Component({
@@ -22,9 +23,10 @@ export class VideosAddComponent implements OnInit {
 
   ngOnInit() {
     jQuery(this._elementRef.nativeElement).find('#input_video').fileupload({
+      url: '/api/v1/videos',
+      dataType: 'json',
       singleFileUploads: true,
       multipart: true,
-      url: '/api/v1/videos',
       autoupload: false,
 
       add: (e, data) => {
@@ -38,7 +40,8 @@ export class VideosAddComponent implements OnInit {
       },
 
       done: (e, data) => {
-        console.log('finished');
+        console.log('Video uploaded.');
+
         // Print all the videos once it's finished
         this._router.navigate(['VideosList']);
       }
index e5af87448ac2a50fca4387416816ea48ee137a6f..eb23ed1ff61d1a9c72bbe228e7d598ff2e2531b2 100644 (file)
@@ -1,8 +1,8 @@
-import {Component, OnInit} from 'angular2/core';
-import {ROUTER_DIRECTIVES} from 'angular2/router';
+import { Component, OnInit } from 'angular2/core';
+import { ROUTER_DIRECTIVES, RouteParams } from 'angular2/router';
 
-import {VideosService} from '../../services/videos.service';
-import {Video} from '../../models/video';
+import { VideosService } from '../../services/videos.service';
+import { Video } from '../../models/video';
 
 @Component({
   selector: 'my-videos-list',
@@ -14,16 +14,29 @@ import {Video} from '../../models/video';
 export class VideosListComponent implements OnInit {
   videos: Video[];
 
+  private search: string;
+
   constructor(
-    private _videosService: VideosService
-  ) { }
+    private _videosService: VideosService,
+    routeParams: RouteParams
+  ) {
+    this.search = routeParams.get('search');
+  }
 
   ngOnInit() {
     this.getVideos();
   }
 
   getVideos() {
-    this._videosService.getVideos().subscribe(
+    let observable = null;
+
+    if (this.search !== null) {
+      observable = this._videosService.searchVideos(this.search);
+    } else {
+      observable = this._videosService.getVideos()
+    }
+
+    observable.subscribe(
       videos => this.videos = videos,
       error => alert(error)
     );
index e3a9738203e7451c682abde49effd585af5165a2..da7f942db4135fe865135eff0b37e11c8fc7dd3b 100644 (file)
@@ -1,8 +1,9 @@
 /// <reference path='../../../../typings/browser/ambient/webtorrent/webtorrent.d.ts' />
 
 import { Component, OnInit, ElementRef } from 'angular2/core';
-import { RouteParams } from 'angular2/router';
+import { RouteParams, CanDeactivate, ComponentInstruction } from 'angular2/router';
 
+// TODO import it with systemjs
 declare var WebTorrent: any;
 
 import { Video } from '../../models/video';
@@ -14,7 +15,7 @@ import { VideosService } from '../../services/videos.service';
   styleUrls: [ 'app/angular/videos/components/watch/videos-watch.component.css' ]
 })
 
-export class VideosWatchComponent {
+export class VideosWatchComponent implements OnInit, CanDeactivate {
   video: Video;
 
   private client: any;
@@ -24,6 +25,7 @@ export class VideosWatchComponent {
     private _routeParams: RouteParams,
     private _elementRef: ElementRef
   ) {
+    // TODO: use a service
     this.client = new WebTorrent({ dht: false });
   }
 
@@ -47,4 +49,10 @@ export class VideosWatchComponent {
       })
     })
   }
+
+  routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) : any {
+    console.log('Removing video from webtorrent.');
+    this.client.remove(this.video.magnetUri);
+    return true;
+  }
 }
index 784eec68d3e4fe8f8f4a032d75c7e893db865704..17ae89c8bf5d2e3b22c69661c0d335817a9bc5c3 100644 (file)
@@ -30,6 +30,12 @@ export class VideosService {
     }
   }
 
+  searchVideos(search: string) {
+    return this.http.get(this._baseVideoUrl + 'search/' + search)
+                    .map(res => <Video> res.json())
+                    .catch(this.handleError);
+  }
+
   private handleError (error: Response) {
     console.error(error);
     return Observable.throw(error.json().error || 'Server error');
index dbb065974201b0876b625a0d15bb91e1ddd55819..78abde7527f0e8e61a67098a6d32be79b1736305 100644 (file)
@@ -30,7 +30,6 @@
     "reflect-metadata": "0.1.2",
     "rxjs": "5.0.0-beta.2",
     "systemjs": "0.19.22",
-    "webtorrent": "^0.85.1",
     "zone.js": "0.5.15"
   },
   "devDependencies": {
index d1b309907e271aaa4bea6935742131b3da0f9a98..b91698056e0100058680886f97af506b48d11fee 100644 (file)
@@ -3,4 +3,3 @@ $icon-font-path: "/app/node_modules/bootstrap-sass/assets/fonts/bootstrap/";
 @import "bootstrap-variables";
 @import "_bootstrap";
 @import "base.scss";
-@import "index.scss";
diff --git a/client/stylesheets/index.scss b/client/stylesheets/index.scss
deleted file mode 100644 (file)
index 5cba547..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-header div {
-  height: 50px;
-  line-height: 25px;
-  margin-bottom: 50px;
-}
index 36730aaa075bd06b25e6a6f1ce4be869416fb54c..6252bac474865af3953dd88fd878fb774c05bd1f 100644 (file)
@@ -40,7 +40,9 @@
     "dev": "npm run build && concurrently \"npm run livereload\" \"npm run client:tsc:watch\" \"npm run client:sass:watch\" \"npm start\"",
     "livereload": "livereload ./client",
     "start": "node server",
-    "test": "standard && mocha server/tests"
+    "test": "standard && mocha server/tests",
+
+    "postinstall": "cd client && npm install"
   },
   "dependencies": {
     "async": "^1.2.1",
index 9398aabb75fe1b6139054bf76befd1b14e574ae1..76cad62d110435be44927f1e8b3659fe195f7caf 100644 (file)
@@ -76,8 +76,8 @@ function addVideo (req, res, next) {
       // Now we'll add the video's meta data to our friends
       friends.addVideoToFriends(video_data)
 
-      // TODO : include Location of the new video
-      res.type('json').status(201).end()
+      // TODO : include Location of the new video -> 201
+      res.type('json').status(204).end()
     })
   })
 }