configure.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. gitUrl: '',
  47. gitBranch: 'master',
  48. gitAuthType: 'ssh',
  49. gitAuthSSHKey: '',
  50. gitAuthUser: '',
  51. gitAuthPass: '',
  52. gitAuthSSL: true,
  53. gitSignatureName: '',
  54. gitSignatureEmail: '',
  55. adminEmail: '',
  56. adminPassword: '',
  57. adminPasswordConfirm: ''
  58. },
  59. considerations: {
  60. https: false,
  61. port: false,
  62. localhost: false
  63. }
  64. },
  65. computed: {
  66. currentProgress: function () {
  67. let perc = '0%'
  68. switch (this.state) {
  69. case 'welcome':
  70. perc = '0%'
  71. break
  72. case 'syscheck':
  73. perc = (this.syscheck.ok) ? '15%' : '5%'
  74. break
  75. case 'general':
  76. perc = '20%'
  77. break
  78. case 'considerations':
  79. perc = '30%'
  80. break
  81. case 'db':
  82. perc = '35%'
  83. break
  84. case 'dbcheck':
  85. perc = (this.dbcheck.ok) ? '50%' : '40%'
  86. break
  87. case 'paths':
  88. perc = '55%'
  89. break
  90. case 'git':
  91. perc = '60%'
  92. break
  93. case 'gitcheck':
  94. perc = (this.gitcheck.ok) ? '75%' : '65%'
  95. break
  96. case 'admin':
  97. perc = '80%'
  98. break
  99. }
  100. return perc
  101. }
  102. },
  103. methods: {
  104. proceedToWelcome: function (ev) {
  105. this.state = 'welcome'
  106. this.loading = false
  107. },
  108. proceedToSyscheck: function (ev) {
  109. let self = this
  110. this.state = 'syscheck'
  111. this.loading = true
  112. self.syscheck = {
  113. ok: false,
  114. error: '',
  115. results: []
  116. }
  117. _.delay(() => {
  118. axios.post('/syscheck').then(resp => {
  119. if (resp.data.ok === true) {
  120. self.syscheck.ok = true
  121. self.syscheck.results = resp.data.results
  122. } else {
  123. self.syscheck.ok = false
  124. self.syscheck.error = resp.data.error
  125. }
  126. self.loading = false
  127. self.$nextTick()
  128. }).catch(err => {
  129. window.alert(err.message)
  130. })
  131. }, 1000)
  132. },
  133. proceedToGeneral: function (ev) {
  134. let self = this
  135. self.state = 'general'
  136. self.loading = false
  137. self.$nextTick(() => {
  138. self.$validator.validateAll('general')
  139. })
  140. },
  141. proceedToConsiderations: function (ev) {
  142. this.considerations = {
  143. https: !_.startsWith(this.conf.host, 'https'),
  144. port: false, // TODO
  145. localhost: _.includes(this.conf.host, 'localhost')
  146. }
  147. this.state = 'considerations'
  148. this.loading = false
  149. },
  150. proceedToDb: function (ev) {
  151. let self = this
  152. self.state = 'db'
  153. self.loading = false
  154. self.$nextTick(() => {
  155. self.$validator.validateAll('db')
  156. })
  157. },
  158. proceedToDbcheck: function (ev) {
  159. let self = this
  160. this.state = 'dbcheck'
  161. this.loading = true
  162. self.dbcheck = {
  163. ok: false,
  164. error: ''
  165. }
  166. _.delay(() => {
  167. axios.post('/dbcheck', {
  168. db: self.conf.db
  169. }).then(resp => {
  170. if (resp.data.ok === true) {
  171. self.dbcheck.ok = true
  172. } else {
  173. self.dbcheck.ok = false
  174. self.dbcheck.error = resp.data.error
  175. }
  176. self.loading = false
  177. self.$nextTick()
  178. }).catch(err => {
  179. window.alert(err.message)
  180. })
  181. }, 1000)
  182. },
  183. proceedToPaths: function (ev) {
  184. let self = this
  185. self.state = 'paths'
  186. self.loading = false
  187. self.$nextTick(() => {
  188. self.$validator.validateAll('paths')
  189. })
  190. },
  191. proceedToGit: function (ev) {
  192. let self = this
  193. self.state = 'git'
  194. self.loading = false
  195. self.$nextTick(() => {
  196. self.$validator.validateAll('git')
  197. })
  198. },
  199. proceedToGitCheck: function (ev) {
  200. let self = this
  201. this.state = 'gitcheck'
  202. this.loading = true
  203. self.gitcheck = {
  204. ok: false,
  205. results: [],
  206. error: ''
  207. }
  208. _.delay(() => {
  209. axios.post('/gitcheck', self.conf).then(resp => {
  210. if (resp.data.ok === true) {
  211. self.gitcheck.ok = true
  212. self.gitcheck.results = resp.data.results
  213. } else {
  214. self.gitcheck.ok = false
  215. self.gitcheck.error = resp.data.error
  216. }
  217. self.loading = false
  218. self.$nextTick()
  219. }).catch(err => {
  220. window.alert(err.message)
  221. })
  222. }, 1000)
  223. },
  224. proceedToAdmin: function (ev) {
  225. let self = this
  226. self.state = 'admin'
  227. self.loading = false
  228. self.$nextTick(() => {
  229. self.$validator.validateAll('admin')
  230. })
  231. },
  232. proceedToFinal: function (ev) {
  233. let self = this
  234. self.state = 'final'
  235. self.loading = true
  236. self.final = {
  237. ok: false,
  238. error: '',
  239. results: []
  240. }
  241. _.delay(() => {
  242. axios.post('/finalize', self.conf).then(resp => {
  243. if (resp.data.ok === true) {
  244. self.final.ok = true
  245. self.final.results = resp.data.results
  246. } else {
  247. self.final.ok = false
  248. self.final.error = resp.data.error
  249. }
  250. self.loading = false
  251. self.$nextTick()
  252. }).catch(err => {
  253. window.alert(err.message)
  254. })
  255. }, 1000)
  256. },
  257. finish: function (ev) {
  258. }
  259. }
  260. })
  261. })