From 5511c94071c3e6b3eea8548e3bd3b1c59fb7103e Mon Sep 17 00:00:00 2001 From: Isaac Grynsztein Date: Mon, 29 Jun 2020 19:35:34 -0400 Subject: [PATCH] Added modify playlist component --- src/app/app.module.ts | 4 +- .../modify-playlist.component.html | 28 +++++++ .../modify-playlist.component.scss | 50 ++++++++++++ .../modify-playlist.component.spec.ts | 25 ++++++ .../modify-playlist.component.ts | 81 +++++++++++++++++++ src/app/file-card/file-card.component.html | 13 ++- src/app/file-card/file-card.component.ts | 18 ++++- src/app/main/main.component.html | 4 +- 8 files changed, 212 insertions(+), 11 deletions(-) create mode 100644 src/app/dialogs/modify-playlist/modify-playlist.component.html create mode 100644 src/app/dialogs/modify-playlist/modify-playlist.component.scss create mode 100644 src/app/dialogs/modify-playlist/modify-playlist.component.spec.ts create mode 100644 src/app/dialogs/modify-playlist/modify-playlist.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index b556899..49bd2cb 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -72,6 +72,7 @@ import { ManageUserComponent } from './components/manage-user/manage-user.compon import { ManageRoleComponent } from './components/manage-role/manage-role.component'; import { CookiesUploaderDialogComponent } from './dialogs/cookies-uploader-dialog/cookies-uploader-dialog.component'; import { LogsViewerComponent } from './components/logs-viewer/logs-viewer.component'; +import { ModifyPlaylistComponent } from './dialogs/modify-playlist/modify-playlist.component'; registerLocaleData(es, 'es'); @@ -111,7 +112,8 @@ export function isVisible({ event, element, scrollContainer, offset }: IsVisible ManageUserComponent, ManageRoleComponent, CookiesUploaderDialogComponent, - LogsViewerComponent + LogsViewerComponent, + ModifyPlaylistComponent ], imports: [ CommonModule, diff --git a/src/app/dialogs/modify-playlist/modify-playlist.component.html b/src/app/dialogs/modify-playlist/modify-playlist.component.html new file mode 100644 index 0000000..f172eb6 --- /dev/null +++ b/src/app/dialogs/modify-playlist/modify-playlist.component.html @@ -0,0 +1,28 @@ +

Modify playlist

