EditStation.vue 32 KB

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