Stations.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. <span v-for='song in station.playlist' track-by='$index'>{{ song }}</span>
  34. </p>
  35. </td>
  36. <td>
  37. <a class='button is-danger' @click='removeStation(index)'>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='(index, genre) in newStation.genres' track-by='$index'>
  77. {{ genre }}
  78. <button class='delete is-info' @click='removeGenre(index)'></button>
  79. </span>
  80. </div>
  81. </div>
  82. <footer class='card-footer'>
  83. <a class='card-footer-item' @click='createStation()'>Create</a>
  84. </footer>
  85. </div>
  86. </div>
  87. </div>
  88. </template>
  89. <script>
  90. import { Toast } from 'vue-roaster';
  91. export default {
  92. data() {
  93. return {
  94. stations: [],
  95. newStation: {
  96. genres: []
  97. }
  98. }
  99. },
  100. methods: {
  101. createStation: function () {
  102. let _this = this;
  103. let { newStation: { _id, displayName, description, genres } } = this;
  104. let playlist = [];
  105. playlist.push(this.newStation.defaultSong);
  106. if (_id == undefined) return Toast.methods.addToast('Field (YouTube ID) cannot be empty', 3000);
  107. if (displayName == undefined) return Toast.methods.addToast('Field (Display Name) cannot be empty', 3000);
  108. if (description == undefined) return Toast.methods.addToast('Field (Description) cannot be empty', 3000);
  109. _this.socket.emit('stations.create', {
  110. _id,
  111. type: 'official',
  112. displayName,
  113. description,
  114. playlist,
  115. genres,
  116. }, result => {
  117. console.log(result);
  118. });
  119. },
  120. removeStation: function (index) {
  121. this.socket.emit('stations.remove', this.stations[index]._id, res => {
  122. if (res.status == 'success') this.stations.splice(index, 1); Toast.methods.addToast(res.message, 3000);
  123. });
  124. },
  125. addGenre: function () {
  126. for (let z = 0; z < this.newStation.genres.length; z++) {
  127. if (this.newStation.genres[z] == $('#new-genre').val()) return Toast.methods.addToast('Genre already exists', 3000);
  128. }
  129. if ($('#new-genre').val() !== '') this.newStation.genres.push($('#new-genre').val());
  130. else Toast.methods.addToast('Genre cannot be empty', 3000);
  131. },
  132. removeGenre: function (index) { this.newStation.genres.splice(index, 1); }
  133. },
  134. ready: function () {
  135. let _this = this;
  136. let socketInterval = setInterval(() => {
  137. if (!!_this.$parent.$parent.socket) {
  138. _this.socket = _this.$parent.$parent.socket;
  139. _this.socket.emit('stations.index', data => {
  140. _this.stations = data.stations;
  141. });
  142. clearInterval(socketInterval);
  143. }
  144. }, 100);
  145. }
  146. }
  147. </script>
  148. <style lang='scss' scoped>
  149. .is-success {
  150. width: 100%;
  151. }
  152. .tag:not(:last-child) { margin-right: 5px; }
  153. </style>