Commands and such
parent
45b4ec5a43
commit
729064ffc8
|
@ -46,7 +46,7 @@ export default {
|
||||||
this.content = CodeMirror(document.getElementById('editor'), {
|
this.content = CodeMirror(document.getElementById('editor'), {
|
||||||
value: this.req.content,
|
value: this.req.content,
|
||||||
lineNumbers: (this.req.language !== 'markdown'),
|
lineNumbers: (this.req.language !== 'markdown'),
|
||||||
viewportMargin: Infinity,
|
viewportMargin: 500,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
mode: this.req.language,
|
mode: this.req.language,
|
||||||
theme: (this.req.language === 'markdown') ? 'markdown' : 'ttcn',
|
theme: (this.req.language === 'markdown') ? 'markdown' : 'ttcn',
|
||||||
|
|
|
@ -81,9 +81,9 @@ export default {
|
||||||
|
|
||||||
for (let i = 0; i < parts.length; i++) {
|
for (let i = 0; i < parts.length; i++) {
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
breadcrumbs.push({ name: parts[i], url: '/' + parts[i] + '/' })
|
breadcrumbs.push({ name: decodeURIComponent(parts[i]), url: '/' + parts[i] + '/' })
|
||||||
} else {
|
} 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
|
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>
|
<code>file</code> will be available with the path of the file.</p>
|
||||||
|
|
||||||
<h3>Before Save</h3>
|
<template v-for="command in commands">
|
||||||
<textarea v-model.trim="beforeSave"></textarea>
|
<h3>{{ capitalize(command.name) }}</h3>
|
||||||
|
<textarea v-model.trim="command.value"></textarea>
|
||||||
<h3>After Save</h3>
|
</template>
|
||||||
<textarea v-model.trim="afterSave"></textarea>
|
|
||||||
|
|
||||||
<p><input type="submit" value="Save"></p>
|
<p><input type="submit" value="Save"></p>
|
||||||
</form>
|
</form>
|
||||||
|
@ -34,6 +33,7 @@ export default {
|
||||||
name: 'settings',
|
name: 'settings',
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
|
commands: [],
|
||||||
beforeSave: '',
|
beforeSave: '',
|
||||||
afterSave: ''
|
afterSave: ''
|
||||||
}
|
}
|
||||||
|
@ -44,23 +44,46 @@ export default {
|
||||||
created () {
|
created () {
|
||||||
api.getCommands()
|
api.getCommands()
|
||||||
.then(commands => {
|
.then(commands => {
|
||||||
this.beforeSave = commands['before_save'].join('\n')
|
for (let key in commands) {
|
||||||
this.afterSave = commands['after_save'].join('\n')
|
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) })
|
.catch(error => { this.showError(error) })
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations([ 'showSuccess', 'showError' ]),
|
...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) {
|
saveCommands (event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
||||||
let commands = {
|
let commands = {}
|
||||||
'before_save': this.beforeSave.split('\n'),
|
|
||||||
'after_save': this.afterSave.split('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (commands['before_save'].length === 1 && commands['before_save'][0] === '') commands['before_save'] = []
|
for (let command of this.commands) {
|
||||||
if (commands['after_save'].length === 1 && commands['after_save'][0] === '') commands['after_save'] = []
|
let value = command.value.split('\n')
|
||||||
|
if (value.length === 1 && value[0] === '') {
|
||||||
|
value = []
|
||||||
|
}
|
||||||
|
|
||||||
|
commands[command.name] = value
|
||||||
|
}
|
||||||
|
|
||||||
api.updateCommands(commands)
|
api.updateCommands(commands)
|
||||||
.then(() => { this.showSuccess('Commands updated!') })
|
.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 {
|
export default {
|
||||||
delete: rm,
|
delete: rm,
|
||||||
fetch,
|
fetch,
|
||||||
|
@ -376,5 +397,6 @@ export default {
|
||||||
updateCSS,
|
updateCSS,
|
||||||
getCommands,
|
getCommands,
|
||||||
updateCommands,
|
updateCommands,
|
||||||
removePrefix
|
removePrefix,
|
||||||
|
getPlugins
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@
|
||||||
regenerate(data, route.path)
|
regenerate(data, route.path)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
data.buttons.done('publish')
|
data.buttons.done('publish')
|
||||||
|
data.store.commit('showSuccess', 'Post published!')
|
||||||
data.store.commit('setReload', true)
|
data.store.commit('setReload', true)
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@ -209,7 +210,7 @@
|
||||||
schedule(data, route.path, date)
|
schedule(data, route.path, date)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
data.buttons.done('schedule')
|
data.buttons.done('schedule')
|
||||||
data.store.commit('setReload', true)
|
data.store.commit('showSuccess', 'Post scheduled!')
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
data.buttons.done('schedule')
|
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.
|
// 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) {
|
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{
|
code, err := serveHTTP(&RequestContext{
|
||||||
FM: m,
|
FM: m,
|
||||||
User: nil,
|
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)
|
code, err = usersHandler(c, w, r)
|
||||||
case "commands":
|
case "commands":
|
||||||
code, err = commandsHandler(c, w, r)
|
code, err = commandsHandler(c, w, r)
|
||||||
|
case "plugins":
|
||||||
|
code, err = pluginsHandler(c, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
if code >= 300 || err != nil {
|
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
|
c.FM.Commands = commands
|
||||||
return http.StatusOK, nil
|
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