diff --git a/internal/dao/events.sql.go b/internal/dao/events.sql.go
index c88c3a5..3b5289b 100644
--- a/internal/dao/events.sql.go
+++ b/internal/dao/events.sql.go
@@ -117,7 +117,7 @@ func (q *Queries) GetEvents(ctx context.Context, ids []int64) ([]Event, error) {
const getEventsForCallsign = `-- name: GetEventsForCallsign :many
SELECT id, created, stream_id, account_id, event_type, event_data
FROM events
-WHERE event_type = ?1
+WHERE event_type = ?1
AND json_extract(event_data, '$.callsign') = ?2
`
diff --git a/internal/handlers/account.go b/internal/handlers/account.go
index 9e741fa..76024ee 100644
--- a/internal/handlers/account.go
+++ b/internal/handlers/account.go
@@ -8,6 +8,7 @@ import (
validator "github.com/go-playground/validator/v10"
"github.com/ryanfaerman/netctl/internal/middleware"
+ "github.com/ryanfaerman/netctl/internal/models"
"github.com/ryanfaerman/netctl/internal/services"
"github.com/ryanfaerman/netctl/internal/views"
"github.com/ryanfaerman/netctl/web/named"
@@ -29,6 +30,7 @@ func (h account) Routes(r chi.Router) {
})
r.Get(named.Route("account-profile", "/profile/{callsign}"), h.Show)
+ r.Get(named.Route("account-profile-self", "/profile"), h.Show)
r.Get(named.Route("account-edit", "/profile/{callsign}/edit"), h.Edit)
r.Post(named.Route("account-edit-save", "/profile/{callsign}/edit/-/save"), h.Update)
}
@@ -87,19 +89,32 @@ func (h account) Setup(w http.ResponseWriter, r *http.Request) {
}
func (h account) Show(w http.ResponseWriter, r *http.Request) {
+ var account *models.Account
+
callsign := chi.URLParam(r, "callsign")
- ctx := services.CSRF.GetContext(r.Context(), r)
+ if callsign == "" {
+ a, err := services.Session.GetAccount(r.Context())
+ if err != nil {
+ ErrorHandler(err)(w, r)
+ return
+ }
+ account = a
+ // get account from session
+ } else {
+ a, err := services.Account.FindByCallsign(r.Context(), callsign)
+ if err != nil {
+ ErrorHandler(err)(w, r)
+ return
+ }
+ account = a
- a, err := services.Account.FindByCallsign(ctx, callsign)
- if err != nil {
- ErrorHandler(err)(w, r)
- return
}
+ ctx := services.CSRF.GetContext(r.Context(), r)
- a.About = services.Markdown.MustRenderString(a.About)
+ account.About = services.Markdown.MustRenderString(account.About)
v := views.Account{
- Account: a,
+ Account: account,
}
v.Profile().Render(ctx, w)
}
diff --git a/internal/middleware/path.go b/internal/middleware/path.go
new file mode 100644
index 0000000..3ceebee
--- /dev/null
+++ b/internal/middleware/path.go
@@ -0,0 +1,19 @@
+package middleware
+
+import (
+ "fmt"
+ "net/http"
+
+ "github.com/davecgh/go-spew/spew"
+ "github.com/go-chi/chi"
+ "github.com/ryanfaerman/netctl/web/named"
+)
+
+func Path(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ c := chi.RouteContext(r.Context())
+ spew.Dump(c.RoutePattern(), c.URLParams)
+ fmt.Println("lookup", named.Lookup(c.RoutePattern()))
+ next.ServeHTTP(w, r)
+ })
+}
diff --git a/internal/services/session.go b/internal/services/session.go
index 7ecdfe9..f42cec7 100644
--- a/internal/services/session.go
+++ b/internal/services/session.go
@@ -8,7 +8,6 @@ import (
"fmt"
"net/http"
- "github.com/davecgh/go-spew/spew"
"github.com/mrz1836/postmark"
"github.com/ryanfaerman/netctl/config"
"github.com/ryanfaerman/netctl/internal/models"
@@ -137,9 +136,7 @@ func (session) Destroy(ctx context.Context) error {
return nil
}
-var (
- ErrNoAccountInSession = errors.New("no account in session")
-)
+var ErrNoAccountInSession = errors.New("no account in session")
func (session) GetAccount(ctx context.Context) (*models.Account, error) {
id, ok := global.session.Get(ctx, "account_id").(int64)
@@ -154,7 +151,5 @@ func (s session) MustGetAccount(ctx context.Context) *models.Account {
if err != nil {
panic(err)
}
- spew.Dump(u)
- spew.Dump(u.Ready())
return u
}
diff --git a/internal/sql/queries/events.sql b/internal/sql/queries/events.sql
index bfc1d53..d15f9ee 100644
--- a/internal/sql/queries/events.sql
+++ b/internal/sql/queries/events.sql
@@ -40,5 +40,5 @@ DELETE FROM events_recovery WHERE id = ?1;
-- name: GetEventsForCallsign :many
SELECT *
FROM events
-WHERE event_type = ?1
+WHERE event_type = ?1
AND json_extract(event_data, '$.callsign') = @callsign;
diff --git a/internal/views/account.templ b/internal/views/account.templ
index d939161..7ddaa5d 100644
--- a/internal/views/account.templ
+++ b/internal/views/account.templ
@@ -7,11 +7,17 @@ type Account struct {
Account *models.Account
}
+func (v Account) Nav() Menu {
+ return Menu{
+ {Value: "Profile", URL: named.URLFor("account-profile", v.Account.Callsign().Call), Icon: IconAttrs{Name: "file-lines"}},
+ {Value: "Billing", URL: "#", Icon: IconAttrs{Name: "list-check"}},
+ {Value: "Reports", URL: "#", Icon: IconAttrs{Name: "receipt"}},
+ {Value: "Settings", URL: "#", Icon: IconAttrs{Name: "sliders"}},
+ }
+}
+
templ (v Account) Profile() {
- @Page() {
-
This page is a work in progress
} diff --git a/internal/views/help_templ.go b/internal/views/help_templ.go index 2346613..3654c85 100644 --- a/internal/views/help_templ.go +++ b/internal/views/help_templ.go @@ -58,7 +58,7 @@ func (Docs) Markdown() templ.Component { } return templ_7745c5c3_Err }) - templ_7745c5c3_Err = Page().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = BarePage().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/views/layout.templ b/internal/views/layout.templ index 6dbfcec..7f47c90 100644 --- a/internal/views/layout.templ +++ b/internal/views/layout.templ @@ -1,6 +1,28 @@ package views -templ Page() { +import "fmt" + +import "github.com/ryanfaerman/netctl/web/named" + +func DefaultMenu() Menu { + return Menu{ + {Value: "Home", URL: named.URLFor("dashboard-index"), Icon: IconAttrs{Name: "house"}}, + {Value: "View Nets", URL: named.URLFor("net-index"), Icon: IconAttrs{Name: "users-rectangle"}}, + } +} + +templ Page(m Menu) { + @BarePage() { + if len(m) == 0 { + @DefaultMenu().NewAppBar() + } else { + @m.NewAppBar() + } + { children... } + } +} + +templ BarePage() { @@ -27,33 +49,34 @@ templ Page() { } -templ Unsupported() { - @Page() { -- Javascript Required or your browser is not supported. Please enabled javascript and use a modern browser such as - Google Chrome or - Mozilla Firefox. -
-") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Var10 := `Javascript Required or your browser is not supported. Please enabled javascript and use a modern browser such as` - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Var11 := `Google Chrome` - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var11) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Var12 := `or` - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var12) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Var13 := `Mozilla Firefox` - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Var14 := `.` - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var14) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("