EditStation.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  1. <template>
  2. <modal title="Edit Station" class="edit-station-modal">
  3. <template #body>
  4. <div class="custom-modal-body" v-if="station && station._id">
  5. <!-- Station Preferences -->
  6. <div class="section left-section">
  7. <div class="col col-2">
  8. <div>
  9. <label class="label">Name</label>
  10. <p class="control">
  11. <input
  12. class="input"
  13. type="text"
  14. v-model="station.name"
  15. />
  16. </p>
  17. </div>
  18. <div>
  19. <label class="label">Display name</label>
  20. <p class="control">
  21. <input
  22. class="input"
  23. type="text"
  24. v-model="station.displayName"
  25. />
  26. </p>
  27. </div>
  28. </div>
  29. <div class="col col-1">
  30. <div>
  31. <label class="label">Description</label>
  32. <p class="control">
  33. <input
  34. class="input"
  35. type="text"
  36. v-model="station.description"
  37. />
  38. </p>
  39. </div>
  40. </div>
  41. <div
  42. class="col col-2"
  43. v-if="station.type === 'official' && station.genres"
  44. >
  45. <div>
  46. <label class="label">Genre(s)</label>
  47. <p class="control has-addons">
  48. <input
  49. class="input"
  50. type="text"
  51. id="new-genre"
  52. v-model="genreInputValue"
  53. @blur="blurGenreInput()"
  54. @focus="focusGenreInput()"
  55. @keydown="keydownGenreInput()"
  56. @keyup.enter="addTag('genres')"
  57. />
  58. <button
  59. class="button is-info add-button blue"
  60. @click="addTag('genres')"
  61. >
  62. <i class="material-icons">add</i>
  63. </button>
  64. </p>
  65. <div
  66. class="autosuggest-container"
  67. v-if="
  68. (genreInputFocussed ||
  69. genreAutosuggestContainerFocussed) &&
  70. genreAutosuggestItems.length > 0
  71. "
  72. @mouseover="focusGenreContainer()"
  73. @mouseleave="blurGenreContainer()"
  74. >
  75. <span
  76. class="autosuggest-item"
  77. tabindex="0"
  78. @click="selectGenreAutosuggest(item)"
  79. v-for="(item,
  80. index) in genreAutosuggestItems"
  81. :key="index"
  82. >{{ item }}</span
  83. >
  84. </div>
  85. <div class="list-container">
  86. <div
  87. class="list-item"
  88. v-for="(genre, index) in station.genres"
  89. :key="index"
  90. >
  91. <div
  92. class="list-item-circle blue"
  93. @click="removeTag('genres', index)"
  94. >
  95. <i class="material-icons">close</i>
  96. </div>
  97. <p>{{ genre }}</p>
  98. </div>
  99. </div>
  100. </div>
  101. <div>
  102. <label class="label">Blacklist genre(s)</label>
  103. <p class="control has-addons">
  104. <input
  105. class="input"
  106. type="text"
  107. v-model="blacklistGenreInputValue"
  108. @blur="blurBlacklistGenreInput()"
  109. @focus="focusBlacklistGenreInput()"
  110. @keydown="keydownBlacklistGenreInput()"
  111. @keyup.enter="addTag('blacklist-genres')"
  112. />
  113. <button
  114. class="button is-info add-button red"
  115. @click="addTag('blacklist-genres')"
  116. >
  117. <i class="material-icons">add</i>
  118. </button>
  119. </p>
  120. <div
  121. class="autosuggest-container"
  122. v-if="
  123. (blacklistGenreInputFocussed ||
  124. blacklistGenreAutosuggestContainerFocussed) &&
  125. blacklistGenreAutosuggestItems.length >
  126. 0
  127. "
  128. @mouseover="focusBlacklistGenreContainer()"
  129. @mouseleave="blurBlacklistGenreContainer()"
  130. >
  131. <span
  132. class="autosuggest-item"
  133. tabindex="0"
  134. @click="
  135. selectBlacklistGenreAutosuggest(item)
  136. "
  137. v-for="(item,
  138. index) in blacklistGenreAutosuggestItems"
  139. :key="index"
  140. >{{ item }}</span
  141. >
  142. </div>
  143. <div class="list-container">
  144. <div
  145. class="list-item"
  146. v-for="(genre,
  147. index) in station.blacklistedGenres"
  148. :key="index"
  149. >
  150. <div
  151. class="list-item-circle red"
  152. @click="
  153. removeTag('blacklist-genres', index)
  154. "
  155. >
  156. <i class="material-icons">close</i>
  157. </div>
  158. <p>{{ genre }}</p>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. </div>
  164. <!-- Buttons changing the privacy settings -->
  165. <div class="section right-section">
  166. <div>
  167. <label class="label">Privacy</label>
  168. <div
  169. @mouseenter="privacyDropdownActive = true"
  170. @mouseleave="privacyDropdownActive = false"
  171. class="button-wrapper"
  172. >
  173. <button
  174. :class="privacyButtons[station.privacy].style"
  175. @click="updatePrivacyLocal(station.privacy)"
  176. >
  177. <i class="material-icons">{{
  178. privacyButtons[station.privacy].iconName
  179. }}</i>
  180. {{ station.privacy }}
  181. </button>
  182. <transition name="slide-down">
  183. <button
  184. class="green"
  185. v-if="
  186. privacyDropdownActive &&
  187. station.privacy !== 'public'
  188. "
  189. @click="updatePrivacyLocal('public')"
  190. >
  191. <i class="material-icons">{{
  192. privacyButtons["public"].iconName
  193. }}</i>
  194. Public
  195. </button>
  196. </transition>
  197. <transition name="slide-down">
  198. <button
  199. class="orange"
  200. v-if="
  201. privacyDropdownActive &&
  202. station.privacy !== 'unlisted'
  203. "
  204. @click="updatePrivacyLocal('unlisted')"
  205. >
  206. <i class="material-icons">{{
  207. privacyButtons["unlisted"].iconName
  208. }}</i>
  209. Unlisted
  210. </button>
  211. </transition>
  212. <transition name="slide-down">
  213. <button
  214. class="red"
  215. v-if="
  216. privacyDropdownActive &&
  217. station.privacy !== 'private'
  218. "
  219. @click="updatePrivacyLocal('private')"
  220. >
  221. <i class="material-icons">{{
  222. privacyButtons["private"].iconName
  223. }}</i>
  224. Private
  225. </button>
  226. </transition>
  227. </div>
  228. </div>
  229. <!-- Buttons changing the mode of the station -->
  230. <div>
  231. <label class="label">Station Mode</label>
  232. <div
  233. @mouseenter="modeDropdownActive = true"
  234. @mouseleave="modeDropdownActive = false"
  235. class="button-wrapper"
  236. >
  237. <button
  238. :class="{
  239. blue: !station.partyMode,
  240. yellow: station.partyMode
  241. }"
  242. @click="
  243. station.partyMode
  244. ? updatePartyModeLocal(true)
  245. : updatePartyModeLocal(false)
  246. "
  247. >
  248. <i class="material-icons">{{
  249. station.partyMode
  250. ? "emoji_people"
  251. : "playlist_play"
  252. }}</i>
  253. {{ station.partyMode ? "Party" : "Playlist" }}
  254. </button>
  255. <transition name="slide-down">
  256. <button
  257. class="blue"
  258. v-if="
  259. modeDropdownActive && station.partyMode
  260. "
  261. @click="updatePartyModeLocal(false)"
  262. >
  263. <i class="material-icons">playlist_play</i>
  264. Playlist
  265. </button>
  266. </transition>
  267. <transition
  268. v-if="station.type === 'community'"
  269. name="slide-down"
  270. >
  271. <button
  272. class="yellow"
  273. v-if="
  274. modeDropdownActive && !station.partyMode
  275. "
  276. @click="updatePartyModeLocal(true)"
  277. >
  278. <i class="material-icons">emoji_people</i>
  279. Party
  280. </button>
  281. </transition>
  282. </div>
  283. </div>
  284. <div>
  285. <label class="label">Play Mode</label>
  286. <div
  287. @mouseenter="playModeDropdownActive = true"
  288. @mouseleave="playModeDropdownActive = false"
  289. class="button-wrapper"
  290. >
  291. <button
  292. class="blue"
  293. @click="
  294. station.playMode === 'random'
  295. ? updatePlayModeLocal('sequential')
  296. : updatePlayModeLocal('random')
  297. "
  298. >
  299. <i class="material-icons">{{
  300. station.playMode === "random"
  301. ? "shuffle"
  302. : "format_list_numbered"
  303. }}</i>
  304. {{
  305. station.playMode === "random"
  306. ? "Random"
  307. : "Sequential"
  308. }}
  309. </button>
  310. <transition name="slide-down">
  311. <button
  312. class="blue"
  313. v-if="
  314. playModeDropdownActive &&
  315. station.playMode === 'sequential'
  316. "
  317. @click="updatePlayModeLocal('random')"
  318. >
  319. <i class="material-icons">shuffle</i>
  320. Random
  321. </button>
  322. </transition>
  323. <transition
  324. v-if="station.type === 'community'"
  325. name="slide-down"
  326. >
  327. <button
  328. class="blue"
  329. v-if="
  330. playModeDropdownActive &&
  331. station.playMode === 'random'
  332. "
  333. @click="updatePlayModeLocal('sequential')"
  334. >
  335. <i class="material-icons"
  336. >format_list_numbered</i
  337. >
  338. Sequential
  339. </button>
  340. </transition>
  341. </div>
  342. </div>
  343. <div
  344. v-if="
  345. station.type === 'community' &&
  346. station.partyMode === true
  347. "
  348. >
  349. <label class="label">Queue lock</label>
  350. <div
  351. @mouseenter="queueLockDropdownActive = true"
  352. @mouseleave="queueLockDropdownActive = false"
  353. class="button-wrapper"
  354. >
  355. <button
  356. :class="{
  357. green: station.locked,
  358. red: !station.locked
  359. }"
  360. @click="
  361. station.locked
  362. ? updateQueueLockLocal(true)
  363. : updateQueueLockLocal(false)
  364. "
  365. >
  366. <i class="material-icons">{{
  367. station.locked ? "lock" : "lock_open"
  368. }}</i>
  369. {{ station.locked ? "Locked" : "Unlocked" }}
  370. </button>
  371. <transition name="slide-down">
  372. <button
  373. class="green"
  374. v-if="
  375. queueLockDropdownActive &&
  376. !station.locked
  377. "
  378. @click="updateQueueLockLocal(true)"
  379. >
  380. <i class="material-icons">lock</i>
  381. Locked
  382. </button>
  383. </transition>
  384. <transition name="slide-down">
  385. <button
  386. class="red"
  387. v-if="
  388. queueLockDropdownActive &&
  389. station.locked
  390. "
  391. @click="updateQueueLockLocal(false)"
  392. >
  393. <i class="material-icons">lock_open</i>
  394. Unlocked
  395. </button>
  396. </transition>
  397. </div>
  398. </div>
  399. <div>
  400. <label class="label">Theme</label>
  401. <div
  402. @mouseenter="themeDropdownActive = true"
  403. @mouseleave="themeDropdownActive = false"
  404. class="button-wrapper"
  405. >
  406. <button
  407. :class="station.theme"
  408. @click="updateThemeLocal(station.theme)"
  409. >
  410. <i class="material-icons">palette</i>
  411. {{ station.theme }}
  412. </button>
  413. <transition name="slide-down">
  414. <button
  415. class="blue"
  416. v-if="
  417. themeDropdownActive &&
  418. station.theme !== 'blue'
  419. "
  420. @click="updateThemeLocal('blue')"
  421. >
  422. <i class="material-icons">palette</i>
  423. Blue
  424. </button>
  425. </transition>
  426. <transition name="slide-down">
  427. <button
  428. class="purple"
  429. v-if="
  430. themeDropdownActive &&
  431. station.theme !== 'purple'
  432. "
  433. @click="updateThemeLocal('purple')"
  434. >
  435. <i class="material-icons">palette</i>
  436. Purple
  437. </button>
  438. </transition>
  439. <transition name="slide-down">
  440. <button
  441. class="teal"
  442. v-if="
  443. themeDropdownActive &&
  444. station.theme !== 'teal'
  445. "
  446. @click="updateThemeLocal('teal')"
  447. >
  448. <i class="material-icons">palette</i>
  449. Teal
  450. </button>
  451. </transition>
  452. <transition name="slide-down">
  453. <button
  454. class="orange"
  455. v-if="
  456. themeDropdownActive &&
  457. station.theme !== 'orange'
  458. "
  459. @click="updateThemeLocal('orange')"
  460. >
  461. <i class="material-icons">palette</i>
  462. Orange
  463. </button>
  464. </transition>
  465. </div>
  466. </div>
  467. </div>
  468. </div>
  469. </template>
  470. <template #footer>
  471. <save-button ref="saveButton" @clicked="saveChanges()" />
  472. <button
  473. v-if="station.type === 'community'"
  474. class="button is-danger"
  475. @click="deleteStation()"
  476. >
  477. Delete station
  478. </button>
  479. </template>
  480. </modal>
  481. </template>
  482. <script>
  483. import { mapState, mapGetters, mapActions } from "vuex";
  484. import Toast from "toasters";
  485. import Modal from "../Modal.vue";
  486. import validation from "../../validation";
  487. import SaveButton from "../ui/SaveButton.vue";
  488. export default {
  489. components: { Modal, SaveButton },
  490. props: {
  491. stationId: { type: String, default: "" },
  492. sector: { type: String, default: "admin" }
  493. },
  494. data() {
  495. return {
  496. genreInputValue: "",
  497. genreInputFocussed: false,
  498. genreAutosuggestContainerFocussed: false,
  499. keydownGenreInputTimeout: 0,
  500. genreAutosuggestItems: [],
  501. blacklistGenreInputValue: "",
  502. blacklistGenreInputFocussed: false,
  503. blacklistGenreAutosuggestContainerFocussed: false,
  504. blacklistKeydownGenreInputTimeout: 0,
  505. blacklistGenreAutosuggestItems: [],
  506. privacyDropdownActive: false,
  507. modeDropdownActive: false,
  508. playModeDropdownActive: false,
  509. queueLockDropdownActive: false,
  510. themeDropdownActive: false,
  511. genres: [
  512. "Blues",
  513. "Country",
  514. "Disco",
  515. "Funk",
  516. "Hip-Hop",
  517. "Jazz",
  518. "Metal",
  519. "Oldies",
  520. "Other",
  521. "Pop",
  522. "Rap",
  523. "Reggae",
  524. "Rock",
  525. "Techno",
  526. "Trance",
  527. "Classical",
  528. "Instrumental",
  529. "House",
  530. "Electronic",
  531. "Christian Rap",
  532. "Lo-Fi",
  533. "Musical",
  534. "Rock 'n' Roll",
  535. "Opera",
  536. "Drum & Bass",
  537. "Club-House",
  538. "Indie",
  539. "Heavy Metal",
  540. "Christian rock",
  541. "Dubstep"
  542. ],
  543. privacyButtons: {
  544. public: {
  545. style: "green",
  546. iconName: "public"
  547. },
  548. private: {
  549. style: "red",
  550. iconName: "lock"
  551. },
  552. unlisted: {
  553. style: "orange",
  554. iconName: "link"
  555. }
  556. }
  557. };
  558. },
  559. computed: {
  560. // ...mapState("admin/stations", {
  561. // stations: state => state.stations
  562. // }),
  563. ...mapState("modals/editStation", {
  564. station: state => state.station,
  565. originalStation: state => state.originalStation
  566. }),
  567. ...mapGetters({
  568. socket: "websockets/getSocket"
  569. })
  570. },
  571. mounted() {
  572. this.socket.dispatch(`stations.getStationById`, this.stationId, res => {
  573. if (res.status === "success") {
  574. const { station } = res;
  575. // this.song = { ...song };
  576. // if (this.song.discogs === undefined)
  577. // this.song.discogs = null;
  578. this.editStation(station);
  579. // this.songDataLoaded = true;
  580. this.socket.dispatch(
  581. `stations.getStationIncludedPlaylistsById`,
  582. this.stationId,
  583. res => {
  584. if (res.status === "success") {
  585. this.station.genres = res.playlists.map(
  586. playlist => {
  587. if (playlist) {
  588. if (playlist.type === "genre")
  589. return playlist.createdFor;
  590. return `Playlist: ${playlist.name}`;
  591. }
  592. return "Unknown/Error";
  593. }
  594. );
  595. this.originalStation.genres = JSON.parse(
  596. JSON.stringify(this.station.genres)
  597. );
  598. }
  599. }
  600. );
  601. this.socket.dispatch(
  602. `stations.getStationExcludedPlaylistsById`,
  603. this.stationId,
  604. res => {
  605. if (res.status === "success") {
  606. this.station.blacklistedGenres = res.playlists.map(
  607. playlist => {
  608. if (playlist) {
  609. if (playlist.type === "genre")
  610. return playlist.createdFor;
  611. return `Playlist: ${playlist.name}`;
  612. }
  613. return "Unknown/Error";
  614. }
  615. );
  616. this.originalStation.blacklistedGenres = JSON.parse(
  617. JSON.stringify(this.station.blacklistedGenres)
  618. );
  619. }
  620. }
  621. );
  622. // this.station.genres = JSON.parse(
  623. // JSON.stringify(this.station.genres)
  624. // );
  625. // this.station.blacklistedGenres = JSON.parse(
  626. // JSON.stringify(this.station.blacklistedGenres)
  627. // );
  628. } else {
  629. new Toast({
  630. content: "Station with that ID not found",
  631. timeout: 3000
  632. });
  633. this.closeModal({
  634. sector: this.sector,
  635. modal: "editStation"
  636. });
  637. }
  638. });
  639. },
  640. methods: {
  641. saveChanges() {
  642. const nameChanged = this.originalStation.name !== this.station.name;
  643. const displayNameChanged =
  644. this.originalStation.displayName !== this.station.displayName;
  645. const descriptionChanged =
  646. this.originalStation.description !== this.station.description;
  647. const privacyChanged =
  648. this.originalStation.privacy !== this.station.privacy;
  649. const partyModeChanged =
  650. this.originalStation.type === "community" &&
  651. this.originalStation.partyMode !== this.station.partyMode;
  652. const playModeChanged =
  653. this.originalStation.playMode !== this.station.playMode;
  654. const queueLockChanged =
  655. this.originalStation.type === "community" &&
  656. this.station.partyMode &&
  657. this.originalStation.locked !== this.station.locked;
  658. const genresChanged =
  659. this.originalStation.genres.toString() !==
  660. this.station.genres.toString();
  661. const blacklistedGenresChanged =
  662. this.originalStation.blacklistedGenres.toString() !==
  663. this.station.blacklistedGenres.toString();
  664. const themeChanged =
  665. this.originalStation.theme !== this.station.theme;
  666. if (nameChanged) this.updateName();
  667. if (displayNameChanged) this.updateDisplayName();
  668. if (descriptionChanged) this.updateDescription();
  669. if (privacyChanged) this.updatePrivacy();
  670. if (partyModeChanged) this.updatePartyMode();
  671. if (playModeChanged) this.updatePlayMode();
  672. if (queueLockChanged) this.updateQueueLock();
  673. if (genresChanged) this.updateGenres();
  674. if (blacklistedGenresChanged) this.updateBlacklistedGenres();
  675. if (themeChanged) this.updateTheme();
  676. if (
  677. !nameChanged &&
  678. !displayNameChanged &&
  679. !descriptionChanged &&
  680. !privacyChanged &&
  681. !partyModeChanged &&
  682. !playModeChanged &&
  683. !queueLockChanged &&
  684. !genresChanged &&
  685. !blacklistedGenresChanged &&
  686. !themeChanged
  687. ) {
  688. this.$refs.saveButton.handleFailedSave();
  689. new Toast({
  690. content: "Please make a change before saving.",
  691. timeout: 8000
  692. });
  693. }
  694. },
  695. updateName() {
  696. const { name } = this.station;
  697. if (!validation.isLength(name, 2, 16))
  698. return new Toast({
  699. content: "Name must have between 2 and 16 characters.",
  700. timeout: 8000
  701. });
  702. if (!validation.regex.az09_.test(name))
  703. return new Toast({
  704. content:
  705. "Invalid name format. Allowed characters: a-z, 0-9 and _.",
  706. timeout: 8000
  707. });
  708. this.$refs.saveButton.status = "disabled";
  709. return this.socket.dispatch(
  710. "stations.updateName",
  711. this.station._id,
  712. name,
  713. res => {
  714. new Toast({ content: res.message, timeout: 8000 });
  715. if (res.status === "success") {
  716. this.originalStation.name = name;
  717. return this.$refs.saveButton.handleSuccessfulSave();
  718. }
  719. return this.$refs.saveButton.handleFailedSave();
  720. }
  721. );
  722. },
  723. updateDisplayName() {
  724. const { displayName } = this.station;
  725. if (!validation.isLength(displayName, 2, 32))
  726. return new Toast({
  727. content:
  728. "Display name must have between 2 and 32 characters.",
  729. timeout: 8000
  730. });
  731. if (!validation.regex.ascii.test(displayName))
  732. return new Toast({
  733. content:
  734. "Invalid display name format. Only ASCII characters are allowed.",
  735. timeout: 8000
  736. });
  737. this.$refs.saveButton.status = "disabled";
  738. return this.socket.dispatch(
  739. "stations.updateDisplayName",
  740. this.station._id,
  741. displayName,
  742. res => {
  743. new Toast({ content: res.message, timeout: 8000 });
  744. if (res.status === "success") {
  745. this.originalStation.displayName = displayName;
  746. return this.$refs.saveButton.handleSuccessfulSave();
  747. }
  748. return this.$refs.saveButton.handleFailedSave();
  749. }
  750. );
  751. },
  752. updateDescription() {
  753. const { description } = this.station;
  754. if (!validation.isLength(description, 2, 200))
  755. return new Toast({
  756. content:
  757. "Description must have between 2 and 200 characters.",
  758. timeout: 8000
  759. });
  760. let characters = description.split("");
  761. characters = characters.filter(character => {
  762. return character.charCodeAt(0) === 21328;
  763. });
  764. if (characters.length !== 0)
  765. return new Toast({
  766. content: "Invalid description format.",
  767. timeout: 8000
  768. });
  769. this.$refs.saveButton.status = "disabled";
  770. return this.socket.dispatch(
  771. "stations.updateDescription",
  772. this.station._id,
  773. description,
  774. res => {
  775. new Toast({ content: res.message, timeout: 8000 });
  776. if (res.status === "success") {
  777. this.originalStation.description = description;
  778. return this.$refs.saveButton.handleSuccessfulSave();
  779. }
  780. return this.$refs.saveButton.handleFailedSave();
  781. }
  782. );
  783. },
  784. updatePrivacyLocal(privacy) {
  785. if (this.station.privacy === privacy) return;
  786. this.station.privacy = privacy;
  787. this.privacyDropdownActive = false;
  788. },
  789. updatePrivacy() {
  790. this.$refs.saveButton.status = "disabled";
  791. this.socket.dispatch(
  792. "stations.updatePrivacy",
  793. this.station._id,
  794. this.station.privacy,
  795. res => {
  796. new Toast({ content: res.message, timeout: 8000 });
  797. if (res.status === "success") {
  798. this.originalStation.privacy = this.station.privacy;
  799. return this.$refs.saveButton.handleSuccessfulSave();
  800. }
  801. return this.$refs.saveButton.handleFailedSave();
  802. }
  803. );
  804. },
  805. updateGenres() {
  806. this.$refs.saveButton.status = "disabled";
  807. this.socket.dispatch(
  808. "stations.updateGenres",
  809. this.station._id,
  810. this.station.genres,
  811. res => {
  812. new Toast({ content: res.message, timeout: 8000 });
  813. if (res.status === "success") {
  814. const genres = JSON.parse(
  815. JSON.stringify(this.station.genres)
  816. );
  817. if (this.originalStation)
  818. this.originalStation.genres = genres;
  819. return this.$refs.saveButton.handleSuccessfulSave();
  820. }
  821. return this.$refs.saveButton.handleFailedSave();
  822. }
  823. );
  824. },
  825. updateBlacklistedGenres() {
  826. this.$refs.saveButton.status = "disabled";
  827. this.socket.dispatch(
  828. "stations.updateBlacklistedGenres",
  829. this.station._id,
  830. this.station.blacklistedGenres,
  831. res => {
  832. new Toast({ content: res.message, timeout: 8000 });
  833. if (res.status === "success") {
  834. const blacklistedGenres = JSON.parse(
  835. JSON.stringify(this.station.blacklistedGenres)
  836. );
  837. this.originalStation.blacklistedGenres = blacklistedGenres;
  838. return this.$refs.saveButton.handleSuccessfulSave();
  839. }
  840. return this.$refs.saveButton.handleFailedSave();
  841. }
  842. );
  843. },
  844. updatePartyModeLocal(partyMode) {
  845. if (this.station.partyMode === partyMode) return;
  846. this.station.partyMode = partyMode;
  847. this.modeDropdownActive = false;
  848. },
  849. updatePartyMode() {
  850. this.$refs.saveButton.status = "disabled";
  851. this.socket.dispatch(
  852. "stations.updatePartyMode",
  853. this.station._id,
  854. this.station.partyMode,
  855. res => {
  856. new Toast({ content: res.message, timeout: 8000 });
  857. if (res.status === "success") {
  858. this.originalStation.partyMode = this.station.partyMode;
  859. return this.$refs.saveButton.handleSuccessfulSave();
  860. }
  861. return this.$refs.saveButton.handleFailedSave();
  862. }
  863. );
  864. },
  865. updatePlayModeLocal(playMode) {
  866. if (this.station.playMode === playMode) return;
  867. this.station.playMode = playMode;
  868. this.playModeDropdownActive = false;
  869. },
  870. updatePlayMode() {
  871. this.$refs.saveButton.status = "disabled";
  872. this.socket.dispatch(
  873. "stations.updatePlayMode",
  874. this.station._id,
  875. this.station.playMode,
  876. res => {
  877. new Toast({ content: res.message, timeout: 8000 });
  878. if (res.status === "success") {
  879. this.originalStation.playMode = this.station.playMode;
  880. return this.$refs.saveButton.handleSuccessfulSave();
  881. }
  882. return this.$refs.saveButton.handleFailedSave();
  883. }
  884. );
  885. },
  886. updateQueueLockLocal(locked) {
  887. if (this.station.locked === locked) return;
  888. this.station.locked = locked;
  889. this.queueLockDropdownActive = false;
  890. },
  891. updateQueueLock() {
  892. this.$refs.saveButton.status = "disabled";
  893. this.socket.dispatch(
  894. "stations.toggleLock",
  895. this.station._id,
  896. res => {
  897. if (res.status === "success") {
  898. if (this.originalStation)
  899. this.originalStation.locked = res.data;
  900. new Toast({
  901. content: `Toggled queue lock successfully to ${res.data}`,
  902. timeout: 4000
  903. });
  904. return this.$refs.saveButton.handleSuccessfulSave();
  905. }
  906. new Toast({
  907. content: "Failed to toggle queue lock.",
  908. timeout: 8000
  909. });
  910. return this.$refs.saveButton.handleFailedSave();
  911. }
  912. );
  913. },
  914. updateThemeLocal(theme) {
  915. if (this.station.theme === theme) return;
  916. this.station.theme = theme;
  917. this.themeDropdownActive = false;
  918. },
  919. updateTheme() {
  920. this.$refs.saveButton.status = "disabled";
  921. this.socket.dispatch(
  922. "stations.updateTheme",
  923. this.station._id,
  924. this.station.theme,
  925. res => {
  926. new Toast({ content: res.message, timeout: 8000 });
  927. if (res.status === "success") {
  928. this.originalStation.theme = this.station.theme;
  929. return this.$refs.saveButton.handleSuccessfulSave();
  930. }
  931. return this.$refs.saveButton.handleFailedSave();
  932. }
  933. );
  934. },
  935. deleteStation() {
  936. this.socket.dispatch("stations.remove", this.station._id, res => {
  937. if (res.status === "success")
  938. this.closeModal({
  939. sector: "station",
  940. modal: "editStation"
  941. });
  942. return new Toast({ content: res.message, timeout: 8000 });
  943. });
  944. },
  945. blurGenreInput() {
  946. this.genreInputFocussed = false;
  947. },
  948. focusGenreInput() {
  949. this.genreInputFocussed = true;
  950. },
  951. keydownGenreInput() {
  952. clearTimeout(this.keydownGenreInputTimeout);
  953. this.keydownGenreInputTimeout = setTimeout(() => {
  954. if (this.genreInputValue.length > 1) {
  955. this.genreAutosuggestItems = this.genres.filter(genre => {
  956. return genre
  957. .toLowerCase()
  958. .startsWith(this.genreInputValue.toLowerCase());
  959. });
  960. } else this.genreAutosuggestItems = [];
  961. }, 1000);
  962. },
  963. focusGenreContainer() {
  964. this.genreAutosuggestContainerFocussed = true;
  965. },
  966. blurGenreContainer() {
  967. this.genreAutosuggestContainerFocussed = false;
  968. },
  969. selectGenreAutosuggest(value) {
  970. this.genreInputValue = value;
  971. },
  972. blurBlacklistGenreInput() {
  973. this.blacklistGenreInputFocussed = false;
  974. },
  975. focusBlacklistGenreInput() {
  976. this.blacklistGenreInputFocussed = true;
  977. },
  978. keydownBlacklistGenreInput() {
  979. clearTimeout(this.keydownBlacklistGenreInputTimeout);
  980. this.keydownBlacklistGenreInputTimeout = setTimeout(() => {
  981. if (this.blacklistGenreInputValue.length > 1) {
  982. this.blacklistGenreAutosuggestItems = this.genres.filter(
  983. genre => {
  984. return genre
  985. .toLowerCase()
  986. .startsWith(
  987. this.blacklistGenreInputValue.toLowerCase()
  988. );
  989. }
  990. );
  991. } else this.blacklistGenreAutosuggestItems = [];
  992. }, 1000);
  993. },
  994. focusBlacklistGenreContainer() {
  995. this.blacklistGenreAutosuggestContainerFocussed = true;
  996. },
  997. blurBlacklistGenreContainer() {
  998. this.blacklistGenreAutosuggestContainerFocussed = false;
  999. },
  1000. selectBlacklistGenreAutosuggest(value) {
  1001. this.blacklistGenreInputValue = value;
  1002. },
  1003. addTag(type) {
  1004. if (type === "genres") {
  1005. const genre = this.genreInputValue.toLowerCase().trim();
  1006. if (this.station.genres.indexOf(genre) !== -1)
  1007. return new Toast({
  1008. content: "Genre already exists",
  1009. timeout: 3000
  1010. });
  1011. if (genre) {
  1012. this.station.genres.push(genre);
  1013. this.genreInputValue = "";
  1014. return false;
  1015. }
  1016. return new Toast({
  1017. content: "Genre cannot be empty",
  1018. timeout: 3000
  1019. });
  1020. }
  1021. if (type === "blacklist-genres") {
  1022. const genre = this.blacklistGenreInputValue
  1023. .toLowerCase()
  1024. .trim();
  1025. if (this.station.blacklistedGenres.indexOf(genre) !== -1)
  1026. return new Toast({
  1027. content: "Blacklist genre already exists",
  1028. timeout: 3000
  1029. });
  1030. if (genre) {
  1031. this.station.blacklistedGenres.push(genre);
  1032. this.blacklistGenreInputValue = "";
  1033. return false;
  1034. }
  1035. return new Toast({
  1036. content: "Blacklist genre cannot be empty",
  1037. timeout: 3000
  1038. });
  1039. }
  1040. return false;
  1041. },
  1042. removeTag(type, index) {
  1043. if (type === "genres") this.station.genres.splice(index, 1);
  1044. else if (type === "blacklist-genres")
  1045. this.station.blacklistedGenres.splice(index, 1);
  1046. },
  1047. ...mapActions("modals/editStation", ["editStation"]),
  1048. ...mapActions("modalVisibility", ["closeModal"])
  1049. }
  1050. };
  1051. </script>
  1052. <style lang="scss">
  1053. .edit-station-modal .modal-card-foot {
  1054. justify-content: flex-end;
  1055. }
  1056. </style>
  1057. <style lang="scss" scoped>
  1058. .night-mode {
  1059. .modal-card,
  1060. .modal-card-head,
  1061. .modal-card-body,
  1062. .modal-card-foot {
  1063. background-color: var(--dark-grey-3);
  1064. }
  1065. .section {
  1066. background-color: var(--dark-grey-3) !important;
  1067. border: 0 !important;
  1068. }
  1069. .label,
  1070. p,
  1071. strong {
  1072. color: var(--light-grey-2);
  1073. }
  1074. }
  1075. .modal-card-title {
  1076. text-align: center;
  1077. margin-left: 24px;
  1078. }
  1079. .custom-modal-body {
  1080. padding: 16px;
  1081. display: flex;
  1082. }
  1083. .section {
  1084. border: 1px solid var(--light-blue);
  1085. background-color: var(--light-grey);
  1086. border-radius: 5px;
  1087. padding: 16px;
  1088. }
  1089. .left-section {
  1090. width: 595px;
  1091. display: grid;
  1092. gap: 16px;
  1093. grid-template-rows: min-content min-content auto;
  1094. .control {
  1095. input {
  1096. width: 100%;
  1097. height: 36px;
  1098. }
  1099. .add-button {
  1100. width: 32px;
  1101. &.blue {
  1102. background-color: var(--primary-color) !important;
  1103. }
  1104. &.red {
  1105. background-color: var(--red) !important;
  1106. }
  1107. i {
  1108. font-size: 32px;
  1109. }
  1110. }
  1111. }
  1112. .col {
  1113. > div {
  1114. position: relative;
  1115. }
  1116. }
  1117. .list-item-circle {
  1118. width: 16px;
  1119. height: 16px;
  1120. border-radius: 8px;
  1121. cursor: pointer;
  1122. margin-right: 8px;
  1123. float: left;
  1124. -webkit-touch-callout: none;
  1125. -webkit-user-select: none;
  1126. -khtml-user-select: none;
  1127. -moz-user-select: none;
  1128. -ms-user-select: none;
  1129. user-select: none;
  1130. &.blue {
  1131. background-color: var(--primary-color);
  1132. i {
  1133. color: var(--primary-color);
  1134. }
  1135. }
  1136. &.red {
  1137. background-color: var(--red);
  1138. i {
  1139. color: var(--red);
  1140. }
  1141. }
  1142. i {
  1143. font-size: 14px;
  1144. margin-left: 1px;
  1145. }
  1146. }
  1147. .list-item-circle:hover,
  1148. .list-item-circle:focus {
  1149. i {
  1150. color: var(--white);
  1151. }
  1152. }
  1153. .list-item > p {
  1154. line-height: 16px;
  1155. word-wrap: break-word;
  1156. width: calc(100% - 24px);
  1157. left: 24px;
  1158. float: left;
  1159. margin-bottom: 8px;
  1160. }
  1161. .list-item:last-child > p {
  1162. margin-bottom: 0;
  1163. }
  1164. .autosuggest-container {
  1165. position: absolute;
  1166. background: var(--white);
  1167. width: calc(100% + 1px);
  1168. top: 57px;
  1169. z-index: 200;
  1170. overflow: auto;
  1171. max-height: 100%;
  1172. clear: both;
  1173. .autosuggest-item {
  1174. padding: 8px;
  1175. display: block;
  1176. border: 1px solid var(--light-grey-2);
  1177. margin-top: -1px;
  1178. line-height: 16px;
  1179. cursor: pointer;
  1180. -webkit-user-select: none;
  1181. -ms-user-select: none;
  1182. -moz-user-select: none;
  1183. user-select: none;
  1184. }
  1185. .autosuggest-item:hover,
  1186. .autosuggest-item:focus {
  1187. background-color: var(--light-grey);
  1188. }
  1189. .autosuggest-item:first-child {
  1190. border-top: none;
  1191. }
  1192. .autosuggest-item:last-child {
  1193. border-radius: 0 0 3px 3px;
  1194. }
  1195. }
  1196. }
  1197. .right-section {
  1198. width: 157px;
  1199. min-height: 515px;
  1200. margin-left: 16px;
  1201. display: grid;
  1202. gap: 16px;
  1203. grid-template-rows: min-content min-content min-content;
  1204. .button-wrapper {
  1205. display: flex;
  1206. flex-direction: column;
  1207. button {
  1208. width: 100%;
  1209. height: 36px;
  1210. border: 0;
  1211. border-radius: 3px;
  1212. font-size: 18px;
  1213. color: var(--white);
  1214. box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25);
  1215. display: block;
  1216. text-align: center;
  1217. justify-content: center;
  1218. display: inline-flex;
  1219. -ms-flex-align: center;
  1220. align-items: center;
  1221. -moz-user-select: none;
  1222. user-select: none;
  1223. cursor: pointer;
  1224. margin-bottom: 10px;
  1225. padding: 0;
  1226. text-transform: capitalize;
  1227. &.red {
  1228. background-color: var(--red);
  1229. }
  1230. &.green {
  1231. background-color: var(--green);
  1232. }
  1233. &.blue {
  1234. background-color: var(--blue);
  1235. }
  1236. &.orange {
  1237. background-color: var(--orange);
  1238. }
  1239. &.yellow {
  1240. background-color: var(--yellow);
  1241. }
  1242. &.purple {
  1243. background-color: var(--purple);
  1244. }
  1245. &.teal {
  1246. background-color: var(--teal);
  1247. }
  1248. i {
  1249. font-size: 20px;
  1250. margin-right: 4px;
  1251. }
  1252. }
  1253. }
  1254. }
  1255. .col {
  1256. display: grid;
  1257. grid-column-gap: 16px;
  1258. }
  1259. .col-1 {
  1260. grid-template-columns: auto;
  1261. }
  1262. .col-2 {
  1263. grid-template-columns: auto auto;
  1264. }
  1265. .slide-down-enter-active {
  1266. transition: transform 0.25s;
  1267. }
  1268. .slide-down-enter {
  1269. transform: translateY(-10px);
  1270. }
  1271. .modal-card {
  1272. overflow: auto;
  1273. }
  1274. .modal-card-body {
  1275. overflow: unset;
  1276. }
  1277. </style>