Stations.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. <div class="control is-grouped genre-wrapper">
  57. <div class="sector">
  58. <p class='control has-addons'>
  59. <input class='input' id='new-genre' type='text' placeholder='Genre' v-on:keyup.enter='addGenre()'>
  60. <a class='button is-info' href='#' @click='addGenre()'>Add genre</a>
  61. </p>
  62. <span class='tag is-info' v-for='(index, genre) in newStation.genres' track-by='$index'>
  63. {{ genre }}
  64. <button class='delete is-info' @click='removeGenre(index)'></button>
  65. </span>
  66. </div>
  67. <div class="sector">
  68. <p class='control has-addons'>
  69. <input class='input' id='new-blacklisted-genre' type='text' placeholder='Blacklisted Genre' v-on:keyup.enter='addBlacklistedGenre()'>
  70. <a class='button is-info' href='#' @click='addBlacklistedGenre()'>Add blacklisted genre</a>
  71. </p>
  72. <span class='tag is-info' v-for='(index, genre) in newStation.blacklistedGenres' track-by='$index'>
  73. {{ genre }}
  74. <button class='delete is-info' @click='removeBlacklistedGenre(index)'></button>
  75. </span>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. <footer class='card-footer'>
  81. <a class='card-footer-item' @click='createStation()' href='#'>Create</a>
  82. </footer>
  83. </div>
  84. </div>
  85. <edit-station v-show='modals.editStation'></edit-station>
  86. </template>
  87. <script>
  88. import { Toast } from 'vue-roaster';
  89. import io from '../../io';
  90. import EditStation from '../Modals/EditStation.vue';
  91. export default {
  92. components: { EditStation },
  93. data() {
  94. return {
  95. stations: [],
  96. newStation: {
  97. genres: [],
  98. blacklistedGenres: []
  99. },
  100. modals: { editStation: false }
  101. }
  102. },
  103. methods: {
  104. toggleModal: function () {
  105. this.modals.editStation = !this.modals.editStation;
  106. },
  107. createStation: function () {
  108. let _this = this;
  109. let { newStation: { _id, displayName, description, genres, blacklistedGenres } } = this;
  110. if (_id == undefined) return Toast.methods.addToast('Field (YouTube ID) cannot be empty', 3000);
  111. if (displayName == undefined) return Toast.methods.addToast('Field (Display Name) cannot be empty', 3000);
  112. if (description == undefined) return Toast.methods.addToast('Field (Description) cannot be empty', 3000);
  113. _this.socket.emit('stations.create', {
  114. _id,
  115. type: 'official',
  116. displayName,
  117. description,
  118. genres,
  119. blacklistedGenres,
  120. }, result => {
  121. Toast.methods.addToast(result.message, 3000);
  122. if (result.status == 'success') this.newStation = {
  123. genres: [],
  124. blacklistedGenres: []
  125. }
  126. });
  127. },
  128. removeStation: function (index) {
  129. this.socket.emit('stations.remove', this.stations[index]._id, res => {
  130. Toast.methods.addToast(res.message, 3000);
  131. });
  132. },
  133. editStation: function (station) {
  134. this.$broadcast('editStation', {
  135. _id: station._id,
  136. type: station.type,
  137. partyMode: station.partyMode,
  138. description: station.description,
  139. privacy: station.privacy,
  140. displayName: station.displayName
  141. });
  142. },
  143. addGenre: function () {
  144. let genre = $('#new-genre').val().toLowerCase().trim();
  145. if (this.newStation.genres.indexOf(genre) !== -1) return Toast.methods.addToast('Genre already exists', 3000);
  146. if (genre) {
  147. this.newStation.genres.push(genre);
  148. $('#new-genre').val('');
  149. }
  150. else Toast.methods.addToast('Genre cannot be empty', 3000);
  151. },
  152. removeGenre: function (index) { this.newStation.genres.splice(index, 1); },
  153. addBlacklistedGenre: function () {
  154. let genre = $('#new-blacklisted-genre').val().toLowerCase().trim();
  155. if (this.newStation.blacklistedGenres.indexOf(genre) !== -1) return Toast.methods.addToast('Genre already exists', 3000);
  156. if (genre) {
  157. this.newStation.blacklistedGenres.push(genre);
  158. $('#new-blacklisted-genre').val('');
  159. }
  160. else Toast.methods.addToast('Genre cannot be empty', 3000);
  161. },
  162. removeBlacklistedGenre: function (index) { this.newStation.blacklistedGenres.splice(index, 1); },
  163. init: function () {
  164. let _this = this;
  165. _this.socket.emit('stations.index', data => {
  166. _this.stations = data.stations;
  167. });
  168. _this.socket.emit('apis.joinAdminRoom', 'stations', data => {});
  169. }
  170. },
  171. ready: function () {
  172. let _this = this;
  173. io.getSocket((socket) => {
  174. _this.socket = socket;
  175. if (_this.socket.connected) _this.init();
  176. _this.socket.on('event:admin.station.added', station => {
  177. _this.stations.push(station);
  178. });
  179. _this.socket.on('event:admin.station.removed', stationId => {
  180. _this.stations = _this.stations.filter(station => {
  181. return station._id !== stationId;
  182. });
  183. });
  184. io.onConnect(() => {
  185. _this.init();
  186. });
  187. });
  188. }
  189. }
  190. </script>
  191. <style lang='scss' scoped>
  192. .tag {
  193. margin-top: 5px;
  194. &:not(:last-child) {
  195. margin-right: 5px;
  196. }
  197. }
  198. td {
  199. word-wrap: break-word;
  200. max-width: 10vw;
  201. vertical-align: middle;
  202. }
  203. .is-info:focus { background-color: #0398db; }
  204. .genre-wrapper {
  205. display: flex;
  206. justify-content: space-around;
  207. }
  208. </style>