feat/muzan
Evan Chen 2021-11-15 12:33:28 +08:00
parent 556f673b3e
commit 733dada3fe
8 changed files with 134 additions and 22 deletions

43
app.go
View File

@ -27,6 +27,7 @@ type Page struct {
BaseUrl string
Actions []Action
Integrations []*Integration
Onitachi map[string]*Oni
Version string
Build string
Files []ActiveFile
@ -79,6 +80,7 @@ func (cui *ConfigUI) App(w http.ResponseWriter, r *http.Request) {
},
Actions: cui.Actions,
Integrations: cui.Integrations,
Onitachi: cui.Onitachi,
Static: cui.NoReconfig,
HideConfig: cui.HideConfig,
ResultBellow: cui.ResultBellow,
@ -127,3 +129,44 @@ func (cui *ConfigUI) App(w http.ResponseWriter, r *http.Request) {
panic(err)
}
}
func (cui *ConfigUI) Program(w http.ResponseWriter, r *http.Request) {
Files := []ActiveFile{}
for _, i := range cui.fileIndex {
Files = append(Files, ActiveFile{
Name: cui.Files[i].Name,
Path: cui.Files[i].Path,
Order: cui.Files[i].Order,
})
}
sort.Slice(Files, func(i, j int) bool {
if Files[i].Order == Files[j].Order {
return Files[i].Name < Files[j].Name
}
return Files[i].Order < Files[j].Order
})
plat := "unix"
if runtime.GOOS == "windows" {
plat = "windows"
}
data := Page{
AppName: cui.AppName,
BaseUrl: cui.BaseUrl,
File: ActiveFile{},
Files: Files,
Editor: Editor{
Platform: plat,
},
Actions: cui.Actions,
Integrations: cui.Integrations,
Onitachi: cui.Onitachi,
Static: cui.NoReconfig,
HideConfig: cui.HideConfig,
Version: version,
}
err := cui.tmpl.ExecuteTemplate(w, "muzan", data)
if err != nil {
panic(err)
}
}

View File

@ -152,6 +152,7 @@ func (cui *ConfigUI) mux() *http.ServeMux {
}
})
cuiR.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.FS(cui.PublicFS))))
cuiR.HandleFunc("/program", cui.Program)
cuiR.HandleFunc("/", cui.App)
return cuiR
}

View File

@ -1,7 +0,0 @@
{{define "action"}}
{{template "base/header" .}}
{{template "components/error" .}}
{{template "base/footer" .}}
{{end}}

View File

@ -6,11 +6,6 @@
</p>
</div>
</footer>
<script src="{{.BaseUrl}}public/ace/js/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="{{.BaseUrl}}public/ace/js/ext-beautify.js" type="text/javascript" charset="utf-8"></script>
<script src="{{.BaseUrl}}public/ace/js/ext-searchbox.js" type="text/javascript" charset="utf-8"></script>
{{template "base/script" .}}
<!-- <script src="/public/js/main.js"></script> -->
</body>
</html>
{{end}}

View File

@ -1,4 +1,8 @@
{{define "base/script"}}
<script src="{{.BaseUrl}}public/ace/js/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="{{.BaseUrl}}public/ace/js/ext-beautify.js" type="text/javascript" charset="utf-8"></script>
<script src="{{.BaseUrl}}public/ace/js/ext-searchbox.js" type="text/javascript" charset="utf-8"></script>
<script>
window.ToolIsFollow = false;
window.LastDelta = 0;

View File

@ -14,24 +14,26 @@
</li>
{{ end }}
</ul>
{{/* {{if .Actions}}
{{if .Onitachi}}
<p class="menu-label">
Actions
Programs
</p>
<ul class="menu-list">
{{- range .Actions -}}
{{- range $key, $value := .Onitachi -}}
<li>
<a class="button has-tooltip-arrow {{.State|state_class}}" id="actbtn-{{.Name|normal}}"
data-tooltip="{{.Cmd}}" onclick="toolDoAction('{{.Name}}')">
<span>{{- .Name -}}</span>
<span class="icon is-small"><span class="material-icons">
{{.State|state_icon}}
</span></span>
<a class="has-tooltip-arrow" data-tooltip="{{$value.Cmd}}" href="{{$.BaseUrl}}program?name={{.Name}}">
<div class="level">
<span>{{$key}}</span>
<div class="tags has-addons">
<span class="tag">State</span>
<span class="tag {{$value.State|state_class}}">{{$value.State}}</span>
</div>
</div>
</a>
</li>
{{- end -}}
</ul>
{{end}} */}}
{{end}}
{{if not .HideConfig}}
<p class="menu-label">
System

View File

@ -80,5 +80,6 @@ async function toolDoIntegration(name){
{{if not .ResultBellow}}
{{template "components/result" .}}
{{end}}
{{template "base/script" .}}
{{template "base/footer" .}}
{{end}}

73
templates/muzan.tmpl Normal file
View File

@ -0,0 +1,73 @@
{{define "muzan"}}
{{template "base/header" .}}
{{template "components/error" .}}
<script>
var Active = "{{.File.Name}}";
</script>
<div class="columns">
<div class="column is-one-quarter">
<div class="box">
{{template "components/menu" .}}
</div>
{{if .Actions}}
<div class="box">
<p class="menu-label has-text-left">Actions</p>
<div class="buttons are-small">
{{- range .Actions -}}
<button class="button has-tooltip-arrow" id="actbtn-{{.Name|normal}}"
data-tooltip="{{.Cmd}}" onclick="toolDoAction('{{.Name}}')">
<span>{{- .Name -}}</span>
</button>
{{- end -}}
</div>
</div>
{{end}}
{{if .Integrations}}
<div class="box">
<p class="menu-label has-text-left">Integrations</p>
<div class="buttons are-small">
{{- range .Integrations -}}
<button class="button has-tooltip-arrow" id="itgbtn-{{.Name|normal}}"
data-tooltip="{{.Description}}" onclick="toolDoIntegration('{{.Name}}')">
<span>{{- .Name -}}</span>
</button>
{{- end -}}
</div>
</div>
{{end}}
<div class="box has-text-centered">
<a href="{{.BaseUrl}}api/export" class="button is-small">Export Files</a>
</div>
</div>
<div class="column">
<div class="box">
Home
{{/* {{template "components/editor" .}} */}}
</div>
</div>
</div>
<script>
async function toolDoAction(name){
let el = document.getElementById('actbtn-'+name.replaceAll(" ","-"));
el.classList.add("is-loading")
el.classList.remove("has-tooltip-arrow")
await DoAction('action',name)
el.classList.remove("is-loading")
el.classList.add("has-tooltip-arrow")
{{if not .ResultBellow}}ResultViewTog(){{end}}
}
async function toolDoIntegration(name){
let el = document.getElementById('itgbtn-'+name.replaceAll(" ","-"));
el.classList.add("is-loading")
el.classList.remove("has-tooltip-arrow")
await DoAction('integration',name)
el.classList.remove("is-loading")
el.classList.add("has-tooltip-arrow")
{{if not .ResultBellow}}ResultViewTog(){{end}}
}
</script>
{{template "base/footer" .}}
{{end}}