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.

239 lines
6.2 KiB

  1. /* global siteConfig */
  2. import axios from 'axios'
  3. export default {
  4. name: 'configManager',
  5. data() {
  6. return {
  7. loading: false,
  8. state: 'welcome',
  9. syscheck: {
  10. ok: false,
  11. error: '',
  12. results: []
  13. },
  14. dbcheck: {
  15. ok: false,
  16. error: ''
  17. },
  18. gitcheck: {
  19. ok: false,
  20. error: ''
  21. },
  22. final: {
  23. ok: false,
  24. error: '',
  25. results: []
  26. },
  27. conf: {
  28. telemetry: true,
  29. upgrade: false,
  30. title: siteConfig.title || 'Wiki',
  31. host: siteConfig.host || 'http://',
  32. port: siteConfig.port || 80,
  33. lang: siteConfig.lang || 'en',
  34. public: (siteConfig.public === true),
  35. pathData: './data',
  36. pathRepo: './repo',
  37. gitUseRemote: (siteConfig.git !== false),
  38. gitUrl: '',
  39. gitBranch: 'master',
  40. gitAuthType: 'ssh',
  41. gitAuthSSHKey: '',
  42. gitAuthUser: '',
  43. gitAuthPass: '',
  44. gitAuthSSL: true,
  45. gitShowUserEmail: true,
  46. gitServerEmail: '',
  47. adminEmail: '',
  48. adminPassword: '',
  49. adminPasswordConfirm: ''
  50. },
  51. considerations: {
  52. https: false,
  53. port: false,
  54. localhost: false
  55. }
  56. }
  57. },
  58. computed: {
  59. currentProgress: function () {
  60. let perc = '0%'
  61. switch (this.state) {
  62. case 'welcome':
  63. perc = '0%'
  64. break
  65. case 'syscheck':
  66. perc = (this.syscheck.ok) ? '15%' : '5%'
  67. break
  68. case 'general':
  69. perc = '25%'
  70. break
  71. case 'considerations':
  72. perc = '30%'
  73. break
  74. case 'git':
  75. perc = '50%'
  76. break
  77. case 'gitcheck':
  78. perc = (this.gitcheck.ok) ? '70%' : '55%'
  79. break
  80. case 'admin':
  81. perc = '75%'
  82. break
  83. }
  84. return perc
  85. }
  86. },
  87. mounted: function () {
  88. /* if (appconfig.paths) {
  89. this.conf.pathData = appconfig.paths.data || './data'
  90. this.conf.pathRepo = appconfig.paths.repo || './repo'
  91. }
  92. if (appconfig.git !== false && _.isPlainObject(appconfig.git)) {
  93. this.conf.gitUrl = appconfig.git.url || ''
  94. this.conf.gitBranch = appconfig.git.branch || 'master'
  95. this.conf.gitShowUserEmail = (appconfig.git.showUserEmail !== false)
  96. this.conf.gitServerEmail = appconfig.git.serverEmail || ''
  97. if (_.isPlainObject(appconfig.git.auth)) {
  98. this.conf.gitAuthType = appconfig.git.auth.type || 'ssh'
  99. this.conf.gitAuthSSHKey = appconfig.git.auth.privateKey || ''
  100. this.conf.gitAuthUser = appconfig.git.auth.username || ''
  101. this.conf.gitAuthPass = appconfig.git.auth.password || ''
  102. this.conf.gitAuthSSL = (appconfig.git.auth.sslVerify !== false)
  103. }
  104. } */
  105. },
  106. methods: {
  107. proceedToWelcome: function (ev) {
  108. this.state = 'welcome'
  109. this.loading = false
  110. },
  111. proceedToSyscheck: function (ev) {
  112. let self = this
  113. this.state = 'syscheck'
  114. this.loading = true
  115. self.syscheck = {
  116. ok: false,
  117. error: '',
  118. results: []
  119. }
  120. this.$helpers._.delay(() => {
  121. axios.post('/syscheck').then(resp => {
  122. if (resp.data.ok === true) {
  123. self.syscheck.ok = true
  124. self.syscheck.results = resp.data.results
  125. } else {
  126. self.syscheck.ok = false
  127. self.syscheck.error = resp.data.error
  128. }
  129. self.loading = false
  130. self.$nextTick()
  131. }).catch(err => {
  132. window.alert(err.message)
  133. })
  134. }, 1000)
  135. },
  136. proceedToGeneral: function (ev) {
  137. let self = this
  138. self.state = 'general'
  139. self.loading = false
  140. self.$nextTick(() => {
  141. self.$validator.validateAll('general')
  142. })
  143. },
  144. proceedToConsiderations: function (ev) {
  145. this.considerations = {
  146. https: !this.$helpers._.startsWith(this.conf.host, 'https'),
  147. port: false, // TODO
  148. localhost: this.$helpers._.includes(this.conf.host, 'localhost')
  149. }
  150. this.state = 'considerations'
  151. this.loading = false
  152. },
  153. proceedToGit: function (ev) {
  154. let self = this
  155. self.state = 'git'
  156. self.loading = false
  157. self.$nextTick(() => {
  158. self.$validator.validateAll('git')
  159. })
  160. },
  161. proceedToGitCheck: function (ev) {
  162. let self = this
  163. this.state = 'gitcheck'
  164. this.loading = true
  165. self.gitcheck = {
  166. ok: false,
  167. results: [],
  168. error: ''
  169. }
  170. this.$helpers._.delay(() => {
  171. axios.post('/gitcheck', self.conf).then(resp => {
  172. if (resp.data.ok === true) {
  173. self.gitcheck.ok = true
  174. self.gitcheck.results = resp.data.results
  175. } else {
  176. self.gitcheck.ok = false
  177. self.gitcheck.error = resp.data.error
  178. }
  179. self.loading = false
  180. self.$nextTick()
  181. }).catch(err => {
  182. window.alert(err.message)
  183. })
  184. }, 1000)
  185. },
  186. proceedToAdmin: function (ev) {
  187. let self = this
  188. self.state = 'admin'
  189. self.loading = false
  190. self.$nextTick(() => {
  191. self.$validator.validateAll('admin')
  192. })
  193. },
  194. proceedToFinal: function (ev) {
  195. let self = this
  196. self.state = 'final'
  197. self.loading = true
  198. self.final = {
  199. ok: false,
  200. error: '',
  201. results: []
  202. }
  203. this.$helpers._.delay(() => {
  204. axios.post('/finalize', self.conf).then(resp => {
  205. if (resp.data.ok === true) {
  206. self.final.ok = true
  207. self.final.results = resp.data.results
  208. } else {
  209. self.final.ok = false
  210. self.final.error = resp.data.error
  211. }
  212. self.loading = false
  213. self.$nextTick()
  214. }).catch(err => {
  215. window.alert(err.message)
  216. })
  217. }, 1000)
  218. },
  219. finish: function (ev) {
  220. let self = this
  221. self.state = 'restart'
  222. this.$helpers._.delay(() => {
  223. axios.post('/restart', {}).then(resp => {
  224. this.$helpers._.delay(() => {
  225. window.location.assign(self.conf.host)
  226. }, 30000)
  227. }).catch(err => {
  228. window.alert(err.message)
  229. })
  230. }, 1000)
  231. }
  232. }
  233. }