EditStation.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  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>
  231. <label class="label">Station 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
  268. v-if="station.type === 'community'"
  269. name="slide-down"
  270. >
  271. <button
  272. class="yellow"
  273. v-if="
  274. modeDropdownActive && !station.partyMode
  275. "
  276. @click="updatePartyModeLocal(true)"
  277. >
  278. <i class="material-icons">emoji_people</i>
  279. Party
  280. </button>
  281. </transition>
  282. </div>
  283. </div>
  284. <div>
  285. <label class="label">Play Mode</label>
  286. <div
  287. @mouseenter="playModeDropdownActive = true"
  288. @mouseleave="playModeDropdownActive = false"
  289. class="button-wrapper"
  290. >
  291. <button
  292. class="blue"
  293. @click="
  294. (station.type === 'official' &&
  295. station.playMode === 'random') ||
  296. station.playMode === 'sequential'
  297. ? updatePlayModeLocal('random')
  298. : updatePlayModeLocal('sequential')
  299. "
  300. >
  301. <i class="material-icons">{{
  302. station.playMode === "random"
  303. ? "shuffle"
  304. : "format_list_numbered"
  305. }}</i>
  306. {{
  307. station.playMode === "random"
  308. ? "Random"
  309. : "Sequential"
  310. }}
  311. </button>
  312. <transition name="slide-down">
  313. <button
  314. class="blue"
  315. v-if="
  316. playModeDropdownActive &&
  317. station.playMode === 'sequential'
  318. "
  319. @click="updatePlayModeLocal('random')"
  320. >
  321. <i class="material-icons">shuffle</i>
  322. Random
  323. </button>
  324. </transition>
  325. <transition
  326. v-if="station.type === 'community'"
  327. name="slide-down"
  328. >
  329. <button
  330. class="blue"
  331. v-if="
  332. playModeDropdownActive &&
  333. station.playMode === 'random'
  334. "
  335. @click="updatePlayModeLocal('sequential')"
  336. >
  337. <i class="material-icons"
  338. >format_list_numbered</i
  339. >
  340. Sequential
  341. </button>
  342. </transition>
  343. </div>
  344. </div>
  345. <div
  346. v-if="
  347. station.type === 'community' &&
  348. station.partyMode === true
  349. "
  350. >
  351. <label class="label">Queue lock</label>
  352. <div
  353. @mouseenter="queueLockDropdownActive = true"
  354. @mouseleave="queueLockDropdownActive = false"
  355. class="button-wrapper"
  356. >
  357. <button
  358. :class="{
  359. green: station.locked,
  360. red: !station.locked
  361. }"
  362. @click="
  363. station.locked
  364. ? updateQueueLockLocal(true)
  365. : updateQueueLockLocal(false)
  366. "
  367. >
  368. <i class="material-icons">{{
  369. station.locked ? "lock" : "lock_open"
  370. }}</i>
  371. {{ station.locked ? "Locked" : "Unlocked" }}
  372. </button>
  373. <transition name="slide-down">
  374. <button
  375. class="green"
  376. v-if="
  377. queueLockDropdownActive &&
  378. !station.locked
  379. "
  380. @click="updateQueueLockLocal(true)"
  381. >
  382. <i class="material-icons">lock</i>
  383. Locked
  384. </button>
  385. </transition>
  386. <transition name="slide-down">
  387. <button
  388. class="red"
  389. v-if="
  390. queueLockDropdownActive &&
  391. station.locked
  392. "
  393. @click="updateQueueLockLocal(false)"
  394. >
  395. <i class="material-icons">lock_open</i>
  396. Unlocked
  397. </button>
  398. </transition>
  399. </div>
  400. </div>
  401. <div>
  402. <label class="label">Theme</label>
  403. <div
  404. @mouseenter="themeDropdownActive = true"
  405. @mouseleave="themeDropdownActive = false"
  406. class="button-wrapper"
  407. >
  408. <button
  409. :class="station.theme"
  410. @click="updateThemeLocal(station.theme)"
  411. >
  412. <i class="material-icons">palette</i>
  413. {{ station.theme }}
  414. </button>
  415. <transition name="slide-down">
  416. <button
  417. class="blue"
  418. v-if="
  419. themeDropdownActive &&
  420. station.theme !== 'blue'
  421. "
  422. @click="updateThemeLocal('blue')"
  423. >
  424. <i class="material-icons">palette</i>
  425. Blue
  426. </button>
  427. </transition>
  428. <transition name="slide-down">
  429. <button
  430. class="purple"
  431. v-if="
  432. themeDropdownActive &&
  433. station.theme !== 'purple'
  434. "
  435. @click="updateThemeLocal('purple')"
  436. >
  437. <i class="material-icons">palette</i>
  438. Purple
  439. </button>
  440. </transition>
  441. <transition name="slide-down">
  442. <button
  443. class="teal"
  444. v-if="
  445. themeDropdownActive &&
  446. station.theme !== 'teal'
  447. "
  448. @click="updateThemeLocal('teal')"
  449. >
  450. <i class="material-icons">palette</i>
  451. Teal
  452. </button>
  453. </transition>
  454. <transition name="slide-down">
  455. <button
  456. class="orange"
  457. v-if="
  458. themeDropdownActive &&
  459. station.theme !== 'orange'
  460. "
  461. @click="updateThemeLocal('orange')"
  462. >
  463. <i class="material-icons">palette</i>
  464. Orange
  465. </button>
  466. </transition>
  467. </div>
  468. </div>
  469. </div>
  470. </div>
  471. </template>
  472. <template #footer>
  473. <save-button ref="saveButton" @clicked="saveChanges()" />
  474. <div class="right">
  475. <confirm @confirm="clearAndRefillStationQueue()">
  476. <a class="button is-danger">
  477. Clear and refill station queue
  478. </a>
  479. </confirm>
  480. <confirm
  481. v-if="station && station.type === 'community'"
  482. @confirm="deleteStation()"
  483. >
  484. <button class="button is-danger">Delete station</button>
  485. </confirm>
  486. </div>
  487. </template>
  488. </modal>
  489. </template>
  490. <script>
  491. import { mapState, mapGetters, mapActions } from "vuex";
  492. import Toast from "toasters";
  493. import validation from "@/validation";
  494. import Confirm from "@/components/Confirm.vue";
  495. import Modal from "../Modal.vue";
  496. import SaveButton from "../SaveButton.vue";
  497. export default {
  498. components: { Modal, Confirm, SaveButton },
  499. props: {
  500. stationId: { type: String, default: "" },
  501. sector: { type: String, default: "admin" }
  502. },
  503. data() {
  504. return {
  505. genreInputValue: "",
  506. genreInputFocussed: false,
  507. genreAutosuggestContainerFocussed: false,
  508. keydownGenreInputTimeout: 0,
  509. genreAutosuggestItems: [],
  510. blacklistGenreInputValue: "",
  511. blacklistGenreInputFocussed: false,
  512. blacklistGenreAutosuggestContainerFocussed: false,
  513. blacklistKeydownGenreInputTimeout: 0,
  514. blacklistGenreAutosuggestItems: [],
  515. privacyDropdownActive: false,
  516. modeDropdownActive: false,
  517. playModeDropdownActive: false,
  518. queueLockDropdownActive: false,
  519. themeDropdownActive: false,
  520. genres: [
  521. "Blues",
  522. "Country",
  523. "Disco",
  524. "Funk",
  525. "Hip-Hop",
  526. "Jazz",
  527. "Metal",
  528. "Oldies",
  529. "Other",
  530. "Pop",
  531. "Rap",
  532. "Reggae",
  533. "Rock",
  534. "Techno",
  535. "Trance",
  536. "Classical",
  537. "Instrumental",
  538. "House",
  539. "Electronic",
  540. "Christian Rap",
  541. "Lo-Fi",
  542. "Musical",
  543. "Rock 'n' Roll",
  544. "Opera",
  545. "Drum & Bass",
  546. "Club-House",
  547. "Indie",
  548. "Heavy Metal",
  549. "Christian rock",
  550. "Dubstep"
  551. ],
  552. privacyButtons: {
  553. public: {
  554. style: "green",
  555. iconName: "public"
  556. },
  557. private: {
  558. style: "red",
  559. iconName: "lock"
  560. },
  561. unlisted: {
  562. style: "orange",
  563. iconName: "link"
  564. }
  565. }
  566. };
  567. },
  568. computed: {
  569. // ...mapState("admin/stations", {
  570. // stations: state => state.stations
  571. // }),
  572. ...mapState("modals/editStation", {
  573. station: state => state.station,
  574. originalStation: state => state.originalStation
  575. }),
  576. ...mapGetters({
  577. socket: "websockets/getSocket"
  578. })
  579. },
  580. mounted() {
  581. this.socket.dispatch(`stations.getStationById`, this.stationId, res => {
  582. if (res.status === "success") {
  583. const { station } = res.data;
  584. // this.song = { ...song };
  585. // if (this.song.discogs === undefined)
  586. // this.song.discogs = null;
  587. this.editStation(station);
  588. // this.songDataLoaded = true;
  589. this.socket.dispatch(
  590. `stations.getStationIncludedPlaylistsById`,
  591. this.stationId,
  592. res => {
  593. if (res.status === "success") {
  594. this.setGenres(
  595. res.data.playlists.map(playlist => {
  596. if (playlist) {
  597. if (playlist.type === "genre")
  598. return playlist.createdFor;
  599. return `Playlist: ${playlist.name}`;
  600. }
  601. return "Unknown/Error";
  602. })
  603. );
  604. this.originalStation.genres = JSON.parse(
  605. JSON.stringify(this.station.genres)
  606. );
  607. }
  608. }
  609. );
  610. this.socket.dispatch(
  611. `stations.getStationExcludedPlaylistsById`,
  612. this.stationId,
  613. res => {
  614. if (res.status === "success") {
  615. this.setBlacklistedGenres(
  616. res.data.playlists.map(playlist => {
  617. if (playlist) {
  618. if (playlist.type === "genre")
  619. return playlist.createdFor;
  620. return `Playlist: ${playlist.name}`;
  621. }
  622. return "Unknown/Error";
  623. })
  624. );
  625. this.originalStation.blacklistedGenres = JSON.parse(
  626. JSON.stringify(this.station.blacklistedGenres)
  627. );
  628. }
  629. }
  630. );
  631. // this.station.genres = JSON.parse(
  632. // JSON.stringify(this.station.genres)
  633. // );
  634. // this.station.blacklistedGenres = JSON.parse(
  635. // JSON.stringify(this.station.blacklistedGenres)
  636. // );
  637. } else {
  638. new Toast("Station with that ID not found");
  639. this.closeModal("editStation");
  640. }
  641. });
  642. },
  643. beforeDestroy() {
  644. this.clearStation();
  645. },
  646. methods: {
  647. saveChanges() {
  648. const nameChanged = this.originalStation.name !== this.station.name;
  649. const displayNameChanged =
  650. this.originalStation.displayName !== this.station.displayName;
  651. const descriptionChanged =
  652. this.originalStation.description !== this.station.description;
  653. const privacyChanged =
  654. this.originalStation.privacy !== this.station.privacy;
  655. const partyModeChanged =
  656. this.originalStation.type === "community" &&
  657. this.originalStation.partyMode !== this.station.partyMode;
  658. const playModeChanged =
  659. this.originalStation.playMode !== this.station.playMode;
  660. const queueLockChanged =
  661. this.originalStation.type === "community" &&
  662. this.station.partyMode &&
  663. this.originalStation.locked !== this.station.locked;
  664. const genresChanged =
  665. this.originalStation.genres.toString() !==
  666. this.station.genres.toString();
  667. const blacklistedGenresChanged =
  668. this.originalStation.blacklistedGenres.toString() !==
  669. this.station.blacklistedGenres.toString();
  670. const themeChanged =
  671. this.originalStation.theme !== this.station.theme;
  672. if (nameChanged) this.updateName();
  673. if (displayNameChanged) this.updateDisplayName();
  674. if (descriptionChanged) this.updateDescription();
  675. if (privacyChanged) this.updatePrivacy();
  676. if (partyModeChanged) this.updatePartyMode();
  677. if (playModeChanged) this.updatePlayMode();
  678. if (queueLockChanged) this.updateQueueLock();
  679. if (genresChanged) this.updateGenres();
  680. if (blacklistedGenresChanged) this.updateBlacklistedGenres();
  681. if (themeChanged) this.updateTheme();
  682. if (
  683. !nameChanged &&
  684. !displayNameChanged &&
  685. !descriptionChanged &&
  686. !privacyChanged &&
  687. !partyModeChanged &&
  688. !playModeChanged &&
  689. !queueLockChanged &&
  690. !genresChanged &&
  691. !blacklistedGenresChanged &&
  692. !themeChanged
  693. ) {
  694. this.$refs.saveButton.handleFailedSave();
  695. new Toast("Please make a change before saving.");
  696. }
  697. },
  698. updateName() {
  699. const { name } = this.station;
  700. if (!validation.isLength(name, 2, 16))
  701. return new Toast("Name must have between 2 and 16 characters.");
  702. if (!validation.regex.az09_.test(name))
  703. return new Toast(
  704. "Invalid name format. Allowed characters: a-z, 0-9 and _."
  705. );
  706. this.$refs.saveButton.status = "disabled";
  707. return this.socket.dispatch(
  708. "stations.updateName",
  709. this.station._id,
  710. name,
  711. res => {
  712. new Toast(res.message);
  713. if (res.status === "success") {
  714. this.originalStation.name = name;
  715. return this.$refs.saveButton.handleSuccessfulSave();
  716. }
  717. return this.$refs.saveButton.handleFailedSave();
  718. }
  719. );
  720. },
  721. updateDisplayName() {
  722. const { displayName } = this.station;
  723. if (!validation.isLength(displayName, 2, 32))
  724. return new Toast(
  725. "Display name must have between 2 and 32 characters."
  726. );
  727. if (!validation.regex.ascii.test(displayName))
  728. return new Toast(
  729. "Invalid display name format. Only ASCII characters are allowed."
  730. );
  731. this.$refs.saveButton.status = "disabled";
  732. return this.socket.dispatch(
  733. "stations.updateDisplayName",
  734. this.station._id,
  735. displayName,
  736. res => {
  737. new Toast(res.message);
  738. if (res.status === "success") {
  739. this.originalStation.displayName = displayName;
  740. return this.$refs.saveButton.handleSuccessfulSave();
  741. }
  742. return this.$refs.saveButton.handleFailedSave();
  743. }
  744. );
  745. },
  746. updateDescription() {
  747. const { description } = this.station;
  748. if (!validation.isLength(description, 2, 200))
  749. return new Toast(
  750. "Description must have between 2 and 200 characters."
  751. );
  752. let characters = description.split("");
  753. characters = characters.filter(character => {
  754. return character.charCodeAt(0) === 21328;
  755. });
  756. if (characters.length !== 0)
  757. return new Toast("Invalid description format.");
  758. this.$refs.saveButton.status = "disabled";
  759. return this.socket.dispatch(
  760. "stations.updateDescription",
  761. this.station._id,
  762. description,
  763. res => {
  764. new Toast(res.message);
  765. if (res.status === "success") {
  766. this.originalStation.description = description;
  767. return this.$refs.saveButton.handleSuccessfulSave();
  768. }
  769. return this.$refs.saveButton.handleFailedSave();
  770. }
  771. );
  772. },
  773. updatePrivacyLocal(privacy) {
  774. if (this.station.privacy === privacy) return;
  775. this.station.privacy = privacy;
  776. this.privacyDropdownActive = false;
  777. },
  778. updatePrivacy() {
  779. this.$refs.saveButton.status = "disabled";
  780. this.socket.dispatch(
  781. "stations.updatePrivacy",
  782. this.station._id,
  783. this.station.privacy,
  784. res => {
  785. new Toast(res.message);
  786. if (res.status === "success") {
  787. this.originalStation.privacy = this.station.privacy;
  788. return this.$refs.saveButton.handleSuccessfulSave();
  789. }
  790. return this.$refs.saveButton.handleFailedSave();
  791. }
  792. );
  793. },
  794. updateGenres() {
  795. this.$refs.saveButton.status = "disabled";
  796. this.socket.dispatch(
  797. "stations.updateGenres",
  798. this.station._id,
  799. this.station.genres,
  800. res => {
  801. new Toast(res.message);
  802. if (res.status === "success") {
  803. const genres = JSON.parse(
  804. JSON.stringify(this.station.genres)
  805. );
  806. if (this.originalStation)
  807. this.originalStation.genres = genres;
  808. return this.$refs.saveButton.handleSuccessfulSave();
  809. }
  810. return this.$refs.saveButton.handleFailedSave();
  811. }
  812. );
  813. },
  814. updateBlacklistedGenres() {
  815. this.$refs.saveButton.status = "disabled";
  816. this.socket.dispatch(
  817. "stations.updateBlacklistedGenres",
  818. this.station._id,
  819. this.station.blacklistedGenres,
  820. res => {
  821. new Toast(res.message);
  822. if (res.status === "success") {
  823. const blacklistedGenres = JSON.parse(
  824. JSON.stringify(this.station.blacklistedGenres)
  825. );
  826. this.originalStation.blacklistedGenres = blacklistedGenres;
  827. return this.$refs.saveButton.handleSuccessfulSave();
  828. }
  829. return this.$refs.saveButton.handleFailedSave();
  830. }
  831. );
  832. },
  833. updatePartyModeLocal(partyMode) {
  834. if (this.station.partyMode === partyMode) return;
  835. this.station.partyMode = partyMode;
  836. this.modeDropdownActive = false;
  837. },
  838. updatePartyMode() {
  839. this.$refs.saveButton.status = "disabled";
  840. this.socket.dispatch(
  841. "stations.updatePartyMode",
  842. this.station._id,
  843. this.station.partyMode,
  844. res => {
  845. new Toast(res.message);
  846. if (res.status === "success") {
  847. this.originalStation.partyMode = this.station.partyMode;
  848. return this.$refs.saveButton.handleSuccessfulSave();
  849. }
  850. return this.$refs.saveButton.handleFailedSave();
  851. }
  852. );
  853. },
  854. updatePlayModeLocal(playMode) {
  855. if (this.station.playMode === playMode) return;
  856. this.station.playMode = playMode;
  857. this.playModeDropdownActive = false;
  858. },
  859. updatePlayMode() {
  860. this.$refs.saveButton.status = "disabled";
  861. this.socket.dispatch(
  862. "stations.updatePlayMode",
  863. this.station._id,
  864. this.station.playMode,
  865. res => {
  866. new Toast(res.message);
  867. if (res.status === "success") {
  868. this.originalStation.playMode = this.station.playMode;
  869. return this.$refs.saveButton.handleSuccessfulSave();
  870. }
  871. return this.$refs.saveButton.handleFailedSave();
  872. }
  873. );
  874. },
  875. updateQueueLockLocal(locked) {
  876. if (this.station.locked === locked) return;
  877. this.station.locked = locked;
  878. this.queueLockDropdownActive = false;
  879. },
  880. updateQueueLock() {
  881. this.$refs.saveButton.status = "disabled";
  882. this.socket.dispatch(
  883. "stations.toggleLock",
  884. this.station._id,
  885. res => {
  886. if (res.status === "success") {
  887. if (this.originalStation)
  888. this.originalStation.locked = res.data.locked;
  889. new Toast(
  890. `Toggled queue lock successfully to ${res.data.locked}`
  891. );
  892. return this.$refs.saveButton.handleSuccessfulSave();
  893. }
  894. new Toast("Failed to toggle queue lock.");
  895. return this.$refs.saveButton.handleFailedSave();
  896. }
  897. );
  898. },
  899. updateThemeLocal(theme) {
  900. if (this.station.theme === theme) return;
  901. this.station.theme = theme;
  902. this.themeDropdownActive = false;
  903. },
  904. updateTheme() {
  905. this.$refs.saveButton.status = "disabled";
  906. this.socket.dispatch(
  907. "stations.updateTheme",
  908. this.station._id,
  909. this.station.theme,
  910. res => {
  911. new Toast(res.message);
  912. if (res.status === "success") {
  913. this.originalStation.theme = this.station.theme;
  914. return this.$refs.saveButton.handleSuccessfulSave();
  915. }
  916. return this.$refs.saveButton.handleFailedSave();
  917. }
  918. );
  919. },
  920. deleteStation() {
  921. this.socket.dispatch("stations.remove", this.station._id, res => {
  922. if (res.status === "success") this.closeModal("editStation");
  923. return new Toast(res.message);
  924. });
  925. },
  926. blurGenreInput() {
  927. this.genreInputFocussed = false;
  928. },
  929. focusGenreInput() {
  930. this.genreInputFocussed = true;
  931. },
  932. keydownGenreInput() {
  933. clearTimeout(this.keydownGenreInputTimeout);
  934. this.keydownGenreInputTimeout = setTimeout(() => {
  935. if (this.genreInputValue.length > 1) {
  936. this.genreAutosuggestItems = this.genres.filter(genre => {
  937. return genre
  938. .toLowerCase()
  939. .startsWith(this.genreInputValue.toLowerCase());
  940. });
  941. } else this.genreAutosuggestItems = [];
  942. }, 1000);
  943. },
  944. focusGenreContainer() {
  945. this.genreAutosuggestContainerFocussed = true;
  946. },
  947. blurGenreContainer() {
  948. this.genreAutosuggestContainerFocussed = false;
  949. },
  950. selectGenreAutosuggest(value) {
  951. this.genreInputValue = value;
  952. },
  953. blurBlacklistGenreInput() {
  954. this.blacklistGenreInputFocussed = false;
  955. },
  956. focusBlacklistGenreInput() {
  957. this.blacklistGenreInputFocussed = true;
  958. },
  959. keydownBlacklistGenreInput() {
  960. clearTimeout(this.keydownBlacklistGenreInputTimeout);
  961. this.keydownBlacklistGenreInputTimeout = setTimeout(() => {
  962. if (this.blacklistGenreInputValue.length > 1) {
  963. this.blacklistGenreAutosuggestItems = this.genres.filter(
  964. genre => {
  965. return genre
  966. .toLowerCase()
  967. .startsWith(
  968. this.blacklistGenreInputValue.toLowerCase()
  969. );
  970. }
  971. );
  972. } else this.blacklistGenreAutosuggestItems = [];
  973. }, 1000);
  974. },
  975. focusBlacklistGenreContainer() {
  976. this.blacklistGenreAutosuggestContainerFocussed = true;
  977. },
  978. blurBlacklistGenreContainer() {
  979. this.blacklistGenreAutosuggestContainerFocussed = false;
  980. },
  981. selectBlacklistGenreAutosuggest(value) {
  982. this.blacklistGenreInputValue = value;
  983. },
  984. addTag(type) {
  985. if (type === "genres") {
  986. const genre = this.genreInputValue.toLowerCase().trim();
  987. if (this.station.genres.indexOf(genre) !== -1)
  988. return new Toast("Genre already exists");
  989. if (genre) {
  990. this.station.genres.push(genre);
  991. this.genreInputValue = "";
  992. return false;
  993. }
  994. return new Toast("Genre cannot be empty");
  995. }
  996. if (type === "blacklist-genres") {
  997. const genre = this.blacklistGenreInputValue
  998. .toLowerCase()
  999. .trim();
  1000. if (this.station.blacklistedGenres.indexOf(genre) !== -1)
  1001. return new Toast("Blacklist genre already exists");
  1002. if (genre) {
  1003. this.station.blacklistedGenres.push(genre);
  1004. this.blacklistGenreInputValue = "";
  1005. return false;
  1006. }
  1007. return new Toast("Blacklist genre cannot be empty");
  1008. }
  1009. return false;
  1010. },
  1011. removeTag(type, index) {
  1012. if (type === "genres") this.station.genres.splice(index, 1);
  1013. else if (type === "blacklist-genres")
  1014. this.station.blacklistedGenres.splice(index, 1);
  1015. },
  1016. clearAndRefillStationQueue() {
  1017. this.socket.dispatch(
  1018. "stations.clearAndRefillStationQueue",
  1019. this.station._id,
  1020. res => {
  1021. if (res.status !== "success")
  1022. new Toast({
  1023. content: `Error: ${res.message}`,
  1024. timeout: 8000
  1025. });
  1026. else new Toast({ content: res.message, timeout: 4000 });
  1027. }
  1028. );
  1029. },
  1030. ...mapActions("modals/editStation", [
  1031. "editStation",
  1032. "setGenres",
  1033. "setBlacklistedGenres",
  1034. "clearStation"
  1035. ]),
  1036. ...mapActions("modalVisibility", ["closeModal"])
  1037. }
  1038. };
  1039. </script>
  1040. <style lang="scss" scoped>
  1041. .night-mode {
  1042. .modal-card,
  1043. .modal-card-head,
  1044. .modal-card-body,
  1045. .modal-card-foot {
  1046. background-color: var(--dark-grey-3);
  1047. }
  1048. .section {
  1049. background-color: var(--dark-grey-3) !important;
  1050. border: 0 !important;
  1051. }
  1052. .label,
  1053. p,
  1054. strong {
  1055. color: var(--light-grey-2);
  1056. }
  1057. }
  1058. .modal-card-title {
  1059. text-align: center;
  1060. margin-left: 24px;
  1061. }
  1062. .custom-modal-body {
  1063. padding: 16px;
  1064. display: flex;
  1065. }
  1066. .section {
  1067. border: 1px solid var(--light-blue);
  1068. background-color: var(--light-grey);
  1069. border-radius: 5px;
  1070. padding: 16px;
  1071. }
  1072. .left-section {
  1073. width: 595px;
  1074. display: grid;
  1075. gap: 16px;
  1076. grid-template-rows: min-content min-content auto;
  1077. .control {
  1078. input {
  1079. width: 100%;
  1080. height: 36px;
  1081. }
  1082. .add-button {
  1083. width: 32px;
  1084. &.blue {
  1085. background-color: var(--primary-color) !important;
  1086. }
  1087. &.red {
  1088. background-color: var(--red) !important;
  1089. }
  1090. i {
  1091. font-size: 32px;
  1092. }
  1093. }
  1094. }
  1095. .col {
  1096. > div {
  1097. position: relative;
  1098. }
  1099. }
  1100. .list-item-circle {
  1101. width: 16px;
  1102. height: 16px;
  1103. border-radius: 8px;
  1104. cursor: pointer;
  1105. margin-right: 8px;
  1106. float: left;
  1107. -webkit-touch-callout: none;
  1108. -webkit-user-select: none;
  1109. -khtml-user-select: none;
  1110. -moz-user-select: none;
  1111. -ms-user-select: none;
  1112. user-select: none;
  1113. &.blue {
  1114. background-color: var(--primary-color);
  1115. i {
  1116. color: var(--primary-color);
  1117. }
  1118. }
  1119. &.red {
  1120. background-color: var(--red);
  1121. i {
  1122. color: var(--red);
  1123. }
  1124. }
  1125. i {
  1126. font-size: 14px;
  1127. margin-left: 1px;
  1128. }
  1129. }
  1130. .list-item-circle:hover,
  1131. .list-item-circle:focus {
  1132. i {
  1133. color: var(--white);
  1134. }
  1135. }
  1136. .list-item > p {
  1137. line-height: 16px;
  1138. word-wrap: break-word;
  1139. width: calc(100% - 24px);
  1140. left: 24px;
  1141. float: left;
  1142. margin-bottom: 8px;
  1143. }
  1144. .list-item:last-child > p {
  1145. margin-bottom: 0;
  1146. }
  1147. .autosuggest-container {
  1148. position: absolute;
  1149. background: var(--white);
  1150. width: calc(100% + 1px);
  1151. top: 57px;
  1152. z-index: 200;
  1153. overflow: auto;
  1154. max-height: 100%;
  1155. clear: both;
  1156. .autosuggest-item {
  1157. padding: 8px;
  1158. display: block;
  1159. border: 1px solid var(--light-grey-2);
  1160. margin-top: -1px;
  1161. line-height: 16px;
  1162. cursor: pointer;
  1163. -webkit-user-select: none;
  1164. -ms-user-select: none;
  1165. -moz-user-select: none;
  1166. user-select: none;
  1167. }
  1168. .autosuggest-item:hover,
  1169. .autosuggest-item:focus {
  1170. background-color: var(--light-grey);
  1171. }
  1172. .autosuggest-item:first-child {
  1173. border-top: none;
  1174. }
  1175. .autosuggest-item:last-child {
  1176. border-radius: 0 0 3px 3px;
  1177. }
  1178. }
  1179. }
  1180. .right-section {
  1181. width: 157px;
  1182. min-height: 515px;
  1183. margin-left: 16px;
  1184. display: grid;
  1185. gap: 16px;
  1186. grid-template-rows: min-content min-content min-content;
  1187. .button-wrapper {
  1188. display: flex;
  1189. flex-direction: column;
  1190. button {
  1191. width: 100%;
  1192. height: 36px;
  1193. border: 0;
  1194. border-radius: 3px;
  1195. font-size: 18px;
  1196. color: var(--white);
  1197. box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25);
  1198. display: block;
  1199. text-align: center;
  1200. justify-content: center;
  1201. display: inline-flex;
  1202. -ms-flex-align: center;
  1203. align-items: center;
  1204. -moz-user-select: none;
  1205. user-select: none;
  1206. cursor: pointer;
  1207. margin-bottom: 10px;
  1208. padding: 0;
  1209. text-transform: capitalize;
  1210. &.red {
  1211. background-color: var(--red);
  1212. }
  1213. &.green {
  1214. background-color: var(--green);
  1215. }
  1216. &.blue {
  1217. background-color: var(--blue);
  1218. }
  1219. &.orange {
  1220. background-color: var(--orange);
  1221. }
  1222. &.yellow {
  1223. background-color: var(--yellow);
  1224. }
  1225. &.purple {
  1226. background-color: var(--purple);
  1227. }
  1228. &.teal {
  1229. background-color: var(--teal);
  1230. }
  1231. i {
  1232. font-size: 20px;
  1233. margin-right: 4px;
  1234. }
  1235. }
  1236. }
  1237. }
  1238. .col {
  1239. display: grid;
  1240. grid-column-gap: 16px;
  1241. }
  1242. .col-1 {
  1243. grid-template-columns: auto;
  1244. }
  1245. .col-2 {
  1246. grid-template-columns: auto auto;
  1247. }
  1248. .slide-down-enter-active {
  1249. transition: transform 0.25s;
  1250. }
  1251. .slide-down-enter {
  1252. transform: translateY(-10px);
  1253. }
  1254. .modal-card {
  1255. overflow: auto;
  1256. }
  1257. .modal-card-body {
  1258. overflow: unset;
  1259. }
  1260. </style>