Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Support drag and drop for video upload and torrent file import

Rigel Kentc9ff8a08a06e
diff --git a/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.html b/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.html
index 4262ff0fce..ada32e3fd1 100644
--- a/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.html
+++ b/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.html
@@ -9,7 +9,7 @@
<div class="modal-body">
<label i18n for="language">Language</label>
<div class="peertube-select-container">
- <select id="language" formControlName="language">
+ <select id="language" formControlName="language" class="form-control">
<option></option>
<option *ngFor="let language of videoCaptionLanguages" [value]="language.id">{{ language.label }}</option>
</select>
diff --git a/client/src/app/videos/+video-edit/video-add-components/drag-drop.directive.ts b/client/src/app/videos/+video-edit/video-add-components/drag-drop.directive.ts
new file mode 100644
index 0000000000..07c7d34ace
--- /dev/null
+++ b/client/src/app/videos/+video-edit/video-add-components/drag-drop.directive.ts
@@ -0,0 +1,30 @@
+import { Directive, Output, EventEmitter, HostBinding, HostListener } from '@angular/core'
+
+@Directive({
+ selector: '[dragDrop]'
+})
+export class DragDropDirective {
+ @Output() onFileDropped = new EventEmitter<FileList>()
+
+ @HostBinding('class.dragover') dragover = false
+
+ @HostListener('dragover', ['$event']) onDragOver(e: Event) {
+ e.preventDefault()
+ e.stopPropagation()
+ this.dragover = true
+ }
+
+ @HostListener('dragleave', ['$event']) public onDragLeave(e: Event) {
+ e.preventDefault()
+ e.stopPropagation()
+ this.dragover = false
+ }
+
+ @HostListener('drop', ['$event']) public ondrop(e: DragEvent) {
+ e.preventDefault()
+ e.stopPropagation()
+ this.dragover = false
+ let files = e.dataTransfer.files
+ if (files.length > 0) this.onFileDropped.emit(files)
+ }
+}
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.html b/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.html
index c290fd4b1b..1d93841612 100644
--- a/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.html
+++ b/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.html
@@ -1,14 +1,13 @@
-<div *ngIf="!hasImportedVideo" class="upload-video-container">
+<div *ngIf="!hasImportedVideo" class="upload-video-container" dragDrop (onFileDropped)="setTorrentFile($event)">
<div class="first-step-block">
<my-global-icon class="upload-icon" iconName="upload"></my-global-icon>
- <div class="button-file">
+ <div class="button-file form-control" [ngbTooltip]="'(extensions: .torrent)'">
<span i18n>Select the torrent to import</span>
<input #torrentfileInput type="file" name="torrentfile" id="torrentfile" accept=".torrent" (change)="fileChange()" />
</div>
- <span class="button-file-extension">(.torrent)</span>
- <div class="torrent-or-magnet" i18n>Or</div>
+ <div class="torrent-or-magnet" i18n-data-content data-content="OR"></div>
<div class="form-group form-group-magnet-uri">
<label i18n for="magnetUri">Paste magnet URI</label>
@@ -21,13 +20,13 @@
</ng-template>
</my-help>
- <input type="text" id="magnetUri" [(ngModel)]="magnetUri" />
+ <input type="text" id="magnetUri" [(ngModel)]="magnetUri" class="form-control" />
</div>
<div class="form-group">
<label i18n for="first-step-channel">Channel</label>
<div class="peertube-select-container">
- <select id="first-step-channel" [(ngModel)]="firstStepChannelId">
+ <select id="first-step-channel" [(ngModel)]="firstStepChannelId" class="form-control">
<option *ngFor="let channel of userVideoChannels" [value]="channel.id">{{ channel.label }}</option>
</select>
</div>
@@ -36,7 +35,7 @@
<div class="form-group">
<label i18n for="first-step-privacy">Privacy</label>
<div class="peertube-select-container">
- <select id="first-step-privacy" [(ngModel)]="firstStepPrivacyId">
+ <select id="first-step-privacy" [(ngModel)]="firstStepPrivacyId" class="form-control">
<option *ngFor="let privacy of videoPrivacies" [value]="privacy.id">{{ privacy.label }}</option>
</select>
</div>
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts
index e47624dd65..4d0b0b0808 100644
--- a/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts
+++ b/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts
@@ -72,6 +72,11 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Ca
this.importVideo(torrentfile)
}
+ setTorrentFile (files: FileList) {
+ this.torrentfileInput.nativeElement.files = files
+ this.fileChange()
+ }
+
importVideo (torrentfile?: Blob) {
this.isImportingVideo = true
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html
index 09d0b8272a..9a26fe3082 100644
--- a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html
+++ b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html
@@ -15,13 +15,13 @@
</ng-template>
</my-help>
- <input type="text" id="targetUrl" [(ngModel)]="targetUrl" />
+ <input type="text" id="targetUrl" [(ngModel)]="targetUrl" class="form-control" />
</div>
<div class="form-group">
<label i18n for="first-step-channel">Channel</label>
<div class="peertube-select-container">
- <select id="first-step-channel" [(ngModel)]="firstStepChannelId">
+ <select id="first-step-channel" [(ngModel)]="firstStepChannelId" class="form-control">
<option *ngFor="let channel of userVideoChannels" [value]="channel.id">{{ channel.label }}</option>
</select>
</div>
@@ -30,7 +30,7 @@
<div class="form-group">
<label i18n for="first-step-privacy">Privacy</label>
<div class="peertube-select-container">
- <select id="first-step-privacy" [(ngModel)]="firstStepPrivacyId">
+ <select id="first-step-privacy" [(ngModel)]="firstStepPrivacyId" class="form-control">
<option *ngFor="let privacy of videoPrivacies" [value]="privacy.id">{{ privacy.label }}</option>
</select>
</div>
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html
index b4e1ceeca9..8db441a8ca 100644
--- a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html
+++ b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html
@@ -1,8 +1,8 @@
-<div *ngIf="!isUploadingVideo" class="upload-video-container">
+<div *ngIf="!isUploadingVideo" class="upload-video-container" dragDrop (onFileDropped)="setVideoFile($event)">
<div class="first-step-block">
<my-global-icon class="upload-icon" iconName="upload"></my-global-icon>
- <div class="button-file form-control" [ngbTooltip]="'(extensions: ' + videoExtensions + ')'" container="body">
+ <div class="button-file form-control" [ngbTooltip]="'(extensions: ' + videoExtensions + ')'">
<span i18n>Select the file to upload</span>
<input #videofileInput type="file" name="videofile" id="videofile" [accept]="videoExtensions" (change)="fileChange()" autofocus />
</div>
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts
index ee4aa7b533..8023459453 100644
--- a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts
+++ b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts
@@ -108,6 +108,11 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
return this.videofileInput.nativeElement.files[0]
}
+ setVideoFile (files: FileList) {
+ this.videofileInput.nativeElement.files = files
+ this.fileChange()
+ }
+
getAudioUploadLabel () {
const videofile = this.getVideoFile()
if (!videofile) return this.i18n('Upload')
diff --git a/client/src/app/videos/+video-edit/video-add.component.scss b/client/src/app/videos/+video-edit/video-add.component.scss
index 9d068afde4..c20467d9b3 100644
--- a/client/src/app/videos/+video-edit/video-add.component.scss
+++ b/client/src/app/videos/+video-edit/video-add.component.scss
@@ -40,14 +40,19 @@ $border-color: #EAEAEA;
::ng-deep .upload-video-container {
border: $border-width $border-type $border-color;
- border-top: none;
+ border-top: transparent;
background-color: var(--submenuColor);
- border-radius: 3px;
+ border-bottom-left-radius: 3px;
+ border-bottom-right-radius: 3px;
width: 100%;
min-height: 440px;
padding-bottom: 20px;
display: flex;
justify-content: center;
align-items: center;
+
+ &.dragover {
+ border: 3px dashed var(--mainColor);
+ }
}
diff --git a/client/src/app/videos/+video-edit/video-add.module.ts b/client/src/app/videos/+video-edit/video-add.module.ts
index 911404badf..b8f5a9a476 100644
--- a/client/src/app/videos/+video-edit/video-add.module.ts
+++ b/client/src/app/videos/+video-edit/video-add.module.ts
@@ -3,6 +3,7 @@ import { SharedModule } from '../../shared'
import { VideoEditModule } from './shared/video-edit.module'
import { VideoAddRoutingModule } from './video-add-routing.module'
import { VideoAddComponent } from './video-add.component'
+import { DragDropDirective } from './video-add-components/drag-drop.directive'
import { CanDeactivateGuard } from '../../shared/guards/can-deactivate-guard.service'
import { VideoUploadComponent } from '@app/videos/+video-edit/video-add-components/video-upload.component'
import { VideoImportUrlComponent } from '@app/videos/+video-edit/video-add-components/video-import-url.component'
@@ -18,10 +19,12 @@ import { VideoImportTorrentComponent } from '@app/videos/+video-edit/video-add-c
VideoAddComponent,
VideoUploadComponent,
VideoImportUrlComponent,
- VideoImportTorrentComponent
+ VideoImportTorrentComponent,
+ DragDropDirective
],
exports: [
- VideoAddComponent
+ VideoAddComponent,
+ DragDropDirective
],
providers: [
CanDeactivateGuard