Skip to content

Commit

Permalink
Add sets to dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
noqqe committed Feb 25, 2023
1 parent 5992d88 commit e1a08fd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
17 changes: 13 additions & 4 deletions src/serra/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -23,19 +24,19 @@ 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])
}
return nil
},
}

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{
Expand Down Expand Up @@ -64,14 +65,22 @@ 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)
fmt.Printf(" Cards: %s%d/%d%s Total: %.0f \n", Yellow, set["unique"], setobj.CardCount, Reset, set["count"])
fmt.Printf(" Value: %s%.2f %s%s\n", Pink, set["value"], getCurrency(), Reset)
fmt.Println()
}

}

func ShowSet(setname string) error {
Expand Down
2 changes: 2 additions & 0 deletions src/serra/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
21 changes: 12 additions & 9 deletions templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -51,15 +52,17 @@
<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>
</div>

<!-- 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>

Expand Down Expand Up @@ -90,7 +93,7 @@
</tr>
</tfoot>
<tbody>
{{range .cards}}
{{range .cards}}
<tr>
<td>{{.SerraCount}}</td>
<td><strong>{{.Name }}</strong></td>
Expand All @@ -101,7 +104,7 @@
<td>{{.Prices.Eur}}</td>
<td>{{.Prices.EurFoil}}</td>
</tr>
{{end}}
{{end}}
</tbody>
</table>
</div>
Expand Down

0 comments on commit e1a08fd

Please sign in to comment.