Settings.vue 13 KB

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