EditStation.vue 32 KB

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