Stations.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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 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 Toast from "toasters";
  194. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  195. import Confirm from "@/components/Confirm.vue";
  196. import ws from "@/ws";
  197. export default {
  198. components: {
  199. RequestSong: () => import("@/components/modals/RequestSong.vue"),
  200. EditPlaylist: () => import("@/components/modals/EditPlaylist.vue"),
  201. CreatePlaylist: () => import("@/components/modals/CreatePlaylist.vue"),
  202. ManageStation: () =>
  203. import("@/components/modals/ManageStation/index.vue"),
  204. Report: () => import("@/components/modals/Report.vue"),
  205. EditSong: () => import("@/components/modals/EditSong.vue"),
  206. UserIdToUsername,
  207. Confirm
  208. },
  209. data() {
  210. return {
  211. editingStationId: "",
  212. newStation: {
  213. genres: [],
  214. blacklistedGenres: []
  215. }
  216. };
  217. },
  218. computed: {
  219. ...mapState("admin/stations", {
  220. stations: state => state.stations
  221. }),
  222. ...mapState("modalVisibility", {
  223. modals: state => state.modals
  224. }),
  225. ...mapGetters({
  226. socket: "websockets/getSocket"
  227. })
  228. },
  229. mounted() {
  230. if (this.socket.readyState === 1) this.init();
  231. ws.onConnect(() => this.init());
  232. this.socket.on("event:admin.station.created", res =>
  233. this.stationAdded(res.data.station)
  234. );
  235. this.socket.on("event:admin.station.deleted", res =>
  236. this.stationRemoved(res.data.stationId)
  237. );
  238. },
  239. methods: {
  240. createStation() {
  241. const {
  242. newStation: {
  243. name,
  244. displayName,
  245. description,
  246. genres,
  247. blacklistedGenres
  248. }
  249. } = this;
  250. if (name === undefined)
  251. return new Toast("Field (Name) cannot be empty");
  252. if (displayName === undefined)
  253. return new Toast("Field (Display Name) cannot be empty");
  254. if (description === undefined)
  255. return new Toast("Field (Description) cannot be empty");
  256. return this.socket.dispatch(
  257. "stations.create",
  258. {
  259. name,
  260. type: "official",
  261. displayName,
  262. description,
  263. genres,
  264. blacklistedGenres
  265. },
  266. res => {
  267. new Toast(res.message);
  268. if (res.status === "success")
  269. this.newStation = {
  270. genres: [],
  271. blacklistedGenres: []
  272. };
  273. }
  274. );
  275. },
  276. removeStation(index) {
  277. this.socket.dispatch(
  278. "stations.remove",
  279. this.stations[index]._id,
  280. res => {
  281. new Toast(res.message);
  282. }
  283. );
  284. },
  285. manage(station) {
  286. this.editingStationId = station._id;
  287. this.openModal("manageStation");
  288. },
  289. addGenre() {
  290. const genre = this.$refs["new-genre"].value.toLowerCase().trim();
  291. if (this.newStation.genres.indexOf(genre) !== -1)
  292. return new Toast("Genre already exists");
  293. if (genre) {
  294. this.newStation.genres.push(genre);
  295. this.$refs["new-genre"].value = "";
  296. return true;
  297. }
  298. return new Toast("Genre cannot be empty");
  299. },
  300. removeGenre(index) {
  301. this.newStation.genres.splice(index, 1);
  302. },
  303. addBlacklistedGenre() {
  304. const genre = this.$refs["new-blacklisted-genre"].value
  305. .toLowerCase()
  306. .trim();
  307. if (this.newStation.blacklistedGenres.indexOf(genre) !== -1)
  308. return new Toast("Genre already exists");
  309. if (genre) {
  310. this.newStation.blacklistedGenres.push(genre);
  311. this.$refs["new-blacklisted-genre"].value = "";
  312. return true;
  313. }
  314. return new Toast("Genre cannot be empty");
  315. },
  316. removeBlacklistedGenre(index) {
  317. this.newStation.blacklistedGenres.splice(index, 1);
  318. },
  319. clearEveryStationQueue() {
  320. this.socket.dispatch("stations.clearEveryStationQueue", res => {
  321. if (res.status === "success") new Toast(res.message);
  322. else new Toast(`Error: ${res.message}`);
  323. });
  324. },
  325. init() {
  326. this.socket.dispatch("stations.index", res => {
  327. if (res.status === "success")
  328. this.loadStations(res.data.stations);
  329. });
  330. this.socket.dispatch("apis.joinAdminRoom", "stations", () => {});
  331. },
  332. ...mapActions("modalVisibility", ["openModal"]),
  333. ...mapActions("admin/stations", [
  334. "manageStation",
  335. "loadStations",
  336. "stationRemoved",
  337. "stationAdded"
  338. ])
  339. }
  340. };
  341. </script>
  342. <style lang="scss" scoped>
  343. .night-mode {
  344. .table {
  345. color: var(--light-grey-2);
  346. background-color: var(--dark-grey-3);
  347. thead tr {
  348. background: var(--dark-grey-3);
  349. td {
  350. color: var(--white);
  351. }
  352. }
  353. tbody tr:hover {
  354. background-color: var(--dark-grey-4) !important;
  355. }
  356. tbody tr:nth-child(even) {
  357. background-color: var(--dark-grey-2);
  358. }
  359. strong {
  360. color: var(--light-grey-2);
  361. }
  362. }
  363. .card {
  364. background: var(--dark-grey-3);
  365. .card-header {
  366. box-shadow: 0 1px 2px rgba(10, 10, 10, 0.8);
  367. }
  368. p,
  369. .label {
  370. color: var(--light-grey-2);
  371. }
  372. }
  373. }
  374. .tag {
  375. margin-top: 5px;
  376. &:not(:last-child) {
  377. margin-right: 5px;
  378. }
  379. }
  380. td {
  381. word-wrap: break-word;
  382. max-width: 10vw;
  383. vertical-align: middle;
  384. & > div {
  385. display: inline-flex;
  386. }
  387. }
  388. .is-info:focus {
  389. background-color: var(--primary-color);
  390. }
  391. .genre-wrapper {
  392. display: flex;
  393. justify-content: space-around;
  394. }
  395. .card-footer-item {
  396. color: var(--primary-color);
  397. }
  398. </style>