EditStation.vue 29 KB

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