Settings.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, watch } from "vue";
  3. import Toast from "toasters";
  4. import { storeToRefs } from "pinia";
  5. import validation from "@/validation";
  6. import { useWebsocketsStore } from "@/stores/websockets";
  7. import { useManageStationStore } from "@/stores/manageStation";
  8. import { useForm } from "@/composables/useForm";
  9. const InfoIcon = defineAsyncComponent(
  10. () => import("@/components/InfoIcon.vue")
  11. );
  12. const props = defineProps({
  13. modalUuid: { type: String, required: true }
  14. });
  15. const { socket } = useWebsocketsStore();
  16. const manageStationStore = useManageStationStore({
  17. modalUuid: props.modalUuid
  18. });
  19. const { station } = storeToRefs(manageStationStore);
  20. const { editStation } = manageStationStore;
  21. const { inputs, save, setOriginalValue } = useForm(
  22. {
  23. name: {
  24. value: station.value.name,
  25. validate: value => {
  26. if (!validation.isLength(value, 2, 16))
  27. return "Name must have between 2 and 16 characters.";
  28. if (!validation.regex.az09_.test(value))
  29. return "Invalid name format. Allowed characters: a-z, 0-9 and _.";
  30. return true;
  31. }
  32. },
  33. displayName: {
  34. value: station.value.displayName,
  35. validate: value => {
  36. if (!validation.isLength(value, 2, 32))
  37. return "Display name must have between 2 and 32 characters.";
  38. if (!validation.regex.ascii.test(value))
  39. return "Invalid display name format. Only ASCII characters are allowed.";
  40. return true;
  41. }
  42. },
  43. description: {
  44. value: station.value.description,
  45. validate: value => {
  46. if (
  47. value
  48. .split("")
  49. .filter(character => character.charCodeAt(0) === 21328)
  50. .length !== 0
  51. )
  52. return "Invalid description format.";
  53. return true;
  54. }
  55. },
  56. theme: station.value.theme,
  57. privacy: station.value.privacy,
  58. skipVoteThreshold: station.value.skipVoteThreshold,
  59. requestsEnabled: station.value.requests.enabled,
  60. requestsAccess: station.value.requests.access,
  61. requestsLimit: station.value.requests.limit,
  62. requestsAllowAutorequest: station.value.requests.allowAutorequest,
  63. requestsAutorequestLimit: station.value.requests.autorequestLimit,
  64. requestsAutorequestDisallowRecentlyPlayedEnabled:
  65. station.value.requests.autorequestDisallowRecentlyPlayedEnabled,
  66. requestsAutorequestDisallowRecentlyPlayedNumber:
  67. station.value.requests.autorequestDisallowRecentlyPlayedNumber,
  68. autofillEnabled: station.value.autofill.enabled,
  69. autofillLimit: station.value.autofill.limit,
  70. autofillMode: station.value.autofill.mode
  71. },
  72. ({ status, messages, values }, resolve, reject) => {
  73. if (status === "success") {
  74. const oldStation = JSON.parse(JSON.stringify(station.value));
  75. const updatedStation = {
  76. ...oldStation,
  77. name: values.name,
  78. displayName: values.displayName,
  79. description: values.description,
  80. theme: values.theme,
  81. privacy: values.privacy,
  82. skipVoteThreshold: values.skipVoteThreshold,
  83. requests: {
  84. ...oldStation.requests,
  85. enabled: values.requestsEnabled,
  86. access: values.requestsAccess,
  87. limit: values.requestsLimit,
  88. allowAutorequest: values.requestsAllowAutorequest,
  89. autorequestLimit: values.requestsAutorequestLimit,
  90. autorequestDisallowRecentlyPlayedEnabled:
  91. values.requestsAutorequestDisallowRecentlyPlayedEnabled,
  92. autorequestDisallowRecentlyPlayedNumber:
  93. values.requestsAutorequestDisallowRecentlyPlayedNumber
  94. },
  95. autofill: {
  96. ...oldStation.autofill,
  97. enabled: values.autofillEnabled,
  98. limit: values.autofillLimit,
  99. mode: values.autofillMode
  100. }
  101. };
  102. socket.dispatch(
  103. "stations.update",
  104. station.value._id,
  105. updatedStation,
  106. res => {
  107. new Toast(res.message);
  108. if (res.status === "success") {
  109. editStation(updatedStation);
  110. resolve();
  111. } else reject(new Error(res.message));
  112. }
  113. );
  114. } else {
  115. Object.values(messages).forEach(message => {
  116. new Toast({ content: message, timeout: 8000 });
  117. });
  118. resolve();
  119. }
  120. },
  121. {
  122. modalUuid: props.modalUuid
  123. }
  124. );
  125. watch(station, value => {
  126. setOriginalValue({
  127. name: value.name,
  128. displayName: value.displayName,
  129. description: value.description,
  130. theme: value.theme,
  131. privacy: value.privacy,
  132. skipVoteThreshold: value.skipVoteThreshold,
  133. requestsEnabled: value.requests.enabled,
  134. requestsAccess: value.requests.access,
  135. requestsLimit: value.requests.limit,
  136. requestsAllowAutorequest: value.requests.allowAutorequest,
  137. requestsAutorequestLimit: value.requests.autorequestLimit,
  138. requestsAutorequestDisallowRecentlyPlayedEnabled:
  139. value.requests.autorequestDisallowRecentlyPlayedEnabled,
  140. requestsAutorequestDisallowRecentlyPlayedNumber:
  141. value.requests.autorequestDisallowRecentlyPlayedNumber,
  142. autofillEnabled: value.autofill.enabled,
  143. autofillLimit: value.autofill.limit,
  144. autofillMode: value.autofill.mode
  145. });
  146. });
  147. </script>
  148. <template>
  149. <div class="station-settings">
  150. <label class="label">Name</label>
  151. <div class="control is-expanded">
  152. <input class="input" type="text" v-model="inputs['name'].value" />
  153. </div>
  154. <label class="label">Display Name</label>
  155. <div class="control is-expanded">
  156. <input
  157. class="input"
  158. type="text"
  159. v-model="inputs['displayName'].value"
  160. />
  161. </div>
  162. <label class="label">Description</label>
  163. <div class="control is-expanded">
  164. <input
  165. class="input"
  166. type="text"
  167. v-model="inputs['description'].value"
  168. />
  169. </div>
  170. <div class="settings-buttons">
  171. <div class="small-section">
  172. <label class="label">Theme</label>
  173. <div class="control is-expanded select">
  174. <select v-model="inputs['theme'].value">
  175. <option value="blue" selected>Blue</option>
  176. <option value="purple">Purple</option>
  177. <option value="teal">Teal</option>
  178. <option value="orange">Orange</option>
  179. <option value="red">Red</option>
  180. </select>
  181. </div>
  182. </div>
  183. <div class="small-section">
  184. <label class="label">Privacy</label>
  185. <div class="control is-expanded select">
  186. <select v-model="inputs['privacy'].value">
  187. <option value="public">Public</option>
  188. <option value="unlisted">Unlisted</option>
  189. <option value="private" selected>Private</option>
  190. </select>
  191. </div>
  192. </div>
  193. <div class="small-section">
  194. <label class="label">
  195. Skip Vote Threshold
  196. <info-icon
  197. tooltip="The % of logged-in station users required to vote to skip a song"
  198. />
  199. </label>
  200. <div class="control is-expanded input-slider">
  201. <input
  202. v-model="inputs['skipVoteThreshold'].value"
  203. type="range"
  204. min="0"
  205. max="100"
  206. />
  207. <span>{{ inputs["skipVoteThreshold"].value }}%</span>
  208. </div>
  209. </div>
  210. <div
  211. class="requests-settings"
  212. :class="{ enabled: inputs['requestsEnabled'].value }"
  213. >
  214. <div class="toggle-row">
  215. <label class="label">
  216. Requests
  217. <info-icon
  218. tooltip="Allow users to add songs to the queue"
  219. />
  220. </label>
  221. <p class="is-expanded checkbox-control">
  222. <label class="switch">
  223. <input
  224. type="checkbox"
  225. id="toggle-requests"
  226. v-model="inputs['requestsEnabled'].value"
  227. />
  228. <span class="slider round"></span>
  229. </label>
  230. <label for="toggle-requests">
  231. <p>
  232. {{
  233. inputs["requestsEnabled"].value
  234. ? "Enabled"
  235. : "Disabled"
  236. }}
  237. </p>
  238. </label>
  239. </p>
  240. </div>
  241. <div
  242. v-if="inputs['requestsEnabled'].value"
  243. class="small-section"
  244. >
  245. <label class="label">Minimum access</label>
  246. <div class="control is-expanded select">
  247. <select v-model="inputs['requestsAccess'].value">
  248. <option value="owner" selected>Owner</option>
  249. <option value="user">User</option>
  250. </select>
  251. </div>
  252. </div>
  253. <div
  254. v-if="inputs['requestsEnabled'].value"
  255. class="small-section"
  256. >
  257. <label class="label">Per user request limit</label>
  258. <div class="control is-expanded">
  259. <input
  260. class="input"
  261. type="number"
  262. min="1"
  263. max="50"
  264. v-model="inputs['requestsLimit'].value"
  265. />
  266. </div>
  267. </div>
  268. <div
  269. v-if="inputs['requestsEnabled'].value"
  270. class="small-section"
  271. >
  272. <label class="label">Allow autorequest</label>
  273. <p class="is-expanded checkbox-control">
  274. <label class="switch">
  275. <input
  276. type="checkbox"
  277. v-model="
  278. inputs['requestsAllowAutorequest'].value
  279. "
  280. />
  281. <span class="slider round"></span>
  282. </label>
  283. </p>
  284. </div>
  285. <div
  286. v-if="inputs['requestsEnabled'].value"
  287. class="small-section"
  288. >
  289. <label class="label">Per user autorequest limit</label>
  290. <div class="control is-expanded">
  291. <input
  292. class="input"
  293. type="number"
  294. min="1"
  295. max="50"
  296. v-model="inputs['requestsAutorequestLimit'].value"
  297. />
  298. </div>
  299. </div>
  300. <div
  301. v-if="inputs['requestsEnabled'].value"
  302. class="small-section"
  303. >
  304. <label class="label">Autorequest disallow recent</label>
  305. <p class="is-expanded checkbox-control">
  306. <label class="switch">
  307. <input
  308. type="checkbox"
  309. v-model="
  310. inputs[
  311. 'requestsAutorequestDisallowRecentlyPlayedEnabled'
  312. ].value
  313. "
  314. />
  315. <span class="slider round"></span>
  316. </label>
  317. </p>
  318. </div>
  319. <div
  320. v-if="inputs['requestsEnabled'].value"
  321. class="small-section"
  322. >
  323. <label class="label">Autorequest disallow recent #</label>
  324. <div class="control is-expanded">
  325. <input
  326. class="input"
  327. type="number"
  328. min="1"
  329. max="250"
  330. v-model="
  331. inputs[
  332. 'requestsAutorequestDisallowRecentlyPlayedNumber'
  333. ].value
  334. "
  335. />
  336. </div>
  337. </div>
  338. </div>
  339. <div
  340. class="autofill-settings"
  341. :class="{ enabled: inputs['autofillEnabled'].value }"
  342. >
  343. <div class="toggle-row">
  344. <label class="label">
  345. Autofill
  346. <info-icon
  347. tooltip="Automatically fill the queue with songs"
  348. />
  349. </label>
  350. <p class="is-expanded checkbox-control">
  351. <label class="switch">
  352. <input
  353. type="checkbox"
  354. id="toggle-autofill"
  355. v-model="inputs['autofillEnabled'].value"
  356. />
  357. <span class="slider round"></span>
  358. </label>
  359. <label for="toggle-autofill">
  360. <p>
  361. {{
  362. inputs["autofillEnabled"].value
  363. ? "Enabled"
  364. : "Disabled"
  365. }}
  366. </p>
  367. </label>
  368. </p>
  369. </div>
  370. <div
  371. v-if="inputs['autofillEnabled'].value"
  372. class="small-section"
  373. >
  374. <label class="label">Song limit</label>
  375. <div class="control is-expanded">
  376. <input
  377. class="input"
  378. type="number"
  379. min="1"
  380. max="50"
  381. v-model="inputs['autofillLimit'].value"
  382. />
  383. </div>
  384. </div>
  385. <div
  386. v-if="inputs['autofillEnabled'].value"
  387. class="small-section"
  388. >
  389. <label class="label">Play mode</label>
  390. <div class="control is-expanded select">
  391. <select v-model="inputs['autofillMode'].value">
  392. <option value="random" selected>Random</option>
  393. <option value="sequential">Sequential</option>
  394. </select>
  395. </div>
  396. </div>
  397. </div>
  398. </div>
  399. <button class="control is-expanded button is-primary" @click="save()">
  400. Save Changes
  401. </button>
  402. </div>
  403. </template>
  404. <style lang="less" scoped>
  405. .night-mode {
  406. .requests-settings,
  407. .autofill-settings {
  408. background-color: var(--dark-grey-2) !important;
  409. }
  410. }
  411. .station-settings {
  412. .settings-buttons {
  413. display: flex;
  414. justify-content: center;
  415. flex-wrap: wrap;
  416. .small-section {
  417. width: calc(50% - 10px);
  418. min-width: 150px;
  419. margin: 5px auto;
  420. &:nth-child(odd) {
  421. margin-left: 0;
  422. }
  423. &:nth-child(even) {
  424. margin-right: 0;
  425. }
  426. }
  427. }
  428. .input-slider {
  429. display: flex;
  430. input[type="range"] {
  431. -webkit-appearance: none;
  432. margin: 0;
  433. padding: 0;
  434. width: 100%;
  435. min-width: 100px;
  436. background: transparent;
  437. }
  438. input[type="range"]:focus {
  439. outline: none;
  440. }
  441. input[type="range"]::-webkit-slider-runnable-track {
  442. width: 100%;
  443. height: 5.2px;
  444. cursor: pointer;
  445. box-shadow: 0;
  446. background: var(--light-grey-3);
  447. border-radius: @border-radius;
  448. border: 0;
  449. }
  450. input[type="range"]::-webkit-slider-thumb {
  451. box-shadow: 0;
  452. border: 0;
  453. height: 19px;
  454. width: 19px;
  455. border-radius: 100%;
  456. background: var(--primary-color);
  457. cursor: pointer;
  458. -webkit-appearance: none;
  459. margin-top: -6.5px;
  460. }
  461. input[type="range"]::-moz-range-track {
  462. width: 100%;
  463. height: 5.2px;
  464. cursor: pointer;
  465. box-shadow: 0;
  466. background: var(--light-grey-3);
  467. border-radius: @border-radius;
  468. border: 0;
  469. }
  470. input[type="range"]::-moz-range-thumb {
  471. box-shadow: 0;
  472. border: 0;
  473. height: 19px;
  474. width: 19px;
  475. border-radius: 100%;
  476. background: var(--primary-color);
  477. cursor: pointer;
  478. -webkit-appearance: none;
  479. margin-top: -6.5px;
  480. }
  481. input[type="range"]::-ms-track {
  482. width: 100%;
  483. height: 5.2px;
  484. cursor: pointer;
  485. box-shadow: 0;
  486. background: var(--light-grey-3);
  487. border-radius: @border-radius;
  488. }
  489. input[type="range"]::-ms-fill-lower {
  490. background: var(--light-grey-3);
  491. border: 0;
  492. border-radius: 0;
  493. box-shadow: 0;
  494. }
  495. input[type="range"]::-ms-fill-upper {
  496. background: var(--light-grey-3);
  497. border: 0;
  498. border-radius: 0;
  499. box-shadow: 0;
  500. }
  501. input[type="range"]::-ms-thumb {
  502. box-shadow: 0;
  503. border: 0;
  504. height: 15px;
  505. width: 15px;
  506. border-radius: 100%;
  507. background: var(--primary-color);
  508. cursor: pointer;
  509. -webkit-appearance: none;
  510. margin-top: 1.5px;
  511. }
  512. & > span {
  513. min-width: 40px;
  514. margin-left: 10px;
  515. text-align: center;
  516. }
  517. }
  518. .requests-settings,
  519. .autofill-settings {
  520. display: flex;
  521. flex-wrap: wrap;
  522. width: 100%;
  523. margin: 10px 0;
  524. padding: 10px;
  525. border-radius: @border-radius;
  526. box-shadow: @box-shadow;
  527. .toggle-row {
  528. display: flex;
  529. width: 100%;
  530. line-height: 36px;
  531. .label {
  532. font-size: 18px;
  533. margin: 0;
  534. }
  535. }
  536. .label {
  537. display: flex;
  538. flex-grow: 1;
  539. }
  540. > .checkbox-control {
  541. justify-content: end;
  542. }
  543. .small-section {
  544. &:nth-child(even) {
  545. margin-left: 0;
  546. margin-right: auto;
  547. }
  548. &:nth-child(odd) {
  549. margin-left: auto;
  550. margin-right: 0;
  551. }
  552. .checkbox-control {
  553. justify-content: center;
  554. }
  555. }
  556. }
  557. }
  558. </style>