Start.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div class='route_container route_container--fullscreen'>
  3. <div v-show='panel === 1'>
  4. <div class='h1'>Hi.</div>
  5. <p class='explanation'>
  6. First create your admin account for the forum.
  7. </p>
  8. <div>
  9. <fancy-input
  10. v-model='username'
  11. :error='errors.username'
  12. width='100%'
  13. placeholder='Username'
  14. ></fancy-input>
  15. <fancy-input
  16. v-model='password'
  17. :error='errors.password'
  18. width='100%'
  19. placeholder='Password'
  20. type='password'
  21. ></fancy-input>
  22. <fancy-input
  23. v-model='confirmPassword'
  24. :error='errors.confirmPassword'
  25. width='100%'
  26. placeholder='Confirm password'
  27. type='password'
  28. ></fancy-input>
  29. <loading-button
  30. style='width: 100%;'
  31. class='button button--green'
  32. :loading='loading'
  33. @click='createAccount'
  34. >
  35. Create account
  36. </loading-button>
  37. </div>
  38. </div>
  39. <div v-show='panel === 2'>
  40. <div class='h1'>A few settings</div>
  41. <p class='explanation'>
  42. You can change these later on the admin page
  43. </p>
  44. <div>
  45. <fancy-input
  46. v-model='forumName'
  47. :error='errors.forumName'
  48. width='100%'
  49. placeholder='Forum name'
  50. ></fancy-input>
  51. <p class='p--small'>What is your forum about?</p>
  52. <fancy-textarea
  53. v-model='forumDescription'
  54. :error='errors.forumDescription'
  55. width='100%'
  56. placeholder='Forum description'
  57. ></fancy-textarea>
  58. <loading-button
  59. style='width: 100%;'
  60. class='button button--green'
  61. :loading='loading'
  62. @click='addSettings'
  63. >
  64. Add settings
  65. </loading-button>
  66. </div>
  67. </div>
  68. <div v-show='panel === 3'>
  69. <div class='h1'>Categories</div>
  70. <p class='explanation'>
  71. People post threads in categories so that they're easier to sort through<br/>
  72. You can add or remove them later on the admin page
  73. </p>
  74. <div>
  75. <p v-if='categories.length'>
  76. <b>Categories:</b>
  77. {{categories.join(', ')}}
  78. </p>
  79. <p v-else>No categories added</p>
  80. <div class='categories_form'>
  81. <fancy-input
  82. v-model='category'
  83. :error='errors.name'
  84. width='100%'
  85. placeholder='Category name'
  86. ></fancy-input>
  87. <loading-button
  88. class='button button--green'
  89. :loading='loading'
  90. @click='addCategory'
  91. >
  92. Add category
  93. </loading-button>
  94. </div>
  95. </div>
  96. <button style='width: 100%;' class='button button--green' @click='finish'>Finish</button>
  97. </div>
  98. </div>
  99. </template>
  100. <script>
  101. import FancyInput from '../FancyInput'
  102. import FancyTextarea from '../FancyTextarea'
  103. import LoadingButton from '../LoadingButton'
  104. import AjaxErrorHandler from '../../assets/js/errorHandler'
  105. export default {
  106. name: 'start',
  107. data () {
  108. return {
  109. username: '',
  110. password: '',
  111. confirmPassword: '',
  112. forumName: '',
  113. forumDescription: '',
  114. loading: false,
  115. category: '',
  116. categories: [],
  117. panel: 1,
  118. errors: {
  119. username: '',
  120. password: '',
  121. confirmPassword: '',
  122. forumName: '',
  123. forumDescription: '',
  124. name: ''
  125. },
  126. modal: {
  127. show: false,
  128. errors: []
  129. }
  130. }
  131. },
  132. components: {
  133. FancyInput,
  134. FancyTextarea,
  135. LoadingButton
  136. },
  137. computed: {},
  138. methods: {
  139. clearErrors () {
  140. this.errors.username = ''
  141. this.errors.password = ''
  142. this.errors.confirmPassword = ''
  143. this.errors.forumName = ''
  144. this.errors.forumDescription = ''
  145. this.errors.name = ''
  146. },
  147. errorCallback (err) {
  148. this.loading = false
  149. AjaxErrorHandler(this.$store)(err, (error, modalErrors) => {
  150. if(this.errors[error.parameter] !== undefined) {
  151. this.errors[error.parameter] = error.message
  152. } else {
  153. modalErrors.push(error.message)
  154. }
  155. })
  156. },
  157. createAccount () {
  158. this.clearErrors()
  159. if(this.password !== this.confirmPassword) {
  160. this.errors.confirmPassword = 'passwords do not match'
  161. return;
  162. }
  163. let req = this.axios.post('/api/v1/user', {
  164. username: this.username,
  165. password: this.password,
  166. admin: true
  167. })
  168. this.loading = true
  169. req.then(res => {
  170. this.$store.commit('setUsername', res.data.username)
  171. this.panel = 2
  172. this.loading = false
  173. }).catch(this.errorCallback)
  174. },
  175. addSettings () {
  176. this.clearErrors()
  177. if(!this.forumName.trim().length) {
  178. this.errors.forumName = 'Forum name can\'t be blank'
  179. return
  180. }
  181. this.loading = true
  182. let settingsReq = this.axios.put('/api/v1/settings', {
  183. forumName: this.forumName,
  184. forumDescription: this.forumDescription
  185. })
  186. settingsReq.then(res => {
  187. this.loading = false
  188. this.$store.commit('setForumName', res.data.forumName)
  189. this.panel = 3
  190. }).catch(this.errorCallback)
  191. },
  192. addCategory () {
  193. this.clearErrors()
  194. if(!this.category.length) {
  195. this.errors.name = 'Category name can\'t be blank'
  196. return
  197. }
  198. this.loading = true
  199. this.axios.post('/api/v1/category', {
  200. name: this.category.trim()
  201. }).then(res => {
  202. this.loading = false
  203. this.$store.commit('addCategories', res.data.name)
  204. this.categories.push(res.data.name)
  205. }).catch(this.errorCallback)
  206. this.category = ''
  207. },
  208. finish () {
  209. if(this.categories.length) this.$router.push('/')
  210. }
  211. }
  212. }
  213. </script>
  214. <style lang='scss' scoped>
  215. @import '../../assets/scss/variables.scss';
  216. .route_container--fullscreen {
  217. position: fixed;
  218. top: 0;
  219. margin: 0;
  220. z-index: 10;
  221. left: 0;
  222. height: 100%;
  223. padding: 0;
  224. width: 100%;
  225. background-color: #fff;
  226. display: flex;
  227. align-items: center;
  228. justify-content: center;
  229. }
  230. .explanation {
  231. font-size: 1.25rem;
  232. width: 25rem;
  233. }
  234. .p--small {
  235. margin: 0.5rem 0;
  236. width: 25rem;
  237. }
  238. .categories_form {
  239. margin-bottom: 1rem;
  240. align-items: center;
  241. display: flex;
  242. .fancy_input {
  243. flex-grow: 6;
  244. margin: 0;
  245. margin-right: 0.5rem;
  246. }
  247. button {
  248. height: 1.9rem;
  249. padding: 0 0.5rem;
  250. }
  251. }
  252. </style>