Stations.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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)'>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'>
  61. <a class='button is-info' @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'>
  70. <a class='button is-info' @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()'>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. console.log(result);
  114. });
  115. },
  116. removeStation: function (index) {
  117. this.socket.emit('stations.remove', this.stations[index]._id, res => {
  118. Toast.methods.addToast(res.message, 3000);
  119. });
  120. },
  121. addGenre: function () {
  122. let genre = $('#new-genre').val().toLowerCase().trim();
  123. if (this.newStation.genres.indexOf(genre) !== -1) return Toast.methods.addToast('Genre already exists', 3000);
  124. if (genre) this.newStation.genres.push(genre);
  125. else Toast.methods.addToast('Genre cannot be empty', 3000);
  126. },
  127. removeGenre: function (index) { this.newStation.genres.splice(index, 1); },
  128. addBlacklistedGenre: function () {
  129. let genre = $('#new-blacklisted-genre').val().toLowerCase().trim();
  130. if (this.newStation.blacklistedGenres.indexOf(genre) !== -1) return Toast.methods.addToast('Genre already exists', 3000);
  131. if (genre) this.newStation.blacklistedGenres.push(genre);
  132. else Toast.methods.addToast('Genre cannot be empty', 3000);
  133. },
  134. removeBlacklistedGenre: function (index) { this.newStation.blacklistedGenres.splice(index, 1); },
  135. init: function() {
  136. let _this = this;
  137. _this.socket.emit('stations.index', data => {
  138. _this.stations = data.stations;
  139. });
  140. _this.socket.emit('apis.joinAdminRoom', 'stations', data => {});
  141. }
  142. },
  143. ready: function () {
  144. let _this = this;
  145. io.getSocket((socket) => {
  146. _this.socket = socket;
  147. if (_this.socket.connected) {
  148. _this.init();
  149. }
  150. _this.socket.on('event:admin.station.added', station => {
  151. _this.stations.push(station);
  152. });
  153. _this.socket.on('event:admin.station.removed', stationId => {
  154. _this.stations = _this.stations.filter(function(station) {
  155. return station._id !== stationId;
  156. });
  157. });
  158. io.onConnect(() => {
  159. _this.init();
  160. });
  161. });
  162. }
  163. }
  164. </script>
  165. <style lang='scss' scoped>
  166. .tag:not(:last-child) { margin-right: 5px; }
  167. td {
  168. word-wrap: break-word;
  169. max-width: 10vw;
  170. vertical-align: middle;
  171. }
  172. </style>