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
|
// Admin
|
||||||
app.Ajax("/admin", admin.Get)
|
app.Ajax("/admin", admin.Get)
|
||||||
app.Ajax("/admin/webdev", admin.WebDev)
|
app.Ajax("/admin/webdev", admin.WebDev)
|
||||||
|
app.Ajax("/admin/purchases", admin.PurchaseHistory)
|
||||||
|
|
||||||
// Editor
|
// Editor
|
||||||
app.Ajax("/editor", editor.Get)
|
app.Ajax("/editor", editor.Get)
|
||||||
|
@ -32,8 +32,12 @@ component Sidebar(user *arn.User)
|
|||||||
Icon("search")
|
Icon("search")
|
||||||
FuzzySearch
|
FuzzySearch
|
||||||
|
|
||||||
if user != nil && (user.Role == "admin" || user.Role == "editor")
|
if user != nil
|
||||||
SidebarButton("Admin", "/admin", "wrench")
|
if user.Role == "admin"
|
||||||
|
SidebarButton("Admin", "/admin", "wrench")
|
||||||
|
|
||||||
|
if user.Role == "editor"
|
||||||
|
SidebarButton("Editor", "/editor", "pencil")
|
||||||
|
|
||||||
SidebarButton("Help", "/thread/I3MMiOtzR", "question-circle")
|
SidebarButton("Help", "/thread/I3MMiOtzR", "question-circle")
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ component AdminTabs
|
|||||||
.tabs
|
.tabs
|
||||||
Tab("Server", "server", "/admin")
|
Tab("Server", "server", "/admin")
|
||||||
Tab("WebDev", "html5", "/admin/webdev")
|
Tab("WebDev", "html5", "/admin/webdev")
|
||||||
|
Tab("Purchases", "shopping-cart", "/admin/purchases")
|
||||||
|
|
||||||
a.tab.ajax(href="/editor", aria-label="Editor")
|
a.tab.ajax(href="/editor", aria-label="Editor")
|
||||||
Icon("pencil")
|
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("Shoboi", "calendar", "/editor/shoboi")
|
||||||
Tab("AniList", "list", "/editor/anilist")
|
Tab("AniList", "list", "/editor/anilist")
|
||||||
|
|
||||||
a.tab.ajax(href="/admin", aria-label="Admin")
|
//- a.tab.ajax(href="/admin", aria-label="Admin")
|
||||||
Icon("wrench")
|
//- Icon("wrench")
|
||||||
span.tab-text Admin
|
//- span.tab-text Admin
|
@ -14,9 +14,12 @@ component PurchaseHistory(purchases []*arn.Purchase, user *arn.User)
|
|||||||
tbody
|
tbody
|
||||||
each purchase in purchases
|
each purchase in purchases
|
||||||
tr.shop-item.mountable(data-item-id=purchase.ItemID)
|
tr.shop-item.mountable(data-item-id=purchase.ItemID)
|
||||||
td.item-icon
|
PurchaseInfo(purchase)
|
||||||
Icon(purchase.Item().Icon)
|
|
||||||
td= purchase.Item().Name
|
component PurchaseInfo(purchase *arn.Purchase)
|
||||||
td.history-quantity= purchase.Quantity
|
td.item-icon
|
||||||
td.history-price= purchase.Price
|
Icon(purchase.Item().Icon)
|
||||||
td.history-date.utc-date(data-date=purchase.Date)
|
td= purchase.Item().Name
|
||||||
|
td.history-quantity= purchase.Quantity
|
||||||
|
td.history-price= purchase.Price
|
||||||
|
td.history-date.utc-date(data-date=purchase.Date)
|
1
tests.go
1
tests.go
@ -242,6 +242,7 @@ var routeTests = map[string][]string{
|
|||||||
"/anime/:id/edit": nil,
|
"/anime/:id/edit": nil,
|
||||||
"/new/thread": nil,
|
"/new/thread": nil,
|
||||||
"/new/soundtrack": nil,
|
"/new/soundtrack": nil,
|
||||||
|
"/admin/purchases": nil,
|
||||||
"/editor/anilist": nil,
|
"/editor/anilist": nil,
|
||||||
"/editor/shoboi": nil,
|
"/editor/shoboi": nil,
|
||||||
"/user": nil,
|
"/user": nil,
|
||||||
|
Loading…
Reference in New Issue
Block a user