index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. <template>
  2. <modal
  3. v-if="station"
  4. :title="
  5. sector === 'home' && !isOwnerOrAdmin()
  6. ? 'View Queue'
  7. : !isOwnerOrAdmin()
  8. ? 'Add Song to Queue'
  9. : 'Manage Station'
  10. "
  11. :style="`--primary-color: var(--${station.theme})`"
  12. class="manage-station-modal"
  13. :size="isOwnerOrAdmin() || sector !== 'home' ? 'wide' : null"
  14. :split="isOwnerOrAdmin() || sector !== 'home'"
  15. >
  16. <template #body v-if="station && station._id">
  17. <div class="left-section">
  18. <div class="section">
  19. <div id="about-station-container">
  20. <div id="station-info">
  21. <div id="station-name">
  22. <h1>{{ station.displayName }}</h1>
  23. <i
  24. v-if="station.type === 'official'"
  25. class="material-icons verified-station"
  26. content="Verified Station"
  27. v-tippy
  28. >
  29. check_circle
  30. </i>
  31. </div>
  32. <p>{{ station.description }}</p>
  33. </div>
  34. <div id="admin-buttons">
  35. <!-- (Admin) Pause/Resume Button -->
  36. <button
  37. v-if="isOwnerOrAdmin() && stationPaused"
  38. class="button is-danger"
  39. @click="resumeStation()"
  40. >
  41. <i class="material-icons icon-with-button"
  42. >play_arrow</i
  43. >
  44. <span> Resume Station </span>
  45. </button>
  46. <button
  47. v-if="isOwnerOrAdmin() && !stationPaused"
  48. class="button is-danger"
  49. @click="pauseStation()"
  50. >
  51. <i class="material-icons icon-with-button"
  52. >pause</i
  53. >
  54. <span> Pause Station </span>
  55. </button>
  56. <!-- (Admin) Skip Button -->
  57. <button
  58. v-if="isOwnerOrAdmin()"
  59. class="button is-danger"
  60. @click="skipStation()"
  61. >
  62. <i class="material-icons icon-with-button"
  63. >skip_next</i
  64. >
  65. <span> Force Skip </span>
  66. </button>
  67. <router-link
  68. v-if="sector !== 'station' && station.name"
  69. :to="{
  70. name: 'station',
  71. params: { id: station.name }
  72. }"
  73. class="button is-primary"
  74. >
  75. Go To Station
  76. </router-link>
  77. </div>
  78. </div>
  79. <div v-if="isOwnerOrAdmin() || sector !== 'home'">
  80. <div class="tab-selection">
  81. <button
  82. v-if="isOwnerOrAdmin()"
  83. class="button is-default"
  84. :class="{ selected: tab === 'settings' }"
  85. ref="settings-tab"
  86. @click="showTab('settings')"
  87. >
  88. Settings
  89. </button>
  90. <button
  91. v-if="
  92. isOwnerOrAdmin() && station.autofill.enabled
  93. "
  94. class="button is-default"
  95. :class="{ selected: tab === 'autofill' }"
  96. ref="autofill-tab"
  97. @click="showTab('autofill')"
  98. >
  99. Autofill
  100. </button>
  101. <button
  102. v-if="canRequest()"
  103. class="button is-default"
  104. :class="{ selected: tab === 'request' }"
  105. ref="request-tab"
  106. @click="showTab('request')"
  107. >
  108. Request
  109. </button>
  110. <button
  111. v-if="isOwnerOrAdmin()"
  112. class="button is-default"
  113. :class="{ selected: tab === 'blacklist' }"
  114. ref="blacklist-tab"
  115. @click="showTab('blacklist')"
  116. >
  117. Blacklist
  118. </button>
  119. </div>
  120. <settings
  121. v-if="isOwnerOrAdmin()"
  122. class="tab"
  123. v-show="tab === 'settings'"
  124. />
  125. <playlist-tab-base
  126. v-if="isOwnerOrAdmin() && station.autofill.enabled"
  127. class="tab"
  128. v-show="tab === 'autofill'"
  129. :type="'autofill'"
  130. />
  131. <request
  132. v-if="canRequest()"
  133. class="tab"
  134. v-show="tab === 'request'"
  135. :sector="'manageStation'"
  136. />
  137. <playlist-tab-base
  138. v-if="isOwnerOrAdmin()"
  139. class="tab"
  140. v-show="tab === 'blacklist'"
  141. :type="'blacklist'"
  142. >
  143. <template #info>
  144. <p>
  145. Blacklist a playlist to prevent all songs
  146. within from playing in this station.
  147. </p>
  148. </template>
  149. </playlist-tab-base>
  150. </div>
  151. </div>
  152. </div>
  153. <div class="right-section">
  154. <div class="section">
  155. <div class="queue-title">
  156. <h4 class="section-title">Queue</h4>
  157. </div>
  158. <hr class="section-horizontal-rule" />
  159. <song-item
  160. v-if="currentSong._id"
  161. :song="currentSong"
  162. :requested-by="true"
  163. header="Currently Playing.."
  164. class="currently-playing"
  165. />
  166. <queue sector="manageStation" />
  167. </div>
  168. </div>
  169. </template>
  170. <template #footer>
  171. <div v-if="isOwnerOrAdmin()" class="right">
  172. <quick-confirm @confirm="resetQueue()">
  173. <a class="button is-danger">Reset queue</a>
  174. </quick-confirm>
  175. <quick-confirm @confirm="removeStation()">
  176. <button class="button is-danger">Delete station</button>
  177. </quick-confirm>
  178. </div>
  179. </template>
  180. </modal>
  181. </template>
  182. <script>
  183. import { mapState, mapGetters, mapActions } from "vuex";
  184. import Toast from "toasters";
  185. import QuickConfirm from "@/components/QuickConfirm.vue";
  186. import Queue from "@/components/Queue.vue";
  187. import SongItem from "@/components/SongItem.vue";
  188. import Modal from "../../Modal.vue";
  189. import Settings from "./Settings.vue";
  190. import PlaylistTabBase from "@/components/PlaylistTabBase.vue";
  191. import Request from "@/components/Request.vue";
  192. export default {
  193. components: {
  194. Modal,
  195. QuickConfirm,
  196. Queue,
  197. SongItem,
  198. Settings,
  199. PlaylistTabBase,
  200. Request
  201. },
  202. props: {
  203. stationId: { type: String, default: "" },
  204. sector: { type: String, default: "admin" }
  205. },
  206. computed: {
  207. ...mapState({
  208. loggedIn: state => state.user.auth.loggedIn,
  209. userId: state => state.user.auth.userId,
  210. role: state => state.user.auth.role
  211. }),
  212. ...mapState("modals/manageStation", {
  213. tab: state => state.tab,
  214. station: state => state.station,
  215. originalStation: state => state.originalStation,
  216. songsList: state => state.songsList,
  217. stationPlaylist: state => state.stationPlaylist,
  218. autofill: state => state.autofill,
  219. blacklist: state => state.blacklist,
  220. stationPaused: state => state.stationPaused,
  221. currentSong: state => state.currentSong
  222. }),
  223. ...mapGetters({
  224. socket: "websockets/getSocket"
  225. })
  226. },
  227. watch: {
  228. // eslint-disable-next-line
  229. "station.requests": function (requests) {
  230. if (this.tab === "request" && !this.canRequest()) {
  231. if (this.isOwnerOrAdmin()) this.showTab("settings");
  232. else this.closeModal("manageStation");
  233. }
  234. },
  235. // eslint-disable-next-line
  236. "station.autofill": function (autofill) {
  237. if (this.tab === "autofill" && autofill && !autofill.enabled)
  238. this.showTab("settings");
  239. }
  240. },
  241. mounted() {
  242. this.socket.dispatch(`stations.getStationById`, this.stationId, res => {
  243. if (res.status === "success") {
  244. const { station } = res.data;
  245. this.editStation(station);
  246. if (!this.isOwnerOrAdmin()) this.showTab("request");
  247. const currentSong = res.data.station.currentSong
  248. ? res.data.station.currentSong
  249. : {};
  250. this.updateCurrentSong(currentSong);
  251. this.updateStationPaused(res.data.station.paused);
  252. this.socket.dispatch(
  253. "stations.getStationAutofillPlaylistsById",
  254. this.stationId,
  255. res => {
  256. if (res.status === "success")
  257. this.setAutofillPlaylists(res.data.playlists);
  258. }
  259. );
  260. this.socket.dispatch(
  261. "stations.getStationBlacklistById",
  262. this.stationId,
  263. res => {
  264. if (res.status === "success")
  265. this.setBlacklist(res.data.playlists);
  266. }
  267. );
  268. if (this.isOwnerOrAdmin()) {
  269. this.socket.dispatch(
  270. "playlists.getPlaylistForStation",
  271. this.station._id,
  272. true,
  273. res => {
  274. if (res.status === "success") {
  275. this.updateStationPlaylist(res.data.playlist);
  276. }
  277. }
  278. );
  279. }
  280. this.socket.dispatch(
  281. "stations.getQueue",
  282. this.stationId,
  283. res => {
  284. if (res.status === "success")
  285. this.updateSongsList(res.data.queue);
  286. }
  287. );
  288. this.socket.dispatch(
  289. "apis.joinRoom",
  290. `manage-station.${this.stationId}`
  291. );
  292. this.socket.on(
  293. "event:station.updated",
  294. res => {
  295. this.updateStation(res.data.station);
  296. },
  297. { modal: "manageStation" }
  298. );
  299. this.socket.on(
  300. "event:station.autofillPlaylist",
  301. res => {
  302. const { playlist } = res.data;
  303. const playlistIndex = this.autofill
  304. .map(autofillPlaylist => autofillPlaylist._id)
  305. .indexOf(playlist._id);
  306. if (playlistIndex === -1) this.autofill.push(playlist);
  307. },
  308. { modal: "manageStation" }
  309. );
  310. this.socket.on(
  311. "event:station.blacklistedPlaylist",
  312. res => {
  313. const { playlist } = res.data;
  314. const playlistIndex = this.blacklist
  315. .map(blacklistedPlaylist => blacklistedPlaylist._id)
  316. .indexOf(playlist._id);
  317. if (playlistIndex === -1) this.blacklist.push(playlist);
  318. },
  319. { modal: "manageStation" }
  320. );
  321. this.socket.on(
  322. "event:station.removedAutofillPlaylist",
  323. res => {
  324. const { playlistId } = res.data;
  325. const playlistIndex = this.autofill
  326. .map(playlist => playlist._id)
  327. .indexOf(playlistId);
  328. if (playlistIndex >= 0)
  329. this.autofill.splice(playlistIndex, 1);
  330. },
  331. { modal: "manageStation" }
  332. );
  333. this.socket.on(
  334. "event:station.removedBlacklistedPlaylist",
  335. res => {
  336. const { playlistId } = res.data;
  337. const playlistIndex = this.blacklist
  338. .map(playlist => playlist._id)
  339. .indexOf(playlistId);
  340. if (playlistIndex >= 0)
  341. this.blacklist.splice(playlistIndex, 1);
  342. },
  343. { modal: "manageStation" }
  344. );
  345. this.socket.on(
  346. "event:station.deleted",
  347. () => {
  348. new Toast(`The station you were editing was deleted.`);
  349. this.closeModal("manageStation");
  350. },
  351. { modal: "manageStation" }
  352. );
  353. } else {
  354. new Toast(`Station with that ID not found`);
  355. this.closeModal("manageStation");
  356. }
  357. });
  358. this.socket.on(
  359. "event:manageStation.queue.updated",
  360. res => {
  361. if (res.data.stationId === this.station._id)
  362. this.updateSongsList(res.data.queue);
  363. },
  364. { modal: "manageStation" }
  365. );
  366. this.socket.on(
  367. "event:manageStation.queue.song.repositioned",
  368. res => {
  369. if (res.data.stationId === this.station._id)
  370. this.repositionSongInList(res.data.song);
  371. },
  372. { modal: "manageStation" }
  373. );
  374. this.socket.on(
  375. "event:station.pause",
  376. res => {
  377. if (res.data.stationId === this.station._id)
  378. this.updateStationPaused(true);
  379. },
  380. { modal: "manageStation" }
  381. );
  382. this.socket.on(
  383. "event:station.resume",
  384. res => {
  385. if (res.data.stationId === this.station._id)
  386. this.updateStationPaused(false);
  387. },
  388. { modal: "manageStation" }
  389. );
  390. this.socket.on(
  391. "event:station.nextSong",
  392. res => {
  393. if (res.data.stationId === this.station._id)
  394. this.updateCurrentSong(res.data.currentSong || {});
  395. },
  396. { modal: "manageStation" }
  397. );
  398. if (this.isOwnerOrAdmin()) {
  399. this.socket.on(
  400. "event:playlist.song.added",
  401. res => {
  402. if (this.stationPlaylist._id === res.data.playlistId)
  403. this.stationPlaylist.songs.push(res.data.song);
  404. },
  405. {
  406. modal: "manageStation"
  407. }
  408. );
  409. this.socket.on(
  410. "event:playlist.song.removed",
  411. res => {
  412. if (this.stationPlaylist._id === res.data.playlistId) {
  413. // remove song from array of playlists
  414. this.stationPlaylist.songs.forEach((song, index) => {
  415. if (song.youtubeId === res.data.youtubeId)
  416. this.stationPlaylist.songs.splice(index, 1);
  417. });
  418. }
  419. },
  420. {
  421. modal: "manageStation"
  422. }
  423. );
  424. this.socket.on(
  425. "event:playlist.songs.repositioned",
  426. res => {
  427. if (this.stationPlaylist._id === res.data.playlistId) {
  428. // for each song that has a new position
  429. res.data.songsBeingChanged.forEach(changedSong => {
  430. this.stationPlaylist.songs.forEach(
  431. (song, index) => {
  432. // find song locally
  433. if (
  434. song.youtubeId === changedSong.youtubeId
  435. ) {
  436. // change song position attribute
  437. this.stationPlaylist.songs[
  438. index
  439. ].position = changedSong.position;
  440. // reposition in array if needed
  441. if (index !== changedSong.position - 1)
  442. this.stationPlaylist.songs.splice(
  443. changedSong.position - 1,
  444. 0,
  445. this.stationPlaylist.songs.splice(
  446. index,
  447. 1
  448. )[0]
  449. );
  450. }
  451. }
  452. );
  453. });
  454. }
  455. },
  456. {
  457. modal: "manageStation"
  458. }
  459. );
  460. }
  461. },
  462. beforeUnmount() {
  463. this.socket.dispatch(
  464. "apis.leaveRoom",
  465. `manage-station.${this.stationId}`,
  466. () => {}
  467. );
  468. if (this.isOwnerOrAdmin()) this.showTab("settings");
  469. this.clearStation();
  470. },
  471. methods: {
  472. isOwner() {
  473. return (
  474. this.loggedIn &&
  475. this.station &&
  476. this.userId === this.station.owner
  477. );
  478. },
  479. isAdmin() {
  480. return this.loggedIn && this.role === "admin";
  481. },
  482. isOwnerOrAdmin() {
  483. return this.isOwner() || this.isAdmin();
  484. },
  485. canRequest() {
  486. return (
  487. this.station &&
  488. this.loggedIn &&
  489. this.station.requests &&
  490. this.station.requests.enabled &&
  491. (this.station.requests.access === "user" ||
  492. (this.station.requests.access === "owner" &&
  493. this.isOwnerOrAdmin()))
  494. );
  495. },
  496. removeStation() {
  497. this.socket.dispatch("stations.remove", this.station._id, res => {
  498. new Toast(res.message);
  499. });
  500. },
  501. resumeStation() {
  502. this.socket.dispatch("stations.resume", this.station._id, res => {
  503. if (res.status !== "success")
  504. new Toast(`Error: ${res.message}`);
  505. else new Toast("Successfully resumed the station.");
  506. });
  507. },
  508. pauseStation() {
  509. this.socket.dispatch("stations.pause", this.station._id, res => {
  510. if (res.status !== "success")
  511. new Toast(`Error: ${res.message}`);
  512. else new Toast("Successfully paused the station.");
  513. });
  514. },
  515. skipStation() {
  516. this.socket.dispatch(
  517. "stations.forceSkip",
  518. this.station._id,
  519. res => {
  520. if (res.status !== "success")
  521. new Toast(`Error: ${res.message}`);
  522. else
  523. new Toast(
  524. "Successfully skipped the station's current song."
  525. );
  526. }
  527. );
  528. },
  529. resetQueue() {
  530. this.socket.dispatch(
  531. "stations.resetQueue",
  532. this.station._id,
  533. res => {
  534. if (res.status !== "success")
  535. new Toast({
  536. content: `Error: ${res.message}`,
  537. timeout: 8000
  538. });
  539. else new Toast({ content: res.message, timeout: 4000 });
  540. }
  541. );
  542. },
  543. ...mapActions("modals/manageStation", [
  544. "editStation",
  545. "setAutofillPlaylists",
  546. "setBlacklist",
  547. "clearStation",
  548. "updateSongsList",
  549. "updateStationPlaylist",
  550. "repositionSongInList",
  551. "updateStationPaused",
  552. "updateCurrentSong",
  553. "updateStation"
  554. ]),
  555. ...mapActions({
  556. showTab(dispatch, payload) {
  557. if (this.$refs[`${payload}-tab`])
  558. this.$refs[`${payload}-tab`].scrollIntoView({
  559. block: "nearest"
  560. }); // Only works if the ref exists, which it doesn't always
  561. return dispatch("modals/manageStation/showTab", payload);
  562. }
  563. }),
  564. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  565. ...mapActions("user/playlists", ["editPlaylist"])
  566. }
  567. };
  568. </script>
  569. <style lang="less">
  570. .manage-station-modal.modal .modal-card {
  571. .tab > button {
  572. width: 100%;
  573. margin-bottom: 10px;
  574. }
  575. .currently-playing.song-item {
  576. .thumbnail {
  577. min-width: 130px;
  578. width: 130px;
  579. height: 130px;
  580. }
  581. }
  582. }
  583. </style>
  584. <style lang="less" scoped>
  585. .night-mode {
  586. .manage-station-modal.modal .modal-card-body {
  587. .left-section {
  588. #about-station-container {
  589. background-color: var(--dark-grey-3) !important;
  590. border: 0;
  591. }
  592. .section {
  593. background-color: transparent !important;
  594. }
  595. .tab-selection .button {
  596. background: var(--dark-grey);
  597. color: var(--white);
  598. }
  599. .tab {
  600. background-color: var(--dark-grey-3);
  601. border: 0;
  602. }
  603. }
  604. .right-section .section,
  605. #queue {
  606. border-radius: @border-radius;
  607. background-color: transparent !important;
  608. }
  609. }
  610. }
  611. .manage-station-modal.modal .modal-card-body {
  612. display: flex;
  613. flex-wrap: wrap;
  614. height: 100%;
  615. .left-section {
  616. #about-station-container {
  617. padding: 20px;
  618. display: flex;
  619. flex-direction: column;
  620. flex-grow: unset;
  621. border-radius: @border-radius;
  622. margin: 0 0 20px 0;
  623. background-color: var(--white);
  624. border: 1px solid var(--light-grey-3);
  625. #station-info {
  626. #station-name {
  627. flex-direction: row !important;
  628. display: flex;
  629. flex-direction: row;
  630. max-width: 100%;
  631. h1 {
  632. margin: 0;
  633. font-size: 36px;
  634. line-height: 0.8;
  635. text-overflow: ellipsis;
  636. overflow: hidden;
  637. }
  638. i {
  639. margin-left: 10px;
  640. font-size: 30px;
  641. color: var(--yellow);
  642. &.stationMode {
  643. padding-left: 10px;
  644. margin-left: auto;
  645. color: var(--primary-color);
  646. }
  647. }
  648. .verified-station {
  649. color: var(--primary-color);
  650. }
  651. }
  652. p {
  653. display: -webkit-box;
  654. max-width: 700px;
  655. margin-bottom: 10px;
  656. overflow: hidden;
  657. text-overflow: ellipsis;
  658. -webkit-box-orient: vertical;
  659. -webkit-line-clamp: 3;
  660. }
  661. }
  662. #admin-buttons {
  663. display: flex;
  664. .button {
  665. margin: 3px;
  666. }
  667. }
  668. }
  669. .tab-selection {
  670. display: flex;
  671. overflow-x: auto;
  672. .button {
  673. border-radius: @border-radius @border-radius 0 0;
  674. border: 0;
  675. text-transform: uppercase;
  676. font-size: 14px;
  677. color: var(--dark-grey-3);
  678. background-color: var(--light-grey-2);
  679. flex-grow: 1;
  680. height: 32px;
  681. &:not(:first-of-type) {
  682. margin-left: 5px;
  683. }
  684. }
  685. .selected {
  686. background-color: var(--primary-color) !important;
  687. color: var(--white) !important;
  688. font-weight: 600;
  689. }
  690. }
  691. .tab {
  692. border: 1px solid var(--light-grey-3);
  693. padding: 15px;
  694. border-radius: 0 0 @border-radius @border-radius;
  695. }
  696. }
  697. .right-section {
  698. .section {
  699. .queue-title {
  700. display: flex;
  701. line-height: 30px;
  702. .material-icons {
  703. margin-left: 5px;
  704. margin-bottom: 5px;
  705. font-size: 28px;
  706. cursor: pointer;
  707. &:first-of-type {
  708. margin-left: auto;
  709. }
  710. &.skip-station {
  711. color: var(--dark-red);
  712. }
  713. &.resume-station,
  714. &.pause-station {
  715. color: var(--primary-color);
  716. }
  717. }
  718. }
  719. .currently-playing {
  720. margin-bottom: 10px;
  721. }
  722. }
  723. }
  724. &.modal-wide .left-section .section:first-child {
  725. padding: 0 15px 15px !important;
  726. }
  727. }
  728. </style>