Client: move video watch modals in their own component
authorChocobozzz <florian.bigard@gmail.com>
Sun, 20 Nov 2016 15:09:38 +0000 (16:09 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 21 Nov 2016 21:09:45 +0000 (22:09 +0100)
client/src/app/app.module.ts
client/src/app/videos/video-watch/index.ts
client/src/app/videos/video-watch/video-magnet.component.html [new file with mode: 0644]
client/src/app/videos/video-watch/video-magnet.component.ts [new file with mode: 0644]
client/src/app/videos/video-watch/video-share.component.html [new file with mode: 0644]
client/src/app/videos/video-watch/video-share.component.ts [new file with mode: 0644]
client/src/app/videos/video-watch/video-watch.component.html
client/src/app/videos/video-watch/video-watch.component.scss
client/src/app/videos/video-watch/video-watch.component.ts
client/src/sass/application.scss

index e40b66c5f1286e47ff807b8aa6cf3a05ebf0d7a7..3f57897fbd9edec8c3a0a0709600d787b6e63d8b 100644 (file)
@@ -52,6 +52,8 @@ import {
   VideoMiniatureComponent,
   VideoSortComponent,
   VideoWatchComponent,
+  VideoShareComponent,
+  VideoMagnetComponent,
   VideoService,
   WebTorrentService
 } from './videos';
@@ -118,6 +120,8 @@ const APP_PROVIDERS = [
     VideosComponent,
     VideoSortComponent,
     VideoWatchComponent,
+    VideoShareComponent,
+    VideoMagnetComponent
   ],
   imports: [ // import Angular's modules
     BrowserModule,
index b17aaacf22d8af70f6abcc4435cefab7ed9bccdb..1a8403b0a65eb4f8fce2fe4481069fa7c23a44c8 100644 (file)
@@ -1,2 +1,4 @@
+export * from './video-magnet.component';
+export * from './video-share.component';
 export * from './video-watch.component';
 export * from './webtorrent.service';
diff --git a/client/src/app/videos/video-watch/video-magnet.component.html b/client/src/app/videos/video-watch/video-magnet.component.html
new file mode 100644 (file)
index 0000000..9108c72
--- /dev/null
@@ -0,0 +1,17 @@
+<div bsModal #modal="bs-modal" class="modal" tabindex="-1">
+  <div class="modal-dialog">
+    <div class="modal-content modal-lg">
+
+      <div class="modal-header">
+        <button type="button" class="close" aria-label="Close" (click)="hideModal()">
+          <span aria-hidden="true">&times;</span>
+        </button>
+        <h4 class="modal-title">Magnet Uri</h4>
+      </div>
+
+      <div class="modal-body">
+        <input #magnetUriInput (click)="magnetUriInput.select()" type="text" class="form-control input-sm readonly" readonly [value]="video.magnetUri" />
+      </div>
+    </div>
+  </div>
+</div>
diff --git a/client/src/app/videos/video-watch/video-magnet.component.ts b/client/src/app/videos/video-watch/video-magnet.component.ts
new file mode 100644 (file)
index 0000000..2894e7d
--- /dev/null
@@ -0,0 +1,27 @@
+import { Component, Input, ViewChild } from '@angular/core';
+
+import { ModalDirective } from 'ng2-bootstrap/components/modal';
+
+import { Video } from '../shared';
+
+@Component({
+  selector: 'my-video-magnet',
+  templateUrl: './video-magnet.component.html'
+})
+export class VideoMagnetComponent {
+  @Input() video: Video = null;
+
+  @ViewChild('modal') modal: ModalDirective;
+
+  constructor() {
+    // empty
+  }
+
+  show() {
+    this.modal.show();
+  }
+
+  hide() {
+    this.modal.hide();
+  }
+}
diff --git a/client/src/app/videos/video-watch/video-share.component.html b/client/src/app/videos/video-watch/video-share.component.html
new file mode 100644 (file)
index 0000000..2e83e9a
--- /dev/null
@@ -0,0 +1,25 @@
+<div bsModal #modal="bs-modal" class="modal" tabindex="-1">
+  <div class="modal-dialog modal-lg">
+    <div class="modal-content">
+
+      <div class="modal-header">
+        <button type="button" class="close" aria-label="Close" (click)="hideModal()">
+          <span aria-hidden="true">&times;</span>
+        </button>
+        <h4 class="modal-title">Share</h4>
+      </div>
+
+      <div class="modal-body">
+        <div class="form-group">
+          <label>URL</label>
+          <input #urlInput (click)="urlInput.select()" type="text" class="form-control input-sm readonly" readonly [value]="getVideoUrl()" />
+        </div>
+
+        <div class="form-group">
+          <label>Embed</label>
+          <input #shareInput (click)="shareInput.select()" type="text" class="form-control input-sm readonly" readonly [value]="getVideoIframeCode()" />
+        </div>
+      </div>
+    </div>
+  </div>
+</div>
diff --git a/client/src/app/videos/video-watch/video-share.component.ts b/client/src/app/videos/video-watch/video-share.component.ts
new file mode 100644 (file)
index 0000000..74b2383
--- /dev/null
@@ -0,0 +1,38 @@
+import { Component, Input, ViewChild } from '@angular/core';
+
+import { ModalDirective } from 'ng2-bootstrap/components/modal';
+
+import { Video } from '../shared';
+
+@Component({
+  selector: 'my-video-share',
+  templateUrl: './video-share.component.html'
+})
+export class VideoShareComponent {
+  @Input() video: Video = null;
+
+  @ViewChild('modal') modal: ModalDirective;
+
+  constructor() {
+    // empty
+  }
+
+  show() {
+    this.modal.show();
+  }
+
+  hide() {
+    this.modal.hide();
+  }
+
+  getVideoIframeCode() {
+    return '<iframe width="560" height="315" ' +
+           'src="' + window.location.origin + '/videos/embed/' + this.video.id + '" ' +
+           'frameborder="0" allowfullscreen>' +
+           '</iframe>';
+  }
+
+  getVideoUrl() {
+    return window.location.href;
+  }
+}
index 2dfc25f56807d1bc42b422575fc1a71712b3e044..0f0fa68cc94de7719accac7386bac2b0bda186fd 100644 (file)
   </div>
 </div>
 
-<div *ngIf="video !== null" bsModal #magnetUriModal="bs-modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="magnetUriModal" aria-hidden="true">
-  <div class="modal-dialog">
-    <div class="modal-content modal-lg">
-
-      <div class="modal-header">
-        <button type="button" class="close" aria-label="Close" (click)="hideMagnetUriModal()">
-          <span aria-hidden="true">&times;</span>
-        </button>
-        <h4 class="modal-title">Magnet Uri</h4>
-      </div>
-
-      <div class="modal-body">
-        <input #magnetUriInput (click)="magnetUriInput.select()" type="text" class="form-control input-sm" readonly [value]="video.magnetUri" />
-      </div>
-    </div>
-  </div>
-</div>
-
-<div *ngIf="video !== null" bsModal #shareModal="bs-modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="shareModal" aria-hidden="true">
-  <div class="modal-dialog modal-lg">
-    <div class="modal-content">
-
-      <div class="modal-header">
-        <button type="button" class="close" aria-label="Close" (click)="hideShareModal()">
-          <span aria-hidden="true">&times;</span>
-        </button>
-        <h4 class="modal-title">Share</h4>
-      </div>
-
-      <div class="modal-body">
-        <div class="form-group">
-          <label>URL</label>
-          <input #urlInput (click)="urlInput.select()" type="text" class="form-control input-sm" readonly [value]="getVideoUrl()" />
-        </div>
-
-        <div class="form-group">
-          <label>Embed</label>
-          <input #shareInput (click)="shareInput.select()" type="text" class="form-control input-sm" readonly [value]="getVideoIframeCode()" />
-        </div>
-      </div>
-    </div>
-  </div>
-</div>
+<my-video-share #videoShareModal *ngIf="video !== null" [video]="video"></my-video-share>
+<my-video-magnet #videoMagnetModal *ngIf="video !== null" [video]="video"></my-video-magnet>
index 45446e175986006387d682d8748b5f65e27a4bd2..ac62b04e7d7562d103592ce6c1f205f181ac4865 100644 (file)
     }
   }
 }
