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.

310 lines
8.4 KiB

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