From 1dc3617df333d56fd8217154b1587b6bcd97af23 Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Wed, 8 May 2024 14:09:00 +0700 Subject: [PATCH] refactor: moved devices locations to cleaner name --- server/routes/device_validate_name.go | 2 +- server/routes/device_validate_slug.go | 2 +- server/routes/page_devices.go | 8 ++++---- server/routes/page_devices_add.go | 2 +- server/routes/page_devices_details.go | 10 +++++----- .../devicedetails => devices/details}/data.go | 2 +- .../devicedetails => devices/details}/filter.templ | 2 +- .../devicedetails => devices/details}/view.templ | 2 +- views/{devicesview => devices}/filter.templ | 2 +- .../put/aspect_ratio_tolerance_input.templ | 0 .../put/max_image_resolution_input.templ | 0 .../put/min_image_resolution_input.templ | 0 views/{devicesview => devices}/put/name_input.templ | 0 views/{devicesview => devices}/put/nsfw_checkbox.templ | 0 .../put/resolution_input.templ | 0 views/{devicesview => devices}/put/slug_input.templ | 0 views/{devicesview => devices}/put/view.templ | 0 .../put/windows_wallpaper_checkbox.templ | 0 views/{devicesview => devices}/view.templ | 8 ++++---- 19 files changed, 20 insertions(+), 20 deletions(-) rename views/{devicesview/devicedetails => devices/details}/data.go (97%) rename views/{devicesview/devicedetails => devices/details}/filter.templ (97%) rename views/{devicesview/devicedetails => devices/details}/view.templ (98%) rename views/{devicesview => devices}/filter.templ (98%) rename views/{devicesview => devices}/put/aspect_ratio_tolerance_input.templ (100%) rename views/{devicesview => devices}/put/max_image_resolution_input.templ (100%) rename views/{devicesview => devices}/put/min_image_resolution_input.templ (100%) rename views/{devicesview => devices}/put/name_input.templ (100%) rename views/{devicesview => devices}/put/nsfw_checkbox.templ (100%) rename views/{devicesview => devices}/put/resolution_input.templ (100%) rename views/{devicesview => devices}/put/slug_input.templ (100%) rename views/{devicesview => devices}/put/view.templ (100%) rename views/{devicesview => devices}/put/windows_wallpaper_checkbox.templ (100%) rename views/{devicesview => devices}/view.templ (94%) diff --git a/server/routes/device_validate_name.go b/server/routes/device_validate_name.go index d1657ae..e31407a 100644 --- a/server/routes/device_validate_name.go +++ b/server/routes/device_validate_name.go @@ -6,7 +6,7 @@ import ( "github.com/gosimple/slug" "github.com/tigorlazuardi/redmage/pkg/errs" "github.com/tigorlazuardi/redmage/pkg/log" - "github.com/tigorlazuardi/redmage/views/devicesview/put" + "github.com/tigorlazuardi/redmage/views/devices/put" ) func (routes *Routes) DevicesValidateNameHTMX(rw http.ResponseWriter, req *http.Request) { diff --git a/server/routes/device_validate_slug.go b/server/routes/device_validate_slug.go index c087bc2..e515a3a 100644 --- a/server/routes/device_validate_slug.go +++ b/server/routes/device_validate_slug.go @@ -6,7 +6,7 @@ import ( "github.com/gosimple/slug" "github.com/tigorlazuardi/redmage/pkg/errs" "github.com/tigorlazuardi/redmage/pkg/log" - "github.com/tigorlazuardi/redmage/views/devicesview/put" + "github.com/tigorlazuardi/redmage/views/devices/put" ) func (routes *Routes) DevicesValidateSlugHTMX(rw http.ResponseWriter, req *http.Request) { diff --git a/server/routes/page_devices.go b/server/routes/page_devices.go index 339251e..4fe1fc4 100644 --- a/server/routes/page_devices.go +++ b/server/routes/page_devices.go @@ -6,7 +6,7 @@ import ( "github.com/tigorlazuardi/redmage/pkg/errs" "github.com/tigorlazuardi/redmage/pkg/log" "github.com/tigorlazuardi/redmage/views" - "github.com/tigorlazuardi/redmage/views/devicesview" + "github.com/tigorlazuardi/redmage/views/devices" ) func (routes *Routes) PageDevices(rw http.ResponseWriter, req *http.Request) { @@ -14,7 +14,7 @@ func (routes *Routes) PageDevices(rw http.ResponseWriter, req *http.Request) { defer start.End() vc := views.NewContext(routes.Config, req) - var data devicesview.Data + var data devices.Data data.Params.FillFromQuery(req.URL.Query()) result, err := routes.API.DevicesList(ctx, data.Params) @@ -23,14 +23,14 @@ func (routes *Routes) PageDevices(rw http.ResponseWriter, req *http.Request) { code, message := errs.HTTPMessage(err) rw.WriteHeader(code) data.Error = message - if err := devicesview.Devices(vc, data).Render(ctx, rw); err != nil { + if err := devices.View(vc, data).Render(ctx, rw); err != nil { log.New(ctx).Err(err).Error("failed to render devices error view") } } data.Devices = result.Devices data.Total = result.Total - if err := devicesview.Devices(vc, data).Render(ctx, rw); err != nil { + if err := devices.View(vc, data).Render(ctx, rw); err != nil { log.New(ctx).Err(err).Error("failed to render devices view") } } diff --git a/server/routes/page_devices_add.go b/server/routes/page_devices_add.go index 21a22ff..0bd49f0 100644 --- a/server/routes/page_devices_add.go +++ b/server/routes/page_devices_add.go @@ -5,7 +5,7 @@ import ( "github.com/tigorlazuardi/redmage/pkg/log" "github.com/tigorlazuardi/redmage/views" - "github.com/tigorlazuardi/redmage/views/devicesview/put" + "github.com/tigorlazuardi/redmage/views/devices/put" ) func (routes *Routes) PageDevicesAdd(rw http.ResponseWriter, req *http.Request) { diff --git a/server/routes/page_devices_details.go b/server/routes/page_devices_details.go index c2297d5..e9037cb 100644 --- a/server/routes/page_devices_details.go +++ b/server/routes/page_devices_details.go @@ -7,7 +7,7 @@ import ( "github.com/tigorlazuardi/redmage/pkg/errs" "github.com/tigorlazuardi/redmage/pkg/log" "github.com/tigorlazuardi/redmage/views" - "github.com/tigorlazuardi/redmage/views/devicesview/devicedetails" + "github.com/tigorlazuardi/redmage/views/devices/details" ) func (routes *Routes) PageDeviceDetails(rw http.ResponseWriter, req *http.Request) { @@ -18,7 +18,7 @@ func (routes *Routes) PageDeviceDetails(rw http.ResponseWriter, req *http.Reques slug := chi.URLParam(req, "slug") - var data devicedetails.Data + var data details.Data data.Params.FillFromQuery(req.URL.Query()) var err error @@ -29,7 +29,7 @@ func (routes *Routes) PageDeviceDetails(rw http.ResponseWriter, req *http.Reques code, message := errs.HTTPMessage(err) rw.WriteHeader(code) data.Error = message - if err := devicedetails.View(c, data).Render(ctx, rw); err != nil { + if err := details.View(c, data).Render(ctx, rw); err != nil { log.New(ctx).Err(err).Error("failed to render device details page") } return @@ -43,7 +43,7 @@ func (routes *Routes) PageDeviceDetails(rw http.ResponseWriter, req *http.Reques code, message := errs.HTTPMessage(err) rw.WriteHeader(code) data.Error = message - if err := devicedetails.View(c, data).Render(ctx, rw); err != nil { + if err := details.View(c, data).Render(ctx, rw); err != nil { log.New(ctx).Err(err).Error("failed to render device details page") } return @@ -52,7 +52,7 @@ func (routes *Routes) PageDeviceDetails(rw http.ResponseWriter, req *http.Reques data.Images = result.Images data.TotalImages = result.Total - if err := devicedetails.View(c, data).Render(ctx, rw); err != nil { + if err := details.View(c, data).Render(ctx, rw); err != nil { log.New(ctx).Err(err).Error("failed to render device details page") } } diff --git a/views/devicesview/devicedetails/data.go b/views/devices/details/data.go similarity index 97% rename from views/devicesview/devicedetails/data.go rename to views/devices/details/data.go index 7af151a..62c15f3 100644 --- a/views/devicesview/devicedetails/data.go +++ b/views/devices/details/data.go @@ -1,4 +1,4 @@ -package devicedetails +package details import ( "github.com/tigorlazuardi/redmage/api" diff --git a/views/devicesview/devicedetails/filter.templ b/views/devices/details/filter.templ similarity index 97% rename from views/devicesview/devicedetails/filter.templ rename to views/devices/details/filter.templ index b7a591b..bc47b80 100644 --- a/views/devicesview/devicedetails/filter.templ +++ b/views/devices/details/filter.templ @@ -1,4 +1,4 @@ -package devicedetails +package details import "fmt" diff --git a/views/devicesview/devicedetails/view.templ b/views/devices/details/view.templ similarity index 98% rename from views/devicesview/devicedetails/view.templ rename to views/devices/details/view.templ index d463483..f21a3e5 100644 --- a/views/devicesview/devicedetails/view.templ +++ b/views/devices/details/view.templ @@ -1,4 +1,4 @@ -package devicedetails +package details import "github.com/tigorlazuardi/redmage/views" import "github.com/tigorlazuardi/redmage/views/components" diff --git a/views/devicesview/filter.templ b/views/devices/filter.templ similarity index 98% rename from views/devicesview/filter.templ rename to views/devices/filter.templ index b642c51..4d7bb2d 100644 --- a/views/devicesview/filter.templ +++ b/views/devices/filter.templ @@ -1,4 +1,4 @@ -package devicesview +package devices import "github.com/tigorlazuardi/redmage/api" import "strconv" diff --git a/views/devicesview/put/aspect_ratio_tolerance_input.templ b/views/devices/put/aspect_ratio_tolerance_input.templ similarity index 100% rename from views/devicesview/put/aspect_ratio_tolerance_input.templ rename to views/devices/put/aspect_ratio_tolerance_input.templ diff --git a/views/devicesview/put/max_image_resolution_input.templ b/views/devices/put/max_image_resolution_input.templ similarity index 100% rename from views/devicesview/put/max_image_resolution_input.templ rename to views/devices/put/max_image_resolution_input.templ diff --git a/views/devicesview/put/min_image_resolution_input.templ b/views/devices/put/min_image_resolution_input.templ similarity index 100% rename from views/devicesview/put/min_image_resolution_input.templ rename to views/devices/put/min_image_resolution_input.templ diff --git a/views/devicesview/put/name_input.templ b/views/devices/put/name_input.templ similarity index 100% rename from views/devicesview/put/name_input.templ rename to views/devices/put/name_input.templ diff --git a/views/devicesview/put/nsfw_checkbox.templ b/views/devices/put/nsfw_checkbox.templ similarity index 100% rename from views/devicesview/put/nsfw_checkbox.templ rename to views/devices/put/nsfw_checkbox.templ diff --git a/views/devicesview/put/resolution_input.templ b/views/devices/put/resolution_input.templ similarity index 100% rename from views/devicesview/put/resolution_input.templ rename to views/devices/put/resolution_input.templ diff --git a/views/devicesview/put/slug_input.templ b/views/devices/put/slug_input.templ similarity index 100% rename from views/devicesview/put/slug_input.templ rename to views/devices/put/slug_input.templ diff --git a/views/devicesview/put/view.templ b/views/devices/put/view.templ similarity index 100% rename from views/devicesview/put/view.templ rename to views/devices/put/view.templ diff --git a/views/devicesview/put/windows_wallpaper_checkbox.templ b/views/devices/put/windows_wallpaper_checkbox.templ similarity index 100% rename from views/devicesview/put/windows_wallpaper_checkbox.templ rename to views/devices/put/windows_wallpaper_checkbox.templ diff --git a/views/devicesview/view.templ b/views/devices/view.templ similarity index 94% rename from views/devicesview/view.templ rename to views/devices/view.templ index 941c539..812c32f 100644 --- a/views/devicesview/view.templ +++ b/views/devices/view.templ @@ -1,4 +1,4 @@ -package devicesview +package devices import "github.com/tigorlazuardi/redmage/views" import "github.com/tigorlazuardi/redmage/views/components" @@ -15,16 +15,16 @@ type Data struct { Params api.DevicesListParams } -templ Devices(c *views.Context, data Data) { +templ View(c *views.Context, data Data) { @components.Doctype() { @components.Head(c, components.HeadTitle("Redmage - Devices")) @components.Body(c) { - @DevicesContent(c, data) + @Content(c, data) } } } -templ DevicesContent(c *views.Context, data Data) { +templ Content(c *views.Context, data Data) {
@components.Container() { if data.Error != "" {