-
-.modal-content {
-  input {
-    /* Force blank on readonly inputs */
-    background-color: #fff;
-  }
-}
index 3dab2bbb7f1432262bdec720d65f497b72528497..afc6fe01cba9df3b29a16e1508f4b336160085c6 100644 (file)
@@ -1,10 +1,11 @@
 import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core';
 import { ActivatedRoute } from '@angular/router';
 
-import { ModalDirective } from 'ng2-bootstrap/components/modal';
 import { MetaService } from 'ng2-meta';
 import * as videojs from 'video.js';
 
+import { VideoMagnetComponent } from './video-magnet.component';
+import { VideoShareComponent } from './video-share.component';
 import { Video, VideoService } from '../shared';
 import { WebTorrentService } from './webtorrent.service';
 
@@ -17,8 +18,8 @@ import { WebTorrentService } from './webtorrent.service';
 export class VideoWatchComponent implements OnInit, OnDestroy {
   private static LOADTIME_TOO_LONG: number = 30000;
 
-  @ViewChild('magnetUriModal') magnetUriModal: ModalDirective;
-  @ViewChild('shareModal') shareModal: ModalDirective;
+  @ViewChild('videoMagnetModal') videoMagnetModal: VideoMagnetComponent;
+  @ViewChild('videoShareModal') videoShareModal: VideoShareComponent;
 
   downloadSpeed: number;
   error: boolean = false;
@@ -121,31 +122,12 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
     });
   }
 
-  showMagnetUriModal() {
-    this.magnetUriModal.show();
-  }
-
-  hideMagnetUriModal() {
-    this.magnetUriModal.hide();
-  }
-
   showShareModal() {
-    this.shareModal.show();
+    this.videoShareModal.show();
   }
 
-  hideShareModal() {
-    this.shareModal.hide();
-  }
-
-  getVideoIframeCode() {
-    return '<iframe width="560" height="315" ' +
-           'src="' + window.location.origin + '/videos/embed/' + this.video.id + '" ' +
-           'frameborder="0" allowfullscreen>' +
-           '</iframe>';
-  }
-
-  getVideoUrl() {
-    return window.location.href;
+  showMagnetUriModal() {
+    this.videoMagnetModal.show();
   }
 
   private loadTooLong() {
index f0526e84ff7ae471f4f4352be707d95302a9a3bb..cdb4865577c4262d86236de4ac96150440ab7c2e 100644 (file)
@@ -50,6 +50,10 @@ menu {
   display: none !important;
 }
 
+input.readonly {
+  /* Force blank on readonly inputs */
+  background-color: #fff !important;
+}
 
 footer {
   border-top: 1px solid rgba(0, 0, 0, 0.2);