EditStation.vue 30 KB

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