Add sets to dropdown

This commit is contained in:
Florian Baumann 2023-02-25 12:15:32 +01:00
parent d7b34d9f7f
commit 026e97c4b7
3 changed files with 27 additions and 13 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
) )
@ -23,7 +24,8 @@ otherwise you'll get a list of sets as a search result.`,
SilenceErrors: true, SilenceErrors: true,
RunE: func(cmd *cobra.Command, set []string) error { RunE: func(cmd *cobra.Command, set []string) error {
if len(set) == 0 { if len(set) == 0 {
Sets() setList := Sets(sort)
show_set_list(setList)
} else { } else {
ShowSet(set[0]) ShowSet(set[0])
} }
@ -31,11 +33,10 @@ otherwise you'll get a list of sets as a search result.`,
}, },
} }
func Sets() { func Sets(sort string) []primitive.M {
client := storage_connect() client := storage_connect()
coll := &Collection{client.Database("serra").Collection("cards")} coll := &Collection{client.Database("serra").Collection("cards")}
setscoll := &Collection{client.Database("serra").Collection("sets")}
defer storage_disconnect(client) defer storage_disconnect(client)
groupStage := bson.D{ groupStage := bson.D{
@ -64,6 +65,15 @@ func Sets() {
} }
sets, _ := coll.storage_aggregate(mongo.Pipeline{groupStage, sortStage}) sets, _ := coll.storage_aggregate(mongo.Pipeline{groupStage, sortStage})
return sets
}
func show_set_list(sets []primitive.M) {
client := storage_connect()
setscoll := &Collection{client.Database("serra").Collection("sets")}
for _, set := range sets { for _, set := range sets {
setobj, _ := find_set_by_code(setscoll, set["code"].(string)) setobj, _ := find_set_by_code(setscoll, set["code"].(string))
fmt.Printf("* %s %s%s%s (%s%s%s)\n", set["release"].(string)[0:4], Purple, set["_id"], Reset, Cyan, set["code"], Reset) fmt.Printf("* %s %s%s%s (%s%s%s)\n", set["release"].(string)[0:4], Purple, set["_id"], Reset, Cyan, set["code"], Reset)
@ -71,7 +81,6 @@ func Sets() {
fmt.Printf(" Value: %s%.2f %s%s\n", Pink, set["value"], getCurrency(), Reset) fmt.Printf(" Value: %s%.2f %s%s\n", Pink, set["value"], getCurrency(), Reset)
fmt.Println() fmt.Println()
} }
} }
func ShowSet(setname string) error { func ShowSet(setname string) error {

View File

@ -46,9 +46,11 @@ func landingPage(c *gin.Context) {
var query Query var query Query
if c.ShouldBind(&query) == nil { if c.ShouldBind(&query) == nil {
cards := Cards("", query.Set, "", query.Name, "", "") cards := Cards("", query.Set, "", query.Name, "", "")
sets := Sets("release")
c.HTML(http.StatusOK, "index.tmpl", gin.H{ c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Serraaaa", "title": "Serraaaa",
"cards": cards, "cards": cards,
"sets": sets,
}) })
} }
} }

View File

@ -32,15 +32,16 @@
<!-- Left side --> <!-- Left side -->
<div class="level-left"> <div class="level-left">
<div class="level-item"> <div class="level-item">
<div class="field"> <div class="field">
<label class="label">Set</label> <label class="label">Set</label>
<div class="control"> <div class="control">
<div class="select"> <div class="select is-primary">
<select> <select name="set" id="set" form="searchform">
<option>Mercadian Masks</option> <option></option>
<option>Urzas Saga</option> {{range .sets}}
<option value="{{ index . "code" }}">{{ index . "_id" }} ({{ index . "count" }})</option>
{{end}}
</select> </select>
</div> </div>
</div> </div>
@ -51,7 +52,7 @@
<div class="field"> <div class="field">
<label class="label">Name</label> <label class="label">Name</label>
<div class="control"> <div class="control">
<input class="input" type="text" placeholder="Tolarian Academy"> <input form="searchform" name="name" class="input" id="name" type="text" placeholder="Tolarian Academy">
</div> </div>
</div> </div>
</div> </div>
@ -59,7 +60,9 @@
<!-- Right side --> <!-- Right side -->
<div class="level-right"> <div class="level-right">
<p class="level-item"><a class="button is-primary">Search</a></p> <form action="/" id="searchform">
<input class="button is-primary" type="submit" value="Search">
</form>
</div> </div>
</nav> </nav>
@ -90,7 +93,7 @@
</tr> </tr>
</tfoot> </tfoot>
<tbody> <tbody>
{{range .cards}} {{range .cards}}
<tr> <tr>
<td>{{.SerraCount}}</td> <td>{{.SerraCount}}</td>
<td><strong>{{.Name }}</strong></td> <td><strong>{{.Name }}</strong></td>
@ -101,7 +104,7 @@
<td>{{.Prices.Eur}}</td> <td>{{.Prices.Eur}}</td>
<td>{{.Prices.EurFoil}}</td> <td>{{.Prices.EurFoil}}</td>
</tr> </tr>
{{end}} {{end}}
</tbody> </tbody>
</table> </table>
</div> </div>