Settings.vue 7.7 KB

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