EditStation.vue 32 KB

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