Stations.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div class='container'>
  3. <table class='table is-striped'>
  4. <thead>
  5. <tr>
  6. <td>ID</td>
  7. <td>Type</td>
  8. <td>Display Name</td>
  9. <td>Description</td>
  10. <td>Options</td>
  11. </tr>
  12. </thead>
  13. <tbody>
  14. <tr v-for='(index, station) in stations' track-by='$index'>
  15. <td>
  16. <span>{{ station._id }}</span>
  17. </td>
  18. <td>
  19. <span>{{ station.type }}</span>
  20. </td>
  21. <td>
  22. <span>{{ station.displayName }}</span>
  23. </td>
  24. <td>
  25. <span>{{ station.description }}</span>
  26. </td>
  27. <td>
  28. <a class='button is-info' @click='editStation(station)'>Edit</a>
  29. <a class='button is-danger' @click='removeStation(index)' href='#'>Remove</a>
  30. </td>
  31. </tr>
  32. </tbody>
  33. </table>
  34. </div>
  35. <div class='container'>
  36. <div class='card is-fullwidth'>
  37. <header class='card-header'>
  38. <p class='card-header-title'>Create official station</p>
  39. </header>
  40. <div class='card-content'>
  41. <div class='content'>
  42. <div class='control is-horizontal'>
  43. <div class='control is-grouped'>
  44. <p class='control is-expanded'>
  45. <input class='input' type='text' placeholder='Unique Identifier' v-model='newStation._id'>
  46. </p>
  47. <p class='control is-expanded'>
  48. <input class='input' type='text' placeholder='Display Name' v-model='newStation.displayName'>
  49. </p>
  50. </div>
  51. </div>
  52. <label class='label'>Description</label>
  53. <p class='control is-expanded'>
  54. <input class='input' type='text' placeholder='Short description' v-model='newStation.description'>
  55. </p>
  56. <label class='label'>Genres</label>
  57. <p class='control has-addons'>
  58. <input class='input' id='new-genre' type='text' placeholder='Genre' v-on:keyup.enter='addGenre()'>
  59. <a class='button is-info' href='#' @click='addGenre()'>Add genre</a>
  60. </p>
  61. <span class='tag is-info' v-for='(index, genre) in newStation.genres' track-by='$index'>
  62. {{ genre }}
  63. <button class='delete is-info' @click='removeGenre(index)'></button>
  64. </span>
  65. <label class='label'>Blacklisted Genres</label>
  66. <p class='control has-addons'>
  67. <input class='input' id='new-blacklisted-genre' type='text' placeholder='Blacklisted Genre' v-on:keyup.enter='addBlacklistedGenre()'>
  68. <a class='button is-info' href='#' @click='addBlacklistedGenre()'>Add blacklisted genre</a>
  69. </p>
  70. <span class='tag is-info' v-for='(index, genre) in newStation.blacklistedGenres' track-by='$index'>
  71. {{ genre }}
  72. <button class='delete is-info' @click='removeBlacklistedGenre(index)'></button>
  73. </span>
  74. </div>
  75. </div>
  76. <footer class='card-footer'>
  77. <a class='card-footer-item' @click='createStation()' href='#'>Create</a>
  78. </footer>
  79. </div>
  80. </div>
  81. <edit-station v-show='modals.editStation'></edit-station>
  82. </template>
  83. <script>
  84. import { Toast } from 'vue-roaster';
  85. import io from '../../io';
  86. import EditStation from '../Modals/EditStation.vue';
  87. export default {
  88. components: { EditStation },
  89. data() {
  90. return {
  91. stations: [],
  92. newStation: {
  93. genres: [],
  94. blacklistedGenres: []
  95. },
  96. modals: { editStation: false }
  97. }
  98. },
  99. methods: {
  100. toggleModal: function () {
  101. this.modals.editStation = !this.modals.editStation;
  102. },
  103. createStation: function () {
  104. let _this = this;
  105. let { newStation: { _id, displayName, description, genres, blacklistedGenres } } = this;
  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. genres,
  115. blacklistedGenres,
  116. }, result => {
  117. Toast.methods.addToast(result.message, 3000);
  118. if (result.status == 'success') this.newStation = {
  119. genres: [],
  120. blacklistedGenres: []
  121. }
  122. });
  123. },
  124. removeStation: function (index) {
  125. this.socket.emit('stations.remove', this.stations[index]._id, res => {
  126. Toast.methods.addToast(res.message, 3000);
  127. });
  128. },
  129. editStation: function (station) {
  130. this.$broadcast('editStation', {
  131. _id: station._id,
  132. type: station.type,
  133. partyMode: station.partyMode,
  134. description: station.description,
  135. privacy: station.privacy,
  136. displayName: station.displayName
  137. });
  138. },
  139. addGenre: function () {
  140. let genre = $('#new-genre').val().toLowerCase().trim();
  141. if (this.newStation.genres.indexOf(genre) !== -1) return Toast.methods.addToast('Genre already exists', 3000);
  142. if (genre) this.newStation.genres.push(genre);
  143. else Toast.methods.addToast('Genre cannot be empty', 3000);
  144. },
  145. removeGenre: function (index) { this.newStation.genres.splice(index, 1); },
  146. addBlacklistedGenre: function () {
  147. let genre = $('#new-blacklisted-genre').val().toLowerCase().trim();
  148. if (this.newStation.blacklistedGenres.indexOf(genre) !== -1) return Toast.methods.addToast('Genre already exists', 3000);
  149. if (genre) this.newStation.blacklistedGenres.push(genre);
  150. else Toast.methods.addToast('Genre cannot be empty', 3000);
  151. },
  152. removeBlacklistedGenre: function (index) { this.newStation.blacklistedGenres.splice(index, 1); },
  153. init: function () {
  154. let _this = this;
  155. _this.socket.emit('stations.index', data => {
  156. _this.stations = data.stations;
  157. });
  158. _this.socket.emit('apis.joinAdminRoom', 'stations', data => {});
  159. }
  160. },
  161. ready: function () {
  162. let _this = this;
  163. io.getSocket((socket) => {
  164. _this.socket = socket;
  165. if (_this.socket.connected) _this.init();
  166. _this.socket.on('event:admin.station.added', station => {
  167. _this.stations.push(station);
  168. });
  169. _this.socket.on('event:admin.station.removed', stationId => {
  170. _this.stations = _this.stations.filter(station => {
  171. return station._id !== stationId;
  172. });
  173. });
  174. io.onConnect(() => {
  175. _this.init();
  176. });
  177. });
  178. }
  179. }
  180. </script>
  181. <style lang='scss' scoped>
  182. .tag:not(:last-child) { margin-right: 5px; }
  183. td {
  184. word-wrap: break-word;
  185. max-width: 10vw;
  186. vertical-align: middle;
  187. }
  188. .is-info:focus { background-color: #0398db; }
  189. </style>