From 5f0805d39b94eb2de1b73e0f43ac8685ae900994 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 Dec 2017 17:49:58 +0100 Subject: Design modals --- .../+video-watch/video-download.component.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'client/src/app/videos/+video-watch/video-download.component.ts') diff --git a/client/src/app/videos/+video-watch/video-download.component.ts b/client/src/app/videos/+video-watch/video-download.component.ts index 095df1698..44ece986c 100644 --- a/client/src/app/videos/+video-watch/video-download.component.ts +++ b/client/src/app/videos/+video-watch/video-download.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, ViewChild } from '@angular/core' +import { Component, Input, OnInit, ViewChild } from '@angular/core' import { ModalDirective } from 'ngx-bootstrap/modal' import { VideoDetails } from '../../shared/video/video-details.model' @@ -7,15 +7,22 @@ import { VideoDetails } from '../../shared/video/video-details.model' templateUrl: './video-download.component.html', styleUrls: [ './video-download.component.scss' ] }) -export class VideoDownloadComponent { +export class VideoDownloadComponent implements OnInit { @Input() video: VideoDetails = null @ViewChild('modal') modal: ModalDirective + downloadType: 'direct' | 'torrent' = 'torrent' + resolution = -1 + constructor () { // empty } + ngOnInit () { + this.resolution = this.video.files[0].resolution + } + show () { this.modal.show() } @@ -23,4 +30,15 @@ export class VideoDownloadComponent { hide () { this.modal.hide() } + + download () { + const file = this.video.files.find(f => f.resolution === this.resolution) + if (!file) { + console.error('Could not find file with resolution %d.', this.resolution) + return + } + + const link = this.downloadType === 'direct' ? file.fileUrl : file.torrentUrl + window.open(link) + } } -- cgit v1.2.3