diff --git a/src/app/player/player.component.css b/src/app/player/player.component.css index 9cb227b..c4d5caf 100644 --- a/src/app/player/player.component.css +++ b/src/app/player/player.component.css @@ -62,4 +62,18 @@ .save-icon { bottom: 1px; position: relative; +} + +.update-playlist-button-div { + float: right; + margin-right: 30px; + margin-top: 25px; + margin-bottom: 15px; +} + +.spinner-div { + position: relative; + display: inline-block; + margin-right: 12px; + top: 8px; } \ No newline at end of file diff --git a/src/app/player/player.component.html b/src/app/player/player.component.html index f3a3e7e..8290849 100644 --- a/src/app/player/player.component.html +++ b/src/app/player/player.component.html @@ -8,13 +8,21 @@
- - {{decodeURI(name)}} + + {{decodeURI(playlist_item.title)}}
+
+
+ +
+ + +
+
diff --git a/src/app/player/player.component.ts b/src/app/player/player.component.ts index 7ea5407..c5e65c7 100644 --- a/src/app/player/player.component.ts +++ b/src/app/player/player.component.ts @@ -4,6 +4,7 @@ import { PostsService } from 'app/posts.services'; import { ActivatedRoute, Router } from '@angular/router'; import { MatDialog, MatSnackBar } from '@angular/material'; import { InputDialogComponent } from 'app/input-dialog/input-dialog.component'; +import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; export interface IMedia { title: string; @@ -19,6 +20,8 @@ export interface IMedia { export class PlayerComponent implements OnInit { playlist: Array = []; + original_playlist: string = null; + playlist_updating = false; currentIndex = 0; currentItem: IMedia = null; @@ -82,6 +85,7 @@ export class PlayerComponent implements OnInit { this.playlist.push(mediaObject); } this.currentItem = this.playlist[this.currentIndex]; + this.original_playlist = JSON.stringify(this.playlist); }); // this.getFileInfos(); @@ -122,11 +126,20 @@ export class PlayerComponent implements OnInit { } getFileInfos() { - this.postsService.getFileInfo(this.fileNames, this.type, false).subscribe(res => { + const fileNames = this.getFileNames(); + this.postsService.getFileInfo(fileNames, this.type, false).subscribe(res => { }); } + getFileNames() { + const fileNames = []; + for (let i = 0; i < this.playlist.length; i++) { + fileNames.push(this.playlist[i].title); + } + return fileNames; + } + decodeURI(string) { return decodeURI(string); } @@ -179,7 +192,8 @@ export class PlayerComponent implements OnInit { // Eventually do additional checks on name if (name) { - this.postsService.createPlaylist(name, this.fileNames, this.type, null).subscribe(res => { + const fileNames = this.getFileNames(); + this.postsService.createPlaylist(name, fileNames, this.type, null).subscribe(res => { if (res['success']) { dialogRef.close(); const new_playlist = res['new_playlist']; @@ -208,6 +222,30 @@ export class PlayerComponent implements OnInit { this.router.navigateByUrl(this.router.url + ';id=' + playlistID); } + drop(event: CdkDragDrop) { + moveItemInArray(this.playlist, event.previousIndex, event.currentIndex); + } + + playlistChanged() { + return JSON.stringify(this.playlist) !== this.original_playlist; + } + + updatePlaylist() { + const fileNames = this.getFileNames(); + this.playlist_updating = true; + this.postsService.updatePlaylist(this.id, fileNames, this.type).subscribe(res => { + this.playlist_updating = false; + if (res['success']) { + const fileNamesEncoded = fileNames.join('|nvr|'); + this.router.navigate(['/player', {fileNames: fileNamesEncoded, type: 'video', id: this.id}]); + this.openSnackBar('Successfully updated playlist.', ''); + this.original_playlist = JSON.stringify(this.playlist); + } else { + this.openSnackBar('ERROR: Failed to update playlist.', ''); + } + }) + } + // snackbar helper public openSnackBar(message: string, action: string) { this.snackBar.open(message, action, { diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index 40ddff8..aede413 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -107,6 +107,12 @@ export class PostsService { thumbnailURL: thumbnailURL}); } + updatePlaylist(playlistID, fileNames, type) { + return this.http.post(this.path + 'updatePlaylist', {playlistID: playlistID, + fileNames: fileNames, + type: type}); + } + removePlaylist(playlistID, type) { return this.http.post(this.path + 'deletePlaylist', {playlistID: playlistID, type: type}); }