Stations.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.description }}</span>
  23. </td>
  24. <td>
  25. <span>{{ station.description }}</span>
  26. </td>
  27. <td>
  28. <a class='button is-danger' @click='removeStation(index)' href='#'>Remove</a>
  29. </td>
  30. </tr>
  31. </tbody>
  32. </table>
  33. </div>
  34. <div class='container'>
  35. <div class='card is-fullwidth'>
  36. <header class='card-header'>
  37. <p class='card-header-title'>Create official station</p>
  38. </header>
  39. <div class='card-content'>
  40. <div class='content'>
  41. <div class='control is-horizontal'>
  42. <div class='control is-grouped'>
  43. <p class='control is-expanded'>
  44. <input class='input' type='text' placeholder='Unique Identifier' v-model='newStation._id'>
  45. </p>
  46. <p class='control is-expanded'>
  47. <input class='input' type='text' placeholder='Display Name' v-model='newStation.displayName'>
  48. </p>
  49. </div>
  50. </div>
  51. <label class='label'>Description</label>
  52. <p class='control is-expanded'>
  53. <input class='input' type='text' placeholder='Short description' v-model='newStation.description'>
  54. </p>
  55. <label class='label'>Genres</label>
  56. <p class='control has-addons'>
  57. <input class='input' id='new-genre' type='text' placeholder='Genre' v-on:keyup.enter='addGenre()'>
  58. <a class='button is-info' href='#' @click='addGenre()'>Add genre</a>
  59. </p>
  60. <span class='tag is-info' v-for='(index, genre) in newStation.genres' track-by='$index'>
  61. {{ genre }}
  62. <button class='delete is-info' @click='removeGenre(index)'></button>
  63. </span>
  64. <label class='label'>Blacklisted Genres</label>
  65. <p class='control has-addons'>
  66. <input class='input' id='new-blacklisted-genre' type='text' placeholder='Blacklisted Genre' v-on:keyup.enter='addBlacklistedGenre()'>
  67. <a class='button is-info' href='#' @click='addBlacklistedGenre()'>Add blacklisted genre</a>
  68. </p>
  69. <span class='tag is-info' v-for='(index, genre) in newStation.blacklistedGenres' track-by='$index'>
  70. {{ genre }}
  71. <button class='delete is-info' @click='removeBlacklistedGenre(index)'></button>
  72. </span>
  73. </div>
  74. </div>
  75. <footer class='card-footer'>
  76. <a class='card-footer-item' @click='createStation()' href='#'>Create</a>
  77. </footer>
  78. </div>
  79. </div>
  80. </template>
  81. <script>
  82. import { Toast } from 'vue-roaster';
  83. import io from '../../io';
  84. export default {
  85. data() {
  86. return {
  87. stations: [],
  88. newStation: {
  89. genres: [],
  90. blacklistedGenres: []
  91. }
  92. }
  93. },
  94. methods: {
  95. createStation: function () {
  96. let _this = this;
  97. let { newStation: { _id, displayName, description, genres, blacklistedGenres } } = this;
  98. if (_id == undefined) return Toast.methods.addToast('Field (YouTube ID) cannot be empty', 3000);
  99. if (displayName == undefined) return Toast.methods.addToast('Field (Display Name) cannot be empty', 3000);
  100. if (description == undefined) return Toast.methods.addToast('Field (Description) cannot be empty', 3000);
  101. _this.socket.emit('stations.create', {
  102. _id,
  103. type: 'official',
  104. displayName,
  105. description,
  106. genres,
  107. blacklistedGenres,
  108. }, result => {
  109. Toast.methods.addToast(result.message, 3000);
  110. if (result.status == 'success') this.newStation = {
  111. genres: [],
  112. blacklistedGenres: []
  113. }
  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) _this.init();
  148. _this.socket.on('event:admin.station.added', station => {
  149. _this.stations.push(station);
  150. });
  151. _this.socket.on('event:admin.station.removed', stationId => {
  152. _this.stations = _this.stations.filter(station => {
  153. return station._id !== stationId;
  154. });
  155. });
  156. io.onConnect(() => {
  157. _this.init();
  158. });
  159. });
  160. }
  161. }
  162. </script>
  163. <style lang='scss' scoped>
  164. .tag:not(:last-child) { margin-right: 5px; }
  165. td {
  166. word-wrap: break-word;
  167. max-width: 10vw;
  168. vertical-align: middle;
  169. }
  170. .is-info:focus { background-color: #0398db; }
  171. </style>