Use PAS UI
This commit is contained in:
@@ -33,9 +33,9 @@ type CDSViewFieldJSON struct {
|
||||
|
||||
//TODO: "https://api.sap.com/api/1.0/container/CDSViews/artifacts?containerType=contentType&$filter=Type%20eq%20'CDSVIEW'&$top=" + fmt.Sprint(top) + "&$skip=" + fmt.Sprint(skip)
|
||||
|
||||
func GetCDSViewField(CDSViewTechnicalName string) error {
|
||||
func GetCDSViewField(CDSViewTechnicalName table.TechnicalName) error {
|
||||
var json CDSViewFieldJSON
|
||||
path := "https://api.sap.com/odata/1.0/catalog.svc/CdsViewsContent.CdsViews('" + CDSViewTechnicalName + "')/$value"
|
||||
path := string("https://api.sap.com/odata/1.0/catalog.svc/CdsViewsContent.CdsViews('" + CDSViewTechnicalName + "')/$value")
|
||||
fmt.Println("Getting: ", CDSViewTechnicalName)
|
||||
err := RequestJSON(path, &json)
|
||||
if err != nil {
|
||||
@@ -60,7 +60,7 @@ func GetCDSViewFields() {
|
||||
|
||||
for _, cdsView := range *cdsViews {
|
||||
var json CDSViewFieldJSON
|
||||
path := "https://api.sap.com/odata/1.0/catalog.svc/CdsViewsContent.CdsViews('" + cdsView + "')/$value"
|
||||
path := string("https://api.sap.com/odata/1.0/catalog.svc/CdsViewsContent.CdsViews('" + cdsView + "')/$value")
|
||||
fmt.Println("Getting: ", cdsView)
|
||||
err := RequestJSON(path, &json)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,19 +23,19 @@ import (
|
||||
)
|
||||
|
||||
type CDSView struct {
|
||||
TechnicalName string `json:"Name"`
|
||||
DisplayName string `json:"DisplayName"`
|
||||
Description string `json:"Description"`
|
||||
Version string `json:"Version"`
|
||||
State string `json:"State"`
|
||||
CreatedAt int `json:"CreatedAt"`
|
||||
ModifiedAt int `json:"ModifiedAt"`
|
||||
TechnicalName `json:"Name"`
|
||||
DisplayName `json:"DisplayName"`
|
||||
Description `json:"Description"`
|
||||
Version `json:"Version"`
|
||||
State `json:"State"`
|
||||
CreatedAt `json:"CreatedAt"`
|
||||
ModifiedAt `json:"ModifiedAt"`
|
||||
}
|
||||
|
||||
//go:embed sql/query_cds_view.sql
|
||||
var query_cds_view string
|
||||
|
||||
func GetCDSView(TechnicalName string) (*CDSView, error) {
|
||||
func GetCDSView(TechnicalName TechnicalName) (*CDSView, error) {
|
||||
row := database.DB.QueryRow(query_cds_view, TechnicalName)
|
||||
|
||||
var CDSView CDSView
|
||||
@@ -50,15 +50,15 @@ func GetCDSView(TechnicalName string) (*CDSView, error) {
|
||||
//go:embed sql/query_all_cds_view_technical_names.sql
|
||||
var query_all_cds_view_technical_names string
|
||||
|
||||
func QueryAllCDSViewTechnicalNames() (*[]string, error) {
|
||||
func QueryAllCDSViewTechnicalNames() (*[]TechnicalName, error) {
|
||||
rows, err := database.DB.Query(query_all_cds_view_technical_names)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var technicalNames []string
|
||||
var technicalNames []TechnicalName
|
||||
for rows.Next() {
|
||||
var technicalName string
|
||||
var technicalName TechnicalName
|
||||
err := rows.Scan(&technicalName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -23,11 +23,11 @@ import (
|
||||
)
|
||||
|
||||
type CDSViewField struct {
|
||||
CDSViewTechnicalName string
|
||||
FieldName string `json:"fieldname"`
|
||||
Description string `json:"description"`
|
||||
DataType string `json:"datatype"`
|
||||
FieldLength string `json:"fieldlength"`
|
||||
CDSViewTechnicalName TechnicalName
|
||||
FieldName `json:"fieldname"`
|
||||
Description `json:"description"`
|
||||
DataType `json:"datatype"`
|
||||
FieldLength `json:"fieldlength"`
|
||||
}
|
||||
|
||||
//go:embed sql/query_cds_view_fields.sql
|
||||
@@ -53,7 +53,7 @@ func GetCDSViewFields(CDSViewTechnicalName string) (*[]CDSViewField, error) {
|
||||
//go:embed sql/query_cds_view_number_of_fields.sql
|
||||
var query_cds_view_number_of_fields string
|
||||
|
||||
func GetCDSViewNumberOfFields(CDSViewTechnicalName string) (int, error) {
|
||||
func GetCDSViewNumberOfFields(CDSViewTechnicalName TechnicalName) (int, error) {
|
||||
rows, err := database.DB.Query(query_cds_view_number_of_fields, CDSViewTechnicalName)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
135
cmd/database/table/field.go
Normal file
135
cmd/database/table/field.go
Normal file
@@ -0,0 +1,135 @@
|
||||
package table
|
||||
|
||||
import "code.achtarmig.org/pas/ui/field"
|
||||
|
||||
// CDS View
|
||||
type (
|
||||
TechnicalName string
|
||||
DisplayName string
|
||||
Description string
|
||||
Version string
|
||||
State string
|
||||
CreatedAt int
|
||||
ModifiedAt int
|
||||
)
|
||||
|
||||
// CDS View Field
|
||||
type (
|
||||
FieldName string
|
||||
DataType string
|
||||
FieldLength string
|
||||
)
|
||||
|
||||
func (t TechnicalName) Info(language string) field.Info {
|
||||
return field.Info{
|
||||
Title: "Technical Name",
|
||||
Details: "Technical Name of the CDS View",
|
||||
}
|
||||
}
|
||||
|
||||
func (t TechnicalName) String() string {
|
||||
return string(t)
|
||||
}
|
||||
|
||||
func (t DisplayName) Info(language string) field.Info {
|
||||
return field.Info{
|
||||
Title: "Name",
|
||||
Details: "Name of the CDS View",
|
||||
}
|
||||
}
|
||||
|
||||
func (t DisplayName) String() string {
|
||||
return string(t)
|
||||
}
|
||||
|
||||
func (t Description) Info(language string) field.Info {
|
||||
return field.Info{
|
||||
Title: "Description",
|
||||
Details: "Discription",
|
||||
}
|
||||
}
|
||||
|
||||
func (t Description) String() string {
|
||||
return string(t)
|
||||
}
|
||||
|
||||
func (t Version) Info(language string) field.Info {
|
||||
return field.Info{
|
||||
Title: "Version",
|
||||
Details: "Version of the CDS View",
|
||||
Justify: field.JustifyRight,
|
||||
}
|
||||
}
|
||||
|
||||
func (t Version) String() string {
|
||||
return string(t)
|
||||
}
|
||||
|
||||
func (t State) Info(language string) field.Info {
|
||||
return field.Info{
|
||||
Title: "Release State",
|
||||
Details: "Release State of the CDS View. Non-Released views may not be used",
|
||||
}
|
||||
}
|
||||
|
||||
func (t State) String() string {
|
||||
return string(t)
|
||||
}
|
||||
|
||||
func (t CreatedAt) Info(language string) field.Info {
|
||||
return field.Info{
|
||||
Title: "Created At",
|
||||
Details: "Timestamp of creation of the dataset",
|
||||
Justify: field.JustifyRight,
|
||||
}
|
||||
}
|
||||
|
||||
func (t CreatedAt) Int() int {
|
||||
return int(t)
|
||||
}
|
||||
|
||||
func (t ModifiedAt) Info(language string) field.Info {
|
||||
return field.Info{
|
||||
Title: "Modified At",
|
||||
Details: "Timestamp of last modification of the dataset",
|
||||
Justify: field.JustifyRight,
|
||||
}
|
||||
}
|
||||
|
||||
func (t ModifiedAt) Int() int {
|
||||
return int(t)
|
||||
}
|
||||
|
||||
func (t FieldName) Info(language string) field.Info {
|
||||
return field.Info{
|
||||
Title: "Field",
|
||||
Details: "Name of the CDS View field",
|
||||
}
|
||||
}
|
||||
|
||||
func (t FieldName) String() string {
|
||||
return string(t)
|
||||
}
|
||||
|
||||
func (t DataType) Info(language string) field.Info {
|
||||
return field.Info{
|
||||
Title: "Type",
|
||||
Details: "Data type of the CDS View field",
|
||||
}
|
||||
}
|
||||
|
||||
func (t DataType) String() string {
|
||||
return string(t)
|
||||
}
|
||||
|
||||
func (t FieldLength) Info(language string) field.Info {
|
||||
return field.Info{
|
||||
Title: "Length",
|
||||
Details: "Length of the CDS View field",
|
||||
Justify: field.JustifyRight,
|
||||
}
|
||||
}
|
||||
|
||||
func (t FieldLength) String() string {
|
||||
return string(t)
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
type Keyword struct {
|
||||
CDSViewTechnicalName string
|
||||
CDSViewTechnicalName TechnicalName
|
||||
Keyword string
|
||||
}
|
||||
|
||||
|
||||
@@ -29,15 +29,16 @@ import (
|
||||
|
||||
type CDSViewFieldModel struct {
|
||||
table.CDSViewField
|
||||
DataTypeTitle string
|
||||
FieldLengthOut string
|
||||
DescriptionOut string
|
||||
FieldNameOut table.FieldName
|
||||
DataTypeTitle table.DataType
|
||||
FieldLengthOut table.FieldLength
|
||||
DescriptionOut table.Description
|
||||
}
|
||||
|
||||
type CDSViewModel struct {
|
||||
*table.CDSView
|
||||
StateTitle string
|
||||
TechnicalNameEncoded string
|
||||
StateTitle table.State
|
||||
TechnicalNameEncoded table.TechnicalName
|
||||
NumberOfFields int
|
||||
}
|
||||
|
||||
@@ -53,8 +54,9 @@ func GetCDSViewModelFields(TechnicalName string) (*[]CDSViewFieldModel, error) {
|
||||
var fieldsModel []CDSViewFieldModel
|
||||
for _, field := range *fields {
|
||||
fieldModel.CDSViewField = field
|
||||
fieldModel.DataTypeTitle = englishCases.String(field.DataType)
|
||||
fieldModel.FieldLengthOut = strings.TrimLeft(field.FieldLength, "0")
|
||||
fieldModel.FieldNameOut = field.FieldName
|
||||
fieldModel.DataTypeTitle = table.DataType(englishCases.String(field.DataType.String()))
|
||||
fieldModel.FieldLengthOut = table.FieldLength(strings.TrimLeft(field.FieldLength.String(), "0"))
|
||||
fieldModel.DescriptionOut = field.Description
|
||||
if fieldModel.DescriptionOut == "" {
|
||||
fieldModel.DescriptionOut = "-"
|
||||
@@ -65,7 +67,7 @@ func GetCDSViewModelFields(TechnicalName string) (*[]CDSViewFieldModel, error) {
|
||||
return &fieldsModel, nil
|
||||
}
|
||||
|
||||
func GetCDSViewModel(TechnicalName string) (*CDSViewModel, error) {
|
||||
func GetCDSViewModel(TechnicalName table.TechnicalName) (*CDSViewModel, error) {
|
||||
var model CDSViewModel
|
||||
|
||||
cdsView, err := table.GetCDSView(TechnicalName)
|
||||
@@ -75,8 +77,8 @@ func GetCDSViewModel(TechnicalName string) (*CDSViewModel, error) {
|
||||
|
||||
model.CDSView = cdsView
|
||||
|
||||
model.StateTitle = englishCases.String(model.State)
|
||||
model.TechnicalNameEncoded = strings.Replace(base64.StdEncoding.EncodeToString([]byte(model.TechnicalName)), "=", "", -1)
|
||||
model.StateTitle = table.State(englishCases.String(model.State.String()))
|
||||
model.TechnicalNameEncoded = table.TechnicalName(strings.Replace(base64.StdEncoding.EncodeToString([]byte(model.TechnicalName)), "=", "", -1))
|
||||
|
||||
model.NumberOfFields, err = table.GetCDSViewNumberOfFields(TechnicalName)
|
||||
if err != nil {
|
||||
|
||||
@@ -18,37 +18,23 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"api-cds-search/cmd/handler"
|
||||
"api-cds-search/cmd/search"
|
||||
"api-cds-search/cmd/ui"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"code.achtarmig.org/pas/ui/context"
|
||||
"code.achtarmig.org/pas/ui/route"
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
func Load() *chi.Mux {
|
||||
r := chi.NewRouter()
|
||||
r.Group(func(r chi.Router) {
|
||||
ui.Load()
|
||||
r.Get("/", handleRoot)
|
||||
r.Route("/search", func(r chi.Router) {
|
||||
r.Get("/", search.HandleSearch)
|
||||
})
|
||||
r.Route("/cds", func(r chi.Router) {
|
||||
r.Get("/field/", handler.GetCDSField)
|
||||
})
|
||||
r.Use(context.Middleware)
|
||||
route.Routes(r)
|
||||
})
|
||||
|
||||
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/search", http.StatusFound)
|
||||
})
|
||||
|
||||
r.Handle("/ui/css/*", http.StripPrefix("/ui/css", http.FileServer(http.Dir("./cmd/ui/css"))))
|
||||
r.Handle("/ui/svg/*", http.StripPrefix("/ui/svg", http.FileServer(http.Dir("./cmd/ui/svg"))))
|
||||
return r
|
||||
}
|
||||
|
||||
func handleRoot(w http.ResponseWriter, r *http.Request) {
|
||||
err := ui.Template.ExecuteTemplate(w, "main", nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"api-cds-search/cmd/database/table"
|
||||
"api-cds-search/cmd/model"
|
||||
"api-cds-search/cmd/ui"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
)
|
||||
|
||||
type fuzzyResult struct {
|
||||
CDSViewTechnicalName string
|
||||
CDSViewTechnicalName table.TechnicalName
|
||||
hits int
|
||||
perfectHits int
|
||||
averageDistance float32
|
||||
@@ -54,7 +54,7 @@ var (
|
||||
ErrNoResults = errors.New("no results")
|
||||
)
|
||||
|
||||
var searchTargets map[string][]string = make(map[string][]string)
|
||||
var searchTargets map[table.TechnicalName][]string = make(map[table.TechnicalName][]string)
|
||||
var resultsBuffer map[string]*resultBuffer = make(map[string]*resultBuffer)
|
||||
|
||||
func Load() error {
|
||||
@@ -82,8 +82,8 @@ func Load() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetSearchTerm(r *http.Request) string {
|
||||
return strings.ToLower(r.URL.Query().Get("q"))
|
||||
func GetSearchTerm(q string) string {
|
||||
return strings.ToLower(q)
|
||||
}
|
||||
|
||||
func GetPage(r *http.Request) int {
|
||||
@@ -195,26 +195,7 @@ func BuildBuffer(searchTerm string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func HandleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
searchTerm := GetSearchTerm(r)
|
||||
|
||||
buffer, err := GetBuffer(searchTerm)
|
||||
if err != nil {
|
||||
err := BuildBuffer(searchTerm)
|
||||
if err != nil {
|
||||
err := ui.Template.ExecuteTemplate(w, "search-placeholder-no-result", nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
buffer, _ = GetBuffer(searchTerm)
|
||||
}
|
||||
|
||||
buffer.mu.Lock()
|
||||
defer buffer.mu.Unlock()
|
||||
|
||||
page := GetPage(r)
|
||||
func GetPages(buffer *resultBuffer, p int) (int, int) {
|
||||
var maxPage int
|
||||
if buffer.hits <= pageStep {
|
||||
maxPage = 0
|
||||
@@ -222,9 +203,17 @@ func HandleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
maxPage = (buffer.hits / pageStep)
|
||||
}
|
||||
|
||||
if page+1 > maxPage {
|
||||
page = maxPage
|
||||
if p+1 > maxPage {
|
||||
return maxPage, maxPage
|
||||
} else if p < 0 {
|
||||
return 0, maxPage
|
||||
}
|
||||
return p, maxPage
|
||||
}
|
||||
|
||||
func Search(buffer *resultBuffer, page int, maxPage int) *model.ResultsModel {
|
||||
buffer.mu.Lock()
|
||||
defer buffer.mu.Unlock()
|
||||
|
||||
resultsModel := model.NewResultsModel()
|
||||
for i := page * pageStep; i < page*pageStep+pageStep; i++ {
|
||||
@@ -241,17 +230,70 @@ func HandleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
resultsModel.AppendResultsModelViews(cdsView, result.score)
|
||||
}
|
||||
|
||||
resultsModel.SearchTerm = searchTerm
|
||||
resultsModel.CurrentPage = page
|
||||
resultsModel.MaxPage = maxPage
|
||||
|
||||
err = ui.Template.ExecuteTemplate(w, "results", resultsModel)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
return resultsModel
|
||||
}
|
||||
|
||||
/*
|
||||
func HandleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
searchTerm := GetSearchTerm(r)
|
||||
|
||||
buffer, err := GetBuffer(searchTerm)
|
||||
if err != nil {
|
||||
err := BuildBuffer(searchTerm)
|
||||
if err != nil {
|
||||
err := ui.Template.ExecuteTemplate(w, "search-placeholder-no-result", nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
buffer, _ = GetBuffer(searchTerm)
|
||||
}
|
||||
|
||||
buffer.mu.Lock()
|
||||
defer buffer.mu.Unlock()
|
||||
|
||||
page := GetPage(r)
|
||||
var maxPage int
|
||||
if buffer.hits <= pageStep {
|
||||
maxPage = 0
|
||||
} else {
|
||||
maxPage = (buffer.hits / pageStep)
|
||||
}
|
||||
|
||||
if page+1 > maxPage {
|
||||
page = maxPage
|
||||
}
|
||||
|
||||
resultsModel := model.NewResultsModel()
|
||||
for i := page * pageStep; i < page*pageStep+pageStep; i++ {
|
||||
if i > len(buffer.results)-1 {
|
||||
break
|
||||
}
|
||||
result := buffer.results[i]
|
||||
cdsView, err := model.GetCDSViewModel(result.CDSViewTechnicalName)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
|
||||
resultsModel.AppendResultsModelViews(cdsView, result.score)
|
||||
}
|
||||
|
||||
resultsModel.SearchTerm = searchTerm
|
||||
resultsModel.CurrentPage = page
|
||||
resultsModel.MaxPage = maxPage
|
||||
|
||||
err = ui.Template.ExecuteTemplate(w, "results", resultsModel)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
*/
|
||||
func ClearOldBuffers() {
|
||||
for key, buffer := range resultsBuffer {
|
||||
if time.Since(buffer.createdAt) >= time.Minute*10 {
|
||||
|
||||
@@ -20,6 +20,12 @@
|
||||
--yellow-5: #e5a50a;
|
||||
|
||||
--default-margin: 8px var(--base_margin) 8px var(--base_margin);
|
||||
|
||||
--default-outline: transparent solid 2px;
|
||||
--default-outline-offset: 1px;
|
||||
|
||||
--transiton-outline:
|
||||
outline-offset 0.1s ease-in-out, outline-color 0.1s ease-in-out;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
@@ -313,13 +319,9 @@ button:active {
|
||||
}
|
||||
|
||||
* {
|
||||
outline-offset: 1px;
|
||||
outline-style: solid;
|
||||
outline-width: 2px;
|
||||
outline-color: transparent;
|
||||
transition:
|
||||
outline-offset 0.1s ease-in-out,
|
||||
outline-color 0.1s ease-in-out;
|
||||
outline-offset: var(--default-outline-offset);
|
||||
outline: var(--default-outline);
|
||||
transition: var(--transiton-outline);
|
||||
}
|
||||
|
||||
*:focus-visible {
|
||||
@@ -412,17 +414,33 @@ button:active {
|
||||
width: 0%;
|
||||
height: 0%;
|
||||
margin: 0%;
|
||||
visibility: hidden;
|
||||
border: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.boxed-list > .expander {
|
||||
border-bottom-color: transparent !important;
|
||||
transition: border-bottom 0.15s steps(1, end);
|
||||
transition:
|
||||
var(--transiton-outline),
|
||||
border-bottom 0.15s steps(1, end),
|
||||
border-bottom-right-radius 0.05s 0.1s,
|
||||
border-bottom-left-radius 0.05s 0.1s;
|
||||
}
|
||||
|
||||
.boxed-list > .active.expander:focus-within {
|
||||
outline-offset: -1px;
|
||||
outline-color: color-mix(in srgb, var(--accent) 50%, transparent);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.expander:has(> .expander-state:checked) {
|
||||
border-bottom: 1px solid var(--border) !important;
|
||||
transition: border-bottom 0.15s steps(1, start);
|
||||
transition:
|
||||
var(--transiton-outline),
|
||||
border-bottom 0.15s steps(1, start),
|
||||
border-bottom-right-radius 0.05s,
|
||||
border-bottom-left-radius 0.05s;
|
||||
transition-delay: 0s;
|
||||
}
|
||||
|
||||
.expander-content {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
{{end}} {{block "result" .}}
|
||||
<label class="active expander" for="{{.TechnicalNameEncoded}}">
|
||||
<input
|
||||
tabindex="0"
|
||||
class="expander-state"
|
||||
type="checkbox"
|
||||
id="{{.TechnicalNameEncoded}}"
|
||||
@@ -25,7 +26,7 @@
|
||||
{{.StateTitle}}
|
||||
</div>
|
||||
</label>
|
||||
<div class="expander-content">
|
||||
<div class="expander-content" tabindex="none">
|
||||
<div class="label heading">Field Properties</div>
|
||||
<div class="container-center">
|
||||
{{template "fields-placeholder" dict "Result" .}}
|
||||
|
||||
78
cmd/view/cdsDetails.go
Normal file
78
cmd/view/cdsDetails.go
Normal file
@@ -0,0 +1,78 @@
|
||||
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")},
|
||||
}
|
||||
}
|
||||
6
cmd/view/load.go
Normal file
6
cmd/view/load.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package view
|
||||
|
||||
func Load() {
|
||||
searchView()
|
||||
cdsDetails()
|
||||
}
|
||||
50
cmd/view/results.go
Normal file
50
cmd/view/results.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"api-cds-search/cmd/model"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"code.achtarmig.org/pas/ui/element"
|
||||
"code.achtarmig.org/pas/ui/element/boxedlist"
|
||||
"code.achtarmig.org/pas/ui/element/boxedlist/expander"
|
||||
"code.achtarmig.org/pas/ui/element/option"
|
||||
"code.achtarmig.org/pas/ui/element/placeholder"
|
||||
"code.achtarmig.org/pas/ui/element/view"
|
||||
)
|
||||
|
||||
func results(v *view.Element, m *model.ResultsModel) element.ElementInterface {
|
||||
cont := v.GetElement("SearchResultsContainer")
|
||||
cont.DeleteAllChildren()
|
||||
|
||||
bl, _ := boxedlist.New(cont, "", func(p *boxedlist.Element) {
|
||||
p.MaxWidth = 42
|
||||
p.MinWidth = 20
|
||||
for _, result := range m.Views {
|
||||
expander.New(p, func(p *expander.Element) {
|
||||
p.Title = result.DisplayName.String()
|
||||
p.Subtitle = result.TechnicalName.String()
|
||||
p.PlaceholderHeight = 21 * result.NumberOfFields
|
||||
p.CallbackLazyLoad = func(e *expander.Element, w http.ResponseWriter, r *http.Request) error {
|
||||
http.Redirect(w, r, "/cds?q="+url.QueryEscape(result.TechnicalName.String()), http.StatusSeeOther)
|
||||
return errors.New("redirect")
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
return bl
|
||||
}
|
||||
|
||||
func noResults(v *view.Element) element.ElementInterface {
|
||||
cont := v.GetElement("SearchResultsContainer")
|
||||
cont.DeleteAllChildren()
|
||||
|
||||
pl, _ := placeholder.New(cont, "", func(p *placeholder.Element) {
|
||||
p.Icon = option.IconLoupe
|
||||
p.Title = "No Results"
|
||||
p.Subtitle = "Try refining your search term"
|
||||
})
|
||||
|
||||
return pl
|
||||
}
|
||||
152
cmd/view/search.go
Normal file
152
cmd/view/search.go
Normal file
@@ -0,0 +1,152 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"api-cds-search/cmd/search"
|
||||
"net/http"
|
||||
|
||||
"code.achtarmig.org/pas/ui/element"
|
||||
"code.achtarmig.org/pas/ui/element/button"
|
||||
"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/placeholder"
|
||||
"code.achtarmig.org/pas/ui/element/view"
|
||||
"code.achtarmig.org/pas/ui/route"
|
||||
)
|
||||
|
||||
func noSearch(v *view.Element) element.ElementInterface {
|
||||
cont := v.GetElement("SearchResultsContainer")
|
||||
cont.DeleteAllChildren()
|
||||
|
||||
pl, _ := placeholder.New(cont, "", func(p *placeholder.Element) {
|
||||
p.Icon = option.IconLoupe
|
||||
p.Title = "Search CDS-Views"
|
||||
p.Subtitle = "Find CDS-Views from the Business Accelerator Hub"
|
||||
})
|
||||
return pl
|
||||
}
|
||||
|
||||
func searchView() {
|
||||
view.New("Search", func(p *view.Element) {
|
||||
route.Register("/search", p)
|
||||
p.Title = "CDS-Search"
|
||||
p.OnRequest = func(v *view.Element, w http.ResponseWriter, r *http.Request) view.ProcessElements {
|
||||
inputQuery := v.GetElement("q").(*input.Element)
|
||||
inputQueryValue, _ := v.GetElement("q").(*input.Element).GetDataText()
|
||||
|
||||
searchTerm := search.GetSearchTerm(inputQueryValue)
|
||||
if inputQueryValue == "" {
|
||||
noSearch(v)
|
||||
}
|
||||
|
||||
inputPage := v.GetElement("p").(*input.Element)
|
||||
inputMaxPage := v.GetElement("MaxPage").(*input.Element)
|
||||
|
||||
currentPage, _ := inputPage.GetDataNumber()
|
||||
|
||||
if inputQuery.GetDataChanged() && inputQueryValue != "" {
|
||||
buf, err := search.GetBuffer(searchTerm)
|
||||
if err != nil {
|
||||
search.BuildBuffer(searchTerm)
|
||||
buf, err = search.GetBuffer(searchTerm)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
noResults(v)
|
||||
} else {
|
||||
currentPage, maxPage := search.GetPages(buf, currentPage)
|
||||
|
||||
m := search.Search(buf, currentPage, maxPage)
|
||||
|
||||
inputPage.Max = m.MaxPage
|
||||
inputMaxPage.Min = m.MaxPage
|
||||
inputMaxPage.Max = m.MaxPage
|
||||
inputMaxPage.SetData(m.MaxPage)
|
||||
|
||||
results(v, m)
|
||||
}
|
||||
}
|
||||
|
||||
return view.ProcessElements{
|
||||
Partial: []element.ElementInterface{v.GetElement("SearchResultsContainer")},
|
||||
OOBUpdate: []element.ElementInterface{inputPage, inputMaxPage},
|
||||
}
|
||||
}
|
||||
container.New(p, "MainContainer", func(p *container.Element) {
|
||||
p.Justify = option.JustifyCenter
|
||||
form.New(p, "SearchForm", func(p *form.Element) {
|
||||
p.SetHTMX(element.HTMX{
|
||||
Method: http.MethodGet,
|
||||
Target: "#SearchResultsContainer>*",
|
||||
Swap: "outerHTML",
|
||||
URL: "/search",
|
||||
PushURL: true,
|
||||
Params: "q, p",
|
||||
})
|
||||
|
||||
container.New(p, "SearchFormLinked", func(p *container.Element) {
|
||||
p.Justify = option.JustifyCenter
|
||||
p.LinkedHorizontal = true
|
||||
input.New(p, "q", input.TypeText, func(p *input.Element) {
|
||||
p.Placeholder = "Search here"
|
||||
p.Shape = option.ShapeRound
|
||||
|
||||
p.MinWidth = 10
|
||||
p.MaxWidth = 36
|
||||
})
|
||||
|
||||
button.New(p, "SearchButton", func(p *button.Element) {
|
||||
p.Label = "Search"
|
||||
p.DisplayStyle = option.DisplayStyleSuggestedAction
|
||||
p.Shape = option.ShapeRound
|
||||
|
||||
p.MaxWidth = 6
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
container.New(p, "CenterPager", func(p *container.Element) {
|
||||
p.Justify = option.JustifyCenter
|
||||
container.New(p, "Pager", func(p *container.Element) {
|
||||
p.MaxWidth = 42
|
||||
p.MinWidth = 10
|
||||
p.Justify = option.JustifyRight
|
||||
p.LinkedHorizontal = true
|
||||
input.New(p, "p", input.TypeNumber, func(p *input.Element) {
|
||||
p.Shape = option.ShapeRound
|
||||
|
||||
p.SetMin = true
|
||||
p.Min = 0
|
||||
|
||||
p.SetMax = true
|
||||
p.Max = 0
|
||||
|
||||
p.MinWidth = 4
|
||||
|
||||
p.SetHTMX(element.HTMX{
|
||||
Method: http.MethodGet,
|
||||
Include: "[name='q'], [name='p']",
|
||||
Target: "#SearchResultsContainer>*",
|
||||
URL: "/search",
|
||||
Swap: "outerHTML",
|
||||
PushURL: true,
|
||||
})
|
||||
})
|
||||
input.New(p, "MaxPage", input.TypeNumber, func(p *input.Element) {
|
||||
p.Disabled = true
|
||||
p.Shape = option.ShapeRound
|
||||
p.MinWidth = 4
|
||||
p.SetMin = true
|
||||
p.SetMax = true
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
container.New(p, "SearchResultsContainer", func(p *container.Element) {
|
||||
p.Justify = option.JustifyCenter
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user