diff options
Diffstat (limited to 'ui/src')
-rw-r--r-- | ui/src/app/app.component.html | 75 | ||||
-rw-r--r-- | ui/src/app/app.component.sass | 16 | ||||
-rw-r--r-- | ui/src/app/app.component.ts | 65 | ||||
-rw-r--r-- | ui/src/app/app.module.ts | 31 | ||||
-rw-r--r-- | ui/src/app/downloads.pipe.ts | 37 | ||||
-rw-r--r-- | ui/src/app/downloads.service.ts | 79 | ||||
-rw-r--r-- | ui/src/assets/.gitkeep | 0 | ||||
-rw-r--r-- | ui/src/environments/environment.prod.ts | 3 | ||||
-rw-r--r-- | ui/src/environments/environment.ts | 16 | ||||
-rw-r--r-- | ui/src/favicon.ico | bin | 0 -> 948 bytes | |||
-rw-r--r-- | ui/src/index.html | 13 | ||||
-rw-r--r-- | ui/src/main.ts | 12 | ||||
-rw-r--r-- | ui/src/polyfills.ts | 63 | ||||
-rw-r--r-- | ui/src/styles.sass | 1 |
14 files changed, 411 insertions, 0 deletions
diff --git a/ui/src/app/app.component.html b/ui/src/app/app.component.html new file mode 100644 index 0000000..3796b72 --- /dev/null +++ b/ui/src/app/app.component.html @@ -0,0 +1,75 @@ +<nav class="navbar navbar-expand-md navbar-dark bg-dark"> + <a class="navbar-brand" href="#">MeTube</a> + <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsDefault" aria-controls="navbarsDefault" aria-expanded="false" aria-label="Toggle navigation"> + <span class="navbar-toggler-icon"></span> + </button> + + <!-- + <div class="collapse navbar-collapse" id="navbarsDefault"> + <ul class="navbar-nav mr-auto"> + <li class="nav-item active"> + <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a> + </li> + </ul> + </div> + --> +</nav> + +<main role="main" class="container"> + <form #f="ngForm"> + <div class="input-group add-url-box"> + <input type="text" class="form-control" placeholder="Video or playlist URL" name="addUrl" [(ngModel)]="addUrl" [disabled]="addInProgress || downloads.loading"> + <div class="input-group-append"> + <button class="btn btn-primary" type="submit" (click)="addDownload()" [disabled]="addInProgress || downloads.loading"> + <span class="spinner-border spinner-border-sm" role="status" id="add-spinner" *ngIf="addInProgress"></span> + {{ addInProgress ? "Adding..." : "Add" }} + </button> + </div> + </div> + </form> + + <p *ngIf="downloads.loading">Loading...</p> + <div *ngIf="!downloads.loading"> + <div *ngIf="downloads.empty()" class="jumbotron jumbotron-fluid px-4"> + <div class="container text-center"> + <h1 class="display-4">Welcome to MeTube!</h1> + <p class="lead">Please add some downloads via the URL box above.</p> + </div> + </div> + <table *ngIf="!downloads.empty()" class="table"> + <thead> + <tr> + <th scope="col" style="width: 1rem; vertical-align: middle;"> + <div class="custom-control custom-checkbox"> + <input type="checkbox" class="custom-control-input" id="select-all" #masterCheckbox [(ngModel)]="masterSelected" (change)="checkUncheckAll()"> + <label class="custom-control-label" for="select-all"></label> + </div> + </th> + <th scope="col"> + <button type="button" class="btn btn-link px-0" disabled #delSelected (click)="delSelectedDownloads()"><fa-icon [icon]="faTrashAlt"></fa-icon> Clear selected</button> + </th> + <th scope="col" style="width: 14rem;"></th> + <th scope="col" style="width: 8rem;">Speed</th> + <th scope="col" style="width: 7rem;">ETA</th> + <th scope="col" style="width: 2rem;"></th> + </tr> + </thead> + <tbody> + <tr *ngFor="let download of downloads.downloads | keyvalue: asIsOrder" [class.disabled]='download.value.deleting'> + <td> + <div class="custom-control custom-checkbox"> + <input type="checkbox" class="custom-control-input" id="select-{{download.key}}" [(ngModel)]="download.value.checked" (change)="selectionChanged()"> + <label class="custom-control-label" for="select-{{download.key}}"></label> + </div> + </td> + <td>{{ download.value.title }}</td> + <td><ngb-progressbar height="1.5rem" [showValue]="download.value.status != 'preparing'" [striped]="download.value.status == 'preparing'" [animated]="download.value.status == 'preparing'" type="success" [value]="download.value.status == 'preparing' ? 100 : download.value.percent | number:'1.0-0'"></ngb-progressbar></td> + <td>{{ download.value.speed | speed }}</td> + <td>{{ download.value.eta | eta }}</td> + <td><button type="button" class="btn btn-link" (click)="delDownload(download.key)"><fa-icon [icon]="faTrashAlt"></fa-icon></button></td> + </tr> + </tbody> + </table> + </div> + +</main><!-- /.container --> diff --git a/ui/src/app/app.component.sass b/ui/src/app/app.component.sass new file mode 100644 index 0000000..847fc30 --- /dev/null +++ b/ui/src/app/app.component.sass @@ -0,0 +1,16 @@ +.add-url-box
+ padding: 5rem 0
+ max-width: 720px
+ margin: auto
+
+.rounded-box
+ border: 1px solid rgba(0,0,0,.125)
+ border-radius: .25rem
+
+th
+ border-top: 0
+ border-bottom: 3px solid #dee2e6 !important
+
+.disabled
+ opacity: 0.5
+ pointer-events: none
diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts new file mode 100644 index 0000000..0b945db --- /dev/null +++ b/ui/src/app/app.component.ts @@ -0,0 +1,65 @@ +import { Component, ViewChild, ElementRef } from '@angular/core'; +import { faTrashAlt } from '@fortawesome/free-regular-svg-icons'; + +import { DownloadsService, Status } from './downloads.service'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.sass'] +}) +export class AppComponent { + addUrl: string; + addInProgress = false; + faTrashAlt = faTrashAlt; + masterSelected: boolean; + @ViewChild('masterCheckbox', {static: false}) masterCheckbox: ElementRef; + @ViewChild('delSelected', {static: false}) delSelected: ElementRef; + + constructor(private downloads: DownloadsService) { + this.downloads.dlChanges.subscribe(() => this.selectionChanged()); + } + + // workaround to allow fetching of Map values in the order they were inserted + // https://github.com/angular/angular/issues/31420 + asIsOrder(a, b) { + return 1; + } + + checkUncheckAll() { + this.downloads.downloads.forEach(dl => dl.checked = this.masterSelected); + this.selectionChanged(); + } + + selectionChanged() { + if (!this.masterCheckbox) + return; + let checked: number = 0; + this.downloads.downloads.forEach(dl => { if(dl.checked) checked++ }); + this.masterSelected = checked > 0 && checked == this.downloads.downloads.size; + this.masterCheckbox.nativeElement.indeterminate = checked > 0 && checked < this.downloads.downloads.size; + this.delSelected.nativeElement.disabled = checked == 0; + } + + addDownload() { + this.addInProgress = true; + this.downloads.add(this.addUrl).subscribe((status: Status) => { + if (status.status === 'error') { + alert(`Error adding URL: ${status.msg}`); + } else { + this.addUrl = ''; + } + this.addInProgress = false; + }); + } + + delDownload(id: string) { + this.downloads.del([id]).subscribe(); + } + + delSelectedDownloads() { + let ids: string[] = []; + this.downloads.downloads.forEach(dl => { if(dl.checked) ids.push(dl.id) }); + this.downloads.del(ids).subscribe(); + } +} diff --git a/ui/src/app/app.module.ts b/ui/src/app/app.module.ts new file mode 100644 index 0000000..a169f14 --- /dev/null +++ b/ui/src/app/app.module.ts @@ -0,0 +1,31 @@ +import { BrowserModule } from '@angular/platform-browser'; +import { NgModule } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; +import { HttpClientModule } from '@angular/common/http'; +import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io'; +import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; + +import { AppComponent } from './app.component'; +import { EtaPipe, SpeedPipe } from './downloads.pipe'; + +const config: SocketIoConfig = { url: '', options: {} }; + +@NgModule({ + declarations: [ + AppComponent, + EtaPipe, + SpeedPipe + ], + imports: [ + BrowserModule, + FormsModule, + NgbModule, + HttpClientModule, + SocketIoModule.forRoot(config), + FontAwesomeModule + ], + providers: [], + bootstrap: [AppComponent] +}) +export class AppModule { } diff --git a/ui/src/app/downloads.pipe.ts b/ui/src/app/downloads.pipe.ts new file mode 100644 index 0000000..d4a1654 --- /dev/null +++ b/ui/src/app/downloads.pipe.ts @@ -0,0 +1,37 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'eta' +}) +export class EtaPipe implements PipeTransform { + transform(value: number, ...args: any[]): any { + if (value === null) { + return null; + } + if (value < 60) { + return `${value}s`; + } + if (value < 3600) { + return `${Math.floor(value/60)}m ${value%60}s`; + } + const hours = Math.floor(value/3600) + const minutes = value % 3600 + return `${hours}h ${Math.floor(minutes/60)}m ${minutes%60}s`; + } +} + +@Pipe({ + name: 'speed' +}) +export class SpeedPipe implements PipeTransform { + transform(value: number, ...args: any[]): any { + if (value === null) { + return null; + } + const k = 1024; + const dm = 2; + const sizes = ['B/s', 'KB/s', 'MB/s', 'GB/s', 'TB/s', 'PB/s', 'EB/s', 'ZB/s', 'YB/s']; + const i = Math.floor(Math.log(value) / Math.log(k)); + return parseFloat((value / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; + } +} diff --git a/ui/src/app/downloads.service.ts b/ui/src/app/downloads.service.ts new file mode 100644 index 0000000..cae16f3 --- /dev/null +++ b/ui/src/app/downloads.service.ts @@ -0,0 +1,79 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpErrorResponse } from '@angular/common/http'; +import { of, Subject } from 'rxjs'; +import { catchError } from 'rxjs/operators'; +import { Socket } from 'ngx-socket-io'; + +export interface Status { + status: string; + msg?: string; +} + +interface Download { + id: string; + title: string; + url: string, + status: string; + percent: number; + speed: number; + eta: number; + checked?: boolean; + deleting?: boolean; +} + +@Injectable({ + providedIn: 'root' +}) +export class DownloadsService { + loading = true; + downloads = new Map<string, Download>(); + dlChanges = new Subject(); + + constructor(private http: HttpClient, private socket: Socket) { + socket.fromEvent('queue').subscribe((strdata: string) => { + this.loading = false; + this.downloads.clear(); + let data: [[string, Download]] = JSON.parse(strdata); + data.forEach(entry => this.downloads.set(...entry)); + this.dlChanges.next(); + }); + socket.fromEvent('added').subscribe((strdata: string) => { + let data: Download = JSON.parse(strdata); + this.downloads.set(data.id, data); + this.dlChanges.next(); + }); + socket.fromEvent('updated').subscribe((strdata: string) => { + let data: Download = JSON.parse(strdata); + let dl: Download = this.downloads.get(data.id); + data.checked = dl.checked; + data.deleting = dl.deleting; + this.downloads.set(data.id, data); + this.dlChanges.next(); + }); + socket.fromEvent('deleted').subscribe((strdata: string) => { + let data: string = JSON.parse(strdata); + this.downloads.delete(data); + this.dlChanges.next(); + }); + } + + empty() { + return this.downloads.size == 0; + } + + handleHTTPError(error: HttpErrorResponse) { + var msg = error.error instanceof ErrorEvent ? error.error.message : error.error; + return of({status: 'error', msg: msg}) + } + + public add(url: string) { + return this.http.post<Status>('add', {url: url}).pipe( + catchError(this.handleHTTPError) + ); + } + + public del(ids: string[]) { + ids.forEach(id => this.downloads.get(id).deleting = true); + return this.http.post('delete', {ids: ids}); + } +} diff --git a/ui/src/assets/.gitkeep b/ui/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ui/src/assets/.gitkeep diff --git a/ui/src/environments/environment.prod.ts b/ui/src/environments/environment.prod.ts new file mode 100644 index 0000000..3612073 --- /dev/null +++ b/ui/src/environments/environment.prod.ts @@ -0,0 +1,3 @@ +export const environment = { + production: true +}; diff --git a/ui/src/environments/environment.ts b/ui/src/environments/environment.ts new file mode 100644 index 0000000..7b4f817 --- /dev/null +++ b/ui/src/environments/environment.ts @@ -0,0 +1,16 @@ +// This file can be replaced during build by using the `fileReplacements` array. +// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. +// The list of file replacements can be found in `angular.json`. + +export const environment = { + production: false +}; + +/* + * For easier debugging in development mode, you can import the following file + * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. + * + * This import should be commented out in production mode because it will have a negative impact + * on performance if an error is thrown. + */ +// import 'zone.js/dist/zone-error'; // Included with Angular CLI. diff --git a/ui/src/favicon.ico b/ui/src/favicon.ico Binary files differnew file mode 100644 index 0000000..997406a --- /dev/null +++ b/ui/src/favicon.ico diff --git a/ui/src/index.html b/ui/src/index.html new file mode 100644 index 0000000..9ae8c8b --- /dev/null +++ b/ui/src/index.html @@ -0,0 +1,13 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>MeTube</title> + <base href="/"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <link rel="icon" type="image/x-icon" href="favicon.ico"> +</head> +<body> + <app-root></app-root> +</body> +</html> diff --git a/ui/src/main.ts b/ui/src/main.ts new file mode 100644 index 0000000..c7b673c --- /dev/null +++ b/ui/src/main.ts @@ -0,0 +1,12 @@ +import { enableProdMode } from '@angular/core'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + +import { AppModule } from './app/app.module'; +import { environment } from './environments/environment'; + +if (environment.production) { + enableProdMode(); +} + +platformBrowserDynamic().bootstrapModule(AppModule) + .catch(err => console.error(err)); diff --git a/ui/src/polyfills.ts b/ui/src/polyfills.ts new file mode 100644 index 0000000..aa665d6 --- /dev/null +++ b/ui/src/polyfills.ts @@ -0,0 +1,63 @@ +/** + * This file includes polyfills needed by Angular and is loaded before the app. + * You can add your own extra polyfills to this file. + * + * This file is divided into 2 sections: + * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. + * 2. Application imports. Files imported after ZoneJS that should be loaded before your main + * file. + * + * The current setup is for so-called "evergreen" browsers; the last versions of browsers that + * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), + * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. + * + * Learn more in https://angular.io/guide/browser-support + */ + +/*************************************************************************************************** + * BROWSER POLYFILLS + */ + +/** IE10 and IE11 requires the following for NgClass support on SVG elements */ +// import 'classlist.js'; // Run `npm install --save classlist.js`. + +/** + * Web Animations `@angular/platform-browser/animations` + * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. + * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). + */ +// import 'web-animations-js'; // Run `npm install --save web-animations-js`. + +/** + * By default, zone.js will patch all possible macroTask and DomEvents + * user can disable parts of macroTask/DomEvents patch by setting following flags + * because those flags need to be set before `zone.js` being loaded, and webpack + * will put import in the top of bundle, so user need to create a separate file + * in this directory (for example: zone-flags.ts), and put the following flags + * into that file, and then add the following code before importing zone.js. + * import './zone-flags.ts'; + * + * The flags allowed in zone-flags.ts are listed here. + * + * The following flags will work for all browsers. + * + * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame + * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick + * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames + * + * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js + * with the following flag, it will bypass `zone.js` patch for IE/Edge + * + * (window as any).__Zone_enable_cross_context_check = true; + * + */ + +/*************************************************************************************************** + * Zone JS is required by default for Angular itself. + */ +import 'zone.js/dist/zone'; // Included with Angular CLI. + + +/*************************************************************************************************** + * APPLICATION IMPORTS + */ diff --git a/ui/src/styles.sass b/ui/src/styles.sass new file mode 100644 index 0000000..90d4ee0 --- /dev/null +++ b/ui/src/styles.sass @@ -0,0 +1 @@ +/* You can add global styles to this file, and also import other style files */ |