90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package view
|
|
|
|
import (
|
|
"api-cds-search/cmd/model"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
db_table "api-cds-search/cmd/database/table"
|
|
|
|
"code.achtarmig.org/pas/ui/element"
|
|
"code.achtarmig.org/pas/ui/element/container"
|
|
"code.achtarmig.org/pas/ui/element/form"
|
|
"code.achtarmig.org/pas/ui/element/input"
|
|
"code.achtarmig.org/pas/ui/element/option"
|
|
"code.achtarmig.org/pas/ui/element/table"
|
|
"code.achtarmig.org/pas/ui/element/view"
|
|
"code.achtarmig.org/pas/ui/route"
|
|
)
|
|
|
|
func cdsDetails() {
|
|
view.New("CDSDetails", func(p *view.Element) {
|
|
route.Register("/cds", p)
|
|
p.Title = "CDSDetails"
|
|
p.OnRequest = onRequestDetails
|
|
container.New(p, "Details", func(p *container.Element) {
|
|
p.Justify = option.JustifyCenter
|
|
form.New(p, "qForm", func(p *form.Element) {
|
|
p.Method = http.MethodGet
|
|
p.Target = "#DetailsTable"
|
|
p.URL = "/cds"
|
|
p.PushURL = true
|
|
input.New(p, "q", input.TypeText, func(p *input.Element) {
|
|
p.ValidateInput = true
|
|
p.RequestDelay = 200
|
|
p.Parameter = true
|
|
p.Placeholder = "CDSViewTechnicalName"
|
|
p.Shape = option.ShapeRound
|
|
|
|
p.OnValidate = func(e *input.Element, v any) error {
|
|
_, err := db_table.GetCDSView(db_table.TechnicalName(v.(string)))
|
|
return err
|
|
}
|
|
})
|
|
})
|
|
})
|
|
container.New(p, "", func(p *container.Element) {
|
|
p.Justify = option.JustifyCenter
|
|
table.New(p, "DetailsTable", func(p *table.Element) {
|
|
p.MinWidth = 20
|
|
p.MaxWidth = 32
|
|
})
|
|
})
|
|
})
|
|
}
|
|
|
|
func onRequestDetails(e *view.Element, w http.ResponseWriter, r *http.Request) view.ProcessElements {
|
|
cds, _ := e.GetElement("q").(*input.Element).GetDataString()
|
|
|
|
e.Title = fmt.Sprintf("CDSDetails - %s", cds)
|
|
|
|
fields, err := model.GetCDSViewModelFields(cds)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return view.ProcessElements{}
|
|
}
|
|
|
|
table := e.GetElement("DetailsTable").(*table.Element)
|
|
|
|
table.SetData(*fields)
|
|
|
|
for _, header := range table.Data.Header {
|
|
switch header.Name {
|
|
case "FieldNameOut":
|
|
header.Option.Font = option.FontMonospaced
|
|
case "DataTypeTitle":
|
|
case "FieldLengthOut":
|
|
header.Option.Font = option.FontMonospaced
|
|
case "DescriptionOut":
|
|
default:
|
|
header.Option.Hidden = true
|
|
}
|
|
}
|
|
|
|
table.Data.SetFieldOrder("FieldNameOut", "DescriptionOut", "DataTypeTitle", "FieldLengthOut")
|
|
|
|
return view.ProcessElements{
|
|
Partial: []element.ElementInterface{e.GetElement("DetailsTable")},
|
|
}
|
|
}
|