Edit.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class='modal is-active'>
  3. <div class='modal-background'></div>
  4. <div class='modal-card'>
  5. <header class='modal-card-head'>
  6. <p class='modal-card-title'>Editing: {{ playlist.displayName }}</p>
  7. <button class='delete' @click='$parent.toggleModal("editPlaylist")'></button>
  8. </header>
  9. <section class='modal-card-body'>
  10. <aside class='menu' v-if='playlist.songs.length > 0'>
  11. <ul class='menu-list'>
  12. <li v-for='song in playlist.songs' track-by='$index'>
  13. <a :href='' target='_blank'>{{ song.title }} - {{ song.artists.join(', ') }}</a>
  14. <div class='controls'>
  15. <a href='#'>
  16. <i class='material-icons' v-if='playlist.songs[0] !== song' @click='promoteSong($index)'>keyboard_arrow_up</i>
  17. <i class='material-icons' v-else>error</i>
  18. </a>
  19. <a href='#' @click=''>
  20. <i class='material-icons' v-if='playlist.songs.length - 1 !== $index' @click='demoteSong($index)'>keyboard_arrow_down</i>
  21. <i class='material-icons' v-else>error</i>
  22. </a>
  23. <a href='#' @click='removeSongFromPlaylist(song._id)'><i class='material-icons'>delete</i></a>
  24. </div>
  25. </li>
  26. </ul>
  27. <br />
  28. </aside>
  29. <div class='control is-grouped'>
  30. <p class='control is-expanded'>
  31. <input class='input' type='text' placeholder='Search for Song to add' v-model='songQuery'>
  32. </p>
  33. <p class='control'>
  34. <a class='button is-info' @click='searchForSongs()'>Search</a>
  35. </p>
  36. </div>
  37. <table class='table' v-if='songQueryResults.length > 0'>
  38. <tbody>
  39. <tr v-for='result in songQueryResults'>
  40. <td>
  41. <img :src='result.thumbnail' />
  42. </td>
  43. <td>{{ result.title }}</td>
  44. <td>
  45. <a class='button is-success' @click='addSongToPlaylist(result.id)'>
  46. Add
  47. </a>
  48. </td>
  49. </tr>
  50. </tbody>
  51. </table>
  52. <div class='control is-grouped'>
  53. <p class='control is-expanded'>
  54. <input class='input' type='text' placeholder='YouTube Playlist URL' v-model='importQuery'>
  55. </p>
  56. <p class='control'>
  57. <a class='button is-info' @click='importPlaylist()'>Import</a>
  58. </p>
  59. </div>
  60. <h5>Edit playlist details:</h5>
  61. <div class='control is-grouped'>
  62. <p class='control is-expanded'>
  63. <input class='input' type='text' placeholder='Playlist Display Name' v-model='playlist.displayName'>
  64. </p>
  65. <p class='control'>
  66. <a class='button is-info' @click='renamePlaylist()'>Rename</a>
  67. </p>
  68. </div>
  69. <div class='control is-grouped'>
  70. <p class='control is-expanded'>
  71. <input class='input' type='text' placeholder='Playlist ID' v-model='playlist._id'>
  72. </p>
  73. <p class='control'>
  74. <a class='button is-info' @click='renamePlaylistId()'>Rename</a>
  75. </p>
  76. </div>
  77. </section>
  78. <footer class='modal-card-foot'>
  79. <a class='button is-danger' @click='removePlaylist()'>Remove Playlist</a>
  80. </footer>
  81. </div>
  82. </div>
  83. </template>
  84. <script>
  85. import { Toast } from 'vue-roaster';
  86. export default {
  87. data() {
  88. return {
  89. playlist: {},
  90. songQueryResults: []
  91. }
  92. },
  93. methods: {
  94. searchForSongs: function () {
  95. let _this = this;
  96. _this.socket.emit('apis.searchYoutube', _this.songQuery, res => {
  97. if (res.status == 'success') {
  98. _this.songQueryResults = [];
  99. for (let i = 0; i < res.data.items.length; i++) {
  100. _this.songQueryResults.push({
  101. id: res.data.items[i].id.videoId,
  102. url: `https://www.youtube.com/watch?v=${this.id}`,
  103. title: res.data.items[i].snippet.title,
  104. thumbnail: res.data.items[i].snippet.thumbnails.default.url
  105. });
  106. }
  107. } else if (res.status == 'error') Toast.methods.addToast(res.message, 3000);
  108. });
  109. },
  110. addSongToPlaylist: function (id) {
  111. let _this = this;
  112. _this.socket.emit('playlists.addSongToPlaylist', id, _this.playlist._id, res => {
  113. if (res.status == 'success') {
  114. Toast.methods.addToast(res.message, 3000);
  115. _this.playlist.songs = res.data;
  116. }
  117. });
  118. },
  119. importPlaylist: function () {
  120. let _this = this;
  121. this.socket.emit('playlists.addSetToPlaylist', _this.importQuery, _this.playlist._id, res => {
  122. if (res.status == 'success') _this.playlist.songs = res.data;
  123. });
  124. },
  125. removeSongFromPlaylist: function (id) {
  126. let _this = this;
  127. this.socket.emit('playlists.removeSongFromPlaylist', id, _this.playlist._id, res => {
  128. if (res.status == 'success') {
  129. Toast.methods.addToast(res.message, 3000);
  130. _this.playlist.songs = res.data;
  131. }
  132. });
  133. },
  134. renamePlaylist: function () {
  135. this.socket.emit('playlists.updateDisplayName', this.playlist._id, this.playlist.displayName, res => {
  136. if (res.status == 'success') Toast.methods.addToast(res.message, 3000);
  137. });
  138. },
  139. renamePlaylistId: function () {
  140. let _this = this;
  141. _this.socket.emit('playlists.updatePlaylistId', _this.playlist.oldId, _this.playlist._id, res => {
  142. if (res.status == 'success') _this.playlist = res.data;
  143. });
  144. },
  145. removePlaylist: function () {
  146. let _this = this;
  147. _this.socket.emit('playlists.remove', _this.playlist._id, res => {
  148. if (res.status == 'success') {
  149. Toast.methods.addToast(res.message, 3000);
  150. _this.$parent.toggleModal('editPlaylist');
  151. }
  152. });
  153. },
  154. promoteSong: function (fromIndex) {
  155. let _this = this;
  156. _this.socket.emit('playlists.promoteSong', _this.playlist._id, fromIndex, res => {
  157. if (res.status == 'success') _this.$set('playlist.songs', res.data); // bug: v-for is not updating
  158. });
  159. },
  160. demoteSong: function (fromIndex) {
  161. let _this = this;
  162. _this.socket.emit('playlists.demoteSong', _this.playlist._id, fromIndex, res => {
  163. if (res.status == 'success') _this.$set('playlist.songs', res.data); // bug: v-for is not updating
  164. });
  165. }
  166. },
  167. ready: function () {
  168. let _this = this;
  169. let socketInterval = setInterval(() => {
  170. if (!!_this.$parent.$parent.socket) {
  171. _this.socket = _this.$parent.$parent.socket;
  172. _this.socket.emit('playlists.getPlaylist', _this.$parent.playlistBeingEdited, res => {
  173. if (res.status == 'success') _this.playlist = res.data; _this.playlist.oldId = res.data._id;
  174. });
  175. clearInterval(socketInterval);
  176. }
  177. }, 100);
  178. }
  179. }
  180. </script>
  181. <style type='scss' scoped>
  182. .menu { padding: 0 20px; }
  183. .menu-list li {
  184. display: flex;
  185. justify-content: space-between;
  186. }
  187. .menu-list a:hover { color: #000 !important; }
  188. li a {
  189. display: flex;
  190. align-items: center;
  191. }
  192. .controls {
  193. display: flex;
  194. a {
  195. display: flex;
  196. align-items: center;
  197. }
  198. }
  199. .table {
  200. margin-bottom: 0;
  201. }
  202. h5 { padding: 20px 0; }
  203. </style>