+ + + +
+ + + +
+ + + +
{{playlist_item}}
+
+ +
+ +
+ + + + +
+ + + + + \ No newline at end of file diff --git a/src/app/dialogs/modify-playlist/modify-playlist.component.scss b/src/app/dialogs/modify-playlist/modify-playlist.component.scss new file mode 100644 index 0000000..84d3c54 --- /dev/null +++ b/src/app/dialogs/modify-playlist/modify-playlist.component.scss @@ -0,0 +1,50 @@ +.media-list { + +} + +.media-box { + +} + +.cdk-drag-preview { +box-sizing: border-box; +border-radius: 4px; +box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2), + 0 8px 10px 1px rgba(0, 0, 0, 0.14), + 0 3px 14px 2px rgba(0, 0, 0, 0.12); +} + +.cdk-drag-placeholder { +opacity: 0; +} + +.cdk-drag-animating { +transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); +} + +.media-box:last-child { +border: none; +} + +.media-list.cdk-drop-list-dragging .media-box:not(.cdk-drag-placeholder) { +transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); +} + +.add-content-button { +margin-top: 15px; +margin-bottom: 10px; +} + +.remove-item-button { + right: 10px; + position: absolute; + top: 4px; +} + +.playlist-item-text { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + max-width: 70%; + margin: 0 auto; +} \ No newline at end of file diff --git a/src/app/dialogs/modify-playlist/modify-playlist.component.spec.ts b/src/app/dialogs/modify-playlist/modify-playlist.component.spec.ts new file mode 100644 index 0000000..13cc64f --- /dev/null +++ b/src/app/dialogs/modify-playlist/modify-playlist.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ModifyPlaylistComponent } from './modify-playlist.component'; + +describe('ModifyPlaylistComponent', () => { + let component: ModifyPlaylistComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ModifyPlaylistComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ModifyPlaylistComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/dialogs/modify-playlist/modify-playlist.component.ts b/src/app/dialogs/modify-playlist/modify-playlist.component.ts new file mode 100644 index 0000000..c6a33b4 --- /dev/null +++ b/src/app/dialogs/modify-playlist/modify-playlist.component.ts @@ -0,0 +1,81 @@ +import { Component, OnInit, Inject } from '@angular/core'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; +import { PostsService } from 'app/posts.services'; + +@Component({ + selector: 'app-modify-playlist', + templateUrl: './modify-playlist.component.html', + styleUrls: ['./modify-playlist.component.scss'] +}) +export class ModifyPlaylistComponent implements OnInit { + + original_playlist = null; + playlist = null; + available_files = []; + all_files = []; + + constructor(@Inject(MAT_DIALOG_DATA) public data: any, + private postsService: PostsService, + public dialogRef: MatDialogRef) { } + + ngOnInit(): void { + if (this.data) { + this.playlist = JSON.parse(JSON.stringify(this.data.playlist)); + this.original_playlist = JSON.parse(JSON.stringify(this.data.playlist)); + this.getFiles(); + } + } + + getFiles() { + if (this.playlist.type === 'audio') { + this.postsService.getMp3s().subscribe(res => { + this.processFiles(res['mp3s']); + }); + } else { + this.postsService.getMp4s().subscribe(res => { + this.processFiles(res['mp4s']); + }); + } + } + + processFiles(new_files = null) { + if (new_files) { this.all_files = new_files.map(file => file.id); } + this.available_files = this.all_files.filter(e => !this.playlist.fileNames.includes(e)) + } + + updatePlaylist() { + this.postsService.updatePlaylist(this.playlist).subscribe(res => { + this.postsService.openSnackBar('Playlist updated successfully.'); + this.getPlaylist(); + }); + } + + playlistChanged() { + return JSON.stringify(this.playlist) === JSON.stringify(this.original_playlist); + } + + getPlaylist() { + this.postsService.getPlaylist(this.playlist.id, this.playlist.type, null).subscribe(res => { + if (res['playlist']) { + this.playlist = res['playlist']; + this.original_playlist = JSON.parse(JSON.stringify(this.playlist)); + } + }); + } + + addContent(file) { + this.playlist.fileNames.push(file); + this.processFiles(); + } + + removeContent(index) { + this.playlist.fileNames.splice(index, 1); + this.processFiles(); + } + + drop(event: CdkDragDrop) { + moveItemInArray(this.playlist.fileNames, event.previousIndex, event.currentIndex); + } + +} diff --git a/src/app/file-card/file-card.component.html b/src/app/file-card/file-card.component.html index f9f62a3..f3c7ffe 100644 --- a/src/app/file-card/file-card.component.html +++ b/src/app/file-card/file-card.component.html @@ -2,10 +2,10 @@
ID: {{name}} -
Count: {{count}}
+
Count: {{count}}
Thumbnail @@ -14,11 +14,16 @@
- - + + + + + + + diff --git a/src/app/file-card/file-card.component.ts b/src/app/file-card/file-card.component.ts index e63a504..9f76f2e 100644 --- a/src/app/file-card/file-card.component.ts +++ b/src/app/file-card/file-card.component.ts @@ -7,6 +7,7 @@ import { Subject, Observable } from 'rxjs'; import 'rxjs/add/observable/merge'; import { MatDialog } from '@angular/material/dialog'; import { VideoInfoDialogComponent } from 'app/dialogs/video-info-dialog/video-info-dialog.component'; +import { ModifyPlaylistComponent } from '../dialogs/modify-playlist/modify-playlist.component'; @Component({ selector: 'app-file-card', @@ -22,7 +23,7 @@ export class FileCardComponent implements OnInit { @Input() thumbnailURL: string; @Input() isAudio = true; @Output() removeFile: EventEmitter = new EventEmitter(); - @Input() isPlaylist = false; + @Input() playlist = null; @Input() count = null; @Input() use_youtubedl_archive = false; type; @@ -46,15 +47,15 @@ export class FileCardComponent implements OnInit { this.type = this.isAudio ? 'audio' : 'video'; if (this.file && this.file.url && this.file.url.includes('youtu')) { - const string_id = (this.isPlaylist ? '?list=' : '?v=') - const index_offset = (this.isPlaylist ? 6 : 3); + const string_id = (this.playlist ? '?list=' : '?v=') + const index_offset = (this.playlist ? 6 : 3); const end_index = this.file.url.indexOf(string_id) + index_offset; this.name = this.file.url.substring(end_index, this.file.url.length); } } deleteFile(blacklistMode = false) { - if (!this.isPlaylist) { + if (!this.playlist) { this.postsService.deleteFile(this.uid, this.isAudio, blacklistMode).subscribe(result => { if (result) { this.openSnackBar('Delete success!', 'OK.'); @@ -80,6 +81,15 @@ export class FileCardComponent implements OnInit { }); } + editPlaylistDialog() { + const dialogRef = this.dialog.open(ModifyPlaylistComponent, { + data: { + playlist: this.playlist, + width: '65vw' + } + }); + } + onImgError(event) { this.image_errored = true; } diff --git a/src/app/main/main.component.html b/src/app/main/main.component.html index 13482a5..ed7f1fe 100644 --- a/src/app/main/main.component.html +++ b/src/app/main/main.component.html @@ -213,7 +213,7 @@ + [length]="null" [isAudio]="true" [playlist]="playlist" [count]="playlist.fileNames.length" [use_youtubedl_archive]="use_youtubedl_archive"> @@ -255,7 +255,7 @@ + [length]="null" [isAudio]="false" [playlist]="playlist" [count]="playlist.fileNames.length" [use_youtubedl_archive]="use_youtubedl_archive">