Improved admin stuff

This commit is contained in:
2017-10-07 23:24:09 +02:00
parent a9324b4740
commit b8f52e1217
8 changed files with 77 additions and 11 deletions

View File

@ -2,6 +2,7 @@ component AdminTabs
.tabs
Tab("Server", "server", "/admin")
Tab("WebDev", "html5", "/admin/webdev")
Tab("Purchases", "shopping-cart", "/admin/purchases")
a.tab.ajax(href="/editor", aria-label="Editor")
Icon("pencil")

36
pages/admin/purchases.go Normal file
View File

@ -0,0 +1,36 @@
package admin
import (
"net/http"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// PurchaseHistory ...
func PurchaseHistory(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
}
if user.Role != "admin" {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
}
purchases, err := arn.AllPurchases()
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Error fetching shop item data", err)
}
sort.Slice(purchases, func(i, j int) bool {
return purchases[i].Date > purchases[j].Date
})
return ctx.HTML(components.GlobalPurchaseHistory(purchases))
}

View File

@ -0,0 +1,20 @@
component GlobalPurchaseHistory(purchases []*arn.Purchase)
AdminTabs
h1.page-title All Purchases
table
thead
tr.mountable
th User
th Icon
th Item
th.history-quantity Quantity
th.history-price Price
th.history-date Date
tbody
each purchase in purchases
tr.shop-item.mountable(data-item-id=purchase.ItemID)
td
a.ajax(href=purchase.User().Link())= purchase.User().Nick
PurchaseInfo(purchase)