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"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
@ -23,7 +24,8 @@ otherwise you'll get a list of sets as a search result.`,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, set []string) error {
if len(set) == 0 {
Sets()
setList := Sets(sort)
show_set_list(setList)
} else {
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()
coll := &Collection{client.Database("serra").Collection("cards")}
setscoll := &Collection{client.Database("serra").Collection("sets")}
defer storage_disconnect(client)
groupStage := bson.D{
@ -64,6 +65,15 @@ func Sets() {
}
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 {
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)
@ -71,7 +81,6 @@ func Sets() {
fmt.Printf(" Value: %s%.2f %s%s\n", Pink, set["value"], getCurrency(), Reset)
fmt.Println()
}
}
func ShowSet(setname string) error {

View File

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

View File

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