filter for binary files
This commit is contained in:
parent
7ceb00799a
commit
bc50388f58
|
@ -25,8 +25,11 @@ func (s *BinaryService) FindById(id string) (*model.BinaryFile, error) {
|
||||||
return s.repo.FindById(id)
|
return s.repo.FindById(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *BinaryService) ListIds() ([]string, error) {
|
// ListIds list all ids of binary files
|
||||||
return s.repo.ListIds()
|
// 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 {
|
func (s *BinaryService) Delete(binary *model.BinaryFile) error {
|
||||||
|
|
|
@ -19,7 +19,10 @@ type BinaryRepository interface {
|
||||||
Create(name string, data []byte, entry model.Entry) (*model.BinaryFile, error)
|
Create(name string, data []byte, entry model.Entry) (*model.BinaryFile, error)
|
||||||
FindById(id string) (*model.BinaryFile, error)
|
FindById(id string) (*model.BinaryFile, error)
|
||||||
FindByNameForEntry(name string, entry model.Entry) (*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
|
Delete(binary *model.BinaryFile) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,9 +101,15 @@ func (repo *DefaultBinaryFileRepo) FindByNameForEntry(name string, entry model.E
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListIds implements repository.BinaryRepository
|
// 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
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,13 @@
|
||||||
--background: {{.SiteConfig.HeaderColor}};
|
--background: {{.SiteConfig.HeaderColor}};
|
||||||
--background-dark: color-mix(in srgb,var(--background),#000 50%);
|
--background-dark: color-mix(in srgb,var(--background),#000 50%);
|
||||||
--background-light: color-mix(in srgb,var(--background),#fff 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"],
|
[data-theme="light"],
|
||||||
|
@ -28,6 +35,10 @@
|
||||||
--primary-hover: color-mix(in srgb,var(--primary),#000 20%);
|
--primary-hover: color-mix(in srgb,var(--primary),#000 20%);
|
||||||
--primary-focus: color-mix(in srgb,var(--primary),#fff 40%);
|
--primary-focus: color-mix(in srgb,var(--primary),#fff 40%);
|
||||||
--primary-inverse: #FFF;
|
--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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,15 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</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">
|
<table role="grid">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -26,7 +26,9 @@ func NewBinaryManageHandler(configRepo repository.ConfigRepository, service *app
|
||||||
func (h *BinaryManageHandler) Handle(c *fiber.Ctx) error {
|
func (h *BinaryManageHandler) Handle(c *fiber.Ctx) error {
|
||||||
siteConfig := getSiteConfig(h.configRepo)
|
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 {
|
sort.Slice(allIds, func(i, j int) bool {
|
||||||
return strings.ToLower(allIds[i]) < strings.ToLower(allIds[j])
|
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,
|
"PrevPage": pageData.page - 1,
|
||||||
"FirstPage": pageData.page == 1,
|
"FirstPage": pageData.page == 1,
|
||||||
"LastPage": pageData.lastPage,
|
"LastPage": pageData.lastPage,
|
||||||
|
"Filter": filter,
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue