From 2bb6ac408dae16da41a3ebea48387372fc120835 Mon Sep 17 00:00:00 2001 From: Bogdan Brinza Date: Mon, 28 Oct 2024 14:18:13 -0700 Subject: [PATCH] Moving over item counter formatter to compton --- go.mod | 2 +- go.sum | 2 + rest/compton_data/count_templates.go | 7 ++++ .../{show_all.go => button.go} | 2 +- rest/compton_fragments/items_count.go | 37 ------------------- rest/compton_pages/search.go | 10 +++-- rest/compton_pages/steam_news.go | 2 +- rest/compton_pages/updates.go | 10 +++-- rest/get_search.go | 2 +- 9 files changed, 27 insertions(+), 47 deletions(-) create mode 100644 rest/compton_data/count_templates.go rename rest/compton_fragments/{show_all.go => button.go} (78%) delete mode 100644 rest/compton_fragments/items_count.go diff --git a/go.mod b/go.mod index a837113e..ae1a109d 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/boggydigital/atomus v0.1.9 github.com/boggydigital/backups v0.1.3 github.com/boggydigital/clo v1.0.4 - github.com/boggydigital/compton v0.1.96 + github.com/boggydigital/compton v0.1.97 github.com/boggydigital/coost v0.3.9 github.com/boggydigital/dolo v0.2.18 github.com/boggydigital/issa v0.1.12 diff --git a/go.sum b/go.sum index 7ba6642d..4bdd87ce 100644 --- a/go.sum +++ b/go.sum @@ -20,6 +20,8 @@ github.com/boggydigital/compton v0.1.95 h1:0TP++8sGf5qe9mBrDIEdhdHhSJ+dJxWtBp0t2 github.com/boggydigital/compton v0.1.95/go.mod h1:dj/yZ2cCfts6+heUS60Favateu+gNTIsoxfX6yNZWLg= github.com/boggydigital/compton v0.1.96 h1:Rg7GvZrDFgsm0htDof/MNCXexkzW/BrLfG0DPsBAaQc= github.com/boggydigital/compton v0.1.96/go.mod h1:dj/yZ2cCfts6+heUS60Favateu+gNTIsoxfX6yNZWLg= +github.com/boggydigital/compton v0.1.97 h1:xRe+lOILJtmav9a+njNtkBqBQsefnwa2VUV5AnBuwAg= +github.com/boggydigital/compton v0.1.97/go.mod h1:dj/yZ2cCfts6+heUS60Favateu+gNTIsoxfX6yNZWLg= github.com/boggydigital/coost v0.3.9 h1:lMfR5PyexBDR4xDOQp0zWZWUk/Dqlrx7gw7i7XdsC4c= github.com/boggydigital/coost v0.3.9/go.mod h1:w7ChGaah1DKsBIXb9ANdILg2pe2Jp7JkNpnK2R6rBec= github.com/boggydigital/dolo v0.2.18 h1:aN/Bq55e0/9VgmVTNw0ru3aoS6lpZJI59ho5YQlFbDE= diff --git a/rest/compton_data/count_templates.go b/rest/compton_data/count_templates.go new file mode 100644 index 00000000..a849789b --- /dev/null +++ b/rest/compton_data/count_templates.go @@ -0,0 +1,7 @@ +package compton_data + +const ( + SingleItemTemplate = "1 item" + ManyItemsSinglePageTemplate = "{total} items" + ManyItemsManyPagesTemplate = "{from}-{to} out of {total} items" +) diff --git a/rest/compton_fragments/show_all.go b/rest/compton_fragments/button.go similarity index 78% rename from rest/compton_fragments/show_all.go rename to rest/compton_fragments/button.go index 6edae319..f6e308db 100644 --- a/rest/compton_fragments/show_all.go +++ b/rest/compton_fragments/button.go @@ -5,7 +5,7 @@ import ( "github.com/boggydigital/compton/consts/input_types" ) -func ShowMoreButton(r compton.Registrar, title, href string) compton.Element { +func Button(r compton.Registrar, title, href string) compton.Element { showAllLink := compton.A(href) diff --git a/rest/compton_fragments/items_count.go b/rest/compton_fragments/items_count.go deleted file mode 100644 index 19ba5f90..00000000 --- a/rest/compton_fragments/items_count.go +++ /dev/null @@ -1,37 +0,0 @@ -package compton_fragments - -import ( - "github.com/boggydigital/compton" - "github.com/boggydigital/compton/consts/color" - "github.com/boggydigital/compton/consts/font_weight" - "github.com/boggydigital/compton/consts/size" - "strconv" - "strings" -) - -const ( - singleItem = "1 item" - manyItemsSinglePage = "{total} items" - manyItemsManyPages = "{from}-{to} out of {total} items" -) - -func ItemsCount(r compton.Registrar, from, to, total int) compton.Element { - title := "" - switch total { - case 1: - title = singleItem - case to: - title = strings.Replace(manyItemsSinglePage, "{total}", strconv.Itoa(total), 1) - default: - title = strings.Replace(manyItemsManyPages, "{from}", strconv.Itoa(from+1), 1) - title = strings.Replace(title, "{to}", strconv.Itoa(to), 1) - title = strings.Replace(title, "{total}", strconv.Itoa(total), 1) - } - - itemsCount := compton.Fspan(r, title). - ForegroundColor(color.Gray). - FontSize(size.XSmall). - FontWeight(font_weight.Normal) - - return itemsCount -} diff --git a/rest/compton_pages/search.go b/rest/compton_pages/search.go index 54b43ba9..dc98a75c 100644 --- a/rest/compton_pages/search.go +++ b/rest/compton_pages/search.go @@ -40,8 +40,12 @@ func Search(query map[string][]string, ids []string, from, to int, rdx kevlar.Re if len(query) > 0 { - itemsCount := compton_fragments.ItemsCount(p, from, to, len(ids)) - filterSearchDetails.AppendSummary(itemsCount) + cf := compton.NewCountFormatter( + compton_data.SingleItemTemplate, + compton_data.ManyItemsSinglePageTemplate, + compton_data.ManyItemsManyPagesTemplate) + + filterSearchDetails.AppendSummary(cf.TitleElement(p, from, to, len(ids))) } searchQuery := compton.Query(p, query, @@ -69,7 +73,7 @@ func Search(query map[string][]string, ids []string, from, to int, rdx kevlar.Re href := "/search?" + enq - pageStack.Append(compton_fragments.ShowMoreButton(p, "Next page", href)) + pageStack.Append(compton_fragments.Button(p, "Next page", href)) } /* Standard app footer */ diff --git a/rest/compton_pages/steam_news.go b/rest/compton_pages/steam_news.go index c5f6373f..495d4b88 100644 --- a/rest/compton_pages/steam_news.go +++ b/rest/compton_pages/steam_news.go @@ -31,7 +31,7 @@ func SteamNews(id string, san *steam_integration.AppNews, all bool) compton.Page title = "Show only community announcements" href = "/steam-news?id=" + id } - pageStack.Append(compton_fragments.ShowMoreButton(s, title, href)) + pageStack.Append(compton_fragments.Button(s, title, href)) } newsItems := communityAnnouncements diff --git a/rest/compton_pages/updates.go b/rest/compton_pages/updates.go index ce57514a..1c24aa70 100644 --- a/rest/compton_pages/updates.go +++ b/rest/compton_pages/updates.go @@ -45,7 +45,7 @@ func Updates(sections []string, var showAll compton.Element if hasMoreItems(sections, updates, updateTotals) { - showAll = compton_fragments.ShowMoreButton(p, "Show all", "?show-all=true") + showAll = compton_fragments.Button(p, "Show all", "?show-all=true") pageStack.Append(showAll) } @@ -65,8 +65,12 @@ func Updates(sections []string, DetailsMarginBlockEnd(size.Unset). SummaryRowGap(size.XXSmall) - itemsCount := compton_fragments.ItemsCount(p, 0, len(ids), updateTotals[section]) - sectionDetailsToggle.AppendSummary(itemsCount) + cf := compton.NewCountFormatter( + compton_data.SingleItemTemplate, + compton_data.ManyItemsSinglePageTemplate, + compton_data.ManyItemsManyPagesTemplate) + + sectionDetailsToggle.AppendSummary(cf.TitleElement(p, 0, len(ids), updateTotals[section])) sectionDetailsToggle.SetId(sectionTitle) pageStack.Append(sectionDetailsToggle) diff --git a/rest/get_search.go b/rest/get_search.go index ec95ce22..562f12cf 100644 --- a/rest/get_search.go +++ b/rest/get_search.go @@ -65,7 +65,7 @@ func GetSearch(w http.ResponseWriter, r *http.Request) { var err error found := rdx.Match(q) - ids, err = rdx.Sort(found, desc, sort, vangogh_local_data.TitleProperty) + ids, err = rdx.Sort(found, desc, sort, vangogh_local_data.TitleProperty, vangogh_local_data.ProductTypeProperty) if err != nil { http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError) return