Skip to content

Commit

Permalink
feat: commodities tab added
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Mar 30, 2024
1 parent dbc8c6e commit a28e680
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 5 deletions.
125 changes: 125 additions & 0 deletions darkstat/front/commodities.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package front

import (
"strconv"
"github.com/darklab8/fl-darkstat/darkstat/front/urls"
"github.com/darklab8/fl-darkstat/darkstat/common/types"
"github.com/darklab8/fl-configs/configs/configs_export"
"fmt"
"strings"
)

func CommoditiesBaseInfoUrl(commodity configs_export.Commodity) string {
return "commodities/comm_base_" + strings.ToLower(commodity.Nickname)
}

// https://www.cssscript.com/minimalist-table-sortable/#:~:text=Description%3A-,sorttable.,clicking%20on%20the%20table%20headers
// https://www.cssscript.com/fast-html-table-sorting/
templ CommoditiesT(commodities []configs_export.Commodity) {
@TabMenu(urls.Commodities)
@TabContent() {
<div class="splitter">
<div id="table-wrapper">
<div id="table-top">
<table class="sortable">
<thead>
<tr>
<th style="width:200px;">Commodity</th>
<th style="width:50px;">Price</th>
<th style="width:50px;">Price Per Volume</th>
<th style="width:50px;">Volume</th>
<th style="width:50px;">Best Buy Price / V</th>
<th style="width:50px;">Best Sell Price / V</th>
<th style="width:50px;">Profit Margin / V</th>
<th style="width:100px;">Nickname</th>
<th style="width:100px;">Name ID</th>
<th style="width:100px;">Infocard ID</th>
<th style="max-width:100%;"></th>
</tr>
</thead>
<tbody>
for _, commodity := range commodities {
<tr
id={ "baseinfo_click" + commodity.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + CommoditiesBaseInfoUrl(commodity) }
hx-trigger="click"
hx-target="#table-bottom"
hx-swap="innerHTML"
>
<td>{ commodity.Name }</td>
<td>{ strconv.Itoa(commodity.Price) }</td>
<td>{ strconv.Itoa(commodity.PricePerVolume) }</td>
<td>{ fmt.Sprintf("%.6f", commodity.Volume) }</td>
<td>{ strconv.Itoa(commodity.BestBuyPricePerVol) }</td>
<td>{ strconv.Itoa(commodity.BestSellPricePerVol) }</td>
<td>{ strconv.Itoa(commodity.ProffitMarginPerVol) }</td>
<td>{ commodity.Nickname }</td>
<td>{ strconv.Itoa(commodity.NameID) }</td>
<td>{ strconv.Itoa(commodity.InfocardID) }</td>
<td
id={ "infocard_click" + commodity.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + InfocardURL(commodity.Infocard) }
hx-trigger="click"
hx-target="#infocard_view"
hx-swap="innerHTML"
></td>
@templ.Raw(JoinClickTriggers("baseinfo_click"+commodity.Nickname, "infocard_click"+commodity.Nickname))
</tr>
}
</tbody>
</table>
</div>
<div id="table-bottom">
@CommoditiesBasesInfoShared()
</div>
</div>
<div id="infocard_view">
@InfocardShared()
</div>
</div>
}
}

templ CommoditiesBasesInfoShared() {
<table class="sortable">
<thead>
<tr class="flexed-tr">
<th style="width:200px;">Base</th>
<th style="width:100px;">Faction</th>
<th style="width:50px;">System</th>
<th style="width:50px;">Price Per foume</th>
<th style="width:50px;">Base Sells</th>
<th style="width:50px;">Level Req'd</th>
<th style="width:50px;">Reputation Req'd</th>
<th style="width:50px;">Base Nickname</th>
<th style="max-width:100%;"></th>
</tr>
</thead>
<tbody>
{ children... }
</tbody>
</table>
}

