Stations.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <div>
  3. <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="(genre,
  155. index) in newStation.blacklistedGenres"
  156. :key="genre"
  157. class="tag is-info"
  158. >
  159. {{ genre }}
  160. <button
  161. class="delete is-info"
  162. @click="removeBlacklistedGenre(index)"
  163. />
  164. </span>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. <footer class="card-footer">
  170. <a
  171. class="card-footer-item"
  172. href="#"
  173. @click="createStation()"
  174. >Create</a
  175. >
  176. </footer>
  177. </div>
  178. </div>
  179. <request-song v-if="modals.requestSong" />
  180. <edit-playlist v-if="modals.editPlaylist" />
  181. <create-playlist v-if="modals.createPlaylist" />
  182. <manage-station
  183. v-if="modals.manageStation"
  184. :station-id="editingStationId"
  185. sector="admin"
  186. />
  187. <report v-if="modals.report" />
  188. <edit-song v-if="modals.editSong" song-type="songs" sector="admin" />
  189. </div>
  190. </template>
  191. <script>
  192. import { mapState, mapActions, mapGetters } from "vuex";
  193. import { defineAsyncComponent } from "vue";
  194. import Toast from "toasters";
  195. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  196. import Confirm from "@/components/Confirm.vue";
  197. import ws from "@/ws";
  198. export default {
  199. components: {
  200. RequestSong: defineAsyncComponent(() =>
  201. import("@/components/modals/RequestSong.vue")
  202. ),
  203. EditPlaylist: defineAsyncComponent(() =>
  204. import("@/components/modals/EditPlaylist")
  205. ),
  206. CreatePlaylist: defineAsyncComponent(() =>
  207. import("@/components/modals/CreatePlaylist.vue")
  208. ),
  209. ManageStation: defineAsyncComponent(() =>
  210. import("@/components/modals/ManageStation/index.vue")
  211. ),
  212. Report: defineAsyncComponent(() =>
  213. import("@/components/modals/Report.vue")
  214. ),
  215. EditSong: defineAsyncComponent(() =>
  216. import("@/components/modals/EditSong")
  217. ),
  218. UserIdToUsername,
  219. Confirm
  220. },
  221. data() {
  222. return {
  223. editingStationId: "",
  224. manageStationVersion: "",
  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. lofig.get("manageStationVersion", manageStationVersion => {
  244. this.manageStationVersion = manageStationVersion;
  245. });
  246. if (this.socket.readyState === 1) this.init();
  247. ws.onConnect(() => this.init());
  248. this.socket.on("event:admin.station.created", res =>
  249. this.stationAdded(res.data.station)
  250. );
  251. this.socket.on("event:admin.station.deleted", res =>
  252. this.stationRemoved(res.data.stationId)
  253. );
  254. },
  255. methods: {
  256. createStation() {
  257. const {
  258. newStation: {
  259. name,
  260. displayName,
  261. description,
  262. genres,
  263. blacklistedGenres
  264. }
  265. } = this;
  266. if (name === undefined)
  267. return new Toast("Field (Name) cannot be empty");
  268. if (displayName === undefined)
  269. return new Toast("Field (Display Name) cannot be empty");
  270. if (description === undefined)
  271. return new Toast("Field (Description) cannot be empty");
  272. return this.socket.dispatch(
  273. "stations.create",
  274. {
  275. name,
  276. type: "official",
  277. displayName,
  278. description,
  279. genres,
  280. blacklistedGenres
  281. },
  282. res => {
  283. new Toast(res.message);
  284. if (res.status === "success")
  285. this.newStation = {
  286. genres: [],
  287. blacklistedGenres: []
  288. };
  289. }
  290. );
  291. },
  292. removeStation(index) {
  293. this.socket.dispatch(
  294. "stations.remove",
  295. this.stations[index]._id,
  296. res => new Toast(res.message)
  297. );
  298. },
  299. manage(station) {
  300. this.editingStationId = station._id;
  301. this.openModal("manageStation");
  302. },
  303. addGenre() {
  304. const genre = this.$refs["new-genre"].value.toLowerCase().trim();
  305. if (this.newStation.genres.indexOf(genre) !== -1)
  306. return new Toast("Genre already exists");
  307. if (genre) {
  308. this.newStation.genres.push(genre);
  309. this.$refs["new-genre"].value = "";
  310. return true;
  311. }
  312. return new Toast("Genre cannot be empty");
  313. },
  314. removeGenre(index) {
  315. this.newStation.genres.splice(index, 1);
  316. },
  317. addBlacklistedGenre() {
  318. const genre = this.$refs["new-blacklisted-genre"].value
  319. .toLowerCase()
  320. .trim();
  321. if (this.newStation.blacklistedGenres.indexOf(genre) !== -1)
  322. return new Toast("Genre already exists");
  323. if (genre) {
  324. this.newStation.blacklistedGenres.push(genre);
  325. this.$refs["new-blacklisted-genre"].value = "";
  326. return true;
  327. }
  328. return new Toast("Genre cannot be empty");
  329. },
  330. removeBlacklistedGenre(index) {
  331. this.newStation.blacklistedGenres.splice(index, 1);
  332. },
  333. clearEveryStationQueue() {
  334. this.socket.dispatch("stations.clearEveryStationQueue", res => {
  335. if (res.status === "success") new Toast(res.message);
  336. else new Toast(`Error: ${res.message}`);
  337. });
  338. },
  339. init() {
  340. this.socket.dispatch("stations.index", res => {
  341. if (res.status === "success")
  342. this.loadStations(res.data.stations);
  343. });
  344. this.socket.dispatch("apis.joinAdminRoom", "stations", () => {});
  345. },
  346. ...mapActions("modalVisibility", ["openModal"]),
  347. ...mapActions("admin/stations", [
  348. "manageStation",
  349. "loadStations",
  350. "stationRemoved",
  351. "stationAdded"
  352. ])
  353. }
  354. };
  355. </script>
  356. <style lang="scss" scoped>
  357. .night-mode {
  358. .table {
  359. color: var(--light-grey-2);
  360. background-color: var(--dark-grey-3);
  361. thead tr {
  362. background: var(--dark-grey-3);
  363. td {
  364. color: var(--white);
  365. }
  366. }
  367. tbody tr:hover {
  368. background-color: var(--dark-grey-4) !important;
  369. }
  370. tbody tr:nth-child(even) {
  371. background-color: var(--dark-grey-2);
  372. }
  373. strong {
  374. color: var(--light-grey-2);
  375. }
  376. }
  377. .card {
  378. background: var(--dark-grey-3);
  379. .card-header {
  380. box-shadow: 0 1px 2px rgba(10, 10, 10, 0.8);
  381. }
  382. p,
  383. .label {
  384. color: var(--light-grey-2);
  385. }
  386. }
  387. }
  388. .tag {
  389. margin-top: 5px;
  390. &:not(:last-child) {
  391. margin-right: 5px;
  392. }
  393. }
  394. td {
  395. word-wrap: break-word;
  396. max-width: 10vw;
  397. vertical-align: middle;
  398. & > div {
  399. display: inline-flex;
  400. }
  401. }
  402. .is-info:focus {
  403. background-color: var(--primary-color);
  404. }
  405. .genre-wrapper {
  406. display: flex;
  407. justify-content: space-around;
  408. }
  409. .card-footer-item {
  410. color: var(--primary-color);
  411. }
  412. </style>