EditStation.vue 32 KB

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