Stations.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. </div>
  68. </div>
  69. <footer class='card-footer'>
  70. <a class='card-footer-item' @click='createStation()'>Create</a>
  71. </footer>
  72. </div>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import { Toast } from 'vue-roaster';
  78. export default {
  79. data() {
  80. return {
  81. stations: [],
  82. newStation: {
  83. genres: []
  84. }
  85. }
  86. },
  87. methods: {
  88. createStation: function () {
  89. let _this = this;
  90. let { newStation: { _id, displayName, description, genres } } = this;
  91. if (_id == undefined) return Toast.methods.addToast('Field (YouTube ID) cannot be empty', 3000);
  92. if (displayName == undefined) return Toast.methods.addToast('Field (Display Name) cannot be empty', 3000);
  93. if (description == undefined) return Toast.methods.addToast('Field (Description) cannot be empty', 3000);
  94. _this.socket.emit('stations.create', {
  95. _id,
  96. type: 'official',
  97. displayName,
  98. description,
  99. genres,
  100. }, result => {
  101. console.log(result);
  102. });
  103. },
  104. removeStation: function (index) {
  105. this.socket.emit('stations.remove', this.stations[index]._id, res => {
  106. if (res.status == 'success') this.stations.splice(index, 1); Toast.methods.addToast(res.message, 3000);
  107. });
  108. },
  109. addGenre: function () {
  110. for (let z = 0; z < this.newStation.genres.length; z++) {
  111. if (this.newStation.genres[z] == $('#new-genre').val()) return Toast.methods.addToast('Genre already exists', 3000);
  112. }
  113. if ($('#new-genre').val() !== '') this.newStation.genres.push($('#new-genre').val());
  114. else Toast.methods.addToast('Genre cannot be empty', 3000);
  115. },
  116. removeGenre: function (index) { this.newStation.genres.splice(index, 1); }
  117. },
  118. ready: function () {
  119. let _this = this;
  120. let socketInterval = setInterval(() => {
  121. if (!!_this.$parent.$parent.socket) {
  122. _this.socket = _this.$parent.$parent.socket;
  123. _this.socket.emit('stations.index', data => {
  124. _this.stations = data.stations;
  125. });
  126. clearInterval(socketInterval);
  127. }
  128. }, 100);
  129. }
  130. }
  131. </script>
  132. <style lang='scss' scoped>
  133. .tag:not(:last-child) { margin-right: 5px; }
  134. td {
  135. word-wrap: break-word;
  136. max-width: 10vw;
  137. }
  138. </style>