EditStation.vue 26 KB

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