Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Improving validation results display
Browse files Browse the repository at this point in the history
  • Loading branch information
boggydigital committed Oct 6, 2024
1 parent 3b0ccee commit 118c40f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 56 deletions.
2 changes: 1 addition & 1 deletion rest/compton_fragments/steam_news_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func SteamNewsItem(r compton.Registrar, item steam_integration.NewsItem, open bo

header := SteamReviewHeadingRow(r, headingTitle)

AppendSteamReviewPropertyValue(r, header, "Posted:", epochDate(item.Date))
AppendSteamReviewPropertyValue(r, header, "Posted:", EpochDate(item.Date))
if item.Author != "" {
AppendSteamReviewPropertyValue(r, header, "Author:", item.Author)
}
Expand Down
6 changes: 3 additions & 3 deletions rest/compton_fragments/steam_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func SteamReview(r compton.Registrar, review steam_integration.Review) compton.E

datesRow := SteamReviewHeadingRow(r, "Review")
if review.TimestampCreated > 0 {
AppendSteamReviewPropertyValue(r, datesRow, "Cr:", epochDate(review.TimestampCreated))
AppendSteamReviewPropertyValue(r, datesRow, "Cr:", EpochDate(review.TimestampCreated))
}
if review.TimestampUpdated > 0 {
AppendSteamReviewPropertyValue(r, datesRow, "Upd:", epochDate(review.TimestampUpdated))
AppendSteamReviewPropertyValue(r, datesRow, "Upd:", EpochDate(review.TimestampUpdated))
}

playtimeRow := SteamReviewHeadingRow(r, "Playtime")
Expand Down Expand Up @@ -133,7 +133,7 @@ func minutesToHours(m int) string {
return strconv.Itoa(m/60) + "h"
}

func epochDate(e int64) string {
func EpochDate(e int64) string {
return time.Unix(e, 0).Format("Jan 2, '06")
}

Expand Down
59 changes: 47 additions & 12 deletions rest/compton_pages/downloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/boggydigital/compton/elements/fspan"
"github.com/boggydigital/compton/elements/svg_use"
"github.com/boggydigital/kevlar"
"strconv"
)

var osOrder = []vangogh_local_data.OperatingSystem{
Expand All @@ -42,22 +43,14 @@ var downloadTypesStrings = map[vangogh_local_data.DownloadType]string{
// Downloads will present available installers, DLCs in the following hierarchy:
// - Operating system heading - Installers and DLCs (separately)
// - title_values list of downloads by version
func Downloads(id string, clientOs vangogh_local_data.OperatingSystem, dls vangogh_local_data.DownloadsList, rdx kevlar.ReadableRedux) compton.Element {
func Downloads(id string, dls vangogh_local_data.DownloadsList, rdx kevlar.ReadableRedux) compton.Element {
s := compton_fragments.ProductSection(compton_data.DownloadsSection)

pageStack := flex_items.FlexItems(s, direction.Column)
s.Append(pageStack)

if _, ok := rdx.GetLastVal(vangogh_local_data.ValidationCompletedProperty, id); ok {
if validationResults, sure := rdx.GetAllValues(vangogh_local_data.ValidationResultProperty, id); sure && len(validationResults) > 0 {

lastResult := validationResults[len(validationResults)-1]
validationSection := flex_items.FlexItems(s, direction.Row).JustifyContent(align.Center)
validationSection.Append(els.DivText(lastResult))
validationSection.AddClass("validation-results", lastResult)

pageStack.Append(validationSection)
}
if valRes := validationResults(s, id, rdx); valRes != nil {
pageStack.Append(valRes)
}

dlOs := downloadsOperatingSystems(dls)
Expand All @@ -77,7 +70,6 @@ func Downloads(id string, clientOs vangogh_local_data.OperatingSystem, dls vango
pageStack.Append(dlLinks)

}

}

if ii != len(dlOs)-1 {
Expand All @@ -88,6 +80,49 @@ func Downloads(id string, clientOs vangogh_local_data.OperatingSystem, dls vango
return s
}

func validationResults(r compton.Registrar, id string, rdx kevlar.ReadableRedux) compton.Element {
if valDate, ok := rdx.GetLastVal(vangogh_local_data.ValidationCompletedProperty, id); ok {
if valRes, sure := rdx.GetAllValues(vangogh_local_data.ValidationResultProperty, id); sure && len(valRes) > 0 {

lastResult := valRes[len(valRes)-1]
valSect := flex_items.FlexItems(r, direction.Row).
JustifyContent(align.Center).
ColumnGap(size.Small)
valSect.AddClass("validation-results", lastResult)

var valDateElement compton.Element

if vd, err := strconv.ParseInt(valDate, 10, 64); err == nil {
valDateElement = fspan.Text(r, compton_fragments.EpochDate(vd)).
FontWeight(font_weight.Bolder).
FontSize(size.Small)
}

valResTitle := ""
switch lastResult {
case "OK":
valResTitle = "All product files have been successfully validated"
case "":
valResTitle = "Product files have not been validated"
default:
valResTitle = "Validation problems found"
}

valResElement := fspan.Text(r, valResTitle).FontSize(size.Small)

if valDateElement != nil {
valSect.Append(valDateElement)
}
valSect.Append(valResElement)

return valSect

}
}

return nil
}

func operatingSystemHeading(r compton.Registrar, os vangogh_local_data.OperatingSystem) compton.Element {
osRow := flex_items.FlexItems(r, direction.Row).
AlignItems(align.Center).
Expand Down
10 changes: 6 additions & 4 deletions rest/gaugin_styles/style/downloads.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ svg {
width: var(--s-n);
height: var(--s-n);

/*&.operating-system {*/
/* color: var(--c-gray);*/
/*}*/

&.installer {
color: var(--c-purple);
}
Expand All @@ -24,6 +20,12 @@ svg {
border-radius: var(--br-n);
color: var(--c-highlight);
background-color: var(--c-gray);
padding: var(--s-xs) var(--s-n);

& fspan {
background-color: transparent;
color: var(--s-highlight);
}

&.OK {
color: var(--c-highlight);
Expand Down
4 changes: 1 addition & 3 deletions rest/get_downloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ func GetDownloads(w http.ResponseWriter, r *http.Request) {

id := r.URL.Query().Get("id")

clientOS := getClientOperatingSystem(r)

idRedux, err := getRedux(
http.DefaultClient,
id,
Expand All @@ -37,7 +35,7 @@ func GetDownloads(w http.ResponseWriter, r *http.Request) {
return
}

p := compton_pages.Downloads(id, clientOS, dls, kevlar.ReduxProxy(idRedux))
p := compton_pages.Downloads(id, dls, kevlar.ReduxProxy(idRedux))

if err := p.WriteContent(w); err != nil {
http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError)
Expand Down
39 changes: 6 additions & 33 deletions rest/get_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,6 @@ var (
}
)

func propertiesFromRedux(redux map[string][]string, property string) []string {
if val, ok := redux[property]; ok {
return val
} else {
return []string{}
}
}

func propertyFromRedux(redux map[string][]string, property string) string {
properties := propertiesFromRedux(redux, property)
if len(properties) > 0 {
return properties[0]
}
return ""
}

// TODO: review and remove this
func FlagFromRedux(redux map[string][]string, property string) bool {
return propertyFromRedux(redux, property) == vangogh_local_data.TrueValue
}

func GetProduct(w http.ResponseWriter, r *http.Request) {

// GET /product?slug -> /product?id
Expand Down Expand Up @@ -110,7 +89,6 @@ func GetProduct(w http.ResponseWriter, r *http.Request) {
}

// fill redux, data presence to allow showing only the section that will have data

hasRedux, err := getHasRedux(http.DefaultClient, id, maps.Keys(propertiesSections)...)

if err != nil {
Expand All @@ -122,12 +100,12 @@ func GetProduct(w http.ResponseWriter, r *http.Request) {
// every product is expected to have at least those sections
hasSections = append(hasSections, compton_data.PropertiesSection, compton_data.ExternalLinksSection)

if hRdx, ok := hasRedux[id]; ok {
for _, property := range propertiesSectionsOrder {
if section, ok := propertiesSections[property]; ok {
if FlagFromRedux(hRdx, property) {
hasSections = append(hasSections, section)
}
hasRdx := kevlar.ReduxProxy(hasRedux)

for _, property := range propertiesSectionsOrder {
if section, ok := propertiesSections[property]; ok {
if val, sure := hasRdx.GetLastVal(property, id); sure && val == vangogh_local_data.TrueValue {
hasSections = append(hasSections, section)
}
}
}
Expand Down Expand Up @@ -192,11 +170,6 @@ func GetProduct(w http.ResponseWriter, r *http.Request) {
} else {
http.NotFound(w, r)
}

//if err := app.RenderItem(id, hasSections, rdx, w); err != nil {
// http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError)
// return
//}
}

func gogLink(p string) string {
Expand Down

0 comments on commit 118c40f

Please sign in to comment.