2017-03-05 04:20:22 +00:00
|
|
|
'use strict'
|
|
|
|
|
2017-05-15 00:17:08 +00:00
|
|
|
/* global appconfig, runmode */
|
2017-04-04 23:50:32 +00:00
|
|
|
|
2017-03-27 02:07:40 +00:00
|
|
|
import jQuery from 'jquery'
|
|
|
|
import _ from 'lodash'
|
|
|
|
import Vue from 'vue'
|
|
|
|
import VeeValidate from 'vee-validate'
|
|
|
|
import axios from 'axios'
|
2017-03-25 21:03:09 +00:00
|
|
|
|
|
|
|
Vue.use(VeeValidate, {
|
|
|
|
enableAutoClasses: true,
|
|
|
|
classNames: {
|
|
|
|
touched: 'is-touched', // the control has been blurred
|
|
|
|
untouched: 'is-untouched', // the control hasn't been blurred
|
|
|
|
valid: 'is-valid', // model is valid
|
|
|
|
invalid: 'is-invalid', // model is invalid
|
|
|
|
pristine: 'is-pristine', // control has not been interacted with
|
|
|
|
dirty: 'is-dirty' // control has been interacted with
|
|
|
|
}
|
|
|
|
})
|
2017-03-05 04:20:22 +00:00
|
|
|
|
|
|
|
jQuery(document).ready(function ($) {
|
|
|
|
new Vue({ // eslint-disable-line no-new
|
|
|
|
el: 'main',
|
|
|
|
data: {
|
|
|
|
loading: false,
|
2017-03-25 21:03:09 +00:00
|
|
|
state: 'welcome',
|
2017-03-05 04:20:22 +00:00
|
|
|
syscheck: {
|
|
|
|
ok: false,
|
2017-03-15 01:23:14 +00:00
|
|
|
error: '',
|
|
|
|
results: []
|
2017-03-05 04:20:22 +00:00
|
|
|
},
|
2017-03-25 21:03:09 +00:00
|
|
|
dbcheck: {
|
|
|
|
ok: false,
|
|
|
|
error: ''
|
|
|
|
},
|
|
|
|
gitcheck: {
|
|
|
|
ok: false,
|
|
|
|
error: ''
|
|
|
|
},
|
|
|
|
final: {
|
|
|
|
ok: false,
|
|
|
|
error: '',
|
|
|
|
results: []
|
|
|
|
},
|
2017-03-05 04:20:22 +00:00
|
|
|
conf: {
|
2017-04-04 23:50:32 +00:00
|
|
|
title: appconfig.title || 'Wiki',
|
|
|
|
host: appconfig.host || 'http://',
|
|
|
|
port: appconfig.port || 80,
|
|
|
|
lang: appconfig.lang || 'en',
|
2017-04-09 02:57:28 +00:00
|
|
|
public: (appconfig.public === true),
|
2017-04-04 23:50:32 +00:00
|
|
|
db: appconfig.db || 'mongodb://localhost:27017/wiki',
|
2017-03-25 21:03:09 +00:00
|
|
|
pathData: './data',
|
|
|
|
pathRepo: './repo',
|
2017-04-04 23:50:32 +00:00
|
|
|
gitUseRemote: (appconfig.git !== false),
|
2017-03-25 21:03:09 +00:00
|
|
|
gitUrl: '',
|
|
|
|
gitBranch: 'master',
|
|
|
|
gitAuthType: 'ssh',
|
|
|
|
gitAuthSSHKey: '',
|
|
|
|
gitAuthUser: '',
|
|
|
|
gitAuthPass: '',
|
|
|
|
gitAuthSSL: true,
|
2017-04-29 22:34:00 +00:00
|
|
|
gitShowUserEmail: true,
|
|
|
|
gitServerEmail: '',
|
2017-03-25 21:03:09 +00:00
|
|
|
adminEmail: '',
|
|
|
|
adminPassword: '',
|
|
|
|
adminPasswordConfirm: ''
|
2017-03-15 01:23:14 +00:00
|
|
|
},
|
|
|
|
considerations: {
|
|
|
|
https: false,
|
|
|
|
port: false,
|
|
|
|
localhost: false
|
2017-03-05 04:20:22 +00:00
|
|
|
}
|
|
|
|
},
|
2017-03-25 21:03:09 +00:00
|
|
|
computed: {
|
|
|
|
currentProgress: function () {
|
|
|
|
let perc = '0%'
|
|
|
|
switch (this.state) {
|
|
|
|
case 'welcome':
|
|
|
|
perc = '0%'
|
|
|
|
break
|
|
|
|
case 'syscheck':
|
|
|
|
perc = (this.syscheck.ok) ? '15%' : '5%'
|
|
|
|
break
|
|
|
|
case 'general':
|
|
|
|
perc = '20%'
|
|
|
|
break
|
|
|
|
case 'considerations':
|
|
|
|
perc = '30%'
|
|
|
|
break
|
|
|
|
case 'db':
|
|
|
|
perc = '35%'
|
|
|
|
break
|
|
|
|
case 'dbcheck':
|
|
|
|
perc = (this.dbcheck.ok) ? '50%' : '40%'
|
|
|
|
break
|
|
|
|
case 'paths':
|
|
|
|
perc = '55%'
|
|
|
|
break
|
|
|
|
case 'git':
|
|
|
|
perc = '60%'
|
|
|
|
break
|
|
|
|
case 'gitcheck':
|
|
|
|
perc = (this.gitcheck.ok) ? '75%' : '65%'
|
|
|
|
break
|
|
|
|
case 'admin':
|
|
|
|
perc = '80%'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return perc
|
|
|
|
}
|
|
|
|
},
|
2017-04-04 23:50:32 +00:00
|
|
|
mounted: function () {
|
|
|
|
if (appconfig.paths) {
|
|
|
|
this.conf.pathData = appconfig.paths.data || './data'
|
|
|
|
this.conf.pathRepo = appconfig.paths.repo || './repo'
|
|
|
|
}
|
|
|
|
if (appconfig.git !== false && _.isPlainObject(appconfig.git)) {
|
|
|
|
this.conf.gitUrl = appconfig.git.url || ''
|
|
|
|
this.conf.gitBranch = appconfig.git.branch || 'master'
|
2017-04-29 22:34:00 +00:00
|
|
|
this.conf.gitShowUserEmail = (appconfig.git.showUserEmail !== false)
|
|
|
|
this.conf.gitServerEmail = appconfig.git.serverEmail || ''
|
2017-04-04 23:50:32 +00:00
|
|
|
if (_.isPlainObject(appconfig.git.auth)) {
|
|
|
|
this.conf.gitAuthType = appconfig.git.auth.type || 'ssh'
|
|
|
|
this.conf.gitAuthSSHKey = appconfig.git.auth.privateKey || ''
|
|
|
|
this.conf.gitAuthUser = appconfig.git.auth.username || ''
|
|
|
|
this.conf.gitAuthPass = appconfig.git.auth.password || ''
|
|
|
|
this.conf.gitAuthSSL = (appconfig.git.auth.sslVerify !== false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2017-03-05 04:20:22 +00:00
|
|
|
methods: {
|
2017-03-06 03:22:21 +00:00
|
|
|
proceedToWelcome: function (ev) {
|
|
|
|
this.state = 'welcome'
|
|
|
|
this.loading = false
|
|
|
|
},
|
2017-03-05 04:20:22 +00:00
|
|
|
proceedToSyscheck: function (ev) {
|
|
|
|
let self = this
|
|
|
|
this.state = 'syscheck'
|
|
|
|
this.loading = true
|
2017-03-15 01:23:14 +00:00
|
|
|
self.syscheck = {
|
|
|
|
ok: false,
|
|
|
|
error: '',
|
|
|
|
results: []
|
|
|
|
}
|
2017-03-05 04:20:22 +00:00
|
|
|
|
|
|
|
_.delay(() => {
|
|
|
|
axios.post('/syscheck').then(resp => {
|
|
|
|
if (resp.data.ok === true) {
|
|
|
|
self.syscheck.ok = true
|
2017-03-15 01:23:14 +00:00
|
|
|
self.syscheck.results = resp.data.results
|
2017-03-05 04:20:22 +00:00
|
|
|
} else {
|
|
|
|
self.syscheck.ok = false
|
|
|
|
self.syscheck.error = resp.data.error
|
|
|
|
}
|
|
|
|
self.loading = false
|
2017-03-15 01:23:14 +00:00
|
|
|
self.$nextTick()
|
2017-03-05 04:20:22 +00:00
|
|
|
}).catch(err => {
|
|
|
|
window.alert(err.message)
|
|
|
|
})
|
|
|
|
}, 1000)
|
|
|
|
},
|
|
|
|
proceedToGeneral: function (ev) {
|
2017-03-25 21:03:09 +00:00
|
|
|
let self = this
|
|
|
|
self.state = 'general'
|
|
|
|
self.loading = false
|
|
|
|
self.$nextTick(() => {
|
|
|
|
self.$validator.validateAll('general')
|
|
|
|
})
|
2017-03-06 03:22:21 +00:00
|
|
|
},
|
2017-03-15 01:23:14 +00:00
|
|
|
proceedToConsiderations: function (ev) {
|
|
|
|
this.considerations = {
|
|
|
|
https: !_.startsWith(this.conf.host, 'https'),
|
|
|
|
port: false, // TODO
|
|
|
|
localhost: _.includes(this.conf.host, 'localhost')
|
|
|
|
}
|
|
|
|
this.state = 'considerations'
|
|
|
|
this.loading = false
|
|
|
|
},
|
2017-03-06 03:22:21 +00:00
|
|
|
proceedToDb: function (ev) {
|
2017-03-25 21:03:09 +00:00
|
|
|
let self = this
|
2017-05-15 00:17:08 +00:00
|
|
|
if (runmode.staticMongo) {
|
|
|
|
return self.proceedToDbcheck()
|
|
|
|
}
|
2017-03-25 21:03:09 +00:00
|
|
|
self.state = 'db'
|
|
|
|
self.loading = false
|
|
|
|
self.$nextTick(() => {
|
|
|
|
self.$validator.validateAll('db')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
proceedToDbcheck: function (ev) {
|
|
|
|
let self = this
|
|
|
|
this.state = 'dbcheck'
|
|
|
|
this.loading = true
|
|
|
|
self.dbcheck = {
|
|
|
|
ok: false,
|
|
|
|
error: ''
|
|
|
|
}
|
|
|
|
|
|
|
|
_.delay(() => {
|
|
|
|
axios.post('/dbcheck', {
|
|
|
|
db: self.conf.db
|
|
|
|
}).then(resp => {
|
|
|
|
if (resp.data.ok === true) {
|
|
|
|
self.dbcheck.ok = true
|
|
|
|
} else {
|
|
|
|
self.dbcheck.ok = false
|
|
|
|
self.dbcheck.error = resp.data.error
|
|
|
|
}
|
|
|
|
self.loading = false
|
|
|
|
self.$nextTick()
|
|
|
|
}).catch(err => {
|
|
|
|
window.alert(err.message)
|
|
|
|
})
|
|
|
|
}, 1000)
|
|
|
|
},
|
|
|
|
proceedToPaths: function (ev) {
|
|
|
|
let self = this
|
|
|
|
self.state = 'paths'
|
|
|
|
self.loading = false
|
|
|
|
self.$nextTick(() => {
|
|
|
|
self.$validator.validateAll('paths')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
proceedToGit: function (ev) {
|
|
|
|
let self = this
|
|
|
|
self.state = 'git'
|
|
|
|
self.loading = false
|
|
|
|
self.$nextTick(() => {
|
|
|
|
self.$validator.validateAll('git')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
proceedToGitCheck: function (ev) {
|
|
|
|
let self = this
|
|
|
|
this.state = 'gitcheck'
|
|
|
|
this.loading = true
|
2017-03-25 22:21:14 +00:00
|
|
|
self.gitcheck = {
|
2017-03-25 21:03:09 +00:00
|
|
|
ok: false,
|
2017-03-25 22:21:14 +00:00
|
|
|
results: [],
|
2017-03-25 21:03:09 +00:00
|
|
|
error: ''
|
|
|
|
}
|
|
|
|
|
|
|
|
_.delay(() => {
|
|
|
|
axios.post('/gitcheck', self.conf).then(resp => {
|
|
|
|
if (resp.data.ok === true) {
|
|
|
|
self.gitcheck.ok = true
|
2017-03-25 22:21:14 +00:00
|
|
|
self.gitcheck.results = resp.data.results
|
2017-03-25 21:03:09 +00:00
|
|
|
} else {
|
|
|
|
self.gitcheck.ok = false
|
|
|
|
self.gitcheck.error = resp.data.error
|
|
|
|
}
|
|
|
|
self.loading = false
|
|
|
|
self.$nextTick()
|
|
|
|
}).catch(err => {
|
|
|
|
window.alert(err.message)
|
|
|
|
})
|
|
|
|
}, 1000)
|
|
|
|
},
|
|
|
|
proceedToAdmin: function (ev) {
|
|
|
|
let self = this
|
|
|
|
self.state = 'admin'
|
|
|
|
self.loading = false
|
|
|
|
self.$nextTick(() => {
|
|
|
|
self.$validator.validateAll('admin')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
proceedToFinal: function (ev) {
|
|
|
|
let self = this
|
|
|
|
self.state = 'final'
|
|
|
|
self.loading = true
|
|
|
|
self.final = {
|
|
|
|
ok: false,
|
|
|
|
error: '',
|
|
|
|
results: []
|
|
|
|
}
|
|
|
|
|
|
|
|
_.delay(() => {
|
|
|
|
axios.post('/finalize', self.conf).then(resp => {
|
|
|
|
if (resp.data.ok === true) {
|
|
|
|
self.final.ok = true
|
|
|
|
self.final.results = resp.data.results
|
|
|
|
} else {
|
|
|
|
self.final.ok = false
|
|
|
|
self.final.error = resp.data.error
|
|
|
|
}
|
|
|
|
self.loading = false
|
|
|
|
self.$nextTick()
|
|
|
|
}).catch(err => {
|
|
|
|
window.alert(err.message)
|
|
|
|
})
|
|
|
|
}, 1000)
|
|
|
|
},
|
|
|
|
finish: function (ev) {
|
2017-03-29 02:29:53 +00:00
|
|
|
let self = this
|
|
|
|
self.state = 'restart'
|
2017-03-25 21:03:09 +00:00
|
|
|
|
2017-03-29 02:29:53 +00:00
|
|
|
_.delay(() => {
|
|
|
|
axios.post('/restart', {}).then(resp => {
|
|
|
|
_.delay(() => {
|
|
|
|
window.location.assign(self.conf.host)
|
2017-04-06 00:33:16 +00:00
|
|
|
}, 30000)
|
2017-03-29 02:29:53 +00:00
|
|
|
}).catch(err => {
|
|
|
|
window.alert(err.message)
|
|
|
|
})
|
|
|
|
}, 1000)
|
2017-03-05 04:20:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|