Stations.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <div>
  3. <page-metadata title="Admin | Stations" />
  4. <div class="container">
  5. <button class="button is-primary" @click="clearEveryStationQueue()">
  6. Clear every station queue
  7. </button>
  8. <br />
  9. <br />
  10. <table class="table is-striped">
  11. <thead>
  12. <tr>
  13. <td>ID</td>
  14. <td>Name</td>
  15. <td>Type</td>
  16. <td>Display Name</td>
  17. <td>Description</td>
  18. <td>Owner</td>
  19. <td>Options</td>
  20. </tr>
  21. </thead>
  22. <tbody>
  23. <tr v-for="(station, index) in stations" :key="station._id">
  24. <td>
  25. <span>{{ station._id }}</span>
  26. </td>
  27. <td>
  28. <span>
  29. <router-link
  30. :to="{
  31. name: 'station',
  32. params: { id: station.name }
  33. }"
  34. >
  35. {{ station.name }}
  36. </router-link>
  37. </span>
  38. </td>
  39. <td>
  40. <span>{{ station.type }}</span>
  41. </td>
  42. <td>
  43. <span>{{ station.displayName }}</span>
  44. </td>
  45. <td>
  46. <span>{{ station.description }}</span>
  47. </td>
  48. <td>
  49. <span
  50. v-if="station.type === 'official'"
  51. title="Musare"
  52. >Musare</span
  53. >
  54. <user-id-to-username
  55. v-else
  56. :user-id="station.owner"
  57. :link="true"
  58. />
  59. </td>
  60. <td>
  61. <a class="button is-info" @click="manage(station)"
  62. >Manage</a
  63. >
  64. <confirm @confirm="removeStation(index)">
  65. <a class="button is-danger">Remove</a>
  66. </confirm>
  67. </td>
  68. </tr>
  69. </tbody>
  70. </table>
  71. </div>
  72. <div class="container">
  73. <div class="card is-fullwidth">
  74. <header class="card-header">
  75. <p class="card-header-title">Create official station</p>
  76. </header>
  77. <div class="card-content">
  78. <div class="content">
  79. <div class="control is-horizontal">
  80. <div class="control is-grouped">
  81. <p class="control is-expanded">
  82. <input
  83. v-model="newStation.name"
  84. class="input"
  85. type="text"
  86. placeholder="Name"
  87. />
  88. </p>
  89. <p class="control is-expanded">
  90. <input
  91. v-model="newStation.displayName"
  92. class="input"
  93. type="text"
  94. placeholder="Display Name"
  95. />
  96. </p>
  97. </div>
  98. </div>
  99. <label class="label">Description</label>
  100. <p class="control is-expanded">
  101. <input
  102. v-model="newStation.description"
  103. class="input"
  104. type="text"
  105. placeholder="Short description"
  106. />
  107. </p>
  108. <div class="control is-grouped genre-wrapper">
  109. <div class="sector">
  110. <p class="control has-addons">
  111. <input
  112. ref="new-genre"
  113. class="input"
  114. type="text"
  115. placeholder="Genre"
  116. @keyup.enter="addGenre()"
  117. />
  118. <a
  119. class="button is-info"
  120. href="#"
  121. @click="addGenre()"
  122. >Add genre</a
  123. >
  124. </p>
  125. <span
  126. v-for="(genre, index) in newStation.genres"
  127. :key="genre"
  128. class="tag is-info"
  129. >
  130. {{ genre }}
  131. <button
  132. class="delete is-info"
  133. @click="removeGenre(index)"
  134. />
  135. </span>
  136. </div>
  137. <div class="sector">
  138. <p class="control has-addons">
  139. <input
  140. ref="new-blacklisted-genre"
  141. class="input"
  142. type="text"
  143. placeholder="Blacklisted Genre"
  144. @keyup.enter="addBlacklistedGenre()"
  145. />
  146. <a
  147. class="button is-info"
  148. href="#"
  149. @click="addBlacklistedGenre()"
  150. >Add blacklisted genre</a
  151. >
  152. </p>
  153. <span
  154. v-for="(
  155. genre, index
  156. ) in newStation.blacklistedGenres"
  157. :key="genre"
  158. class="tag is-info"
  159. >
  160. {{ genre }}
  161. <button
  162. class="delete is-info"
  163. @click="removeBlacklistedGenre(index)"
  164. />
  165. </span>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. <footer class="card-footer">
  171. <a
  172. class="card-footer-item"
  173. href="#"
  174. @click="createStation()"
  175. >Create</a
  176. >
  177. </footer>
  178. </div>
  179. </div>
  180. <request-song v-if="modals.requestSong" />
  181. <edit-playlist v-if="modals.editPlaylist" />
  182. <create-playlist v-if="modals.createPlaylist" />
  183. <manage-station
  184. v-if="modals.manageStation"
  185. :station-id="editingStationId"
  186. sector="admin"
  187. />
  188. <report v-if="modals.report" />
  189. <edit-song v-if="modals.editSong" song-type="songs" sector="admin" />
  190. </div>
  191. </template>
  192. <script>
  193. import { mapState, mapActions, mapGetters } from "vuex";
  194. import { defineAsyncComponent } from "vue";
  195. import Toast from "toasters";
  196. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  197. import Confirm from "@/components/Confirm.vue";
  198. import ws from "@/ws";
  199. export default {
  200. components: {
  201. RequestSong: defineAsyncComponent(() =>
  202. import("@/components/modals/RequestSong.vue")
  203. ),
  204. EditPlaylist: defineAsyncComponent(() =>
  205. import("@/components/modals/EditPlaylist")
  206. ),
  207. CreatePlaylist: defineAsyncComponent(() =>
  208. import("@/components/modals/CreatePlaylist.vue")
  209. ),
  210. ManageStation: defineAsyncComponent(() =>
  211. import("@/components/modals/ManageStation/index.vue")
  212. ),
  213. Report: defineAsyncComponent(() =>
  214. import("@/components/modals/Report.vue")
  215. ),
  216. EditSong: defineAsyncComponent(() =>
  217. import("@/components/modals/EditSong")
  218. ),
  219. UserIdToUsername,
  220. Confirm
  221. },
  222. data() {
  223. return {
  224. editingStationId: "",
  225. newStation: {
  226. genres: [],
  227. blacklistedGenres: []
  228. }
  229. };
  230. },
  231. computed: {
  232. ...mapState("admin/stations", {
  233. stations: state => state.stations
  234. }),
  235. ...mapState("modalVisibility", {
  236. modals: state => state.modals
  237. }),
  238. ...mapGetters({
  239. socket: "websockets/getSocket"
  240. })
  241. },
  242. mounted() {
  243. ws.onConnect(this.init);
  244. this.socket.on("event:admin.station.created", res =>
  245. this.stationAdded(res.data.station)
  246. );
  247. this.socket.on("event:admin.station.deleted", res =>
  248. this.stationRemoved(res.data.stationId)
  249. );
  250. },
  251. methods: {
  252. createStation() {
  253. const {
  254. newStation: {
  255. name,
  256. displayName,
  257. description,
  258. genres,
  259. blacklistedGenres
  260. }
  261. } = this;
  262. if (name === undefined)
  263. return new Toast("Field (Name) cannot be empty");
  264. if (displayName === undefined)
  265. return new Toast("Field (Display Name) cannot be empty");
  266. if (description === undefined)
  267. return new Toast("Field (Description) cannot be empty");
  268. return this.socket.dispatch(
  269. "stations.create",
  270. {
  271. name,
  272. type: "official",
  273. displayName,
  274. description,
  275. genres,
  276. blacklistedGenres
  277. },
  278. res => {
  279. new Toast(res.message);
  280. if (res.status === "success")
  281. this.newStation = {
  282. genres: [],
  283. blacklistedGenres: []
  284. };
  285. }
  286. );
  287. },
  288. removeStation(index) {
  289. this.socket.dispatch(
  290. "stations.remove",
  291. this.stations[index]._id,
  292. res => new Toast(res.message)
  293. );
  294. },
  295. manage(station) {
  296. this.editingStationId = station._id;
  297. this.openModal("manageStation");
  298. },
  299. addGenre() {
  300. const genre = this.$refs["new-genre"].value.toLowerCase().trim();
  301. if (this.newStation.genres.indexOf(genre) !== -1)
  302. return new Toast("Genre already exists");
  303. if (genre) {
  304. this.newStation.genres.push(genre);
  305. this.$refs["new-genre"].value = "";
  306. return true;
  307. }
  308. return new Toast("Genre cannot be empty");
  309. },
  310. removeGenre(index) {
  311. this.newStation.genres.splice(index, 1);
  312. },
  313. addBlacklistedGenre() {
  314. const genre = this.$refs["new-blacklisted-genre"].value
  315. .toLowerCase()
  316. .trim();
  317. if (this.newStation.blacklistedGenres.indexOf(genre) !== -1)
  318. return new Toast("Genre already exists");
  319. if (genre) {
  320. this.newStation.blacklistedGenres.push(genre);
  321. this.$refs["new-blacklisted-genre"].value = "";
  322. return true;
  323. }
  324. return new Toast("Genre cannot be empty");
  325. },
  326. removeBlacklistedGenre(index) {
  327. this.newStation.blacklistedGenres.splice(index, 1);
  328. },
  329. clearEveryStationQueue() {
  330. this.socket.dispatch("stations.clearEveryStationQueue", res => {
  331. if (res.status === "success") new Toast(res.message);
  332. else new Toast(`Error: ${res.message}`);
  333. });
  334. },
  335. init() {
  336. this.socket.dispatch("stations.index", res => {
  337. if (res.status === "success")
  338. this.loadStations(res.data.stations);
  339. });
  340. this.socket.dispatch("apis.joinAdminRoom", "stations", () => {});
  341. },
  342. ...mapActions("modalVisibility", ["openModal"]),
  343. ...mapActions("admin/stations", [
  344. "manageStation",
  345. "loadStations",
  346. "stationRemoved",
  347. "stationAdded"
  348. ])
  349. }
  350. };
  351. </script>
  352. <style lang="scss" scoped>
  353. .night-mode {
  354. .table {
  355. color: var(--light-grey-2);
  356. background-color: var(--dark-grey-3);
  357. thead tr {
  358. background: var(--dark-grey-3);
  359. td {
  360. color: var(--white);
  361. }
  362. }
  363. tbody tr:hover {
  364. background-color: var(--dark-grey-4) !important;
  365. }
  366. tbody tr:nth-child(even) {
  367. background-color: var(--dark-grey-2);
  368. }
  369. strong {
  370. color: var(--light-grey-2);
  371. }
  372. }
  373. .card {
  374. background: var(--dark-grey-3);
  375. .card-header {
  376. box-shadow: 0 1px 2px rgba(10, 10, 10, 0.8);
  377. }
  378. p,
  379. .label {
  380. color: var(--light-grey-2);
  381. }
  382. }
  383. }
  384. .tag {
  385. margin-top: 5px;
  386. &:not(:last-child) {
  387. margin-right: 5px;
  388. }
  389. }
  390. td {
  391. word-wrap: break-word;
  392. max-width: 10vw;
  393. vertical-align: middle;
  394. & > div {
  395. display: inline-flex;
  396. }
  397. }
  398. .is-info:focus {
  399. background-color: var(--primary-color);
  400. }
  401. .genre-wrapper {
  402. display: flex;
  403. justify-content: space-around;
  404. }
  405. .card-footer-item {
  406. color: var(--primary-color);
  407. }
  408. </style>