index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <modal
  3. v-if="station"
  4. :title="
  5. !isOwnerOrAdmin() && station.partyMode
  6. ? 'Add Song to Queue'
  7. : 'Manage Station'
  8. "
  9. class="manage-station-modal"
  10. >
  11. <template #body>
  12. <div class="custom-modal-body" v-if="station && station._id">
  13. <div class="left-section">
  14. <div class="section tabs-container">
  15. <div class="tab-selection">
  16. <button
  17. v-if="isOwnerOrAdmin()"
  18. class="button is-default"
  19. :class="{ selected: tab === 'settings' }"
  20. @click="showTab('settings')"
  21. >
  22. Settings
  23. </button>
  24. <button
  25. v-if="
  26. isOwnerOrAdmin() ||
  27. (loggedIn &&
  28. station.type === 'community' &&
  29. station.partyMode &&
  30. ((station.locked &&
  31. isOwnerOrAdmin()) ||
  32. !station.locked))
  33. "
  34. class="button is-default"
  35. :class="{ selected: tab === 'playlists' }"
  36. @click="showTab('playlists')"
  37. >
  38. Playlists
  39. </button>
  40. <button
  41. v-if="
  42. loggedIn &&
  43. station.type === 'community' &&
  44. station.partyMode &&
  45. ((station.locked && isOwnerOrAdmin()) ||
  46. !station.locked)
  47. "
  48. class="button is-default"
  49. :class="{ selected: tab === 'search' }"
  50. @click="showTab('search')"
  51. >
  52. Search
  53. </button>
  54. <button
  55. v-if="isOwnerOrAdmin()"
  56. class="button is-default"
  57. :class="{ selected: tab === 'blacklist' }"
  58. @click="showTab('blacklist')"
  59. >
  60. Blacklist
  61. </button>
  62. </div>
  63. <settings
  64. v-if="isOwnerOrAdmin()"
  65. class="tab"
  66. v-show="tab === 'settings'"
  67. />
  68. <playlists
  69. v-if="
  70. isOwnerOrAdmin() ||
  71. (loggedIn &&
  72. station.type === 'community' &&
  73. station.partyMode &&
  74. ((station.locked && isOwnerOrAdmin()) ||
  75. !station.locked))
  76. "
  77. class="tab"
  78. v-show="tab === 'playlists'"
  79. />
  80. <search
  81. v-if="
  82. loggedIn &&
  83. station.type === 'community' &&
  84. station.partyMode &&
  85. ((station.locked && isOwnerOrAdmin()) ||
  86. !station.locked)
  87. "
  88. class="tab"
  89. v-show="tab === 'search'"
  90. />
  91. <blacklist
  92. v-if="isOwnerOrAdmin()"
  93. class="tab"
  94. v-show="tab === 'blacklist'"
  95. />
  96. </div>
  97. </div>
  98. <div class="right-section">
  99. <div class="section">
  100. <div class="queue-title">
  101. <h4 class="section-title">Queue</h4>
  102. <i
  103. v-if="isOwnerOrAdmin() && stationPaused"
  104. @click="resumeStation()"
  105. class="material-icons resume-station"
  106. content="Resume Station"
  107. v-tippy
  108. >
  109. play_arrow
  110. </i>
  111. <i
  112. v-if="isOwnerOrAdmin() && !stationPaused"
  113. @click="pauseStation()"
  114. class="material-icons pause-station"
  115. content="Pause Station"
  116. v-tippy
  117. >
  118. pause
  119. </i>
  120. <confirm
  121. v-if="isOwnerOrAdmin()"
  122. @confirm="skipStation()"
  123. >
  124. <i
  125. class="material-icons skip-station"
  126. content="Force Skip Station"
  127. v-tippy
  128. >
  129. skip_next
  130. </i>
  131. </confirm>
  132. </div>
  133. <hr class="section-horizontal-rule" />
  134. <song-item
  135. v-if="currentSong._id"
  136. :song="currentSong"
  137. :large-thumbnail="true"
  138. :requested-by="
  139. station.type === 'community' &&
  140. station.partyMode === true
  141. "
  142. header="Currently Playing.."
  143. class="currently-playing"
  144. />
  145. <queue sector="manageStation" />
  146. </div>
  147. </div>
  148. </div>
  149. </template>
  150. <template #footer>
  151. <a
  152. class="button is-default"
  153. v-if="isOwnerOrAdmin() && !station.partyMode"
  154. @click="stationPlaylist()"
  155. >
  156. View Station Playlist
  157. </a>
  158. <button
  159. class="button is-primary tab-actionable-button"
  160. v-if="loggedIn && station.type === 'official'"
  161. @click="openModal('requestSong')"
  162. >
  163. <i class="material-icons icon-with-button">queue</i>
  164. <span class="optional-desktop-only-text"> Request Song </span>
  165. </button>
  166. <div v-if="isOwnerOrAdmin()" class="right">
  167. <confirm @confirm="clearAndRefillStationQueue()">
  168. <a class="button is-danger">
  169. Clear and refill station queue
  170. </a>
  171. </confirm>
  172. <confirm
  173. v-if="station && station.type === 'community'"
  174. @confirm="deleteStation()"
  175. >
  176. <button class="button is-danger">Delete station</button>
  177. </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 Confirm from "@/components/Confirm.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 "./Tabs/Settings.vue";
  190. import Playlists from "./Tabs/Playlists.vue";
  191. import Search from "./Tabs/Search.vue";
  192. import Blacklist from "./Tabs/Blacklist.vue";
  193. export default {
  194. components: {
  195. Modal,
  196. Confirm,
  197. Queue,
  198. SongItem,
  199. Settings,
  200. Playlists,
  201. Search,
  202. Blacklist
  203. },
  204. props: {
  205. stationId: { type: String, default: "" },
  206. sector: { type: String, default: "admin" }
  207. },
  208. data() {
  209. return {
  210. tab: "settings"
  211. };
  212. },
  213. computed: {
  214. ...mapState({
  215. loggedIn: state => state.user.auth.loggedIn,
  216. userId: state => state.user.auth.userId,
  217. role: state => state.user.auth.role
  218. }),
  219. ...mapState("modals/manageStation", {
  220. station: state => state.station,
  221. originalStation: state => state.originalStation,
  222. songsList: state => state.songsList,
  223. stationPaused: state => state.stationPaused,
  224. currentSong: state => state.currentSong
  225. }),
  226. ...mapGetters({
  227. socket: "websockets/getSocket"
  228. })
  229. },
  230. mounted() {
  231. this.socket.dispatch(`stations.getStationById`, this.stationId, res => {
  232. if (res.status === "success") {
  233. const { station } = res.data;
  234. this.editStation(station);
  235. if (!this.isOwnerOrAdmin() && this.station.partyMode)
  236. this.tab = "search";
  237. const currentSong = res.data.station.currentSong
  238. ? res.data.station.currentSong
  239. : {};
  240. this.updateCurrentSong(currentSong);
  241. this.updateStationPaused(res.data.station.paused);
  242. this.socket.dispatch(
  243. "stations.getStationIncludedPlaylistsById",
  244. this.stationId,
  245. res => {
  246. if (res.status === "success") {
  247. this.setIncludedPlaylists(res.data.playlists);
  248. }
  249. }
  250. );
  251. this.socket.dispatch(
  252. "stations.getStationExcludedPlaylistsById",
  253. this.stationId,
  254. res => {
  255. if (res.status === "success") {
  256. this.setExcludedPlaylists(res.data.playlists);
  257. }
  258. }
  259. );
  260. this.socket.dispatch(
  261. "stations.getQueue",
  262. this.stationId,
  263. res => {
  264. if (res.status === "success") {
  265. this.updateSongsList(res.data.queue);
  266. }
  267. }
  268. );
  269. } else {
  270. new Toast(`Station with that ID not found`);
  271. this.closeModal("manageStation");
  272. }
  273. });
  274. this.socket.on("event:queue.update", res => {
  275. this.updateSongsList(res.data.queue);
  276. });
  277. this.socket.on("event:queue.repositionSong", res => {
  278. this.repositionSongInList(res.data.song);
  279. });
  280. this.socket.on("event:stations.pause", res => {
  281. this.pausedAt = res.data.pausedAt;
  282. this.updateStationPaused(true);
  283. });
  284. this.socket.on("event:stations.resume", res => {
  285. this.timePaused = res.data.timePaused;
  286. this.updateStationPaused(false);
  287. });
  288. this.socket.on("event:songs.next", res => {
  289. const { currentSong } = res.data;
  290. this.updateCurrentSong(currentSong || {});
  291. });
  292. },
  293. beforeDestroy() {
  294. this.repositionSongInList([]);
  295. this.clearStation();
  296. },
  297. methods: {
  298. showTab(tab) {
  299. this.tab = tab;
  300. },
  301. isOwner() {
  302. return this.loggedIn && this.userId === this.station.owner;
  303. },
  304. isAdmin() {
  305. return this.loggedIn && this.role === "admin";
  306. },
  307. isOwnerOrAdmin() {
  308. return this.isOwner() || this.isAdmin();
  309. },
  310. resumeStation() {
  311. this.socket.dispatch("stations.resume", this.station._id, res => {
  312. if (res.status !== "success")
  313. new Toast(`Error: ${res.message}`);
  314. else new Toast("Successfully resumed the station.");
  315. });
  316. },
  317. pauseStation() {
  318. this.socket.dispatch("stations.pause", this.station._id, res => {
  319. if (res.status !== "success")
  320. new Toast(`Error: ${res.message}`);
  321. else new Toast("Successfully paused the station.");
  322. });
  323. },
  324. skipStation() {
  325. this.socket.dispatch(
  326. "stations.forceSkip",
  327. this.station._id,
  328. res => {
  329. if (res.status !== "success")
  330. new Toast(`Error: ${res.message}`);
  331. else
  332. new Toast(
  333. "Successfully skipped the station's current song."
  334. );
  335. }
  336. );
  337. },
  338. clearAndRefillStationQueue() {
  339. this.socket.dispatch(
  340. "stations.clearAndRefillStationQueue",
  341. this.station._id,
  342. res => {
  343. if (res.status !== "success")
  344. new Toast({
  345. content: `Error: ${res.message}`,
  346. timeout: 8000
  347. });
  348. else new Toast({ content: res.message, timeout: 4000 });
  349. }
  350. );
  351. },
  352. stationPlaylist() {
  353. this.socket.dispatch(
  354. "playlists.getPlaylistForStation",
  355. this.station._id,
  356. false,
  357. res => {
  358. if (res.status === "success") {
  359. this.editPlaylist(res.data.playlist._id);
  360. this.openModal("editPlaylist");
  361. } else {
  362. new Toast(res.message);
  363. }
  364. }
  365. );
  366. },
  367. ...mapActions("modals/manageStation", [
  368. "editStation",
  369. "setIncludedPlaylists",
  370. "setExcludedPlaylists",
  371. "clearStation",
  372. "updateSongsList",
  373. "repositionSongInList",
  374. "updateStationPaused",
  375. "updateCurrentSong"
  376. ]),
  377. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  378. ...mapActions("user/playlists", ["editPlaylist"])
  379. }
  380. };
  381. </script>
  382. <style lang="scss">
  383. .manage-station-modal.modal {
  384. z-index: 1800;
  385. .modal-card {
  386. width: 1300px;
  387. height: 100%;
  388. overflow: auto;
  389. .tab > button {
  390. width: 100%;
  391. margin-bottom: 10px;
  392. }
  393. }
  394. }
  395. </style>
  396. <style lang="scss" scoped>
  397. .manage-station-modal.modal .modal-card-body .custom-modal-body {
  398. display: flex;
  399. flex-wrap: wrap;
  400. height: 100%;
  401. .section {
  402. display: flex;
  403. flex-direction: column;
  404. flex-grow: 1;
  405. width: auto;
  406. padding: 15px !important;
  407. margin: 0 10px;
  408. }
  409. .left-section {
  410. flex-basis: 50%;
  411. height: 100%;
  412. overflow-y: auto;
  413. flex-grow: 1;
  414. .tabs-container {
  415. .tab-selection {
  416. display: flex;
  417. .button {
  418. border-radius: 5px 5px 0 0;
  419. border: 0;
  420. text-transform: uppercase;
  421. font-size: 14px;
  422. color: var(--dark-grey-3);
  423. background-color: var(--light-grey-2);
  424. flex-grow: 1;
  425. height: 32px;
  426. &:not(:first-of-type) {
  427. margin-left: 5px;
  428. }
  429. }
  430. .selected {
  431. background-color: var(--dark-grey-3) !important;
  432. color: var(--white) !important;
  433. }
  434. }
  435. .tab {
  436. border: 1px solid var(--light-grey-3);
  437. padding: 15px;
  438. border-radius: 0 0 5px 5px;
  439. }
  440. }
  441. }
  442. .right-section {
  443. flex-basis: 50%;
  444. height: 100%;
  445. overflow-y: auto;
  446. flex-grow: 1;
  447. .section {
  448. .queue-title {
  449. display: flex;
  450. line-height: 30px;
  451. .material-icons {
  452. margin-left: 5px;
  453. margin-bottom: 5px;
  454. font-size: 28px;
  455. cursor: pointer;
  456. &:first-of-type {
  457. margin-left: auto;
  458. }
  459. &.skip-station {
  460. color: var(--red);
  461. }
  462. &.resume-station,
  463. &.pause-station {
  464. color: var(--primary-color);
  465. }
  466. }
  467. }
  468. .currently-playing {
  469. margin-bottom: 10px;
  470. }
  471. }
  472. }
  473. }
  474. @media screen and (max-width: 1100px) {
  475. .manage-station-modal.modal .modal-card-body .custom-modal-body {
  476. .left-section,
  477. .right-section {
  478. flex-basis: unset;
  479. height: auto;
  480. }
  481. }
  482. }
  483. </style>