You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

285 lines
7.2 KiB

  1. 'use strict'
  2. import jQuery from 'jquery'
  3. import _ from 'lodash'
  4. import Vue from 'vue'
  5. import VeeValidate from 'vee-validate'
  6. import axios from 'axios'
  7. Vue.use(VeeValidate, {
  8. enableAutoClasses: true,
  9. classNames: {
  10. touched: 'is-touched', // the control has been blurred
  11. untouched: 'is-untouched', // the control hasn't been blurred
  12. valid: 'is-valid', // model is valid
  13. invalid: 'is-invalid', // model is invalid
  14. pristine: 'is-pristine', // control has not been interacted with
  15. dirty: 'is-dirty' // control has been interacted with
  16. }
  17. })
  18. jQuery(document).ready(function ($) {
  19. new Vue({ // eslint-disable-line no-new
  20. el: 'main',
  21. data: {
  22. loading: false,
  23. state: 'welcome',
  24. syscheck: {
  25. ok: false,
  26. error: '',
  27. results: []
  28. },
  29. dbcheck: {
  30. ok: false,
  31. error: ''
  32. },
  33. gitcheck: {
  34. ok: false,
  35. error: ''
  36. },
  37. final: {
  38. ok: false,
  39. error: '',
  40. results: []
  41. },
  42. conf: {
  43. title: 'Wiki',
  44. host: 'http://',
  45. port: 80,
  46. lang: 'en',
  47. db: 'mongodb://localhost:27017/wiki',
  48. pathData: './data',
  49. pathRepo: './repo',
  50. gitUseRemote: true,
  51. gitUrl: '',
  52. gitBranch: 'master',
  53. gitAuthType: 'ssh',
  54. gitAuthSSHKey: '',
  55. gitAuthUser: '',
  56. gitAuthPass: '',
  57. gitAuthSSL: true,
  58. gitSignatureName: '',
  59. gitSignatureEmail: '',
  60. adminEmail: '',
  61. adminPassword: '',
  62. adminPasswordConfirm: ''
  63. },
  64. considerations: {
  65. https: false,
  66. port: false,
  67. localhost: false
  68. }
  69. },
  70. computed: {
  71. currentProgress: function () {
  72. let perc = '0%'
  73. switch (this.state) {
  74. case 'welcome':
  75. perc = '0%'
  76. break
  77. case 'syscheck':
  78. perc = (this.syscheck.ok) ? '15%' : '5%'
  79. break
  80. case 'general':
  81. perc = '20%'
  82. break
  83. case 'considerations':
  84. perc = '30%'
  85. break
  86. case 'db':
  87. perc = '35%'
  88. break
  89. case 'dbcheck':
  90. perc = (this.dbcheck.ok) ? '50%' : '40%'
  91. break
  92. case 'paths':
  93. perc = '55%'
  94. break
  95. case 'git':
  96. perc = '60%'
  97. break
  98. case 'gitcheck':
  99. perc = (this.gitcheck.ok) ? '75%' : '65%'
  100. break
  101. case 'admin':
  102. perc = '80%'
  103. break
  104. }
  105. return perc
  106. }
  107. },
  108. methods: {
  109. proceedToWelcome: function (ev) {
  110. this.state = 'welcome'
  111. this.loading = false
  112. },
  113. proceedToSyscheck: function (ev) {
  114. let self = this
  115. this.state = 'syscheck'
  116. this.loading = true
  117. self.syscheck = {
  118. ok: false,
  119. error: '',
  120. results: []
  121. }
  122. _.delay(() => {
  123. axios.post('/syscheck').then(resp => {
  124. if (resp.data.ok === true) {
  125. self.syscheck.ok = true
  126. self.syscheck.results = resp.data.results
  127. } else {
  128. self.syscheck.ok = false
  129. self.syscheck.error = resp.data.error
  130. }
  131. self.loading = false
  132. self.$nextTick()
  133. }).catch(err => {
  134. window.alert(err.message)
  135. })
  136. }, 1000)
  137. },
  138. proceedToGeneral: function (ev) {
  139. let self = this
  140. self.state = 'general'
  141. self.loading = false
  142. self.$nextTick(() => {
  143. self.$validator.validateAll('general')
  144. })
  145. },
  146. proceedToConsiderations: function (ev) {
  147. this.considerations = {
  148. https: !_.startsWith(this.conf.host, 'https'),
  149. port: false, // TODO
  150. localhost: _.includes(this.conf.host, 'localhost')
  151. }
  152. this.state = 'considerations'
  153. this.loading = false
  154. },
  155. proceedToDb: function (ev) {
  156. let self = this
  157. self.state = 'db'
  158. self.loading = false
  159. self.$nextTick(() => {
  160. self.$validator.validateAll('db')
  161. })
  162. },
  163. proceedToDbcheck: function (ev) {
  164. let self = this
  165. this.state = 'dbcheck'
  166. this.loading = true
  167. self.dbcheck = {
  168. ok: false,
  169. error: ''
  170. }
  171. _.delay(() => {
  172. axios.post('/dbcheck', {
  173. db: self.conf.db
  174. }).then(resp => {
  175. if (resp.data.ok === true) {
  176. self.dbcheck.ok = true
  177. } else {
  178. self.dbcheck.ok = false
  179. self.dbcheck.error = resp.data.error
  180. }
  181. self.loading = false
  182. self.$nextTick()
  183. }).catch(err => {
  184. window.alert(err.message)
  185. })
  186. }, 1000)
  187. },
  188. proceedToPaths: function (ev) {
  189. let self = this
  190. self.state = 'paths'
  191. self.loading = false
  192. self.$nextTick(() => {
  193. self.$validator.validateAll('paths')
  194. })
  195. },
  196. proceedToGit: function (ev) {
  197. let self = this
  198. self.state = 'git'
  199. self.loading = false
  200. self.$nextTick(() => {
  201. self.$validator.validateAll('git')
  202. })
  203. },
  204. proceedToGitCheck: function (ev) {
  205. let self = this
  206. this.state = 'gitcheck'
  207. this.loading = true
  208. self.gitcheck = {
  209. ok: false,
  210. results: [],
  211. error: ''
  212. }
  213. _.delay(() => {
  214. axios.post('/gitcheck', self.conf).then(resp => {
  215. if (resp.data.ok === true) {
  216. self.gitcheck.ok = true
  217. self.gitcheck.results = resp.data.results
  218. } else {
  219. self.gitcheck.ok = false
  220. self.gitcheck.error = resp.data.error
  221. }
  222. self.loading = false
  223. self.$nextTick()
  224. }).catch(err => {
  225. window.alert(err.message)
  226. })
  227. }, 1000)
  228. },
  229. proceedToAdmin: function (ev) {
  230. let self = this
  231. self.state = 'admin'
  232. self.loading = false
  233. self.$nextTick(() => {
  234. self.$validator.validateAll('admin')
  235. })
  236. },
  237. proceedToFinal: function (ev) {
  238. let self = this
  239. self.state = 'final'
  240. self.loading = true
  241. self.final = {
  242. ok: false,
  243. error: '',
  244. results: []
  245. }
  246. _.delay(() => {
  247. axios.post('/finalize', self.conf).then(resp => {
  248. if (resp.data.ok === true) {
  249. self.final.ok = true
  250. self.final.results = resp.data.results
  251. } else {
  252. self.final.ok = false
  253. self.final.error = resp.data.error
  254. }
  255. self.loading = false
  256. self.$nextTick()
  257. }).catch(err => {
  258. window.alert(err.message)
  259. })
  260. }, 1000)
  261. },
  262. finish: function (ev) {
  263. let self = this
  264. self.state = 'restart'
  265. _.delay(() => {
  266. axios.post('/restart', {}).then(resp => {
  267. _.delay(() => {
  268. window.location.assign(self.conf.host)
  269. }, 10000)
  270. }).catch(err => {
  271. window.alert(err.message)
  272. })
  273. }, 1000)
  274. }
  275. }
  276. })
  277. })