EditStation.vue 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. <template>
  2. <modal title="Edit Station" class="edit-station-modal">
  3. <template v-slot:body>
  4. <div class="section left-section">
  5. <div class="col col-2">
  6. <div>
  7. <label class="label">Name</label>
  8. <p class="control">
  9. <input
  10. class="input"
  11. type="text"
  12. v-model="editing.name"
  13. />
  14. </p>
  15. </div>
  16. <div>
  17. <label class="label">Display name</label>
  18. <p class="control">
  19. <input
  20. class="input"
  21. type="text"
  22. v-model="editing.displayName"
  23. />
  24. </p>
  25. </div>
  26. </div>
  27. <div class="col col-1">
  28. <div>
  29. <label class="label">Description</label>
  30. <p class="control">
  31. <input
  32. class="input"
  33. type="text"
  34. v-model="editing.description"
  35. />
  36. </p>
  37. </div>
  38. </div>
  39. <div class="col col-2" v-if="editing.genres">
  40. <div>
  41. <label class="label">Genre(s)</label>
  42. <p class="control has-addons">
  43. <input
  44. class="input"
  45. type="text"
  46. id="new-genre"
  47. v-model="genreInputValue"
  48. v-on:blur="blurGenreInput()"
  49. v-on:focus="focusGenreInput()"
  50. v-on:keydown="keydownGenreInput()"
  51. v-on:keyup.enter="addTag('genres')"
  52. />
  53. <button
  54. class="button is-info add-button blue"
  55. v-on:click="addTag('genres')"
  56. >
  57. <i class="material-icons">add</i>
  58. </button>
  59. </p>
  60. <div
  61. class="autosuggest-container"
  62. v-if="
  63. (genreInputFocussed ||
  64. genreAutosuggestContainerFocussed) &&
  65. genreAutosuggestItems.length > 0
  66. "
  67. @mouseover="focusGenreContainer()"
  68. @mouseleave="blurGenreContainer()"
  69. >
  70. <span
  71. class="autosuggest-item"
  72. tabindex="0"
  73. v-on:click="selectGenreAutosuggest(item)"
  74. v-for="(item, index) in genreAutosuggestItems"
  75. :key="index"
  76. >{{ item }}</span
  77. >
  78. </div>
  79. <div class="list-container">
  80. <div
  81. class="list-item"
  82. v-for="(genre, index) in editing.genres"
  83. :key="index"
  84. >
  85. <div
  86. class="list-item-circle blue"
  87. v-on:click="removeTag('genres', index)"
  88. >
  89. <i class="material-icons">close</i>
  90. </div>
  91. <p>{{ genre }}</p>
  92. </div>
  93. </div>
  94. </div>
  95. <div>
  96. <label class="label">Blacklist genre(s)</label>
  97. <p class="control has-addons">
  98. <input
  99. class="input"
  100. type="text"
  101. v-model="blacklistGenreInputValue"
  102. v-on:blur="blurBlacklistGenreInput()"
  103. v-on:focus="focusBlacklistGenreInput()"
  104. v-on:keydown="keydownBlacklistGenreInput()"
  105. v-on:keyup.enter="addTag('blacklist-genres')"
  106. />
  107. <button
  108. class="button is-info add-button red"
  109. v-on:click="addTag('blacklist-genres')"
  110. >
  111. <i class="material-icons">add</i>
  112. </button>
  113. </p>
  114. <div
  115. class="autosuggest-container"
  116. v-if="
  117. (blacklistGenreInputFocussed ||
  118. blacklistGenreAutosuggestContainerFocussed) &&
  119. blacklistGenreAutosuggestItems.length > 0
  120. "
  121. @mouseover="focusBlacklistGenreContainer()"
  122. @mouseleave="blurBlacklistGenreContainer()"
  123. >
  124. <span
  125. class="autosuggest-item"
  126. tabindex="0"
  127. v-on:click="
  128. selectBlacklistGenreAutosuggest(item)
  129. "
  130. v-for="(item,
  131. index) in blacklistGenreAutosuggestItems"
  132. :key="index"
  133. >{{ item }}</span
  134. >
  135. </div>
  136. <div class="list-container">
  137. <div
  138. class="list-item"
  139. v-for="(genre,
  140. index) in editing.blacklistedGenres"
  141. :key="index"
  142. >
  143. <div
  144. class="list-item-circle red"
  145. v-on:click="
  146. removeTag('blacklist-genres', index)
  147. "
  148. >
  149. <i class="material-icons">close</i>
  150. </div>
  151. <p>{{ genre }}</p>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. <div class="section right-section">
  158. <div>
  159. <label class="label">Privacy</label>
  160. <div
  161. @mouseenter="privacyDropdownActive = true"
  162. @mouseleave="privacyDropdownActive = false"
  163. class="button-wrapper"
  164. >
  165. <button
  166. v-bind:class="{
  167. green: true,
  168. current: editing.privacy === 'public'
  169. }"
  170. v-if="
  171. privacyDropdownActive ||
  172. editing.privacy === 'public'
  173. "
  174. @click="updatePrivacyLocal('public')"
  175. >
  176. <i class="material-icons">people</i>
  177. Public
  178. </button>
  179. <button
  180. v-bind:class="{
  181. orange: true,
  182. current: editing.privacy === 'unlisted'
  183. }"
  184. v-if="
  185. privacyDropdownActive ||
  186. editing.privacy === 'unlisted'
  187. "
  188. @click="updatePrivacyLocal('unlisted')"
  189. >
  190. <i class="material-icons">link</i>
  191. Unlisted
  192. </button>
  193. <button
  194. v-bind:class="{
  195. red: true,
  196. current: editing.privacy === 'private'
  197. }"
  198. v-if="
  199. privacyDropdownActive ||
  200. editing.privacy === 'private'
  201. "
  202. @click="updatePrivacyLocal('private')"
  203. >
  204. <i class="material-icons">lock</i>
  205. Private
  206. </button>
  207. </div>
  208. </div>
  209. <div v-if="editing.type === 'community'">
  210. <label class="label">Mode</label>
  211. <div
  212. @mouseenter="modeDropdownActive = true"
  213. @mouseleave="modeDropdownActive = false"
  214. class="button-wrapper"
  215. >
  216. <button
  217. v-bind:class="{
  218. blue: true,
  219. current: editing.partyMode === false
  220. }"
  221. v-if="modeDropdownActive || !editing.partyMode"
  222. @click="updatePartyModeLocal(false)"
  223. >
  224. <i class="material-icons">queue_music</i>
  225. Playlist
  226. </button>
  227. <button
  228. v-bind:class="{
  229. yellow: true,
  230. current: editing.partyMode === true
  231. }"
  232. v-if="
  233. modeDropdownActive || editing.partyMode === true
  234. "
  235. @click="updatePartyModeLocal(true)"
  236. >
  237. <i class="material-icons">post_add</i>
  238. Party
  239. </button>
  240. </div>
  241. </div>
  242. <div
  243. v-if="
  244. editing.type === 'community' &&
  245. editing.partyMode === true
  246. "
  247. >
  248. <label class="label">Queue lock</label>
  249. <div
  250. @mouseenter="queueLockDropdownActive = true"
  251. @mouseleave="queueLockDropdownActive = false"
  252. class="button-wrapper"
  253. >
  254. <button
  255. v-bind:class="{
  256. green: true,
  257. current: editing.locked
  258. }"
  259. v-if="queueLockDropdownActive || editing.locked"
  260. @click="updateQueueLockLocal(true)"
  261. >
  262. <i class="material-icons">done</i>
  263. On
  264. </button>
  265. <button
  266. v-bind:class="{
  267. red: true,
  268. current: !editing.locked
  269. }"
  270. v-if="queueLockDropdownActive || !editing.locked"
  271. @click="updateQueueLockLocal(false)"
  272. >
  273. <i class="material-icons">not_interested</i>
  274. Off
  275. </button>
  276. </div>
  277. </div>
  278. <div>
  279. <label class="label">Theme</label>
  280. <div
  281. @mouseenter="themeDropdownActive = true"
  282. @mouseleave="themeDropdownActive = false"
  283. class="button-wrapper"
  284. >
  285. <button
  286. v-bind:class="{
  287. blue: true,
  288. current: editing.theme === 'blue'
  289. }"
  290. v-if="
  291. themeDropdownActive || editing.theme === 'blue'
  292. "
  293. @click="updateThemeLocal('blue')"
  294. >
  295. <i class="material-icons">palette</i>
  296. Blue
  297. </button>
  298. <button
  299. v-bind:class="{
  300. purple: true,
  301. current: editing.theme === 'purple'
  302. }"
  303. v-if="
  304. themeDropdownActive ||
  305. editing.theme === 'purple'
  306. "
  307. @click="updateThemeLocal('purple')"
  308. >
  309. <i class="material-icons">palette</i>
  310. Purple
  311. </button>
  312. <button
  313. v-bind:class="{
  314. teal: true,
  315. current: editing.theme === 'teal'
  316. }"
  317. v-if="
  318. themeDropdownActive || editing.theme === 'teal'
  319. "
  320. @click="updateThemeLocal('teal')"
  321. >
  322. <i class="material-icons">palette</i>
  323. Teal
  324. </button>
  325. <button
  326. v-bind:class="{
  327. dark: true,
  328. current: editing.theme === 'dark'
  329. }"
  330. v-if="
  331. themeDropdownActive || editing.theme === 'dark'
  332. "
  333. @click="updateThemeLocal('dark')"
  334. >
  335. <i class="material-icons">palette</i>
  336. Dark
  337. </button>
  338. </div>
  339. </div>
  340. </div>
  341. </template>
  342. <template v-slot:footer>
  343. <button class="button is-success" v-on:click="update()">
  344. Update Settings
  345. </button>
  346. <button
  347. v-if="station.type === 'community'"
  348. class="button is-danger"
  349. @click="deleteStation()"
  350. >
  351. Delete station
  352. </button>
  353. </template>
  354. </modal>
  355. </template>
  356. <script>
  357. import { mapState, mapActions } from "vuex";
  358. import Toast from "toasters";
  359. import Modal from "./Modal.vue";
  360. import io from "../../io";
  361. import validation from "../../validation";
  362. export default {
  363. computed: mapState({
  364. editing(state) {
  365. return this.$props.store.split("/").reduce((a, v) => a[v], state)
  366. .editing;
  367. },
  368. station(state) {
  369. return this.$props.store.split("/").reduce((a, v) => a[v], state)
  370. .station;
  371. }
  372. }),
  373. mounted() {
  374. io.getSocket(socket => {
  375. this.socket = socket;
  376. return socket;
  377. });
  378. },
  379. data() {
  380. return {
  381. genreInputValue: "",
  382. genreInputFocussed: false,
  383. genreAutosuggestContainerFocussed: false,
  384. keydownGenreInputTimeout: 0,
  385. genreAutosuggestItems: [],
  386. blacklistGenreInputValue: "",
  387. blacklistGenreInputFocussed: false,
  388. blacklistGenreAutosuggestContainerFocussed: false,
  389. blacklistKeydownGenreInputTimeout: 0,
  390. blacklistGenreAutosuggestItems: [],
  391. privacyDropdownActive: false,
  392. modeDropdownActive: false,
  393. queueLockDropdownActive: false,
  394. themeDropdownActive: false,
  395. genres: [
  396. "Blues",
  397. "Country",
  398. "Disco",
  399. "Funk",
  400. "Hip-Hop",
  401. "Jazz",
  402. "Metal",
  403. "Oldies",
  404. "Other",
  405. "Pop",
  406. "Rap",
  407. "Reggae",
  408. "Rock",
  409. "Techno",
  410. "Trance",
  411. "Classical",
  412. "Instrumental",
  413. "House",
  414. "Electronic",
  415. "Christian Rap",
  416. "Lo-Fi",
  417. "Musical",
  418. "Rock 'n' Roll",
  419. "Opera",
  420. "Drum & Bass",
  421. "Club-House",
  422. "Indie",
  423. "Heavy Metal",
  424. "Christian rock",
  425. "Dubstep"
  426. ]
  427. };
  428. },
  429. props: ["store"],
  430. methods: {
  431. update() {
  432. if (this.station.name !== this.editing.name) this.updateName();
  433. if (this.station.displayName !== this.editing.displayName)
  434. this.updateDisplayName();
  435. if (this.station.description !== this.editing.description)
  436. this.updateDescription();
  437. if (this.station.privacy !== this.editing.privacy)
  438. this.updatePrivacy();
  439. if (this.station.theme !== this.editing.theme) this.updateTheme();
  440. if (
  441. this.station.type === "community" &&
  442. this.station.partyMode !== this.editing.partyMode
  443. )
  444. this.updatePartyMode();
  445. if (
  446. this.station.type === "community" &&
  447. this.editing.partyMode &&
  448. this.station.locked !== this.editing.locked
  449. )
  450. this.updateQueueLock();
  451. if (this.$props.store !== "station") {
  452. if (
  453. this.station.genres.toString() !==
  454. this.editing.genres.toString()
  455. )
  456. this.updateGenres();
  457. if (
  458. this.station.blacklistedGenres.toString() !==
  459. this.editing.blacklistedGenres.toString()
  460. )
  461. this.updateBlacklistedGenres();
  462. }
  463. },
  464. updateName() {
  465. const { name } = this.editing;
  466. if (!validation.isLength(name, 2, 16))
  467. return new Toast({
  468. content: "Name must have between 2 and 16 characters.",
  469. timeout: 8000
  470. });
  471. if (!validation.regex.az09_.test(name))
  472. return new Toast({
  473. content:
  474. "Invalid name format. Allowed characters: a-z, 0-9 and _.",
  475. timeout: 8000
  476. });
  477. return this.socket.emit(
  478. "stations.updateName",
  479. this.editing._id,
  480. name,
  481. res => {
  482. if (res.status === "success") {
  483. if (this.station) this.station.name = name;
  484. else {
  485. this.$parent.stations.forEach((station, index) => {
  486. if (station._id === this.editing._id) {
  487. this.$parent.stations[index].name = name;
  488. return name;
  489. }
  490. return false;
  491. });
  492. }
  493. }
  494. new Toast({ content: res.message, timeout: 8000 });
  495. }
  496. );
  497. },
  498. updateDisplayName() {
  499. const { displayName } = this.editing;
  500. if (!validation.isLength(displayName, 2, 32))
  501. return new Toast({
  502. content:
  503. "Display name must have between 2 and 32 characters.",
  504. timeout: 8000
  505. });
  506. if (!validation.regex.ascii.test(displayName))
  507. return new Toast({
  508. content:
  509. "Invalid display name format. Only ASCII characters are allowed.",
  510. timeout: 8000
  511. });
  512. return this.socket.emit(
  513. "stations.updateDisplayName",
  514. this.editing._id,
  515. displayName,
  516. res => {
  517. if (res.status === "success") {
  518. if (this.station)
  519. this.station.displayName = displayName;
  520. else {
  521. this.$parent.stations.forEach((station, index) => {
  522. if (station._id === this.editing._id) {
  523. this.$parent.stations[
  524. index
  525. ].displayName = displayName;
  526. return displayName;
  527. }
  528. return false;
  529. });
  530. }
  531. }
  532. new Toast({ content: res.message, timeout: 8000 });
  533. }
  534. );
  535. },
  536. updateDescription() {
  537. const { description } = this.editing;
  538. if (!validation.isLength(description, 2, 200))
  539. return new Toast({
  540. content:
  541. "Description must have between 2 and 200 characters.",
  542. timeout: 8000
  543. });
  544. let characters = description.split("");
  545. characters = characters.filter(character => {
  546. return character.charCodeAt(0) === 21328;
  547. });
  548. if (characters.length !== 0)
  549. return new Toast({
  550. content: "Invalid description format.",
  551. timeout: 8000
  552. });
  553. return this.socket.emit(
  554. "stations.updateDescription",
  555. this.editing._id,
  556. description,
  557. res => {
  558. if (res.status === "success") {
  559. if (this.station)
  560. this.station.description = description;
  561. else {
  562. this.$parent.stations.forEach((station, index) => {
  563. if (station._id === this.editing._id) {
  564. this.$parent.stations[
  565. index
  566. ].description = description;
  567. return description;
  568. }
  569. return false;
  570. });
  571. }
  572. return new Toast({
  573. content: res.message,
  574. timeout: 4000
  575. });
  576. }
  577. return new Toast({ content: res.message, timeout: 8000 });
  578. }
  579. );
  580. },
  581. updatePrivacyLocal(privacy) {
  582. if (this.editing.privacy === privacy) return;
  583. this.editing.privacy = privacy;
  584. this.privacyDropdownActive = false;
  585. },
  586. updatePrivacy() {
  587. this.socket.emit(
  588. "stations.updatePrivacy",
  589. this.editing._id,
  590. this.editing.privacy,
  591. res => {
  592. if (res.status === "success") {
  593. if (this.station)
  594. this.station.privacy = this.editing.privacy;
  595. else {
  596. this.$parent.stations.forEach((station, index) => {
  597. if (station._id === this.editing._id) {
  598. this.$parent.stations[
  599. index
  600. ].privacy = this.editing.privacy;
  601. return this.editing.privacy;
  602. }
  603. return false;
  604. });
  605. }
  606. return new Toast({
  607. content: res.message,
  608. timeout: 4000
  609. });
  610. }
  611. return new Toast({ content: res.message, timeout: 8000 });
  612. }
  613. );
  614. },
  615. updateGenres() {
  616. this.socket.emit(
  617. "stations.updateGenres",
  618. this.editing._id,
  619. this.editing.genres,
  620. res => {
  621. if (res.status === "success") {
  622. const genres = JSON.parse(
  623. JSON.stringify(this.editing.genres)
  624. );
  625. if (this.station) this.station.genres = genres;
  626. this.$parent.stations.forEach((station, index) => {
  627. if (station._id === this.editing._id) {
  628. this.$parent.stations[index].genres = genres;
  629. return genres;
  630. }
  631. return false;
  632. });
  633. return new Toast({
  634. content: res.message,
  635. timeout: 4000
  636. });
  637. }
  638. return new Toast({ content: res.message, timeout: 8000 });
  639. }
  640. );
  641. },
  642. updateBlacklistedGenres() {
  643. this.socket.emit(
  644. "stations.updateBlacklistedGenres",
  645. this.editing._id,
  646. this.editing.blacklistedGenres,
  647. res => {
  648. if (res.status === "success") {
  649. const blacklistedGenres = JSON.parse(
  650. JSON.stringify(this.editing.blacklistedGenres)
  651. );
  652. if (this.station)
  653. this.station.blacklistedGenres = blacklistedGenres;
  654. this.$parent.stations.forEach((station, index) => {
  655. if (station._id === this.editing._id) {
  656. this.$parent.stations[
  657. index
  658. ].blacklistedGenres = blacklistedGenres;
  659. return blacklistedGenres;
  660. }
  661. return false;
  662. });
  663. return new Toast({
  664. content: res.message,
  665. timeout: 4000
  666. });
  667. }
  668. return new Toast({ content: res.message, timeout: 8000 });
  669. }
  670. );
  671. },
  672. updatePartyModeLocal(partyMode) {
  673. if (this.editing.partyMode === partyMode) return;
  674. this.editing.partyMode = partyMode;
  675. this.modeDropdownActive = false;
  676. },
  677. updatePartyMode() {
  678. this.socket.emit(
  679. "stations.updatePartyMode",
  680. this.editing._id,
  681. this.editing.partyMode,
  682. res => {
  683. if (res.status === "success") {
  684. if (this.station)
  685. this.station.partyMode = this.editing.partyMode;
  686. // if (this.station)
  687. // this.station.partyMode = this.editing.partyMode;
  688. // this.$parent.stations.forEach((station, index) => {
  689. // if (station._id === this.editing._id) {
  690. // this.$parent.stations[
  691. // index
  692. // ].partyMode = this.editing.partyMode;
  693. // return this.editing.partyMode;
  694. // }
  695. // return false;
  696. // });
  697. return new Toast({
  698. content: res.message,
  699. timeout: 4000
  700. });
  701. }
  702. return new Toast({ content: res.message, timeout: 8000 });
  703. }
  704. );
  705. },
  706. updateQueueLockLocal(locked) {
  707. if (this.editing.locked === locked) return;
  708. this.editing.locked = locked;
  709. this.queueLockDropdownActive = false;
  710. },
  711. updateQueueLock() {
  712. this.socket.emit("stations.toggleLock", this.editing._id, res => {
  713. console.log(res);
  714. if (res.status === "success") {
  715. if (this.station) this.station.locked = res.data;
  716. return new Toast({
  717. content: `Toggled queue lock succesfully to ${res.data}`,
  718. timeout: 4000
  719. });
  720. }
  721. return new Toast({
  722. content: "Failed to toggle queue lock.",
  723. timeout: 8000
  724. });
  725. });
  726. },
  727. updateThemeLocal(theme) {
  728. if (this.editing.theme === theme) return;
  729. this.editing.theme = theme;
  730. this.themeDropdownActive = false;
  731. },
  732. updateTheme() {
  733. this.socket.emit(
  734. "stations.updateTheme",
  735. this.editing._id,
  736. this.editing.theme,
  737. res => {
  738. if (res.status === "success") {
  739. if (this.station)
  740. this.station.theme = this.editing.theme;
  741. else {
  742. this.$parent.stations.forEach((station, index) => {
  743. if (station._id === this.editing._id) {
  744. this.$parent.stations[
  745. index
  746. ].theme = this.editing.theme;
  747. return this.editing.theme;
  748. }
  749. return false;
  750. });
  751. }
  752. return new Toast({
  753. content: res.message,
  754. timeout: 4000
  755. });
  756. }
  757. return new Toast({ content: res.message, timeout: 8000 });
  758. }
  759. );
  760. },
  761. deleteStation() {
  762. this.socket.emit("stations.remove", this.editing._id, res => {
  763. if (res.status === "success")
  764. this.closeModal({
  765. sector: "station",
  766. modal: "editStation"
  767. });
  768. return new Toast({ content: res.message, timeout: 8000 });
  769. });
  770. },
  771. blurGenreInput() {
  772. this.genreInputFocussed = false;
  773. },
  774. focusGenreInput() {
  775. this.genreInputFocussed = true;
  776. },
  777. keydownGenreInput() {
  778. clearTimeout(this.keydownGenreInputTimeout);
  779. this.keydownGenreInputTimeout = setTimeout(() => {
  780. if (this.genreInputValue.length > 1) {
  781. this.genreAutosuggestItems = this.genres.filter(genre => {
  782. return genre
  783. .toLowerCase()
  784. .startsWith(this.genreInputValue.toLowerCase());
  785. });
  786. } else this.genreAutosuggestItems = [];
  787. }, 1000);
  788. },
  789. focusGenreContainer() {
  790. this.genreAutosuggestContainerFocussed = true;
  791. },
  792. blurGenreContainer() {
  793. this.genreAutosuggestContainerFocussed = false;
  794. },
  795. selectGenreAutosuggest(value) {
  796. this.genreInputValue = value;
  797. },
  798. blurBlacklistGenreInput() {
  799. this.blacklistGenreInputFocussed = false;
  800. },
  801. focusBlacklistGenreInput() {
  802. this.blacklistGenreInputFocussed = true;
  803. },
  804. keydownBlacklistGenreInput() {
  805. clearTimeout(this.keydownBlacklistGenreInputTimeout);
  806. this.keydownBlacklistGenreInputTimeout = setTimeout(() => {
  807. console.log(123, this.blacklistGenreInputValue);
  808. if (this.blacklistGenreInputValue.length > 1) {
  809. console.log(333);
  810. this.blacklistGenreAutosuggestItems = this.genres.filter(
  811. genre => {
  812. console.log(444);
  813. return genre
  814. .toLowerCase()
  815. .startsWith(
  816. this.blacklistGenreInputValue.toLowerCase()
  817. );
  818. }
  819. );
  820. } else this.blacklistGenreAutosuggestItems = [];
  821. }, 1000);
  822. },
  823. focusBlacklistGenreContainer() {
  824. this.blacklistGenreAutosuggestContainerFocussed = true;
  825. },
  826. blurBlacklistGenreContainer() {
  827. this.blacklistGenreAutosuggestContainerFocussed = false;
  828. },
  829. selectBlacklistGenreAutosuggest(value) {
  830. this.blacklistGenreInputValue = value;
  831. },
  832. addTag(type) {
  833. if (type === "genres") {
  834. const genre = this.genreInputValue.toLowerCase().trim();
  835. if (this.editing.genres.indexOf(genre) !== -1)
  836. return new Toast({
  837. content: "Genre already exists",
  838. timeout: 3000
  839. });
  840. if (genre) {
  841. this.editing.genres.push(genre);
  842. this.genreInputValue = "";
  843. return false;
  844. }
  845. return new Toast({
  846. content: "Genre cannot be empty",
  847. timeout: 3000
  848. });
  849. }
  850. if (type === "blacklist-genres") {
  851. const genre = this.blacklistGenreInputValue
  852. .toLowerCase()
  853. .trim();
  854. if (this.editing.blacklistedGenres.indexOf(genre) !== -1)
  855. return new Toast({
  856. content: "Blacklist genre already exists",
  857. timeout: 3000
  858. });
  859. if (genre) {
  860. this.editing.blacklistedGenres.push(genre);
  861. this.blacklistGenreInputValue = "";
  862. return false;
  863. }
  864. return new Toast({
  865. content: "Blacklist genre cannot be empty",
  866. timeout: 3000
  867. });
  868. }
  869. return false;
  870. },
  871. removeTag(type, index) {
  872. if (type === "genres") this.editing.genres.splice(index, 1);
  873. else if (type === "blacklist-genres")
  874. this.editing.blacklistedGenres.splice(index, 1);
  875. },
  876. ...mapActions("modals", ["closeModal"])
  877. },
  878. components: { Modal }
  879. };
  880. </script>
  881. <style lang="scss">
  882. .edit-station-modal {
  883. .modal-card-title {
  884. text-align: center;
  885. margin-left: 24px;
  886. }
  887. .modal-card {
  888. width: 800px;
  889. height: 550px;
  890. .modal-card-body {
  891. padding: 16px;
  892. display: flex;
  893. }
  894. }
  895. }
  896. </style>
  897. <style lang="scss" scoped>
  898. @import "scss/variables/colors.scss";
  899. .section {
  900. border: 1px solid #a3e0ff;
  901. background-color: #f4f4f4;
  902. border-radius: 5px;
  903. padding: 16px;
  904. }
  905. .left-section {
  906. width: 595px;
  907. display: grid;
  908. gap: 16px;
  909. grid-template-rows: min-content min-content auto;
  910. .control {
  911. input {
  912. width: 100%;
  913. }
  914. .add-button {
  915. width: 32px;
  916. &.blue {
  917. background-color: $musareBlue !important;
  918. }
  919. &.red {
  920. background-color: $red !important;
  921. }
  922. i {
  923. font-size: 32px;
  924. }
  925. }
  926. }
  927. .col {
  928. > div {
  929. position: relative;
  930. }
  931. }
  932. .list-item-circle {
  933. width: 16px;
  934. height: 16px;
  935. border-radius: 8px;
  936. cursor: pointer;
  937. margin-right: 8px;
  938. float: left;
  939. -webkit-touch-callout: none;
  940. -webkit-user-select: none;
  941. -khtml-user-select: none;
  942. -moz-user-select: none;
  943. -ms-user-select: none;
  944. user-select: none;
  945. &.blue {
  946. background-color: $musareBlue;
  947. i {
  948. color: $musareBlue;
  949. }
  950. }
  951. &.red {
  952. background-color: $red;
  953. i {
  954. color: $red;
  955. }
  956. }
  957. i {
  958. font-size: 14px;
  959. margin-left: 1px;
  960. }
  961. }
  962. .list-item-circle:hover,
  963. .list-item-circle:focus {
  964. i {
  965. color: white;
  966. }
  967. }
  968. .list-item > p {
  969. line-height: 16px;
  970. word-wrap: break-word;
  971. width: calc(100% - 24px);
  972. left: 24px;
  973. float: left;
  974. margin-bottom: 8px;
  975. }
  976. .list-item:last-child > p {
  977. margin-bottom: 0;
  978. }
  979. .autosuggest-container {
  980. position: absolute;
  981. background: white;
  982. width: calc(100% + 1px);
  983. top: 57px;
  984. z-index: 200;
  985. overflow: auto;
  986. max-height: 100%;
  987. clear: both;
  988. .autosuggest-item {
  989. padding: 8px;
  990. display: block;
  991. border: 1px solid #dbdbdb;
  992. margin-top: -1px;
  993. line-height: 16px;
  994. cursor: pointer;
  995. -webkit-user-select: none;
  996. -ms-user-select: none;
  997. -moz-user-select: none;
  998. user-select: none;
  999. }
  1000. .autosuggest-item:hover,
  1001. .autosuggest-item:focus {
  1002. background-color: #eee;
  1003. }
  1004. .autosuggest-item:first-child {
  1005. border-top: none;
  1006. }
  1007. .autosuggest-item:last-child {
  1008. border-radius: 0 0 3px 3px;
  1009. }
  1010. }
  1011. }
  1012. .right-section {
  1013. width: 157px;
  1014. margin-left: 16px;
  1015. display: grid;
  1016. gap: 16px;
  1017. grid-template-rows: min-content min-content min-content;
  1018. .button-wrapper {
  1019. display: flex;
  1020. flex-direction: column;
  1021. }
  1022. button {
  1023. width: 100%;
  1024. height: 36px;
  1025. border: 0;
  1026. border-radius: 10px;
  1027. font-size: 18px;
  1028. color: white;
  1029. box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25);
  1030. display: block;
  1031. text-align: center;
  1032. justify-content: center;
  1033. display: inline-flex;
  1034. -ms-flex-align: center;
  1035. align-items: center;
  1036. -moz-user-select: none;
  1037. user-select: none;
  1038. cursor: pointer;
  1039. margin-bottom: 16px;
  1040. padding: 0;
  1041. &.current {
  1042. order: -1;
  1043. }
  1044. &.red {
  1045. &.current,
  1046. &:hover {
  1047. background-color: $red;
  1048. }
  1049. background-color: rgba($red, 0.7);
  1050. transition: all 0.3s ease-in-out;
  1051. }
  1052. &.green {
  1053. &.current,
  1054. &:hover {
  1055. background-color: $green;
  1056. }
  1057. background-color: rgba($green, 0.7);
  1058. transition: all 0.3s ease-in-out;
  1059. }
  1060. &.teal {
  1061. &.current,
  1062. &:hover {
  1063. background-color: $teal;
  1064. }
  1065. background-color: rgba($teal, 0.7);
  1066. transition: all 0.3s ease-in-out;
  1067. }
  1068. &.blue {
  1069. &.current,
  1070. &:hover {
  1071. background-color: $musareBlue;
  1072. }
  1073. background-color: rgba($musareBlue, 0.7);
  1074. transition: all 0.3s ease-in-out;
  1075. }
  1076. &.orange {
  1077. &.current,
  1078. &:hover {
  1079. background-color: $light-orange;
  1080. }
  1081. background-color: rgba($light-orange, 0.7);
  1082. transition: all 0.3s ease-in-out;
  1083. }
  1084. &.purple {
  1085. &.current,
  1086. &:hover {
  1087. background-color: $light-purple;
  1088. }
  1089. background-color: rgba($light-purple, 0.7);
  1090. transition: all 0.3s ease-in-out;
  1091. }
  1092. &.yellow {
  1093. &.current,
  1094. &:hover {
  1095. background-color: $yellow;
  1096. }
  1097. background-color: rgba($yellow, 0.7);
  1098. transition: all 0.3s ease-in-out;
  1099. }
  1100. &.dark {
  1101. &.current,
  1102. &:hover {
  1103. background-color: $dark-grey;
  1104. }
  1105. background-color: rgba($dark-grey, 0.7);
  1106. transition: all 0.3s ease-in-out;
  1107. }
  1108. i {
  1109. font-size: 20px;
  1110. margin-right: 4px;
  1111. }
  1112. }
  1113. }
  1114. .col {
  1115. display: grid;
  1116. grid-column-gap: 16px;
  1117. }
  1118. .col-1 {
  1119. grid-template-columns: auto;
  1120. }
  1121. .col-2 {
  1122. grid-template-columns: auto auto;
  1123. }
  1124. </style>