Settings.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 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 tooltip="Fill station queue with songs" />
  109. </label>
  110. <p class="is-expanded checkbox-control">
  111. <label class="switch">
  112. <input
  113. type="checkbox"
  114. id="toggle-autofill"
  115. v-model="localStation.autofill.enabled"
  116. />
  117. <span class="slider round"></span>
  118. </label>
  119. <label for="toggle-autofill">
  120. <p>
  121. {{
  122. localStation.autofill.enabled
  123. ? "Enabled"
  124. : "Disabled"
  125. }}
  126. </p>
  127. </label>
  128. </p>
  129. </div>
  130. <div v-if="localStation.autofill.enabled" class="small-section">
  131. <label class="label">Song limit</label>
  132. <div class="control is-expanded">
  133. <input
  134. class="input"
  135. type="number"
  136. min="1"
  137. max="50"
  138. v-model="localStation.autofill.limit"
  139. />
  140. </div>
  141. </div>
  142. <div v-if="localStation.autofill.enabled" class="small-section">
  143. <label class="label">Play mode</label>
  144. <div class="control is-expanded select">
  145. <select v-model="localStation.autofill.mode">
  146. <option value="random" selected>Random</option>
  147. <option value="sequential">Sequential</option>
  148. </select>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. <button class="control is-expanded button is-primary" @click="update()">
  154. Save Changes
  155. </button>
  156. </div>
  157. </template>
  158. <script>
  159. import { mapGetters, mapActions } from "vuex";
  160. import Toast from "toasters";
  161. import { mapModalState, mapModalActions } from "@/vuex_helpers";
  162. import validation from "@/validation";
  163. export default {
  164. props: {
  165. modalUuid: { type: String, default: "" }
  166. },
  167. data() {
  168. return {
  169. localStation: {
  170. name: "",
  171. displayName: "",
  172. description: "",
  173. theme: "blue",
  174. privacy: "private",
  175. requests: {
  176. enabled: true,
  177. access: "owner",
  178. limit: 3
  179. },
  180. autofill: {
  181. enabled: true,
  182. limit: 30,
  183. mode: "random"
  184. }
  185. }
  186. };
  187. },
  188. computed: {
  189. ...mapModalState("modals/manageStation/MODAL_UUID", {
  190. station: state => state.station
  191. }),
  192. ...mapGetters({
  193. socket: "websockets/getSocket"
  194. })
  195. },
  196. mounted() {
  197. this.localStation = JSON.parse(JSON.stringify(this.station));
  198. },
  199. methods: {
  200. update() {
  201. if (
  202. JSON.stringify({
  203. name: this.localStation.name,
  204. displayName: this.localStation.displayName,
  205. description: this.localStation.description,
  206. theme: this.localStation.theme,
  207. privacy: this.localStation.privacy,
  208. requests: {
  209. enabled: this.localStation.requests.enabled,
  210. access: this.localStation.requests.access,
  211. limit: this.localStation.requests.limit
  212. },
  213. autofill: {
  214. enabled: this.localStation.autofill.enabled,
  215. limit: this.localStation.autofill.limit,
  216. mode: this.localStation.autofill.mode
  217. }
  218. }) !==
  219. JSON.stringify({
  220. name: this.station.name,
  221. displayName: this.station.displayName,
  222. description: this.station.description,
  223. theme: this.station.theme,
  224. privacy: this.station.privacy,
  225. requests: {
  226. enabled: this.station.requests.enabled,
  227. access: this.station.requests.access,
  228. limit: this.station.requests.limit
  229. },
  230. autofill: {
  231. enabled: this.station.autofill.enabled,
  232. limit: this.station.autofill.limit,
  233. mode: this.station.autofill.mode
  234. }
  235. })
  236. ) {
  237. const { name, displayName, description } = this.localStation;
  238. if (!validation.isLength(name, 2, 16))
  239. new Toast("Name must have between 2 and 16 characters.");
  240. else if (!validation.regex.az09_.test(name))
  241. new Toast(
  242. "Invalid name format. Allowed characters: a-z, 0-9 and _."
  243. );
  244. else if (!validation.isLength(displayName, 2, 32))
  245. new Toast(
  246. "Display name must have between 2 and 32 characters."
  247. );
  248. else if (!validation.regex.ascii.test(displayName))
  249. new Toast(
  250. "Invalid display name format. Only ASCII characters are allowed."
  251. );
  252. else if (!validation.isLength(description, 2, 200))
  253. new Toast(
  254. "Description must have between 2 and 200 characters."
  255. );
  256. else if (
  257. description
  258. .split("")
  259. .filter(character => character.charCodeAt(0) === 21328)
  260. .length !== 0
  261. )
  262. new Toast("Invalid description format.");
  263. else
  264. this.socket.dispatch(
  265. "stations.update",
  266. this.station._id,
  267. this.localStation,
  268. res => {
  269. new Toast(res.message);
  270. if (res.status === "success") {
  271. this.editStation(this.localStation);
  272. }
  273. }
  274. );
  275. } else {
  276. new Toast("Please make a change before saving.");
  277. }
  278. },
  279. onCloseModal() {
  280. this.closeModal("manageStation");
  281. },
  282. ...mapModalActions("modals/manageStation/MODAL_UUID", ["editStation"]),
  283. ...mapActions("modalVisibility", ["closeModal"])
  284. }
  285. };
  286. </script>
  287. <style lang="less" scoped>
  288. .night-mode {
  289. .requests-settings,
  290. .autofill-settings {
  291. background-color: var(--dark-grey-2) !important;
  292. }
  293. }
  294. .station-settings {
  295. .settings-buttons {
  296. display: flex;
  297. justify-content: center;
  298. flex-wrap: wrap;
  299. .small-section {
  300. width: calc(50% - 10px);
  301. min-width: 150px;
  302. margin: 5px auto;
  303. &:nth-child(odd) {
  304. margin-left: 0;
  305. }
  306. &:nth-child(even) {
  307. margin-right: 0;
  308. }
  309. }
  310. }
  311. .requests-settings,
  312. .autofill-settings {
  313. display: flex;
  314. flex-wrap: wrap;
  315. width: 100%;
  316. margin: 10px 0;
  317. padding: 10px;
  318. border-radius: @border-radius;
  319. box-shadow: @box-shadow;
  320. .toggle-row {
  321. display: flex;
  322. width: 100%;
  323. line-height: 36px;
  324. .label {
  325. font-size: 18px;
  326. margin: 0;
  327. }
  328. }
  329. .label {
  330. display: flex;
  331. flex-grow: 1;
  332. }
  333. .checkbox-control {
  334. justify-content: end;
  335. }
  336. .small-section {
  337. &:nth-child(even) {
  338. margin-left: 0;
  339. margin-right: auto;
  340. }
  341. &:nth-child(odd) {
  342. margin-left: auto;
  343. margin-right: 0;
  344. }
  345. }
  346. }
  347. }
  348. </style>