diff --git a/rest/compton_fragments/steam_news_item.go b/rest/compton_fragments/steam_news_item.go index d1c9df7..02c6b6e 100644 --- a/rest/compton_fragments/steam_news_item.go +++ b/rest/compton_fragments/steam_news_item.go @@ -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) } diff --git a/rest/compton_fragments/steam_review.go b/rest/compton_fragments/steam_review.go index 128c422..0415574 100644 --- a/rest/compton_fragments/steam_review.go +++ b/rest/compton_fragments/steam_review.go @@ -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") @@ -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") } diff --git a/rest/compton_pages/downloads.go b/rest/compton_pages/downloads.go index caef1b1..3e23cee 100644 --- a/rest/compton_pages/downloads.go +++ b/rest/compton_pages/downloads.go @@ -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{ @@ -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) @@ -77,7 +70,6 @@ func Downloads(id string, clientOs vangogh_local_data.OperatingSystem, dls vango pageStack.Append(dlLinks) } - } if ii != len(dlOs)-1 { @@ -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). diff --git a/rest/gaugin_styles/style/downloads.css b/rest/gaugin_styles/style/downloads.css index ed0bfb4..9807a9f 100644 --- a/rest/gaugin_styles/style/downloads.css +++ b/rest/gaugin_styles/style/downloads.css @@ -2,10 +2,6 @@ svg { width: var(--s-n); height: var(--s-n); - /*&.operating-system {*/ - /* color: var(--c-gray);*/ - /*}*/ - &.installer { color: var(--c-purple); } @@ -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); diff --git a/rest/get_downloads.go b/rest/get_downloads.go index d8f32c1..7fb75f0 100644 --- a/rest/get_downloads.go +++ b/rest/get_downloads.go @@ -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, @@ -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) diff --git a/rest/get_product.go b/rest/get_product.go index e2cfa31..a40afad 100644 --- a/rest/get_product.go +++ b/rest/get_product.go @@ -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 @@ -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 { @@ -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) } } } @@ -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 {