index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. computed: {
  209. ...mapState({
  210. loggedIn: state => state.user.auth.loggedIn,
  211. userId: state => state.user.auth.userId,
  212. role: state => state.user.auth.role
  213. }),
  214. ...mapState("modals/manageStation", {
  215. tab: state => state.tab,
  216. station: state => state.station,
  217. originalStation: state => state.originalStation,
  218. songsList: state => state.songsList,
  219. stationPaused: state => state.stationPaused,
  220. currentSong: state => state.currentSong
  221. }),
  222. ...mapGetters({
  223. socket: "websockets/getSocket"
  224. })
  225. },
  226. mounted() {
  227. this.socket.dispatch(`stations.getStationById`, this.stationId, res => {
  228. if (res.status === "success") {
  229. const { station } = res.data;
  230. this.editStation(station);
  231. if (!this.isOwnerOrAdmin() && this.station.partyMode)
  232. this.showTab("search");
  233. const currentSong = res.data.station.currentSong
  234. ? res.data.station.currentSong
  235. : {};
  236. this.updateCurrentSong(currentSong);
  237. this.updateStationPaused(res.data.station.paused);
  238. this.socket.dispatch(
  239. "stations.getStationIncludedPlaylistsById",
  240. this.stationId,
  241. res => {
  242. if (res.status === "success") {
  243. this.setIncludedPlaylists(res.data.playlists);
  244. }
  245. }
  246. );
  247. this.socket.dispatch(
  248. "stations.getStationExcludedPlaylistsById",
  249. this.stationId,
  250. res => {
  251. if (res.status === "success") {
  252. this.setExcludedPlaylists(res.data.playlists);
  253. }
  254. }
  255. );
  256. this.socket.dispatch(
  257. "stations.getQueue",
  258. this.stationId,
  259. res => {
  260. if (res.status === "success") {
  261. this.updateSongsList(res.data.queue);
  262. }
  263. }
  264. );
  265. } else {
  266. new Toast(`Station with that ID not found`);
  267. this.closeModal("manageStation");
  268. }
  269. });
  270. this.socket.on("event:queue.update", res => {
  271. this.updateSongsList(res.data.queue);
  272. });
  273. this.socket.on("event:queue.repositionSong", res => {
  274. this.repositionSongInList(res.data.song);
  275. });
  276. this.socket.on("event:stations.pause", res => {
  277. this.pausedAt = res.data.pausedAt;
  278. this.updateStationPaused(true);
  279. });
  280. this.socket.on("event:stations.resume", res => {
  281. this.timePaused = res.data.timePaused;
  282. this.updateStationPaused(false);
  283. });
  284. this.socket.on("event:songs.next", res => {
  285. const { currentSong } = res.data;
  286. this.updateCurrentSong(currentSong || {});
  287. });
  288. },
  289. beforeDestroy() {
  290. this.repositionSongInList([]);
  291. this.clearStation();
  292. this.showTab("settings");
  293. },
  294. methods: {
  295. isOwner() {
  296. return this.loggedIn && this.userId === this.station.owner;
  297. },
  298. isAdmin() {
  299. return this.loggedIn && this.role === "admin";
  300. },
  301. isOwnerOrAdmin() {
  302. return this.isOwner() || this.isAdmin();
  303. },
  304. resumeStation() {
  305. this.socket.dispatch("stations.resume", this.station._id, res => {
  306. if (res.status !== "success")
  307. new Toast(`Error: ${res.message}`);
  308. else new Toast("Successfully resumed the station.");
  309. });
  310. },
  311. pauseStation() {
  312. this.socket.dispatch("stations.pause", this.station._id, res => {
  313. if (res.status !== "success")
  314. new Toast(`Error: ${res.message}`);
  315. else new Toast("Successfully paused the station.");
  316. });
  317. },
  318. skipStation() {
  319. this.socket.dispatch(
  320. "stations.forceSkip",
  321. this.station._id,
  322. res => {
  323. if (res.status !== "success")
  324. new Toast(`Error: ${res.message}`);
  325. else
  326. new Toast(
  327. "Successfully skipped the station's current song."
  328. );
  329. }
  330. );
  331. },
  332. clearAndRefillStationQueue() {
  333. this.socket.dispatch(
  334. "stations.clearAndRefillStationQueue",
  335. this.station._id,
  336. res => {
  337. if (res.status !== "success")
  338. new Toast({
  339. content: `Error: ${res.message}`,
  340. timeout: 8000
  341. });
  342. else new Toast({ content: res.message, timeout: 4000 });
  343. }
  344. );
  345. },
  346. stationPlaylist() {
  347. this.socket.dispatch(
  348. "playlists.getPlaylistForStation",
  349. this.station._id,
  350. false,
  351. res => {
  352. if (res.status === "success") {
  353. this.editPlaylist(res.data.playlist._id);
  354. this.openModal("editPlaylist");
  355. } else {
  356. new Toast(res.message);
  357. }
  358. }
  359. );
  360. },
  361. ...mapActions("modals/manageStation", [
  362. "showTab",
  363. "editStation",
  364. "setIncludedPlaylists",
  365. "setExcludedPlaylists",
  366. "clearStation",
  367. "updateSongsList",
  368. "repositionSongInList",
  369. "updateStationPaused",
  370. "updateCurrentSong"
  371. ]),
  372. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  373. ...mapActions("user/playlists", ["editPlaylist"])
  374. }
  375. };
  376. </script>
  377. <style lang="scss">
  378. .manage-station-modal.modal {
  379. z-index: 1800;
  380. .modal-card {
  381. width: 1300px;
  382. height: 100%;
  383. overflow: auto;
  384. .tab > button {
  385. width: 100%;
  386. margin-bottom: 10px;
  387. }
  388. }
  389. }
  390. </style>
  391. <style lang="scss" scoped>
  392. .manage-station-modal.modal .modal-card-body .custom-modal-body {
  393. display: flex;
  394. flex-wrap: wrap;
  395. height: 100%;
  396. .section {
  397. display: flex;
  398. flex-direction: column;
  399. flex-grow: 1;
  400. width: auto;
  401. padding: 15px !important;
  402. margin: 0 10px;
  403. }
  404. .left-section {
  405. flex-basis: 50%;
  406. height: 100%;
  407. overflow-y: auto;
  408. flex-grow: 1;
  409. .tabs-container {
  410. .tab-selection {
  411. display: flex;
  412. .button {
  413. border-radius: 5px 5px 0 0;
  414. border: 0;
  415. text-transform: uppercase;
  416. font-size: 14px;
  417. color: var(--dark-grey-3);
  418. background-color: var(--light-grey-2);
  419. flex-grow: 1;
  420. height: 32px;
  421. &:not(:first-of-type) {
  422. margin-left: 5px;
  423. }
  424. }
  425. .selected {
  426. background-color: var(--dark-grey-3) !important;
  427. color: var(--white) !important;
  428. }
  429. }
  430. .tab {
  431. border: 1px solid var(--light-grey-3);
  432. padding: 15px;
  433. border-radius: 0 0 5px 5px;
  434. }
  435. }
  436. }
  437. .right-section {
  438. flex-basis: 50%;
  439. height: 100%;
  440. overflow-y: auto;
  441. flex-grow: 1;
  442. .section {
  443. .queue-title {
  444. display: flex;
  445. line-height: 30px;
  446. .material-icons {
  447. margin-left: 5px;
  448. margin-bottom: 5px;
  449. font-size: 28px;
  450. cursor: pointer;
  451. &:first-of-type {
  452. margin-left: auto;
  453. }
  454. &.skip-station {
  455. color: var(--red);
  456. }
  457. &.resume-station,
  458. &.pause-station {
  459. color: var(--primary-color);
  460. }
  461. }
  462. }
  463. .currently-playing {
  464. margin-bottom: 10px;
  465. }
  466. }
  467. }
  468. }
  469. @media screen and (max-width: 1100px) {
  470. .manage-station-modal.modal .modal-card-body .custom-modal-body {
  471. .left-section,
  472. .right-section {
  473. flex-basis: unset;
  474. height: auto;
  475. }
  476. }
  477. }
  478. </style>