EditStation.vue 27 KB

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