Commands and such
Former-commit-id: e2a84ea45e19a6c34c2a89fa2804ce63c35cbf53 [formerly d995af7874f5ee0ee22442357ebd4e160bed2786] [formerly ee876a568e127817caae55506ab128246237b5a8 [formerly 729064ffc8
]]
Former-commit-id: 64554cfd503eab2e5daf0b33971fea1924ac8249 [formerly 8b6fa3f88083530ceeab62d52fbc381b1ac6c335]
Former-commit-id: 3df08dbb64f46dee8c4ceebfcac273038960eec1
pull/726/head
parent
efdc61f791
commit
fc1a78bb27
|
@ -46,7 +46,7 @@ export default {
|
|||
this.content = CodeMirror(document.getElementById('editor'), {
|
||||
value: this.req.content,
|
||||
lineNumbers: (this.req.language !== 'markdown'),
|
||||
viewportMargin: Infinity,
|
||||
viewportMargin: 500,
|
||||
autofocus: true,
|
||||
mode: this.req.language,
|
||||
theme: (this.req.language === 'markdown') ? 'markdown' : 'ttcn',
|
||||
|
|
|
@ -81,9 +81,9 @@ export default {
|
|||
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (i === 0) {
|
||||
breadcrumbs.push({ name: parts[i], url: '/' + parts[i] + '/' })
|
||||
breadcrumbs.push({ name: decodeURIComponent(parts[i]), url: '/' + parts[i] + '/' })
|
||||
} else {
|
||||
breadcrumbs.push({ name: parts[i], url: breadcrumbs[i - 1].url + parts[i] + '/' })
|
||||
breadcrumbs.push({ name: decodeURIComponent(parts[i]), url: breadcrumbs[i - 1].url + parts[i] + '/' })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,11 +14,10 @@
|
|||
per line. If the event is related to files, such as before and after saving, the environment variable
|
||||
<code>file</code> will be available with the path of the file.</p>
|
||||
|
||||
<h3>Before Save</h3>
|
||||
<textarea v-model.trim="beforeSave"></textarea>
|
||||
|
||||
<h3>After Save</h3>
|
||||
<textarea v-model.trim="afterSave"></textarea>
|
||||
<template v-for="command in commands">
|
||||
<h3>{{ capitalize(command.name) }}</h3>
|
||||
<textarea v-model.trim="command.value"></textarea>
|
||||
</template>
|
||||
|
||||
<p><input type="submit" value="Save"></p>
|
||||
</form>
|
||||
|
@ -34,6 +33,7 @@ export default {
|
|||
name: 'settings',
|
||||
data: function () {
|
||||
return {
|
||||
commands: [],
|
||||
beforeSave: '',
|
||||
afterSave: ''
|
||||
}
|
||||
|
@ -44,23 +44,46 @@ export default {
|
|||
created () {
|
||||
api.getCommands()
|
||||
.then(commands => {
|
||||
this.beforeSave = commands['before_save'].join('\n')
|
||||
this.afterSave = commands['after_save'].join('\n')
|
||||
for (let key in commands) {
|
||||
this.commands.push({
|
||||
name: key,
|
||||
value: commands[key].join('\n')
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(error => { this.showError(error) })
|
||||
|
||||
api.getPlugins()
|
||||
.then(plugins => {
|
||||
console.log(plugins)
|
||||
})
|
||||
.catch(error => { this.showError(error) })
|
||||
},
|
||||
methods: {
|
||||
...mapMutations([ 'showSuccess', 'showError' ]),
|
||||
capitalize (name) {
|
||||
let splitted = name.split('_')
|
||||
name = ''
|
||||
|
||||
for (let i = 0; i < splitted.length; i++) {
|
||||
name += splitted[i].charAt(0).toUpperCase() + splitted[i].slice(1) + ' '
|
||||
}
|
||||
|
||||
return name.slice(0, -1)
|
||||
},
|
||||
saveCommands (event) {
|
||||
event.preventDefault()
|
||||
|
||||
let commands = {
|
||||
'before_save': this.beforeSave.split('\n'),
|
||||
'after_save': this.afterSave.split('\n')
|
||||
}
|
||||
let commands = {}
|
||||
|
||||
if (commands['before_save'].length === 1 && commands['before_save'][0] === '') commands['before_save'] = []
|
||||
if (commands['after_save'].length === 1 && commands['after_save'][0] === '') commands['after_save'] = []
|
||||
for (let command of this.commands) {
|
||||
let value = command.value.split('\n')
|
||||
if (value.length === 1 && value[0] === '') {
|
||||
value = []
|
||||
}
|
||||
|
||||
commands[command.name] = value
|
||||
}
|
||||
|
||||
api.updateCommands(commands)
|
||||
.then(() => { this.showSuccess('Commands updated!') })
|
||||
|
|
|
@ -358,6 +358,27 @@ function updateCommands (commands) {
|
|||
})
|
||||
}
|
||||
|
||||
function getPlugins () {
|
||||
return new Promise((resolve, reject) => {
|
||||
let request = new window.XMLHttpRequest()
|
||||
request.open('GET', `${store.state.baseURL}/api/plugins/`, true)
|
||||
request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`)
|
||||
|
||||
request.onload = () => {
|
||||
switch (request.status) {
|
||||
case 200:
|
||||
resolve(JSON.parse(request.responseText))
|
||||
break
|
||||
default:
|
||||
reject(request.responseText)
|
||||
break
|
||||
}
|
||||
}
|
||||
request.onerror = (error) => reject(error)
|
||||
request.send()
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
delete: rm,
|
||||
fetch,
|
||||
|
@ -376,5 +397,6 @@ export default {
|
|||
updateCSS,
|
||||
getCommands,
|
||||
updateCommands,
|
||||
removePrefix
|
||||
removePrefix,
|
||||
getPlugins
|
||||
}
|
||||
|
|
|
@ -94,6 +94,7 @@
|
|||
regenerate(data, route.path)
|
||||
.then(() => {
|
||||
data.buttons.done('publish')
|
||||
data.store.commit('showSuccess', 'Post published!')
|
||||
data.store.commit('setReload', true)
|
||||
})
|
||||
.catch((error) => {
|
||||
|
@ -209,7 +210,7 @@
|
|||
schedule(data, route.path, date)
|
||||
.then(() => {
|
||||
data.buttons.done('schedule')
|
||||
data.store.commit('setReload', true)
|
||||
data.store.commit('showSuccess', 'Post scheduled!')
|
||||
})
|
||||
.catch((error) => {
|
||||
data.buttons.done('schedule')
|
||||
|
|
|
@ -278,7 +278,6 @@ func (m *FileManager) RegisterEventType(name string) error {
|
|||
|
||||
// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
|
||||
func (m *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
// TODO: Handle errors here and make it compatible with http.Handler
|
||||
code, err := serveHTTP(&RequestContext{
|
||||
FM: m,
|
||||
User: nil,
|
||||
|
|
2
http.go
2
http.go
|
@ -140,6 +140,8 @@ func apiHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int,
|
|||
code, err = usersHandler(c, w, r)
|
||||
case "commands":
|
||||
code, err = commandsHandler(c, w, r)
|
||||
case "plugins":
|
||||
code, err = pluginsHandler(c, w, r)
|
||||
}
|
||||
|
||||
if code >= 300 || err != nil {
|
||||
|
|
32
settings.go
32
settings.go
|
@ -49,3 +49,35 @@ func commandsPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Reques
|
|||
c.FM.Commands = commands
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
|
||||
func pluginsHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
return pluginsGetHandler(c, w, r)
|
||||
case http.MethodPut:
|
||||
return pluginsPutHandler(c, w, r)
|
||||
}
|
||||
|
||||
return http.StatusMethodNotAllowed, nil
|
||||
}
|
||||
|
||||
func pluginsGetHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
if !c.User.Admin {
|
||||
return http.StatusForbidden, nil
|
||||
}
|
||||
|
||||
return renderJSON(w, c.FM.Plugins)
|
||||
}
|
||||
|
||||
func pluginsPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
if !c.User.Admin {
|
||||
return http.StatusForbidden, nil
|
||||
}
|
||||
|
||||
if r.Body == nil {
|
||||
return http.StatusBadGateway, errors.New("Empty request body")
|
||||
}
|
||||
|
||||
// TODO
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue