123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <template>
- <modal title='Add Song To Queue'>
- <div slot='body'>
- <aside class='menu' v-if='$parent.$parent.loggedIn && $parent.type === "community"'>
- <ul class='menu-list'>
- <li v-for='playlist in playlists' track-by='$index'>
- <a href='#' target='_blank' @click='$parent.editPlaylist(playlist._id)'>{{ playlist.displayName }}</a>
- <div class='controls'>
- <a href='#' @click='selectPlaylist(playlist._id)' v-if="!isPlaylistSelected(playlist._id)"><i class='material-icons'>panorama_fish_eye</i></a>
- <a href='#' @click='unSelectPlaylist()' v-if="isPlaylistSelected(playlist._id)"><i class='material-icons'>lens</i></a>
- </div>
- </li>
- </ul>
- <br />
- </aside>
- <div class="control is-grouped">
- <p class="control is-expanded">
- <input class="input" type="text" placeholder="YouTube Query" v-model='querySearch' autofocus @keyup.enter='submitQuery()'>
- </p>
- <p class="control">
- <a class="button is-info" @click="submitQuery()" href='#'>
- Search
- </a>
- </p>
- </div>
- <table class="table">
- <tbody>
- <tr v-for="result in queryResults">
- <td>
- <img :src="result.thumbnail" />
- </td>
- <td>{{ result.title }}</td>
- <td>
- <a class="button is-success" @click="addSongToQueue(result.id)" href='#'>
- Add
- </a>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </modal>
- </template>
- <script>
- import { Toast } from 'vue-roaster';
- import Modal from './Modal.vue';
- import io from '../../io';
- import auth from '../../auth';
- export default {
- data() {
- return {
- querySearch: '',
- queryResults: [],
- playlists: [],
- privatePlaylistQueueSelected: null
- }
- },
- methods: {
- isPlaylistSelected: function(playlistId) {
- return this.privatePlaylistQueueSelected === playlistId;
- },
- selectPlaylist: function (playlistId) {
- let _this = this;
- if (_this.$parent.type === 'community') {
- _this.privatePlaylistQueueSelected = playlistId;
- _this.$parent.privatePlaylistQueueSelected = playlistId;
- _this.$parent.addFirstPrivatePlaylistSongToQueue();
- }
- },
- unSelectPlaylist: function () {
- let _this = this;
- if (_this.$parent.type === 'community') {
- _this.privatePlaylistQueueSelected = null;
- _this.$parent.privatePlaylistQueueSelected = null;
- }
- },
- addSongToQueue: function (songId) {
- let _this = this;
- if (_this.$parent.type === 'community') {
- _this.socket.emit('stations.addToQueue', _this.$parent.stationId, songId, data => {
- if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
- else Toast.methods.addToast(`${data.message}`, 4000);
- });
- } else {
- _this.socket.emit('queueSongs.add', songId, data => {
- if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
- else Toast.methods.addToast(`${data.message}`, 4000);
- });
- }
- },
- submitQuery: function () {
- let _this = this;
- let query = _this.querySearch;
- if (query.indexOf('&index=') !== -1) {
- query = query.split('&index=');
- query.pop();
- query = query.join('');
- }
- if (query.indexOf('&list=') !== -1) {
- query = query.split('&list=');
- query.pop();
- query = query.join('');
- }
- _this.socket.emit('apis.searchYoutube', query, results => {
- results = results.data;
- _this.queryResults = [];
- for (let i = 0; i < results.items.length; i++) {
- _this.queryResults.push({
- id: results.items[i].id.videoId,
- url: `https://www.youtube.com/watch?v=${this.id}`,
- title: results.items[i].snippet.title,
- thumbnail: results.items[i].snippet.thumbnails.default.url
- });
- }
- });
- }
- },
- ready: function () {
- let _this = this;
- io.getSocket((socket) => {
- _this.socket = socket;
- _this.socket.emit('playlists.indexForUser', res => {
- if (res.status === 'success') _this.playlists = res.data;
- });
- _this.privatePlaylistQueueSelected = _this.$parent.privatePlaylistQueueSelected;
- });
- },
- events: {
- closeModal: function () {
- this.$parent.modals.addSongToQueue = !this.$parent.modals.addSongToQueue;
- }
- },
- components: { Modal }
- }
- </script>
- <style type='scss' scoped>
- tr td {
- vertical-align: middle;
- img { width: 55px; }
- }
- </style>
|