1st phase - Global CSS
parent
dd7cd110db
commit
67fb6f8a78
|
@ -91,6 +91,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<style title="global-css" type="text/css">{{ .CSS }}</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|
|
@ -21,6 +21,12 @@
|
||||||
<p><input type="submit" value="Save"></p>
|
<p><input type="submit" value="Save"></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form @submit="saveCSS">
|
||||||
|
<h2>{{ $t('settings.customStylesheet') }}</h2>
|
||||||
|
<textarea v-model="css"></textarea>
|
||||||
|
<p><input type="submit" value="Save"></p>
|
||||||
|
</form>
|
||||||
|
|
||||||
<form @submit="saveCommands">
|
<form @submit="saveCommands">
|
||||||
<h2>{{ $t('settings.commands') }}</h2>
|
<h2>{{ $t('settings.commands') }}</h2>
|
||||||
|
|
||||||
|
@ -46,7 +52,8 @@ export default {
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
commands: [],
|
commands: [],
|
||||||
staticGen: []
|
staticGen: [],
|
||||||
|
css: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -65,8 +72,10 @@ export default {
|
||||||
value: settings.commands[key].join('\n')
|
value: settings.commands[key].join('\n')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.css = settings.css
|
||||||
})
|
})
|
||||||
.catch(error => { this.$showError(error) })
|
.catch(this.$showError)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
capitalize (name, where = '_') {
|
capitalize (name, where = '_') {
|
||||||
|
@ -96,7 +105,19 @@ export default {
|
||||||
|
|
||||||
updateSettings(commands, 'commands')
|
updateSettings(commands, 'commands')
|
||||||
.then(() => { this.$showSuccess(this.$t('settings.commandsUpdated')) })
|
.then(() => { this.$showSuccess(this.$t('settings.commandsUpdated')) })
|
||||||
.catch(error => { this.$showError(error) })
|
.catch(this.$showError)
|
||||||
|
},
|
||||||
|
saveCSS (event) {
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
|
updateSettings(this.css, 'css')
|
||||||
|
.then(() => {
|
||||||
|
this.$showSuccess(this.$t('settings.settingsUpdated'))
|
||||||
|
let style = document.querySelector('style[title="global-css"]')
|
||||||
|
style.innerHTML = ''
|
||||||
|
style.appendChild(document.createTextNode(this.css))
|
||||||
|
})
|
||||||
|
.catch(this.$showError)
|
||||||
},
|
},
|
||||||
saveStaticGen (event) {
|
saveStaticGen (event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
@ -117,7 +138,7 @@ export default {
|
||||||
|
|
||||||
updateSettings(staticGen, 'staticGen')
|
updateSettings(staticGen, 'staticGen')
|
||||||
.then(() => { this.$showSuccess(this.$t('settings.settingsUpdated')) })
|
.then(() => { this.$showSuccess(this.$t('settings.settingsUpdated')) })
|
||||||
.catch(error => { this.$showError(error) })
|
.catch(this.$showError)
|
||||||
},
|
},
|
||||||
parseStaticGen (staticgen) {
|
parseStaticGen (staticgen) {
|
||||||
for (let option of staticgen) {
|
for (let option of staticgen) {
|
||||||
|
|
|
@ -74,6 +74,9 @@ type FileManager struct {
|
||||||
// A map of events to a slice of commands.
|
// A map of events to a slice of commands.
|
||||||
Commands map[string][]string
|
Commands map[string][]string
|
||||||
|
|
||||||
|
// Global stylesheet.
|
||||||
|
CSS string
|
||||||
|
|
||||||
// NewFS should build a new file system for a given path.
|
// NewFS should build a new file system for a given path.
|
||||||
NewFS FSBuilder
|
NewFS FSBuilder
|
||||||
}
|
}
|
||||||
|
@ -111,6 +114,16 @@ func (m *FileManager) Setup() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the global CSS.
|
||||||
|
err = m.Store.Config.Get("css", &m.CSS)
|
||||||
|
if err != nil && err == ErrNotExist {
|
||||||
|
err = m.Store.Config.Save("css", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Tries to get the event commands from the database.
|
// Tries to get the event commands from the database.
|
||||||
// If they don't exist, initialize them.
|
// If they don't exist, initialize them.
|
||||||
err = m.Store.Config.Get("commands", &m.Commands)
|
err = m.Store.Config.Get("commands", &m.Commands)
|
||||||
|
|
|
@ -229,6 +229,7 @@ func renderFile(c *fm.Context, w http.ResponseWriter, file string) (int, error)
|
||||||
"BaseURL": c.RootURL(),
|
"BaseURL": c.RootURL(),
|
||||||
"NoAuth": c.NoAuth,
|
"NoAuth": c.NoAuth,
|
||||||
"Version": fm.Version,
|
"Version": fm.Version,
|
||||||
|
"CSS": template.CSS(c.CSS),
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.StaticGen != nil {
|
if c.StaticGen != nil {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
type modifySettingsRequest struct {
|
type modifySettingsRequest struct {
|
||||||
*modifyRequest
|
*modifyRequest
|
||||||
Data struct {
|
Data struct {
|
||||||
|
CSS string `json:"css"`
|
||||||
Commands map[string][]string `json:"commands"`
|
Commands map[string][]string `json:"commands"`
|
||||||
StaticGen map[string]interface{} `json:"staticGen"`
|
StaticGen map[string]interface{} `json:"staticGen"`
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
|
@ -61,6 +62,7 @@ func settingsHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int
|
||||||
}
|
}
|
||||||
|
|
||||||
type settingsGetRequest struct {
|
type settingsGetRequest struct {
|
||||||
|
CSS string `json:"css"`
|
||||||
Commands map[string][]string `json:"commands"`
|
Commands map[string][]string `json:"commands"`
|
||||||
StaticGen []option `json:"staticGen"`
|
StaticGen []option `json:"staticGen"`
|
||||||
}
|
}
|
||||||
|
@ -73,6 +75,7 @@ func settingsGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (
|
||||||
result := &settingsGetRequest{
|
result := &settingsGetRequest{
|
||||||
Commands: c.Commands,
|
Commands: c.Commands,
|
||||||
StaticGen: []option{},
|
StaticGen: []option{},
|
||||||
|
CSS: c.CSS,
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.StaticGen != nil {
|
if c.StaticGen != nil {
|
||||||
|
@ -114,6 +117,16 @@ func settingsPutHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (
|
||||||
return http.StatusOK, nil
|
return http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the global CSS.
|
||||||
|
if mod.Which == "css" {
|
||||||
|
if err := c.Store.Config.Save("css", mod.Data.CSS); err != nil {
|
||||||
|
return http.StatusInternalServerError, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.CSS = mod.Data.CSS
|
||||||
|
return http.StatusOK, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Update the static generator options.
|
// Update the static generator options.
|
||||||
if mod.Which == "staticGen" {
|
if mod.Which == "staticGen" {
|
||||||
err = mapstructure.Decode(mod.Data.StaticGen, c.StaticGen)
|
err = mapstructure.Decode(mod.Data.StaticGen, c.StaticGen)
|
||||||
|
|
2342
rice-box.go
2342
rice-box.go
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue