config-manager.component.js 6.1 KB

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