Skip to content

Commit

Permalink
wip: select operator
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed May 23, 2024
1 parent af121a2 commit faf4629
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/xdg-go/scram v1.0.2
github.com/zeiss/fiber-authz v1.0.24
github.com/zeiss/fiber-goth v1.2.1
github.com/zeiss/fiber-htmx v1.2.8-0.20240522115326-7199b75ca39e
github.com/zeiss/fiber-htmx v1.2.8-0.20240523133310-14e7c0153f18
github.com/zeiss/snow-go v0.0.0-20240312201415-88f059622cff
go.opencensus.io v0.24.0
go.uber.org/zap v1.27.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,10 @@ github.com/zeiss/fiber-htmx v1.2.8-0.20240522090130-3a5a33b84c41 h1:z/oRe+OnEr1+
github.com/zeiss/fiber-htmx v1.2.8-0.20240522090130-3a5a33b84c41/go.mod h1:aZjZpybS/yfTU53EHmmPPlpHIhj+9ETLWMl1z9VqUhc=
github.com/zeiss/fiber-htmx v1.2.8-0.20240522115326-7199b75ca39e h1:fX51DUIikOoLzqVy5FIEFQjGjpiiz+T9p/+EfzlsNdM=
github.com/zeiss/fiber-htmx v1.2.8-0.20240522115326-7199b75ca39e/go.mod h1:aZjZpybS/yfTU53EHmmPPlpHIhj+9ETLWMl1z9VqUhc=
github.com/zeiss/fiber-htmx v1.2.8-0.20240523131348-b10bcfa66aa0 h1:uqQKZzsPQuw9zxn+P8o2/YmRaDA5IX0hKoTz1UmpLYY=
github.com/zeiss/fiber-htmx v1.2.8-0.20240523131348-b10bcfa66aa0/go.mod h1:aZjZpybS/yfTU53EHmmPPlpHIhj+9ETLWMl1z9VqUhc=
github.com/zeiss/fiber-htmx v1.2.8-0.20240523133310-14e7c0153f18 h1:v9wHldvYG/xUSpEYxmmaRPZu0zmDDVwiy4IP7U8mCgE=
github.com/zeiss/fiber-htmx v1.2.8-0.20240523133310-14e7c0153f18/go.mod h1:aZjZpybS/yfTU53EHmmPPlpHIhj+9ETLWMl1z9VqUhc=
github.com/zeiss/snow-go v0.0.0-20240312201415-88f059622cff h1:IguG+jnCnFyAzZ8Fp+6v2lJNvUFPfu8Q2UUgSFw4doU=
github.com/zeiss/snow-go v0.0.0-20240312201415-88f059622cff/go.mod h1:HvitS/QkqgqhV/bNWxPKn0NjByjTaEACZnNgHKZEuio=
gitlab.com/bosi/decorder v0.4.2 h1:qbQaV3zgwnBZ4zPMhGLW4KZe7A7NwxEhJx39R3shffo=
Expand Down
2 changes: 1 addition & 1 deletion internal/web/components/accounts/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func AccountsTable(props AccountsTableProps, children ...htmx.Node) htmx.Node {
Rows: tables.NewRows(props.Accounts),
Toolbar: tables.TableToolbar(
tables.TableToolbarProps[*models.Account]{
ClassName: htmx.ClassNames{
ClassNames: htmx.ClassNames{
"flex": true,
"items-center": true,
"justify-between": true,
Expand Down
2 changes: 1 addition & 1 deletion internal/web/components/operators/operators_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func OperatorsTable(props OperatorsTableProps, children ...htmx.Node) htmx.Node
Rows: tables.NewRows(props.Operators),
Toolbar: tables.TableToolbar(
tables.TableToolbarProps[*models.Operator]{
ClassName: htmx.ClassNames{
ClassNames: htmx.ClassNames{
"flex": true,
"items-center": true,
"justify-between": true,
Expand Down
2 changes: 1 addition & 1 deletion internal/web/controllers/accounts/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (l *CreateControllerImpl) Post() error {
// return err
// }

htmx.HxRedirect(l.Ctx(), "/accounts")
htmx.Redirect(l.Ctx(), "/accounts")

return nil
}
Expand Down
63 changes: 57 additions & 6 deletions internal/web/controllers/accounts/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,47 @@ import (
"github.com/zeiss/fiber-htmx/components/buttons"
"github.com/zeiss/fiber-htmx/components/cards"
"github.com/zeiss/fiber-htmx/components/forms"
"github.com/zeiss/typhoon/internal/api/models"
"github.com/zeiss/typhoon/internal/web/components"
"github.com/zeiss/typhoon/internal/web/ports"
)

// NewAccountControllerImpl ...
type NewAccountControllerImpl struct {
ports.Accounts
Operators []*models.Operator

ports.Repository
htmx.DefaultController
}

// NewAccountController ...
func NewAccountController(db ports.Accounts) *NewAccountControllerImpl {
func NewAccountController(db ports.Repository) *NewAccountControllerImpl {
return &NewAccountControllerImpl{
Accounts: db,
Repository: db,
DefaultController: htmx.DefaultController{},
}
}

// Prepare ...
func (l *NewAccountControllerImpl) Prepare() error {
pagination := models.Pagination[models.Operator]{}

err := l.BindQuery(&pagination)
if err != nil {
return err
}

err = l.ListOperators(l.Context(), &pagination)
if err != nil {
return err
}
for _, operator := range pagination.Rows {
l.Operators = append(l.Operators, &operator)
}

return nil
}

// Get ...
func (l *NewAccountControllerImpl) Get() error {
return htmx.RenderComp(
Expand Down Expand Up @@ -55,7 +78,35 @@ func (l *NewAccountControllerImpl) Get() error {
"-my-4": true,
},
},
htmx.Text("Name"),
htmx.Text("Operator "),
),
),
forms.FormControlLabel(
forms.FormControlLabelProps{},
forms.FormControlLabelText(
forms.FormControlLabelTextProps{
ClassNames: htmx.ClassNames{
"text-neutral-500": true,
},
},
forms.SelectBordered(
forms.SelectProps{},
forms.Option(
forms.OptionProps{
Selected: true,
Disabled: true,
},
htmx.Text("Select an operator"),
),
htmx.ForEach(l.Operators, func(operator *models.Operator) htmx.Node {
return forms.Option(
forms.OptionProps{
Value: operator.ID.String(),
},
htmx.Text(operator.Name),
)
}),
),
),
),
forms.FormControlLabel(
Expand All @@ -66,7 +117,7 @@ func (l *NewAccountControllerImpl) Get() error {
"text-neutral-500": true,
},
},
htmx.Text("A unique identifier for operator."),
htmx.Text("A unique identifier for the account."),
),
),
forms.TextInputBordered(
Expand Down Expand Up @@ -110,7 +161,7 @@ func (l *NewAccountControllerImpl) Get() error {
"text-neutral-500": true,
},
},
htmx.Text("A brief description of the operator to provide context."),
htmx.Text("A brief description of the acount to provide context."),
),
),
forms.TextareaBordered(
Expand Down
3 changes: 2 additions & 1 deletion internal/web/controllers/login/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func (l *IndexLoginController) Prepare() error {

// Get ...
func (l *IndexLoginController) Get() error {
return l.Hx().RenderComp(
return htmx.RenderComp(
l.Ctx(),
components.Page(
components.PageProps{},
components.Wrap(
Expand Down
3 changes: 2 additions & 1 deletion internal/web/controllers/me/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func (m *MeController) Prepare() error {
func (m *MeController) Get() error {
user := htmx.Values[adapters.GothUser](m.Ctx().UserContext(), resolvers.ValuesKeyUser)

return m.Hx().RenderComp(
return htmx.RenderComp(
m.Ctx(),
components.Page(
components.PageProps{},
components.Layout(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (l *DeleteOperatorController) Delete() error {
return err
}

htmx.HxRedirect(l.Ctx(), "/operators")
htmx.Redirect(l.Ctx(), "/operators")

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (l *NewOperatorControllerImpl) Post() error {
return err
}

htmx.HxRedirect(l.Ctx(), "/operators")
htmx.Redirect(l.Ctx(), "/operators")

return nil
}
Expand Down

0 comments on commit faf4629

Please sign in to comment.