configure.js 6.8 KB

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