devices: added view page

This commit is contained in:
Tigor Hutasuhut 2024-05-07 10:50:40 +07:00
parent 6bd219ea4f
commit b8fcb37db8
5 changed files with 48 additions and 2 deletions

View file

@ -0,0 +1,20 @@
package routes
import (
"net/http"
"github.com/tigorlazuardi/redmage/pkg/log"
"github.com/tigorlazuardi/redmage/views"
"github.com/tigorlazuardi/redmage/views/devicesview/adddevice"
)
func (routes *Routes) PageDevicesAdd(rw http.ResponseWriter, req *http.Request) {
ctx, span := tracer.Start(req.Context(), "*Routes.PageDevicesAdd")
defer span.End()
c := views.NewContext(routes.Config, req)
if err := adddevice.View(c).Render(ctx, rw); err != nil {
log.New(ctx).Err(err).Error("failed to render add device page")
}
}

View file

@ -82,6 +82,7 @@ func (routes *Routes) registerWWWRoutes(router chi.Router) {
r.Get("/subreddits/add", routes.PageSubredditsAdd) r.Get("/subreddits/add", routes.PageSubredditsAdd)
r.Get("/config", routes.PageConfig) r.Get("/config", routes.PageConfig)
r.Get("/devices", routes.PageDevices) r.Get("/devices", routes.PageDevices)
r.Get("/devices/add", routes.PageDevicesAdd)
r.Get("/devices/details/{slug}", routes.PageDeviceDetails) r.Get("/devices/details/{slug}", routes.PageDeviceDetails)
r.Get("/schedules", routes.PageScheduleHistory) r.Get("/schedules", routes.PageScheduleHistory)
}) })

View file

@ -0,0 +1,22 @@
package adddevice
import "github.com/tigorlazuardi/redmage/views"
import "github.com/tigorlazuardi/redmage/views/components"
templ View(c *views.Context) {
@components.Doctype() {
@components.Head(c, components.HeadTitle("Device - Add"))
@components.Body(c) {
@Content(c)
}
}
}
templ Content(c *views.Context) {
<main class="prose min-w-full">
@components.Container() {
<h1>Add Device</h1>
<div class="divider"></div>
}
</main>
}

View file

@ -13,7 +13,7 @@ templ filter(data Data) {
hx-select="main" hx-select="main"
hx-swap="outerHTML" hx-swap="outerHTML"
hx-push-url="true" hx-push-url="true"
class="grid md:grid-cols-2 gap-4" class="grid md:grid-cols-[1fr,3fr] lg:grid-cols-2 gap-4"
> >
<label class="input input-bordered flex items-center gap-2"> <label class="input input-bordered flex items-center gap-2">
<input <input

View file

@ -30,7 +30,10 @@ templ DevicesContent(c *views.Context, data Data) {
if data.Error != "" { if data.Error != "" {
@components.ErrorToast(data.Error) @components.ErrorToast(data.Error)
} else { } else {
<h1>Devices</h1> <div class="flex justify-between items-center">
<h1 class="my-auto">Devices</h1>
<a href="/devices/add" class="btn btn-primary no-underline text-base-100">Add Device</a>
</div>
<div class="divider"></div> <div class="divider"></div>
@filter(data) @filter(data)
<h2>{ strconv.FormatInt(data.Total, 10) } Devices</h2> <h2>{ strconv.FormatInt(data.Total, 10) } Devices</h2>