devices: enhances filter bar

This commit is contained in:
Tigor Hutasuhut 2024-05-08 19:51:49 +07:00
parent 111e855a6e
commit b066ba8d66
2 changed files with 9 additions and 17 deletions

View file

@ -2,6 +2,7 @@ package views
import ( import (
"net/http" "net/http"
"net/url"
"github.com/tigorlazuardi/redmage/config" "github.com/tigorlazuardi/redmage/config"
) )
@ -9,6 +10,7 @@ import (
type Context struct { type Context struct {
Config *config.Config Config *config.Config
Request *http.Request Request *http.Request
Query url.Values
} }
func (c *Context) AppendQuery(keyValue ...string) string { func (c *Context) AppendQuery(keyValue ...string) string {
@ -23,5 +25,6 @@ func NewContext(config *config.Config, request *http.Request) *Context {
return &Context{ return &Context{
Config: config, Config: config,
Request: request, Request: request,
Query: request.URL.Query(),
} }
} }

View file

@ -1,8 +1,5 @@
package devices package devices
import "github.com/tigorlazuardi/redmage/api"
import "strconv"
templ filter(data Data) { templ filter(data Data) {
<div <div
id="filter-bar" id="filter-bar"
@ -36,24 +33,16 @@ templ filter(data Data) {
<label for="status">Status</label> <label for="status">Status</label>
<select id="status" name="status" class="select select-bordered w-full"> <select id="status" name="status" class="select select-bordered w-full">
<option value="">*No Filter</option> <option value="">*No Filter</option>
<option value="2" selected?={ data.Params.Status == 2 }>Enabled</option> <option value="1" selected?={ data.Params.Status == 1 }>Enabled</option>
<option value="1" selected?={ data.Params.Status == 1 }>Disabled</option> <option value="0" selected?={ data.Params.Status == 0 }>Disabled</option>
</select> </select>
<label for="limit">Limit</label> <label for="limit">Limit</label>
<select id="limit" name="limit" class="select select-bordered w-full"> <select id="limit" name="limit" class="select select-bordered w-full">
@limitOption(data.Params, 25) <option value="25" selected?={ data.Params.Limit == 25 }>25</option>
@limitOption(data.Params, 50) <option value="50" selected?={ data.Params.Limit == 50 }>50</option>
@limitOption(data.Params, 75) <option value="75" selected?={ data.Params.Limit == 75 }>75</option>
@limitOption(data.Params, 100) <option value="100" selected?={ data.Params.Limit == 100 }>100</option>
</select> </select>
</div> </div>
</div> </div>
} }
templ limitOption(params api.DevicesListParams, value int) {
if int(params.Limit) == value {
<option selected>{ strconv.Itoa(value) }</option>
} else {
<option>{ strconv.Itoa(value) }</option>
}
}