filter for binary files

This commit is contained in:
Niko Abeler 2024-02-23 12:34:05 +01:00
parent 7ceb00799a
commit bc50388f58
7 changed files with 45 additions and 6 deletions

View File

@ -25,8 +25,11 @@ func (s *BinaryService) FindById(id string) (*model.BinaryFile, error) {
return s.repo.FindById(id)
}
func (s *BinaryService) ListIds() ([]string, error) {
return s.repo.ListIds()
// ListIds list all ids of binary files
// if filter is not empty, the list will be filter to all ids which include the filter filter substring
// ids and filters are compared in lower case
func (s *BinaryService) ListIds(filter string) ([]string, error) {
return s.repo.ListIds(filter)
}
func (s *BinaryService) Delete(binary *model.BinaryFile) error {

View File

@ -19,7 +19,10 @@ type BinaryRepository interface {
Create(name string, data []byte, entry model.Entry) (*model.BinaryFile, error)
FindById(id string) (*model.BinaryFile, error)
FindByNameForEntry(name string, entry model.Entry) (*model.BinaryFile, error)
ListIds() ([]string, error)
// ListIds list all ids of binary files
// if filter is not empty, the list will be filter to all ids which include the filter filter substring
// ids and filters are compared in lower case
ListIds(filter string) ([]string, error)
Delete(binary *model.BinaryFile) error
}

View File

@ -101,9 +101,15 @@ func (repo *DefaultBinaryFileRepo) FindByNameForEntry(name string, entry model.E
}
// ListIds implements repository.BinaryRepository
func (repo *DefaultBinaryFileRepo) ListIds() ([]string, error) {
func (repo *DefaultBinaryFileRepo) ListIds(filter string) ([]string, error) {
filter = strings.TrimSpace(strings.ToLower(filter))
if filter == "" {
filter = "%"
} else {
filter = "%" + filter + "%"
}
var ids []string
err := repo.db.Select(&ids, "SELECT id FROM binary_files")
err := repo.db.Select(&ids, "SELECT id FROM binary_files WHERE LOWER(id) LIKE ?", filter)
if err != nil {
return nil, err
}

View File

@ -20,6 +20,13 @@
--background: {{.SiteConfig.HeaderColor}};
--background-dark: color-mix(in srgb,var(--background),#000 50%);
--background-light: color-mix(in srgb,var(--background),#fff 50%);
--pico-primary: {{.SiteConfig.PrimaryColor}};
--pico-primary-hover: color-mix(in srgb,var(--primary),#000 20%);
--pico-primary-focus: color-mix(in srgb,var(--primary),#fff 40%);
--pico-primary-inverse: #FFF;
--pico-background: {{.SiteConfig.HeaderColor}};
--pico-background-dark: color-mix(in srgb,var(--background),#000 50%);
--pico-background-light: color-mix(in srgb,var(--background),#fff 50%);
}
[data-theme="light"],
@ -28,6 +35,10 @@
--primary-hover: color-mix(in srgb,var(--primary),#000 20%);
--primary-focus: color-mix(in srgb,var(--primary),#fff 40%);
--primary-inverse: #FFF;
--pico-primary: {{.SiteConfig.PrimaryColor}};
--pico-primary-hover: color-mix(in srgb,var(--primary),#000 20%);
--pico-primary-focus: color-mix(in srgb,var(--primary),#fff 40%);
--pico-primary-inverse: #FFF;
}

View File

@ -18,6 +18,15 @@
</div>
</form>
<hr>
<form action="" method="get">
<fieldset role="group">
<input type="filter" name="filter" id="filter" value="{{.Filter}}">
<input type="submit" value="Search">
</fieldset>
</form>
<table role="grid">
<thead>
<tr>

View File

@ -26,7 +26,9 @@ func NewBinaryManageHandler(configRepo repository.ConfigRepository, service *app
func (h *BinaryManageHandler) Handle(c *fiber.Ctx) error {
siteConfig := getSiteConfig(h.configRepo)
allIds, err := h.service.ListIds()
filter := c.Query("filter", "")
allIds, err := h.service.ListIds(filter)
sort.Slice(allIds, func(i, j int) bool {
return strings.ToLower(allIds[i]) < strings.ToLower(allIds[j])
})
@ -43,6 +45,7 @@ func (h *BinaryManageHandler) Handle(c *fiber.Ctx) error {
"PrevPage": pageData.page - 1,
"FirstPage": pageData.page == 1,
"LastPage": pageData.lastPage,
"Filter": filter,
})
}

4
web/static/pico-2.min.css vendored Normal file

File diff suppressed because one or more lines are too long