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.

307 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. 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. self.state = 'db'
  179. self.loading = false
  180. self.$nextTick(() => {
  181. self.$validator.validateAll('db')
  182. })
  183. },
  184. proceedToDbcheck: function (ev) {
  185. let self = this
  186. this.state = 'dbcheck'
  187. this.loading = true
  188. self.dbcheck = {
  189. ok: false,
  190. error: ''
  191. }
  192. _.delay(() => {
  193. axios.post('/dbcheck', {
  194. db: self.conf.db
  195. }).then(resp => {
  196. if (resp.data.ok === true) {
  197. self.dbcheck.ok = true
  198. } else {
  199. self.dbcheck.ok = false
  200. self.dbcheck.error = resp.data.error
  201. }
  202. self.loading = false
  203. self.$nextTick()
  204. }).catch(err => {
  205. window.alert(err.message)
  206. })
  207. }, 1000)
  208. },
  209. proceedToPaths: function (ev) {
  210. let self = this
  211. self.state = 'paths'
  212. self.loading = false
  213. self.$nextTick(() => {
  214. self.$validator.validateAll('paths')
  215. })
  216. },
  217. proceedToGit: function (ev) {
  218. let self = this
  219. self.state = 'git'
  220. self.loading = false
  221. self.$nextTick(() => {
  222. self.$validator.validateAll('git')
  223. })
  224. },
  225. proceedToGitCheck: function (ev) {
  226. let self = this
  227. this.state = 'gitcheck'
  228. this.loading = true
  229. self.gitcheck = {
  230. ok: false,
  231. results: [],
  232. error: ''
  233. }
  234. _.delay(() => {
  235. axios.post('/gitcheck', self.conf).then(resp => {
  236. if (resp.data.ok === true) {
  237. self.gitcheck.ok = true
  238. self.gitcheck.results = resp.data.results
  239. } else {
  240. self.gitcheck.ok = false
  241. self.gitcheck.error = resp.data.error
  242. }
  243. self.loading = false
  244. self.$nextTick()
  245. }).catch(err => {
  246. window.alert(err.message)
  247. })
  248. }, 1000)
  249. },
  250. proceedToAdmin: function (ev) {
  251. let self = this
  252. self.state = 'admin'
  253. self.loading = false
  254. self.$nextTick(() => {
  255. self.$validator.validateAll('admin')
  256. })
  257. },
  258. proceedToFinal: function (ev) {
  259. let self = this
  260. self.state = 'final'
  261. self.loading = true
  262. self.final = {
  263. ok: false,
  264. error: '',
  265. results: []
  266. }
  267. _.delay(() => {
  268. axios.post('/finalize', self.conf).then(resp => {
  269. if (resp.data.ok === true) {
  270. self.final.ok = true
  271. self.final.results = resp.data.results
  272. } else {
  273. self.final.ok = false
  274. self.final.error = resp.data.error
  275. }
  276. self.loading = false
  277. self.$nextTick()
  278. }).catch(err => {
  279. window.alert(err.message)
  280. })
  281. }, 1000)
  282. },
  283. finish: function (ev) {
  284. let self = this
  285. self.state = 'restart'
  286. _.delay(() => {
  287. axios.post('/restart', {}).then(resp => {
  288. _.delay(() => {
  289. window.location.assign(self.conf.host)
  290. }, 30000)
  291. }).catch(err => {
  292. window.alert(err.message)
  293. })
  294. }, 1000)
  295. }
  296. }
  297. })
  298. })