upgrades - plugins

pull/10/head
Hunter Long 2018-06-18 23:00:56 -07:00
parent 8a6f6a2cf8
commit ade9c69f25
7 changed files with 53 additions and 23 deletions

View File

@ -17,7 +17,7 @@ services:
- mongodb
env:
- VERSION=0.16
- VERSION=0.161
matrix:
allow_failures:

View File

@ -1,7 +1,8 @@
# Statup [![Build Status](https://travis-ci.org/hunterlong/statup.svg?branch=master)](https://travis-ci.org/hunterlong/statup)
An easy to use Status Page for your websites and applications. Statup will automatically fetch the application and render a beutiful status page.
# Statup - Status Page [![Build Status](https://travis-ci.org/hunterlong/statup.svg?branch=master)](https://travis-ci.org/hunterlong/statup)
An easy to use Status Page for your websites and applications. Statup will automatically fetch the application and render a beautiful status page with tons of features
for you to build an even better status page.
## Docker
## Run on Docker
Use the [Statup Docker Image](https://hub.docker.com/r/hunterlong/statup) to create a status page in seconds.
```
docker run -it -p 8080:8080 hunterlong/statup
@ -10,4 +11,9 @@ docker run -it -p 8080:8080 hunterlong/statup
### Install on Linux
```
bash <(curl -s https://statup.io/install.sh)
```
```
## User Created Plugins
Statup isn't just another Status Page for your applications, it's a framework that allows you to create your own plugins to interact with every element of your status page.
Plugin are created in Golang using the [statup/plugin](https://github.com/hunterlong/statup/tree/master/plugin) golang package. The plugin package has a list of
interfaces/events to accept into your own plugin application.

View File

@ -56,6 +56,6 @@
</div>
<script src="/js/jquery-3.3.1.slim.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
</body>
</html>

View File

@ -26,7 +26,7 @@
<a class="nav-link" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-style" role="tab" aria-controls="v-pills-style" aria-selected="false">Styling</a>
<a class="nav-link" id="v-pills-browse-tab" data-toggle="pill" href="#v-pills-browse" role="tab" aria-controls="v-pills-home" aria-selected="false">Browse Plugins</a>
{{ range .Plugins }}
<a class="nav-link text-capitalize" id="v-pills-{{.Name}}-tab" data-toggle="pill" href="#v-pills-{{.Name}}" role="tab" aria-controls="v-pills-profile" aria-selected="false">{{.Name}}</a>
<a class="nav-link text-capitalize" id="v-pills-{{underscore .Name}}-tab" data-toggle="pill" href="#v-pills-{{underscore .Name}}" role="tab" aria-controls="v-pills-profile" aria-selected="false">{{.Name}}</a>
{{end}}
</div>
</div>
@ -86,25 +86,13 @@
{{ range .Plugins }}
<div class="tab-pane fade" id="v-pills-{{.Name}}" role="tabpanel" aria-labelledby="v-pills-{{.Name}}-tab">
<div class="tab-pane fade" id="v-pills-{{underscore .Name}}" role="tabpanel" aria-labelledby="v-pills-{{underscore .Name}}-tab">
<h4 class="text-capitalize">{{ .Name }}</h4>
<span class="text-muted">{{ .Description }}</span>
<form class="mt-3" method="POST" action="/plugins/{{.Name}}/save">
{{ range .Form }}
<div class="form-group">
<label for="input_{{ .InputName }}" class="text-capitalize">{{ .Name }}</label>
<input type="text" class="form-control" name="{{ .InputName }}" value="{{ .Value }}" id="input_{{ .InputName }}" placeholder="Example input" aria-describedby="help_{{ .InputName }}">
{{ if .Description }}
<small id="help_{{ .InputName }}" class="form-text text-muted">
{{ .Description }}
</small>
{{ end }}
</div>
{{ end }}
<button type="submit" class="btn btn-primary">Save</button>
</form>
{{ safe .Form }}
</div>
{{end}}

View File

@ -35,8 +35,13 @@ type PluginInfo struct {
PluginActions
}
func (p *PluginInfo) Form() string {
return "okkokokkok"
}
type PluginActions interface {
GetInfo() Info
GetForm() string
SetInfo(map[string]interface{}) Info
Routes() []Routing
OnSave(map[string]interface{})
@ -64,4 +69,5 @@ type Routing struct {
type Info struct {
Name string
Description string
Form string
}

Binary file not shown.

32
web.go
View File

@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"time"
"regexp"
)
var (
@ -284,7 +285,7 @@ func PluginsHandler(w http.ResponseWriter, r *http.Request) {
for _, p := range allPlugins {
fields := structs.Map(p.GetInfo())
pluginFields = append(pluginFields, PluginSelect{p.GetInfo().Name, fields})
pluginFields = append(pluginFields, PluginSelect{p.GetInfo().Name, p.GetForm(),fields})
}
core.PluginFields = pluginFields
@ -293,6 +294,7 @@ func PluginsHandler(w http.ResponseWriter, r *http.Request) {
type PluginSelect struct {
Plugin string
Form string
Params map[string]interface{}
}
@ -391,6 +393,9 @@ func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data i
"VERSION": func() string {
return VERSION
},
"underscore": func(html string) string {
return UnderScoreString(html)
},
})
t, _ = t.Parse(nav)
t.Parse(render)
@ -425,3 +430,28 @@ func UsersDeleteHandler(w http.ResponseWriter, r *http.Request) {
user.Delete()
http.Redirect(w, r, "/users", http.StatusSeeOther)
}
func UnderScoreString(str string) string {
// convert every letter to lower case
newStr := strings.ToLower(str)
// convert all spaces/tab to underscore
regExp := regexp.MustCompile("[[:space:][:blank:]]")
newStrByte := regExp.ReplaceAll([]byte(newStr), []byte("_"))
regExp = regexp.MustCompile("`[^a-z0-9]`i")
newStrByte = regExp.ReplaceAll(newStrByte, []byte("_"))
regExp = regexp.MustCompile("[!/']")
newStrByte = regExp.ReplaceAll(newStrByte, []byte("_"))
// and remove underscore from beginning and ending
newStr = strings.TrimPrefix(string(newStrByte), "_")
newStr = strings.TrimSuffix(newStr, "_")
return newStr
}