EditStation.vue 29 KB

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