1
0

Settings.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <div class="station-settings">
  3. <label class="label">Name</label>
  4. <div class="control is-expanded">
  5. <input class="input" type="text" v-model="localStation.name" />
  6. </div>
  7. <label class="label">Display Name</label>
  8. <div class="control is-expanded">
  9. <input
  10. class="input"
  11. type="text"
  12. v-model="localStation.displayName"
  13. />
  14. </div>
  15. <label class="label">Description</label>
  16. <div class="control is-expanded">
  17. <input
  18. class="input"
  19. type="text"
  20. v-model="localStation.description"
  21. />
  22. </div>
  23. <div class="settings-buttons">
  24. <div class="small-section">
  25. <label class="label">Theme</label>
  26. <div class="control is-expanded select">
  27. <select v-model="localStation.theme">
  28. <option value="blue" selected>Blue</option>
  29. <option value="purple">Purple</option>
  30. <option value="teal">Teal</option>
  31. <option value="orange">Orange</option>
  32. <option value="red">Red</option>
  33. </select>
  34. </div>
  35. </div>
  36. <div class="small-section">
  37. <label class="label">Privacy</label>
  38. <div class="control is-expanded select">
  39. <select v-model="localStation.privacy">
  40. <option value="public">Public</option>
  41. <option value="unlisted">Unlisted</option>
  42. <option value="private" selected>Private</option>
  43. </select>
  44. </div>
  45. </div>
  46. <div
  47. v-if="localStation.requests"
  48. class="requests-settings"
  49. :class="{ enabled: localStation.requests.enabled }"
  50. >
  51. <div class="toggle-row">
  52. <label class="label">
  53. Requests
  54. <info-icon
  55. tooltip="Allow users to add songs to the queue"
  56. />
  57. </label>
  58. <p class="is-expanded checkbox-control">
  59. <label class="switch">
  60. <input
  61. type="checkbox"
  62. id="toggle-requests"
  63. v-model="localStation.requests.enabled"
  64. />
  65. <span class="slider round"></span>
  66. </label>
  67. <label for="toggle-requests">
  68. <p>
  69. {{
  70. localStation.requests.enabled
  71. ? "Enabled"
  72. : "Disabled"
  73. }}
  74. </p>
  75. </label>
  76. </p>
  77. </div>
  78. <div v-if="localStation.requests.enabled" class="small-section">
  79. <label class="label">Minimum access</label>
  80. <div class="control is-expanded select">
  81. <select v-model="localStation.requests.access">
  82. <option value="owner" selected>Owner</option>
  83. <option value="user">User</option>
  84. </select>
  85. </div>
  86. </div>
  87. <div v-if="localStation.requests.enabled" class="small-section">
  88. <label class="label">Per user request limit</label>
  89. <div class="control is-expanded">
  90. <input
  91. class="input"
  92. type="number"
  93. min="1"
  94. max="50"
  95. v-model="localStation.requests.limit"
  96. />
  97. </div>
  98. </div>
  99. </div>
  100. <div
  101. v-if="localStation.autofill"
  102. class="autofill-settings"
  103. :class="{ enabled: localStation.autofill.enabled }"
  104. >
  105. <div class="toggle-row">
  106. <label class="label">
  107. Autofill
  108. <info-icon
  109. tooltip="Automatically fill the queue with songs"
  110. />
  111. </label>
  112. <p class="is-expanded checkbox-control">
  113. <label class="switch">
  114. <input
  115. type="checkbox"
  116. id="toggle-autofill"
  117. v-model="localStation.autofill.enabled"
  118. />
  119. <span class="slider round"></span>
  120. </label>
  121. <label for="toggle-autofill">
  122. <p>
  123. {{
  124. localStation.autofill.enabled
  125. ? "Enabled"
  126. : "Disabled"
  127. }}
  128. </p>
  129. </label>
  130. </p>
  131. </div>
  132. <div v-if="localStation.autofill.enabled" class="small-section">
  133. <label class="label">Song limit</label>
  134. <div class="control is-expanded">
  135. <input
  136. class="input"
  137. type="number"
  138. min="1"
  139. max="50"
  140. v-model="localStation.autofill.limit"
  141. />
  142. </div>
  143. </div>
  144. <div v-if="localStation.autofill.enabled" class="small-section">
  145. <label class="label">Play mode</label>
  146. <div class="control is-expanded select">
  147. <select v-model="localStation.autofill.mode">
  148. <option value="random" selected>Random</option>
  149. <option value="sequential">Sequential</option>
  150. </select>
  151. </div>
  152. </div>
  153. </div>
  154. </div>
  155. <button class="control is-expanded button is-primary" @click="update()">
  156. Save Changes
  157. </button>
  158. </div>
  159. </template>
  160. <script>
  161. import { mapGetters, mapActions } from "vuex";
  162. import Toast from "toasters";
  163. import { mapModalState, mapModalActions } from "@/vuex_helpers";
  164. import validation from "@/validation";
  165. export default {
  166. props: {
  167. modalUuid: { type: String, default: "" }
  168. },
  169. data() {
  170. return {
  171. localStation: {
  172. name: "",
  173. displayName: "",
  174. description: "",
  175. theme: "blue",
  176. privacy: "private",
  177. requests: {
  178. enabled: true,
  179. access: "owner",
  180. limit: 3
  181. },
  182. autofill: {
  183. enabled: true,
  184. limit: 30,
  185. mode: "random"
  186. }
  187. }
  188. };
  189. },
  190. computed: {
  191. ...mapModalState("modals/manageStation/MODAL_UUID", {
  192. station: state => state.station
  193. }),
  194. ...mapGetters({
  195. socket: "websockets/getSocket"
  196. })
  197. },
  198. mounted() {
  199. this.localStation = JSON.parse(JSON.stringify(this.station));
  200. },
  201. methods: {
  202. update() {
  203. if (
  204. JSON.stringify({
  205. name: this.localStation.name,
  206. displayName: this.localStation.displayName,
  207. description: this.localStation.description,
  208. theme: this.localStation.theme,
  209. privacy: this.localStation.privacy,
  210. requests: {
  211. enabled: this.localStation.requests.enabled,
  212. access: this.localStation.requests.access,
  213. limit: this.localStation.requests.limit
  214. },
  215. autofill: {
  216. enabled: this.localStation.autofill.enabled,
  217. limit: this.localStation.autofill.limit,
  218. mode: this.localStation.autofill.mode
  219. }
  220. }) !==
  221. JSON.stringify({
  222. name: this.station.name,
  223. displayName: this.station.displayName,
  224. description: this.station.description,
  225. theme: this.station.theme,
  226. privacy: this.station.privacy,
  227. requests: {
  228. enabled: this.station.requests.enabled,
  229. access: this.station.requests.access,
  230. limit: this.station.requests.limit
  231. },
  232. autofill: {
  233. enabled: this.station.autofill.enabled,
  234. limit: this.station.autofill.limit,
  235. mode: this.station.autofill.mode
  236. }
  237. })
  238. ) {
  239. const { name, displayName, description } = this.localStation;
  240. if (!validation.isLength(name, 2, 16))
  241. new Toast("Name must have between 2 and 16 characters.");
  242. else if (!validation.regex.az09_.test(name))
  243. new Toast(
  244. "Invalid name format. Allowed characters: a-z, 0-9 and _."
  245. );
  246. else if (!validation.isLength(displayName, 2, 32))
  247. new Toast(
  248. "Display name must have between 2 and 32 characters."
  249. );
  250. else if (!validation.regex.ascii.test(displayName))
  251. new Toast(
  252. "Invalid display name format. Only ASCII characters are allowed."
  253. );
  254. else if (!validation.isLength(description, 2, 200))
  255. new Toast(
  256. "Description must have between 2 and 200 characters."
  257. );
  258. else if (
  259. description
  260. .split("")
  261. .filter(character => character.charCodeAt(0) === 21328)
  262. .length !== 0
  263. )
  264. new Toast("Invalid description format.");
  265. else
  266. this.socket.dispatch(
  267. "stations.update",
  268. this.station._id,
  269. this.localStation,
  270. res => {
  271. new Toast(res.message);
  272. if (res.status === "success") {
  273. this.editStation(this.localStation);
  274. }
  275. }
  276. );
  277. } else {
  278. new Toast("Please make a change before saving.");
  279. }
  280. },
  281. onCloseModal() {
  282. this.closeModal("manageStation");
  283. },
  284. ...mapModalActions("modals/manageStation/MODAL_UUID", ["editStation"]),
  285. ...mapActions("modalVisibility", ["closeModal"])
  286. }
  287. };
  288. </script>
  289. <style lang="less" scoped>
  290. .night-mode {
  291. .requests-settings,
  292. .autofill-settings {
  293. background-color: var(--dark-grey-2) !important;
  294. }
  295. }
  296. .station-settings {
  297. .settings-buttons {
  298. display: flex;
  299. justify-content: center;
  300. flex-wrap: wrap;
  301. .small-section {
  302. width: calc(50% - 10px);
  303. min-width: 150px;
  304. margin: 5px auto;
  305. &:nth-child(odd) {
  306. margin-left: 0;
  307. }
  308. &:nth-child(even) {
  309. margin-right: 0;
  310. }
  311. }
  312. }
  313. .requests-settings,
  314. .autofill-settings {
  315. display: flex;
  316. flex-wrap: wrap;
  317. width: 100%;
  318. margin: 10px 0;
  319. padding: 10px;
  320. border-radius: @border-radius;
  321. box-shadow: @box-shadow;
  322. .toggle-row {
  323. display: flex;
  324. width: 100%;
  325. line-height: 36px;
  326. .label {
  327. font-size: 18px;
  328. margin: 0;
  329. }
  330. }
  331. .label {
  332. display: flex;
  333. flex-grow: 1;
  334. }
  335. .checkbox-control {
  336. justify-content: end;
  337. }
  338. .small-section {
  339. &:nth-child(even) {
  340. margin-left: 0;
  341. margin-right: auto;
  342. }
  343. &:nth-child(odd) {
  344. margin-left: auto;
  345. margin-right: 0;
  346. }
  347. }
  348. }
  349. }
  350. </style>