Stations.vue 5.9 KB

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