79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
package view
|
|
|
|
import (
|
|
"api-cds-search/cmd/model"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"code.achtarmig.org/pas/ui/element"
|
|
"code.achtarmig.org/pas/ui/element/container"
|
|
"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
|
|
input.New(p, "q", input.TypeText, func(p *input.Element) {
|
|
p.Placeholder = "CDSViewTechnicalName"
|
|
p.Shape = option.ShapeRound
|
|
p.SetHTMX(element.HTMX{
|
|
Method: http.MethodGet,
|
|
Target: "#DetailsTable",
|
|
URL: "/cds",
|
|
PushURL: true,
|
|
})
|
|
})
|
|
})
|
|
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).GetDataText()
|
|
|
|
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")},
|
|
}
|
|
}
|