2
0

config-manager.component.js 6.5 KB

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