EditStation.vue 7.6 KB

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