Improved admin stuff
This commit is contained in:
parent
a9324b4740
commit
b8f52e1217
1
main.go
1
main.go
@ -136,6 +136,7 @@ func configure(app *aero.Application) *aero.Application {
|
||||
// Admin
|
||||
app.Ajax("/admin", admin.Get)
|
||||
app.Ajax("/admin/webdev", admin.WebDev)
|
||||
app.Ajax("/admin/purchases", admin.PurchaseHistory)
|
||||
|
||||
// Editor
|
||||
app.Ajax("/editor", editor.Get)
|
||||
|
@ -32,8 +32,12 @@ component Sidebar(user *arn.User)
|
||||
Icon("search")
|
||||
FuzzySearch
|
||||
|
||||
if user != nil && (user.Role == "admin" || user.Role == "editor")
|
||||
SidebarButton("Admin", "/admin", "wrench")
|
||||
if user != nil
|
||||
if user.Role == "admin"
|
||||
SidebarButton("Admin", "/admin", "wrench")
|
||||
|
||||
if user.Role == "editor"
|
||||
SidebarButton("Editor", "/editor", "pencil")
|
||||
|
||||
SidebarButton("Help", "/thread/I3MMiOtzR", "question-circle")
|
||||
|
||||
|
@ -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
36
pages/admin/purchases.go
Normal 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))
|
||||
}
|
20
pages/admin/purchases.pixy
Normal file
20
pages/admin/purchases.pixy
Normal 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)
|
@ -11,6 +11,6 @@ component EditorTabs
|
||||
Tab("Shoboi", "calendar", "/editor/shoboi")
|
||||
Tab("AniList", "list", "/editor/anilist")
|
||||
|
||||
a.tab.ajax(href="/admin", aria-label="Admin")
|
||||
Icon("wrench")
|
||||
span.tab-text Admin
|
||||
//- a.tab.ajax(href="/admin", aria-label="Admin")
|
||||
//- Icon("wrench")
|
||||
//- span.tab-text Admin
|
@ -14,9 +14,12 @@ component PurchaseHistory(purchases []*arn.Purchase, user *arn.User)
|
||||
tbody
|
||||
each purchase in purchases
|
||||
tr.shop-item.mountable(data-item-id=purchase.ItemID)
|
||||
td.item-icon
|
||||
Icon(purchase.Item().Icon)
|
||||
td= purchase.Item().Name
|
||||
td.history-quantity= purchase.Quantity
|
||||
td.history-price= purchase.Price
|
||||
td.history-date.utc-date(data-date=purchase.Date)
|
||||
PurchaseInfo(purchase)
|
||||
|
||||
component PurchaseInfo(purchase *arn.Purchase)
|
||||
td.item-icon
|
||||
Icon(purchase.Item().Icon)
|
||||
td= purchase.Item().Name
|
||||
td.history-quantity= purchase.Quantity
|
||||
td.history-price= purchase.Price
|
||||
td.history-date.utc-date(data-date=purchase.Date)
|
Loading…
Reference in New Issue
Block a user