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.

309 lines
8.4 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. 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. gitSignatureName: '',
  61. gitSignatureEmail: '',
  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. if (_.isPlainObject(appconfig.git.auth)) {
  119. this.conf.gitAuthType = appconfig.git.auth.type || 'ssh'
  120. this.conf.gitAuthSSHKey = appconfig.git.auth.privateKey || ''
  121. this.conf.gitAuthUser = appconfig.git.auth.username || ''
  122. this.conf.gitAuthPass = appconfig.git.auth.password || ''
  123. this.conf.gitAuthSSL = (appconfig.git.auth.sslVerify !== false)
  124. }
  125. if (_.isPlainObject(appconfig.git.signature)) {
  126. this.conf.gitSignatureName = appconfig.git.signature.name || ''
  127. this.conf.gitSignatureEmail = appconfig.git.signature.email || ''
  128. }
  129. }
  130. },
  131. methods: {
  132. proceedToWelcome: function (ev) {
  133. this.state = 'welcome'
  134. this.loading = false
  135. },
  136. proceedToSyscheck: function (ev) {
  137. let self = this
  138. this.state = 'syscheck'
  139. this.loading = true
  140. self.syscheck = {
  141. ok: false,
  142. error: '',
  143. results: []
  144. }
  145. _.delay(() => {
  146. axios.post('/syscheck').then(resp => {
  147. if (resp.data.ok === true) {
  148. self.syscheck.ok = true
  149. self.syscheck.results = resp.data.results
  150. } else {
  151. self.syscheck.ok = false
  152. self.syscheck.error = resp.data.error
  153. }
  154. self.loading = false
  155. self.$nextTick()
  156. }).catch(err => {
  157. window.alert(err.message)
  158. })
  159. }, 1000)
  160. },
  161. proceedToGeneral: function (ev) {
  162. let self = this
  163. self.state = 'general'
  164. self.loading = false
  165. self.$nextTick(() => {
  166. self.$validator.validateAll('general')
  167. })
  168. },
  169. proceedToConsiderations: function (ev) {
  170. this.considerations = {
  171. https: !_.startsWith(this.conf.host, 'https'),
  172. port: false, // TODO
  173. localhost: _.includes(this.conf.host, 'localhost')
  174. }
  175. this.state = 'considerations'
  176. this.loading = false
  177. },
  178. proceedToDb: function (ev) {
  179. let self = this
  180. self.state = 'db'
  181. self.loading = false
  182. self.$nextTick(() => {
  183. self.$validator.validateAll('db')
  184. })
  185. },
  186. proceedToDbcheck: function (ev) {
  187. let self = this
  188. this.state = 'dbcheck'
  189. this.loading = true
  190. self.dbcheck = {
  191. ok: false,
  192. error: ''
  193. }
  194. _.delay(() => {
  195. axios.post('/dbcheck', {
  196. db: self.conf.db
  197. }).then(resp => {
  198. if (resp.data.ok === true) {
  199. self.dbcheck.ok = true
  200. } else {
  201. self.dbcheck.ok = false
  202. self.dbcheck.error = resp.data.error
  203. }
  204. self.loading = false
  205. self.$nextTick()
  206. }).catch(err => {
  207. window.alert(err.message)
  208. })
  209. }, 1000)
  210. },
  211. proceedToPaths: function (ev) {
  212. let self = this
  213. self.state = 'paths'
  214. self.loading = false
  215. self.$nextTick(() => {
  216. self.$validator.validateAll('paths')
  217. })
  218. },
  219. proceedToGit: function (ev) {
  220. let self = this
  221. self.state = 'git'
  222. self.loading = false
  223. self.$nextTick(() => {
  224. self.$validator.validateAll('git')
  225. })
  226. },
  227. proceedToGitCheck: function (ev) {
  228. let self = this
  229. this.state = 'gitcheck'
  230. this.loading = true
  231. self.gitcheck = {
  232. ok: false,
  233. results: [],
  234. error: ''
  235. }
  236. _.delay(() => {
  237. axios.post('/gitcheck', self.conf).then(resp => {
  238. if (resp.data.ok === true) {
  239. self.gitcheck.ok = true
  240. self.gitcheck.results = resp.data.results
  241. } else {
  242. self.gitcheck.ok = false
  243. self.gitcheck.error = resp.data.error
  244. }
  245. self.loading = false
  246. self.$nextTick()
  247. }).catch(err => {
  248. window.alert(err.message)
  249. })
  250. }, 1000)
  251. },
  252. proceedToAdmin: function (ev) {
  253. let self = this
  254. self.state = 'admin'
  255. self.loading = false
  256. self.$nextTick(() => {
  257. self.$validator.validateAll('admin')
  258. })
  259. },
  260. proceedToFinal: function (ev) {
  261. let self = this
  262. self.state = 'final'
  263. self.loading = true
  264. self.final = {
  265. ok: false,
  266. error: '',
  267. results: []
  268. }
  269. _.delay(() => {
  270. axios.post('/finalize', self.conf).then(resp => {
  271. if (resp.data.ok === true) {
  272. self.final.ok = true
  273. self.final.results = resp.data.results
  274. } else {
  275. self.final.ok = false
  276. self.final.error = resp.data.error
  277. }
  278. self.loading = false
  279. self.$nextTick()
  280. }).catch(err => {
  281. window.alert(err.message)
  282. })
  283. }, 1000)
  284. },
  285. finish: function (ev) {
  286. let self = this
  287. self.state = 'restart'
  288. _.delay(() => {
  289. axios.post('/restart', {}).then(resp => {
  290. _.delay(() => {
  291. window.location.assign(self.conf.host)
  292. }, 30000)
  293. }).catch(err => {
  294. window.alert(err.message)
  295. })
  296. }, 1000)
  297. }
  298. }
  299. })
  300. })