From dadaa2cd36a4dc4b2a1a67e843e6de05e519d917 Mon Sep 17 00:00:00 2001 From: stickyPiston Date: Sun, 6 Oct 2019 16:25:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Continued=20work=20on=20AddSongC?= =?UTF-8?q?omponent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now you can enter details about a song and it will be updated. --- .../components/addsong/addsong.component.html | 35 ++++++++++++++++--- .../components/addsong/addsong.component.ts | 27 ++++++++++++-- src/app/services/data.service.ts | 12 +++++++ src/app/services/download.service.ts | 17 ++++++++- 4 files changed, 83 insertions(+), 8 deletions(-) diff --git a/src/app/components/addsong/addsong.component.html b/src/app/components/addsong/addsong.component.html index 273f5f7..c3fe676 100644 --- a/src/app/components/addsong/addsong.component.html +++ b/src/app/components/addsong/addsong.component.html @@ -1,4 +1,31 @@ -
- - -
+
+ +
+

Enter the youtube video url

+
+ + +
+
+ +
+

Enter the details of this song

+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ +
diff --git a/src/app/components/addsong/addsong.component.ts b/src/app/components/addsong/addsong.component.ts index 91f16dc..6a420a8 100644 --- a/src/app/components/addsong/addsong.component.ts +++ b/src/app/components/addsong/addsong.component.ts @@ -9,10 +9,19 @@ import { FormBuilder } from '@angular/forms'; }) export class AddsongComponent implements OnInit { - form = this.fb.group({ + idForm = this.fb.group({ id: '' }); + detailsForm = this.fb.group({ + song: '', + artist: '', + path: '' + }); + + currentStep = 1; + videoInfo; + constructor( private download: DownloadService, private fb: FormBuilder @@ -20,8 +29,20 @@ export class AddsongComponent implements OnInit { ngOnInit() { } - onSubmit() { - this.download.addQueueItem(this.form.value.id); + onIdSubmit() { + this.download.addQueueItem(this.idForm.value.id); + this.currentStep = 2; + this.download.getVideoDetails(this.idForm.value.id).then(res => { + this.videoInfo = res.data.result; + this.detailsForm.get('song').setValue(this.videoInfo.title); + this.detailsForm.get('artist').setValue(this.videoInfo.author.name); + this.detailsForm.get('path').setValue(this.videoInfo.title + '.mp3'); + }); + } + + onDetailsSubmit() { + console.log(this.detailsForm.value); + this.download.insertSong(this.detailsForm.value); } } diff --git a/src/app/services/data.service.ts b/src/app/services/data.service.ts index 2b84200..9d8c700 100644 --- a/src/app/services/data.service.ts +++ b/src/app/services/data.service.ts @@ -91,4 +91,16 @@ export class DataService { downloadqueue(): Promise> { return this.axiosInstance.get(`${this.apiUrl}/downloadqueue`); } + + videoInfo(id: string): Promise> { + return this.axiosInstance.get(`${this.apiUrl}/info/${id}`); + } + + update(database: string, index: number, field: string, value: number | string | boolean): Promise> { + return this.axiosInstance.get(`${this.apiUrl}/update/${database}/${index}/${field}/${value}`); + } + + insert(database: string): Promise> { + return this.axiosInstance.get(`${this.apiUrl}/insert/${database}`); + } } diff --git a/src/app/services/download.service.ts b/src/app/services/download.service.ts index 9cf00da..dac8bff 100644 --- a/src/app/services/download.service.ts +++ b/src/app/services/download.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { DataService } from './data.service'; +import { DataService, ApiData } from './data.service'; import { AxiosResponse } from 'axios'; import { NotificationService } from './notification.service'; @@ -16,6 +16,9 @@ export class DownloadService { downloadQueue: Promise[] = []; addQueueItem(id: string) { + console.log(`downloading ${id}...`); + + this.data.download(id); const index = this.downloadQueue.push(this.data.download(id)) - 1; this.downloadQueue[index].then(res => { // tslint:disable-next-line: max-line-length @@ -28,6 +31,18 @@ export class DownloadService { return this.data.downloadqueue(); } + getVideoDetails(id: string): Promise> { + return this.data.videoInfo(id); + } + + async insertSong(formData: any) { + const songResult = (await this.data.insert('songs')).data.result; + this.data.update('songs', songResult.id, 'name', formData.song); + this.data.update('songs', songResult.id, 'artist', formData.artist); + this.data.update('songs', songResult.id, 'path', formData.path); + this.data.update('songs', songResult.id, 'liked', false); + } + // Input like: "00:00:54.43" convertTimeToSeconds(input: string): number { if (typeof input === 'string') {