EditStation.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. const _this = this;
  106. io.getSocket(socket => {
  107. _this.socket = socket;
  108. return socket;
  109. });
  110. },
  111. methods: {
  112. update() {
  113. if (this.station.name !== this.editing.name) this.updateName();
  114. if (this.station.displayName !== this.editing.displayName)
  115. this.updateDisplayName();
  116. if (this.station.description !== this.editing.description)
  117. this.updateDescription();
  118. if (this.station.privacy !== this.editing.privacy)
  119. this.updatePrivacy();
  120. if (this.station.partyMode !== this.editing.partyMode)
  121. this.updatePartyMode();
  122. },
  123. updateName() {
  124. const { name } = this.editing;
  125. if (!validation.isLength(name, 2, 16))
  126. return Toast.methods.addToast(
  127. "Name must have between 2 and 16 characters.",
  128. 8000
  129. );
  130. if (!validation.regex.az09_.test(name))
  131. return Toast.methods.addToast(
  132. "Invalid name format. Allowed characters: a-z, 0-9 and _.",
  133. 8000
  134. );
  135. return this.socket.emit(
  136. "stations.updateName",
  137. this.editing._id,
  138. name,
  139. res => {
  140. if (res.status === "success") {
  141. if (this.station) {
  142. this.station.name = name;
  143. return name;
  144. }
  145. this.$parent.stations.forEach((station, index) => {
  146. if (station._id === this.editing._id) {
  147. this.$parent.stations[index].name = name;
  148. return name;
  149. }
  150. return false;
  151. });
  152. }
  153. return Toast.methods.addToast(res.message, 8000);
  154. }
  155. );
  156. },
  157. updateDisplayName() {
  158. const { displayName } = this.editing;
  159. if (!validation.isLength(displayName, 2, 32))
  160. return Toast.methods.addToast(
  161. "Display name must have between 2 and 32 characters.",
  162. 8000
  163. );
  164. if (!validation.regex.azAZ09_.test(displayName))
  165. return Toast.methods.addToast(
  166. "Invalid display name format. Allowed characters: a-z, A-Z, 0-9 and _.",
  167. 8000
  168. );
  169. return this.socket.emit(
  170. "stations.updateDisplayName",
  171. this.editing._id,
  172. displayName,
  173. res => {
  174. if (res.status === "success") {
  175. if (this.station)
  176. this.station.displayName = displayName;
  177. else {
  178. this.$parent.stations.forEach((station, index) => {
  179. if (station._id === this.editing._id)
  180. this.$parent.stations[
  181. index
  182. ].displayName = displayName;
  183. return displayName;
  184. });
  185. }
  186. }
  187. Toast.methods.addToast(res.message, 8000);
  188. }
  189. );
  190. },
  191. updateDescription() {
  192. const _this = this;
  193. const { description } = this.editing;
  194. if (!validation.isLength(description, 2, 200))
  195. return Toast.methods.addToast(
  196. "Description must have between 2 and 200 characters.",
  197. 8000
  198. );
  199. let characters = description.split("");
  200. characters = characters.filter(character => {
  201. return character.charCodeAt(0) === 21328;
  202. });
  203. if (characters.length !== 0)
  204. return Toast.methods.addToast(
  205. "Invalid description format. Swastika's are not allowed.",
  206. 8000
  207. );
  208. return this.socket.emit(
  209. "stations.updateDescription",
  210. this.editing._id,
  211. description,
  212. res => {
  213. if (res.status === "success") {
  214. if (_this.station) {
  215. _this.station.description = description;
  216. return description;
  217. }
  218. _this.$parent.stations.forEach((station, index) => {
  219. if (station._id === this.editing._id) {
  220. _this.$parent.stations[
  221. index
  222. ].description = description;
  223. return description;
  224. }
  225. return false;
  226. });
  227. return Toast.methods.addToast(res.message, 4000);
  228. }
  229. return Toast.methods.addToast(res.message, 8000);
  230. }
  231. );
  232. },
  233. updatePrivacy() {
  234. const _this = this;
  235. return this.socket.emit(
  236. "stations.updatePrivacy",
  237. this.editing._id,
  238. this.editing.privacy,
  239. res => {
  240. if (res.status === "success") {
  241. if (_this.station) {
  242. _this.station.privacy = _this.editing.privacy;
  243. return _this.editing.privacy;
  244. }
  245. _this.$parent.stations.forEach((station, index) => {
  246. if (station._id === _this.editing._id) {
  247. _this.$parent.stations[index].privacy =
  248. _this.editing.privacy;
  249. return _this.editing.privacy;
  250. }
  251. return false;
  252. });
  253. return Toast.methods.addToast(res.message, 4000);
  254. }
  255. return Toast.methods.addToast(res.message, 8000);
  256. }
  257. );
  258. },
  259. updatePartyMode() {
  260. const _this = this;
  261. return this.socket.emit(
  262. "stations.updatePartyMode",
  263. this.editing._id,
  264. this.editing.partyMode,
  265. res => {
  266. if (res.status === "success") {
  267. if (_this.station) {
  268. _this.station.partyMode = _this.editing.partyMode;
  269. return _this.editing.partyMode;
  270. }
  271. _this.$parent.stations.forEach((station, index) => {
  272. if (station._id === _this.editing._id) {
  273. _this.$parent.stations[index].partyMode =
  274. _this.editing.partyMode;
  275. return _this.editing.partyMode;
  276. }
  277. return false;
  278. });
  279. return Toast.methods.addToast(res.message, 4000);
  280. }
  281. return Toast.methods.addToast(res.message, 8000);
  282. }
  283. );
  284. },
  285. deleteStation() {
  286. this.socket.emit("stations.remove", this.editing._id, res => {
  287. Toast.methods.addToast(res.message, 8000);
  288. });
  289. }
  290. },
  291. components: { Modal }
  292. };
  293. </script>
  294. <style lang="scss" scoped>
  295. .controls {
  296. display: flex;
  297. a {
  298. display: flex;
  299. align-items: center;
  300. }
  301. }
  302. .table {
  303. margin-bottom: 0;
  304. }
  305. h5 {
  306. padding: 20px 0;
  307. }
  308. .party-mode-inner,
  309. .party-mode-outer {
  310. display: flex;
  311. align-items: center;
  312. }
  313. .select:after {
  314. border-color: #029ce3;
  315. }
  316. </style>