Edit.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 && 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 }}</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' style='opacity: 0' v-else>error</i>
  18. </a>
  19. <a href='#'>
  20. <i class='material-icons' v-if='playlist.songs.length - 1 !== $index' @click='demoteSong($index)'>keyboard_arrow_down</i>
  21. <i class='material-icons' style='opacity: 0' 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' autofocus @keyup.enter='searchForSongs()'>
  32. </p>
  33. <p class='control'>
  34. <a class='button is-info' @click='searchForSongs()' href="#">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)' href='#'>
  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' @keyup.enter="importPlaylist()">
  55. </p>
  56. <p class='control'>
  57. <a class='button is-info' @click='importPlaylist()' href="#">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' @keyup.enter="renamePlaylist()">
  64. </p>
  65. <p class='control'>
  66. <a class='button is-info' @click='renamePlaylist()' href="#">Rename</a>
  67. </p>
  68. </div>
  69. </section>
  70. <footer class='modal-card-foot'>
  71. <a class='button is-danger' @click='removePlaylist()' href="#">Remove Playlist</a>
  72. </footer>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import { Toast } from 'vue-roaster';
  78. import io from '../../../io';
  79. export default {
  80. data() {
  81. return {
  82. playlist: {},
  83. songQueryResults: [],
  84. songQuery: '',
  85. importQuery: ''
  86. }
  87. },
  88. methods: {
  89. searchForSongs: function () {
  90. let _this = this;
  91. let query = _this.songQuery;
  92. if (query.indexOf('&index=') !== -1) {
  93. query = query.split('&index=');
  94. query.pop();
  95. query = query.join('');
  96. }
  97. if (query.indexOf('&list=') !== -1) {
  98. query = query.split('&list=');
  99. query.pop();
  100. query = query.join('');
  101. }
  102. _this.socket.emit('apis.searchYoutube', query, res => {
  103. if (res.status == 'success') {
  104. _this.songQueryResults = [];
  105. for (let i = 0; i < res.data.items.length; i++) {
  106. _this.songQueryResults.push({
  107. id: res.data.items[i].id.videoId,
  108. url: `https://www.youtube.com/watch?v=${this.id}`,
  109. title: res.data.items[i].snippet.title,
  110. thumbnail: res.data.items[i].snippet.thumbnails.default.url
  111. });
  112. }
  113. } else if (res.status === 'error') Toast.methods.addToast(res.message, 3000);
  114. });
  115. },
  116. addSongToPlaylist: function (id) {
  117. let _this = this;
  118. _this.socket.emit('playlists.addSongToPlaylist', id, _this.playlist._id, res => {
  119. Toast.methods.addToast(res.message, 4000);
  120. });
  121. },
  122. importPlaylist: function () {
  123. let _this = this;
  124. Toast.methods.addToast('Starting to import your playlist. This can take some time to do.', 4000);
  125. this.socket.emit('playlists.addSetToPlaylist', _this.importQuery, _this.playlist._id, res => {
  126. if (res.status === 'success') _this.playlist.songs = res.data;
  127. Toast.methods.addToast(res.message, 4000);
  128. });
  129. },
  130. removeSongFromPlaylist: function (id) {
  131. let _this = this;
  132. this.socket.emit('playlists.removeSongFromPlaylist', id, _this.playlist._id, res => {
  133. Toast.methods.addToast(res.message, 4000);
  134. });
  135. },
  136. renamePlaylist: function () {
  137. this.socket.emit('playlists.updateDisplayName', this.playlist._id, this.playlist.displayName, res => {
  138. Toast.methods.addToast(res.message, 4000);
  139. });
  140. },
  141. removePlaylist: function () {
  142. let _this = this;
  143. _this.socket.emit('playlists.remove', _this.playlist._id, res => {
  144. if (res.status === 'success') {
  145. Toast.methods.addToast(res.message, 3000);
  146. _this.$parent.toggleModal('editPlaylist');
  147. }
  148. });
  149. },/*
  150. promoteSong: function (fromIndex) {
  151. let _this = this;
  152. _this.socket.emit('playlists.promoteSong', _this.playlist._id, fromIndex, res => {
  153. if (res.status === 'success') _this.$set('playlist.songs', res.data); // bug: v-for is not updating
  154. });
  155. },
  156. demoteSong: function (fromIndex) {
  157. let _this = this;
  158. _this.socket.emit('playlists.demoteSong', _this.playlist._id, fromIndex, res => {
  159. if (res.status === 'success') _this.$set('playlist.songs', res.data); // bug: v-for is not updating
  160. });
  161. }*/
  162. },
  163. ready: function () {
  164. let _this = this;
  165. io.getSocket((socket) => {
  166. _this.socket = socket;
  167. _this.socket.emit('playlists.getPlaylist', _this.$parent.playlistBeingEdited, res => {
  168. if (res.status == 'success') _this.playlist = res.data; _this.playlist.oldId = res.data._id;
  169. });
  170. _this.socket.on('event:playlist.addSong', (data) => {
  171. if (_this.playlist._id === data.playlistId) _this.playlist.songs.push(data.song);
  172. });
  173. _this.socket.on('event:playlist.removeSong', (data) => {
  174. if (_this.playlist._id === data.playlistId) {
  175. _this.playlist.songs.forEach((song, index) => {
  176. if (song._id === data.songId) _this.playlist.songs.splice(index, 1);
  177. });
  178. }
  179. });
  180. _this.socket.on('event:playlist.updateDisplayName', (data) => {
  181. if (_this.playlist._id === data.playlistId) _this.playlist.displayName = data.displayName;
  182. });
  183. _this.socket.on('event:playlist.moveSongToBottom', (data) => {
  184. if (_this.playlist._id === data.playlistId) {
  185. let songIndex;
  186. _this.playlist.songs.forEach((song, index) => {
  187. if (song._id === data.songId) songIndex = index;
  188. });
  189. let song = _this.playlist.songs.splice(songIndex, 1)[0];
  190. _this.playlist.songs.push(song);
  191. }
  192. });
  193. _this.socket.on('event:playlist.moveSongToTop', (data) => {
  194. if (_this.playlist._id === data.playlistId) {
  195. let songIndex;
  196. _this.playlist.songs.forEach((song, index) => {
  197. if (song._id === data.songId) songIndex = index;
  198. });
  199. let song = _this.playlist.songs.splice(songIndex, 1)[0];
  200. _this.playlist.songs.unshift(song);
  201. }
  202. });
  203. });
  204. },
  205. events: {
  206. closeModal: function() {
  207. this.$parent.toggleModal("editPlaylist");
  208. }
  209. }
  210. }
  211. </script>
  212. <style type='scss' scoped>
  213. .menu { padding: 0 20px; }
  214. .menu-list li {
  215. display: flex;
  216. justify-content: space-between;
  217. }
  218. .menu-list a:hover { color: #000 !important; }
  219. li a {
  220. display: flex;
  221. align-items: center;
  222. }
  223. .controls {
  224. display: flex;
  225. a {
  226. display: flex;
  227. align-items: center;
  228. }
  229. }
  230. .table {
  231. margin-bottom: 0;
  232. }
  233. h5 { padding: 20px 0; }
  234. </style>