Stations.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div class="columns is-mobile">
  3. <div class="column is-8-desktop is-offset-2-desktop is-12-mobile">
  4. <table class="table is-striped">
  5. <thead>
  6. <tr>
  7. <td>ID</td>
  8. <td>Display Name</td>
  9. <td>Description</td>
  10. <td>Playlist</td>
  11. <td>Options</td>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. <tr v-for="(index, station) in stations" track-by="$index">
  16. <td>
  17. <p class="control">
  18. <input class="input" type="text" :value="station.id" v-model="station._id">
  19. </p>
  20. </td>
  21. <td>
  22. <p class="control">
  23. <input class="input" type="text" :value="station.displayName" v-model="station.displayName">
  24. </p>
  25. </td>
  26. <td>
  27. <p class="control">
  28. <input class="input" type="text" :value="station.description" v-model="station.description">
  29. </p>
  30. </td>
  31. <td>
  32. <div class="control">
  33. <input v-for="song in station.playlist" track-by="$index" class="input" type="text" :value="song.id" v-model="song.id">
  34. </p>
  35. </td>
  36. <td>
  37. <a class="button is-danger" @click="stations.splice(index, 1)">Remove</a>
  38. </td>
  39. </tr>
  40. </tbody>
  41. </table>
  42. <a class="button is-success" @click="update()">Save Changes</a>
  43. </div>
  44. </div>
  45. <div class="columns is-mobile">
  46. <div class="column is-8-desktop is-offset-2-desktop is-12-mobile">
  47. <div class="card is-fullwidth">
  48. <header class="card-header">
  49. <p class="card-header-title">Create official station</p>
  50. </header>
  51. <div class="card-content">
  52. <div class="content">
  53. <div class="control is-horizontal">
  54. <div class="control is-grouped">
  55. <p class="control is-expanded">
  56. <input class="input" type="text" placeholder="Unique Identifier" v-model="newStation._id">
  57. </p>
  58. <p class="control is-expanded">
  59. <input class="input" type="text" placeholder="Display Name" v-model="newStation.displayName">
  60. </p>
  61. </div>
  62. </div>
  63. <label class="label">Description</label>
  64. <p class="control is-expanded">
  65. <input class="input" type="text" placeholder="Short description" v-model="newStation.description">
  66. </p>
  67. <label class="label">Default Song</label>
  68. <p class="control is-expanded">
  69. <input class="input" type="text" placeholder="YouTube ID" v-model="newStation.defaultSong">
  70. </p>
  71. <label class="label">Genres</label>
  72. <p class="control has-addons">
  73. <input class="input" id="new-genre" type="text" placeholder="Genre">
  74. <a class="button is-info" @click="addGenre()">Add genre</a>
  75. </p>
  76. <span class="tag is-info" v-for="genre in newStation.genres" track-by="$index">{{ genre }}<button class="delete is-info"></button></span>
  77. </div>
  78. </div>
  79. <footer class="card-footer">
  80. <a class="card-footer-item" @click="createStation()">Create</a>
  81. </footer>
  82. </div>
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import { Toast } from 'vue-roaster';
  88. export default {
  89. data() {
  90. return {
  91. stations: [],
  92. newStation: {
  93. genres: []
  94. }
  95. }
  96. },
  97. methods: {
  98. // saveQueueSongChanges: function() {
  99. // let local = this;
  100. // let songId = local.reviewSongId;
  101. // let songObject = {};
  102. // songObject._id = $("#reviewId").val();
  103. // songObject.title = $("#reviewTitle").val();
  104. // songObject.artists = $("#reviewArtists").val();
  105. // songObject.genres = $("#reviewGenres").val();
  106. // songObject.duration = $("#reviewDuration").val();
  107. // songObject.skipDuration = $("#reviewSkipDuration").val();
  108. // songObject.image = $("#reviewImage").val();
  109. // if (typeof songObject.artists === "string") {
  110. // songObject.artists = songObject.artists.split(", ");
  111. // }
  112. // if (typeof songObject.genres === "string") {
  113. // songObject.genres = songObject.genres.split(", ");
  114. // }
  115. // local.socket.emit("/songs/queue/updateSong/:id", songId, songObject, function(data) {
  116. // console.log(data);
  117. // });
  118. // },
  119. createStation: function () {
  120. let _this = this;
  121. let { newStation: { _id, displayName, description, genres } } = this;
  122. let playlist = [];
  123. playlist.push(this.newStation.defaultSong);
  124. if (_id == undefined) return Toast.methods.addToast('Field (YouTube ID) cannot be empty', 2000);
  125. if (displayName == undefined) return Toast.methods.addToast('Field (Display Name) cannot be empty', 2000);
  126. if (description == undefined) return Toast.methods.addToast('Field (Description) cannot be empty', 2000);
  127. _this.socket.emit('stations.create', {
  128. _id,
  129. type: "official",
  130. displayName,
  131. description,
  132. playlist,
  133. genres,
  134. }, result => {
  135. console.log(result);
  136. });
  137. },
  138. addGenre: function () {
  139. if ($("#new-genre").val() !== "") this.newStation.genres.push($("#new-genre").val());
  140. else Toast.methods.addToast('Genre cannot be empty', 2000);
  141. }
  142. },
  143. ready: function () {
  144. let _this = this;
  145. let socketInterval = setInterval(() => {
  146. if (!!_this.$parent.$parent.socket) {
  147. _this.socket = _this.$parent.$parent.socket;
  148. _this.socket.emit("stations.index", data => {
  149. _this.stations = data.stations;
  150. });
  151. clearInterval(socketInterval);
  152. }
  153. }, 100);
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. .is-success {
  159. width: 100%;
  160. }
  161. .tag:not(:last-child) { margin-right: 5px; }
  162. </style>