EditStation.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  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.socket.emit(
  519. `stations.getStationIncludedPlaylistsById`,
  520. this.stationId,
  521. res => {
  522. if (res.status === "success") {
  523. this.station.genres = res.playlists.map(
  524. playlist => {
  525. if (playlist) {
  526. if (playlist.type === "genre")
  527. return playlist.createdFor;
  528. return `Playlist: ${playlist.name}`;
  529. }
  530. return "Unknown/Error";
  531. }
  532. );
  533. this.originalStation.genres = JSON.parse(
  534. JSON.stringify(this.station.genres)
  535. );
  536. }
  537. }
  538. );
  539. this.socket.emit(
  540. `stations.getStationExcludedPlaylistsById`,
  541. this.stationId,
  542. res => {
  543. if (res.status === "success") {
  544. this.station.blacklistedGenres = res.playlists.map(
  545. playlist => {
  546. if (playlist) {
  547. if (playlist.type === "genre")
  548. return playlist.createdFor;
  549. return `Playlist: ${playlist.name}`;
  550. }
  551. return "Unknown/Error";
  552. }
  553. );
  554. this.originalStation.blacklistedGenres = JSON.parse(
  555. JSON.stringify(
  556. this.station.blacklistedGenres
  557. )
  558. );
  559. }
  560. }
  561. );
  562. // this.station.genres = JSON.parse(
  563. // JSON.stringify(this.station.genres)
  564. // );
  565. // this.station.blacklistedGenres = JSON.parse(
  566. // JSON.stringify(this.station.blacklistedGenres)
  567. // );
  568. } else {
  569. new Toast({
  570. content: "Station with that ID not found",
  571. timeout: 3000
  572. });
  573. this.closeModal({
  574. sector: this.sector,
  575. modal: "editStation"
  576. });
  577. }
  578. });
  579. return socket;
  580. });
  581. },
  582. methods: {
  583. update() {
  584. if (this.originalStation.name !== this.station.name)
  585. this.updateName();
  586. if (this.originalStation.displayName !== this.station.displayName)
  587. this.updateDisplayName();
  588. if (this.originalStation.description !== this.station.description)
  589. this.updateDescription();
  590. if (this.originalStation.privacy !== this.station.privacy)
  591. this.updatePrivacy();
  592. if (
  593. this.originalStation.type === "community" &&
  594. this.originalStation.partyMode !== this.station.partyMode
  595. )
  596. this.updatePartyMode();
  597. if (
  598. this.originalStation.type === "community" &&
  599. this.station.partyMode &&
  600. this.originalStation.locked !== this.station.locked
  601. )
  602. this.updateQueueLock();
  603. if (
  604. this.originalStation.genres.toString() !==
  605. this.station.genres.toString()
  606. )
  607. this.updateGenres();
  608. if (
  609. this.originalStation.blacklistedGenres.toString() !==
  610. this.station.blacklistedGenres.toString()
  611. )
  612. this.updateBlacklistedGenres();
  613. if (this.originalStation.theme !== this.station.theme)
  614. this.updateTheme();
  615. },
  616. updateName() {
  617. const { name } = this.station;
  618. if (!validation.isLength(name, 2, 16))
  619. return new Toast({
  620. content: "Name must have between 2 and 16 characters.",
  621. timeout: 8000
  622. });
  623. if (!validation.regex.az09_.test(name))
  624. return new Toast({
  625. content:
  626. "Invalid name format. Allowed characters: a-z, 0-9 and _.",
  627. timeout: 8000
  628. });
  629. return this.socket.emit(
  630. "stations.updateName",
  631. this.station._id,
  632. name,
  633. res => {
  634. if (res.status === "success")
  635. this.originalStation.name = name;
  636. new Toast({ content: res.message, timeout: 8000 });
  637. }
  638. );
  639. },
  640. updateDisplayName() {
  641. const { displayName } = this.station;
  642. if (!validation.isLength(displayName, 2, 32))
  643. return new Toast({
  644. content:
  645. "Display name must have between 2 and 32 characters.",
  646. timeout: 8000
  647. });
  648. if (!validation.regex.ascii.test(displayName))
  649. return new Toast({
  650. content:
  651. "Invalid display name format. Only ASCII characters are allowed.",
  652. timeout: 8000
  653. });
  654. return this.socket.emit(
  655. "stations.updateDisplayName",
  656. this.station._id,
  657. displayName,
  658. res => {
  659. if (res.status === "success")
  660. this.originalStation.displayName = displayName;
  661. new Toast({ content: res.message, timeout: 8000 });
  662. }
  663. );
  664. },
  665. updateDescription() {
  666. const { description } = this.station;
  667. if (!validation.isLength(description, 2, 200))
  668. return new Toast({
  669. content:
  670. "Description must have between 2 and 200 characters.",
  671. timeout: 8000
  672. });
  673. let characters = description.split("");
  674. characters = characters.filter(character => {
  675. return character.charCodeAt(0) === 21328;
  676. });
  677. if (characters.length !== 0)
  678. return new Toast({
  679. content: "Invalid description format.",
  680. timeout: 8000
  681. });
  682. return this.socket.emit(
  683. "stations.updateDescription",
  684. this.station._id,
  685. description,
  686. res => {
  687. if (res.status === "success")
  688. this.originalStation.description = description;
  689. return new Toast({ content: res.message, timeout: 8000 });
  690. }
  691. );
  692. },
  693. updatePrivacyLocal(privacy) {
  694. if (this.station.privacy === privacy) return;
  695. this.station.privacy = privacy;
  696. this.privacyDropdownActive = false;
  697. },
  698. updatePrivacy() {
  699. this.socket.emit(
  700. "stations.updatePrivacy",
  701. this.station._id,
  702. this.station.privacy,
  703. res => {
  704. if (res.status === "success")
  705. this.originalStation.privacy = this.station.privacy;
  706. return new Toast({ content: res.message, timeout: 8000 });
  707. }
  708. );
  709. },
  710. updateGenres() {
  711. this.socket.emit(
  712. "stations.updateGenres",
  713. this.station._id,
  714. this.station.genres,
  715. res => {
  716. console.log(res);
  717. if (res.status === "success") {
  718. const genres = JSON.parse(
  719. JSON.stringify(this.station.genres)
  720. );
  721. if (this.originalStation)
  722. this.originalStation.genres = genres;
  723. return new Toast({
  724. content: res.message,
  725. timeout: 4000
  726. });
  727. }
  728. return new Toast({ content: res.message, timeout: 8000 });
  729. }
  730. );
  731. },
  732. updateBlacklistedGenres() {
  733. this.socket.emit(
  734. "stations.updateBlacklistedGenres",
  735. this.station._id,
  736. this.station.blacklistedGenres,
  737. res => {
  738. if (res.status === "success") {
  739. const blacklistedGenres = JSON.parse(
  740. JSON.stringify(this.station.blacklistedGenres)
  741. );
  742. this.originalStation.blacklistedGenres = blacklistedGenres;
  743. }
  744. return new Toast({ content: res.message, timeout: 8000 });
  745. }
  746. );
  747. },
  748. updatePartyModeLocal(partyMode) {
  749. if (this.station.partyMode === partyMode) return;
  750. this.station.partyMode = partyMode;
  751. this.modeDropdownActive = false;
  752. },
  753. updatePartyMode() {
  754. this.socket.emit(
  755. "stations.updatePartyMode",
  756. this.station._id,
  757. this.station.partyMode,
  758. res => {
  759. if (res.status === "success")
  760. this.originalStation.partyMode = this.station.partyMode;
  761. return new Toast({ content: res.message, timeout: 8000 });
  762. }
  763. );
  764. },
  765. updateQueueLockLocal(locked) {
  766. if (this.station.locked === locked) return;
  767. this.station.locked = locked;
  768. this.queueLockDropdownActive = false;
  769. },
  770. updateQueueLock() {
  771. this.socket.emit("stations.toggleLock", this.station._id, res => {
  772. console.log(res);
  773. if (res.status === "success") {
  774. if (this.originalStation)
  775. this.originalStation.locked = res.data;
  776. return new Toast({
  777. content: `Toggled queue lock successfully to ${res.data}`,
  778. timeout: 4000
  779. });
  780. }
  781. return new Toast({
  782. content: "Failed to toggle queue lock.",
  783. timeout: 8000
  784. });
  785. });
  786. },
  787. updateThemeLocal(theme) {
  788. if (this.station.theme === theme) return;
  789. this.station.theme = theme;
  790. this.themeDropdownActive = false;
  791. },
  792. updateTheme() {
  793. this.socket.emit(
  794. "stations.updateTheme",
  795. this.station._id,
  796. this.station.theme,
  797. res => {
  798. if (res.status === "success")
  799. this.originalStation.theme = this.station.theme;
  800. return new Toast({ content: res.message, timeout: 8000 });
  801. }
  802. );
  803. },
  804. deleteStation() {
  805. this.socket.emit("stations.remove", this.station._id, res => {
  806. if (res.status === "success")
  807. this.closeModal({
  808. sector: "station",
  809. modal: "editStation"
  810. });
  811. return new Toast({ content: res.message, timeout: 8000 });
  812. });
  813. },
  814. blurGenreInput() {
  815. this.genreInputFocussed = false;
  816. },
  817. focusGenreInput() {
  818. this.genreInputFocussed = true;
  819. },
  820. keydownGenreInput() {
  821. clearTimeout(this.keydownGenreInputTimeout);
  822. this.keydownGenreInputTimeout = setTimeout(() => {
  823. if (this.genreInputValue.length > 1) {
  824. this.genreAutosuggestItems = this.genres.filter(genre => {
  825. return genre
  826. .toLowerCase()
  827. .startsWith(this.genreInputValue.toLowerCase());
  828. });
  829. } else this.genreAutosuggestItems = [];
  830. }, 1000);
  831. },
  832. focusGenreContainer() {
  833. this.genreAutosuggestContainerFocussed = true;
  834. },
  835. blurGenreContainer() {
  836. this.genreAutosuggestContainerFocussed = false;
  837. },
  838. selectGenreAutosuggest(value) {
  839. this.genreInputValue = value;
  840. },
  841. blurBlacklistGenreInput() {
  842. this.blacklistGenreInputFocussed = false;
  843. },
  844. focusBlacklistGenreInput() {
  845. this.blacklistGenreInputFocussed = true;
  846. },
  847. keydownBlacklistGenreInput() {
  848. clearTimeout(this.keydownBlacklistGenreInputTimeout);
  849. this.keydownBlacklistGenreInputTimeout = setTimeout(() => {
  850. if (this.blacklistGenreInputValue.length > 1) {
  851. this.blacklistGenreAutosuggestItems = this.genres.filter(
  852. genre => {
  853. return genre
  854. .toLowerCase()
  855. .startsWith(
  856. this.blacklistGenreInputValue.toLowerCase()
  857. );
  858. }
  859. );
  860. } else this.blacklistGenreAutosuggestItems = [];
  861. }, 1000);
  862. },
  863. focusBlacklistGenreContainer() {
  864. this.blacklistGenreAutosuggestContainerFocussed = true;
  865. },
  866. blurBlacklistGenreContainer() {
  867. this.blacklistGenreAutosuggestContainerFocussed = false;
  868. },
  869. selectBlacklistGenreAutosuggest(value) {
  870. this.blacklistGenreInputValue = value;
  871. },
  872. addTag(type) {
  873. if (type === "genres") {
  874. const genre = this.genreInputValue.toLowerCase().trim();
  875. if (this.station.genres.indexOf(genre) !== -1)
  876. return new Toast({
  877. content: "Genre already exists",
  878. timeout: 3000
  879. });
  880. if (genre) {
  881. this.station.genres.push(genre);
  882. this.genreInputValue = "";
  883. return false;
  884. }
  885. return new Toast({
  886. content: "Genre cannot be empty",
  887. timeout: 3000
  888. });
  889. }
  890. if (type === "blacklist-genres") {
  891. const genre = this.blacklistGenreInputValue
  892. .toLowerCase()
  893. .trim();
  894. if (this.station.blacklistedGenres.indexOf(genre) !== -1)
  895. return new Toast({
  896. content: "Blacklist genre already exists",
  897. timeout: 3000
  898. });
  899. if (genre) {
  900. this.station.blacklistedGenres.push(genre);
  901. this.blacklistGenreInputValue = "";
  902. return false;
  903. }
  904. return new Toast({
  905. content: "Blacklist genre cannot be empty",
  906. timeout: 3000
  907. });
  908. }
  909. return false;
  910. },
  911. removeTag(type, index) {
  912. if (type === "genres") this.station.genres.splice(index, 1);
  913. else if (type === "blacklist-genres")
  914. this.station.blacklistedGenres.splice(index, 1);
  915. },
  916. ...mapActions("modals/editStation", ["editStation"]),
  917. ...mapActions("modalVisibility", ["closeModal"])
  918. }
  919. };
  920. </script>
  921. <style lang="scss" scoped>
  922. .night-mode {
  923. .modal-card,
  924. .modal-card-head,
  925. .modal-card-body,
  926. .modal-card-foot {
  927. background-color: var(--dark-grey-3);
  928. }
  929. .section {
  930. background-color: var(--dark-grey-3) !important;
  931. border: 0 !important;
  932. }
  933. .label,
  934. p,
  935. strong {
  936. color: var(--light-grey-2);
  937. }
  938. }
  939. .modal-card-title {
  940. text-align: center;
  941. margin-left: 24px;
  942. }
  943. .custom-modal-body {
  944. padding: 16px;
  945. display: flex;
  946. }
  947. .section {
  948. border: 1px solid var(--light-blue);
  949. background-color: var(--light-grey);
  950. border-radius: 5px;
  951. padding: 16px;
  952. }
  953. .left-section {
  954. width: 595px;
  955. display: grid;
  956. gap: 16px;
  957. grid-template-rows: min-content min-content auto;
  958. .control {
  959. input {
  960. width: 100%;
  961. height: 36px;
  962. }
  963. .add-button {
  964. width: 32px;
  965. &.blue {
  966. background-color: var(--primary-color) !important;
  967. }
  968. &.red {
  969. background-color: var(--red) !important;
  970. }
  971. i {
  972. font-size: 32px;
  973. }
  974. }
  975. }
  976. .col {
  977. > div {
  978. position: relative;
  979. }
  980. }
  981. .list-item-circle {
  982. width: 16px;
  983. height: 16px;
  984. border-radius: 8px;
  985. cursor: pointer;
  986. margin-right: 8px;
  987. float: left;
  988. -webkit-touch-callout: none;
  989. -webkit-user-select: none;
  990. -khtml-user-select: none;
  991. -moz-user-select: none;
  992. -ms-user-select: none;
  993. user-select: none;
  994. &.blue {
  995. background-color: var(--primary-color);
  996. i {
  997. color: var(--primary-color);
  998. }
  999. }
  1000. &.red {
  1001. background-color: var(--red);
  1002. i {
  1003. color: var(--red);
  1004. }
  1005. }
  1006. i {
  1007. font-size: 14px;
  1008. margin-left: 1px;
  1009. }
  1010. }
  1011. .list-item-circle:hover,
  1012. .list-item-circle:focus {
  1013. i {
  1014. color: var(--white);
  1015. }
  1016. }
  1017. .list-item > p {
  1018. line-height: 16px;
  1019. word-wrap: break-word;
  1020. width: calc(100% - 24px);
  1021. left: 24px;
  1022. float: left;
  1023. margin-bottom: 8px;
  1024. }
  1025. .list-item:last-child > p {
  1026. margin-bottom: 0;
  1027. }
  1028. .autosuggest-container {
  1029. position: absolute;
  1030. background: var(--white);
  1031. width: calc(100% + 1px);
  1032. top: 57px;
  1033. z-index: 200;
  1034. overflow: auto;
  1035. max-height: 100%;
  1036. clear: both;
  1037. .autosuggest-item {
  1038. padding: 8px;
  1039. display: block;
  1040. border: 1px solid var(--light-grey-2);
  1041. margin-top: -1px;
  1042. line-height: 16px;
  1043. cursor: pointer;
  1044. -webkit-user-select: none;
  1045. -ms-user-select: none;
  1046. -moz-user-select: none;
  1047. user-select: none;
  1048. }
  1049. .autosuggest-item:hover,
  1050. .autosuggest-item:focus {
  1051. background-color: var(--light-grey);
  1052. }
  1053. .autosuggest-item:first-child {
  1054. border-top: none;
  1055. }
  1056. .autosuggest-item:last-child {
  1057. border-radius: 0 0 3px 3px;
  1058. }
  1059. }
  1060. }
  1061. .right-section {
  1062. width: 157px;
  1063. min-height: 515px;
  1064. margin-left: 16px;
  1065. display: grid;
  1066. gap: 16px;
  1067. grid-template-rows: min-content min-content min-content;
  1068. .button-wrapper {
  1069. display: flex;
  1070. flex-direction: column;
  1071. button {
  1072. width: 100%;
  1073. height: 36px;
  1074. border: 0;
  1075. border-radius: 3px;
  1076. font-size: 18px;
  1077. color: var(--white);
  1078. box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25);
  1079. display: block;
  1080. text-align: center;
  1081. justify-content: center;
  1082. display: inline-flex;
  1083. -ms-flex-align: center;
  1084. align-items: center;
  1085. -moz-user-select: none;
  1086. user-select: none;
  1087. cursor: pointer;
  1088. margin-bottom: 10px;
  1089. padding: 0;
  1090. text-transform: capitalize;
  1091. &.red {
  1092. background-color: var(--red);
  1093. }
  1094. &.green {
  1095. background-color: var(--green);
  1096. }
  1097. &.blue {
  1098. background-color: var(--primary-color);
  1099. }
  1100. &.orange {
  1101. background-color: var(--orange);
  1102. }
  1103. &.yellow {
  1104. background-color: var(--yellow);
  1105. }
  1106. &.purple {
  1107. background-color: var(--purple);
  1108. }
  1109. &.teal {
  1110. background-color: var(--teal);
  1111. }
  1112. i {
  1113. font-size: 20px;
  1114. margin-right: 4px;
  1115. }
  1116. }
  1117. }
  1118. }
  1119. .col {
  1120. display: grid;
  1121. grid-column-gap: 16px;
  1122. }
  1123. .col-1 {
  1124. grid-template-columns: auto;
  1125. }
  1126. .col-2 {
  1127. grid-template-columns: auto auto;
  1128. }
  1129. .slide-down-enter-active {
  1130. transition: transform 0.25s;
  1131. }
  1132. .slide-down-enter {
  1133. transform: translateY(-10px);
  1134. }
  1135. .modal-card {
  1136. overflow: auto;
  1137. }
  1138. .modal-card-body {
  1139. overflow: unset;
  1140. }
  1141. </style>