EditStation.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <modal title="Edit Station">
  3. <template v-slot:body>
  4. <label class="label">Name</label>
  5. <p class="control">
  6. <input
  7. v-model="editing.name"
  8. class="input"
  9. type="text"
  10. placeholder="Station Name"
  11. />
  12. </p>
  13. <label class="label">Display name</label>
  14. <p class="control">
  15. <input
  16. v-model="editing.displayName"
  17. class="input"
  18. type="text"
  19. placeholder="Station Display Name"
  20. />
  21. </p>
  22. <label class="label">Description</label>
  23. <p class="control">
  24. <input
  25. v-model="editing.description"
  26. class="input"
  27. type="text"
  28. placeholder="Station Description"
  29. />
  30. </p>
  31. <label class="label">Privacy</label>
  32. <p class="control">
  33. <span class="select">
  34. <select v-model="editing.privacy">
  35. <option value="public">Public</option>
  36. <option value="unlisted">Unlisted</option>
  37. <option value="private">Private</option>
  38. </select>
  39. </span>
  40. </p>
  41. <br />
  42. <p class="control">
  43. <label class="checkbox party-mode-inner">
  44. <input v-model="editing.partyMode" type="checkbox" />
  45. &nbsp;Party mode
  46. </label>
  47. </p>
  48. <small
  49. >With party mode enabled, people can add songs to a queue that
  50. plays. With party mode disabled you can play a private playlist
  51. on loop.</small
  52. >
  53. <br />
  54. <div v-if="station.partyMode">
  55. <br />
  56. <br />
  57. <label class="label">Queue lock</label>
  58. <small v-if="station.partyMode"
  59. >With the queue locked, only owners (you) can add songs to
  60. the queue.</small
  61. >
  62. <br />
  63. <button
  64. v-if="!station.locked"
  65. class="button is-danger"
  66. @click="$parent.toggleLock()"
  67. >
  68. Lock the queue
  69. </button>
  70. <button
  71. v-if="station.locked"
  72. class="button is-success"
  73. @click="$parent.toggleLock()"
  74. >
  75. Unlock the queue
  76. </button>
  77. </div>
  78. </template>
  79. <template v-slot:footer>
  80. <button class="button is-success" v-on:click="update()">
  81. Update Settings
  82. </button>
  83. <button
  84. v-if="station.type === 'community'"
  85. class="button is-danger"
  86. @click="deleteStation()"
  87. >
  88. Delete station
  89. </button>
  90. </template>
  91. </modal>
  92. </template>
  93. <script>
  94. import { mapState } from "vuex";
  95. import { Toast } from "vue-roaster";
  96. import Modal from "./Modal.vue";
  97. import io from "../../io";
  98. import validation from "../../validation";
  99. export default {
  100. computed: mapState("station", {
  101. station: state => state.station,
  102. editing: state => state.editing
  103. }),
  104. mounted() {
  105. io.getSocket(socket => {
  106. this.socket = socket;
  107. return socket;
  108. });
  109. },
  110. methods: {
  111. update() {
  112. if (this.station.name !== this.editing.name) this.updateName();
  113. if (this.station.displayName !== this.editing.displayName)
  114. this.updateDisplayName();
  115. if (this.station.description !== this.editing.description)
  116. this.updateDescription();
  117. if (this.station.privacy !== this.editing.privacy)
  118. this.updatePrivacy();
  119. if (this.station.partyMode !== this.editing.partyMode)
  120. this.updatePartyMode();
  121. },
  122. updateName() {
  123. const { name } = this.editing;
  124. if (!validation.isLength(name, 2, 16))
  125. return Toast.methods.addToast(
  126. "Name must have between 2 and 16 characters.",
  127. 8000
  128. );
  129. if (!validation.regex.az09_.test(name))
  130. return Toast.methods.addToast(
  131. "Invalid name format. Allowed characters: a-z, 0-9 and _.",
  132. 8000
  133. );
  134. return this.socket.emit(
  135. "stations.updateName",
  136. this.editing._id,
  137. name,
  138. res => {
  139. if (res.status === "success") {
  140. if (this.station) {
  141. this.station.name = name;
  142. return name;
  143. }
  144. this.$parent.stations.forEach((station, index) => {
  145. if (station._id === this.editing._id) {
  146. this.$parent.stations[index].name = name;
  147. return name;
  148. }
  149. return false;
  150. });
  151. }
  152. return Toast.methods.addToast(res.message, 8000);
  153. }
  154. );
  155. },
  156. updateDisplayName() {
  157. const { displayName } = this.editing;
  158. if (!validation.isLength(displayName, 2, 32))
  159. return Toast.methods.addToast(
  160. "Display name must have between 2 and 32 characters.",
  161. 8000
  162. );
  163. if (!validation.regex.azAZ09_.test(displayName))
  164. return Toast.methods.addToast(
  165. "Invalid display name format. Allowed characters: a-z, A-Z, 0-9 and _.",
  166. 8000
  167. );
  168. return this.socket.emit(
  169. "stations.updateDisplayName",
  170. this.editing._id,
  171. displayName,
  172. res => {
  173. if (res.status === "success") {
  174. if (this.station)
  175. this.station.displayName = displayName;
  176. else {
  177. this.$parent.stations.forEach((station, index) => {
  178. if (station._id === this.editing._id)
  179. this.$parent.stations[
  180. index
  181. ].displayName = displayName;
  182. return displayName;
  183. });
  184. }
  185. }
  186. Toast.methods.addToast(res.message, 8000);
  187. }
  188. );
  189. },
  190. updateDescription() {
  191. const { description } = this.editing;
  192. if (!validation.isLength(description, 2, 200))
  193. return Toast.methods.addToast(
  194. "Description must have between 2 and 200 characters.",
  195. 8000
  196. );
  197. let characters = description.split("");
  198. characters = characters.filter(character => {
  199. return character.charCodeAt(0) === 21328;
  200. });
  201. if (characters.length !== 0)
  202. return Toast.methods.addToast(
  203. "Invalid description format. Swastika's are not allowed.",
  204. 8000
  205. );
  206. return this.socket.emit(
  207. "stations.updateDescription",
  208. this.editing._id,
  209. description,
  210. res => {
  211. if (res.status === "success") {
  212. if (this.station) {
  213. this.station.description = description;
  214. return description;
  215. }
  216. this.$parent.stations.forEach((station, index) => {
  217. if (station._id === this.editing._id) {
  218. this.$parent.stations[
  219. index
  220. ].description = description;
  221. return description;
  222. }
  223. return false;
  224. });
  225. return Toast.methods.addToast(res.message, 4000);
  226. }
  227. return Toast.methods.addToast(res.message, 8000);
  228. }
  229. );
  230. },
  231. updatePrivacy() {
  232. return this.socket.emit(
  233. "stations.updatePrivacy",
  234. this.editing._id,
  235. this.editing.privacy,
  236. res => {
  237. if (res.status === "success") {
  238. if (this.station) {
  239. this.station.privacy = this.editing.privacy;
  240. return this.editing.privacy;
  241. }
  242. this.$parent.stations.forEach((station, index) => {
  243. if (station._id === this.editing._id) {
  244. this.$parent.stations[
  245. index
  246. ].privacy = this.editing.privacy;
  247. return this.editing.privacy;
  248. }
  249. return false;
  250. });
  251. return Toast.methods.addToast(res.message, 4000);
  252. }
  253. return Toast.methods.addToast(res.message, 8000);
  254. }
  255. );
  256. },
  257. updatePartyMode() {
  258. return this.socket.emit(
  259. "stations.updatePartyMode",
  260. this.editing._id,
  261. this.editing.partyMode,
  262. res => {
  263. if (res.status === "success") {
  264. if (this.station) {
  265. this.station.partyMode = this.editing.partyMode;
  266. return this.editing.partyMode;
  267. }
  268. this.$parent.stations.forEach((station, index) => {
  269. if (station._id === this.editing._id) {
  270. this.$parent.stations[
  271. index
  272. ].partyMode = this.editing.partyMode;
  273. return this.editing.partyMode;
  274. }
  275. return false;
  276. });
  277. return Toast.methods.addToast(res.message, 4000);
  278. }
  279. return Toast.methods.addToast(res.message, 8000);
  280. }
  281. );
  282. },
  283. deleteStation() {
  284. this.socket.emit("stations.remove", this.editing._id, res => {
  285. Toast.methods.addToast(res.message, 8000);
  286. });
  287. }
  288. },
  289. components: { Modal }
  290. };
  291. </script>
  292. <style lang="scss" scoped>
  293. @import "styles/global.scss";
  294. .controls {
  295. display: flex;
  296. a {
  297. display: flex;
  298. align-items: center;
  299. }
  300. }
  301. .table {
  302. margin-bottom: 0;
  303. }
  304. h5 {
  305. padding: 20px 0;
  306. }
  307. .party-mode-inner,
  308. .party-mode-outer {
  309. display: flex;
  310. align-items: center;
  311. }
  312. .select:after {
  313. border-color: #029ce3;
  314. }
  315. </style>