templ CommoditiesBaseInfo(base_infos []configs_export.CommodityAtBase) {
@CommoditiesBasesInfoShared() {
for _, base_info := range base_infos {
<tr
hx-get={ types.GetCtx(ctx).SiteRoot + InfocardURL(configs_export.InfocardKey(base_info.BaseNickname)) }
hx-trigger="click"
hx-target="#infocard_view"
hx-swap="innerHTML"
>
<td>{ base_info.BaseName }</td>
<td>{ base_info.Faction }</td>
<td>{ base_info.SystemName }</td>
<td>{ strconv.Itoa(base_info.PricePerVolume) }</td>
<td>{ strconv.FormatBool(base_info.BaseSells) }</td>
<td>{ strconv.Itoa(base_info.LevelRequired) }</td>
<td>{ fmt.Sprintf("%.2f", base_info.RepRequired) }</td>
<td>{ base_info.BaseNickname }</td>
<td></td>
</tr>
}
}
}
1 change: 1 addition & 0 deletions darkstat/front/shared.templ
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ templ TabMenu(url utils_types.FilePath) {
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Bases.ToString() } class={ templ.KV("selected", urls.Bases == url) } role="tab" aria-selected="false" aria-controls="tab-content">Bases</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Factions.ToString() } class={ templ.KV("selected", urls.Factions == url) } role="tab" aria-selected="false" aria-controls="tab-content">Factions</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Rephacks.ToString() } class={ templ.KV("selected", urls.Rephacks == url) } role="tab" aria-selected="false" aria-controls="tab-content">Rephacks</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Commodities.ToString() } class={ templ.KV("selected", urls.Commodities == url) } role="tab" aria-selected="false" aria-controls="tab-content">Commodities</button>
</div>
}
<hr/>
Expand Down
9 changes: 5 additions & 4 deletions darkstat/front/urls/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
)

const (
Index utils_types.FilePath = "index.html"
Bases utils_types.FilePath = "bases.html"
Factions utils_types.FilePath = "factions.html"
Rephacks utils_types.FilePath = "rephacks.html"
Index utils_types.FilePath = "index.html"
Bases utils_types.FilePath = "bases.html"
Factions utils_types.FilePath = "factions.html"
Rephacks utils_types.FilePath = "rephacks.html"
Commodities utils_types.FilePath = "commodities.html"
)
29 changes: 29 additions & 0 deletions darkstat/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ func (l *Linker) Link() *builder.Builder {
})
}

sort.Slice(data.Commodities, func(i, j int) bool {
if data.Commodities[i].Name != "" && data.Commodities[j].Name == "" {
return true
}
return data.Commodities[i].Name < data.Commodities[j].Name
})

for _, base_info := range data.Commodities {
sort.Slice(base_info.Bases, func(i, j int) bool {
if base_info.Bases[i].BaseName != "" && base_info.Bases[j].BaseName == "" {
return true
}
return base_info.Bases[i].BaseName < base_info.Bases[j].BaseName
})
}

build := builder.NewBuilder()
build.RegComps(
builder.NewComponent(
Expand All @@ -94,6 +110,10 @@ func (l *Linker) Link() *builder.Builder {
urls.Rephacks,
front.RephacksT(data.Factions),
),
builder.NewComponent(
urls.Commodities,
front.CommoditiesT(data.Commodities),
),
)

for _, base := range data.Bases {
Expand Down Expand Up @@ -128,5 +148,14 @@ func (l *Linker) Link() *builder.Builder {
)
})

for _, base_info := range data.Commodities {
build.RegComps(
builder.NewComponent(
utils_types.FilePath(front.CommoditiesBaseInfoUrl(base_info)),
front.CommoditiesBaseInfo(base_info.Bases),
),
)
}

return build
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.1

require (
github.com/a-h/templ v0.2.543
github.com/darklab8/fl-configs v0.18.0
github.com/darklab8/fl-configs v0.19.0
github.com/darklab8/go-typelog v0.6.0
github.com/darklab8/go-utils v0.12.0
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/darklab8/fl-configs v0.17.1 h1:S12fnKenPCC4sEeSR8ifxEWRpt4H7UqjOHUFNm
github.com/darklab8/fl-configs v0.17.1/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.18.0 h1:KhkPQdJo6+4u4IoB29vem/+bkDEO3Qima+PsHwmSCQs=
github.com/darklab8/fl-configs v0.18.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.19.0 h1:8WH/lvBOlEG97Qw4traWR3e4UjiZwHIi0sCcwcSDBF8=
github.com/darklab8/fl-configs v0.19.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/go-typelog v0.6.0 h1:Ci8imc7ScXiy5e1qMgf46NyJjrqNLPoIE1gbVe7bxl4=
github.com/darklab8/go-typelog v0.6.0/go.mod h1:AwwOf3dkp/tpevHFNbkB+PbwlDrUUgO1CVFkEnj+q5w=
github.com/darklab8/go-utils v0.12.0 h1:LxsG3yVNf9W4xyV+tHPOaZB2ewItgM/1BzOXyKFvofs=
Expand Down

0 comments on commit a28e680

Please sign in to comment.