index.vue 18 KB

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