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.

308 lines
8.3 KiB

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