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