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