mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-15 03:30:39 +03:00
Filter playlists by names and comments
This commit is contained in:
parent
66a9cbb7d9
commit
074732b1dc
@ -30,9 +30,19 @@ func NewPlaylistRepository(ctx context.Context, o orm.Ormer) model.PlaylistRepos
|
||||
r.ctx = ctx
|
||||
r.ormer = o
|
||||
r.tableName = "playlist"
|
||||
r.filterMappings = map[string]filterFunc{
|
||||
"q": playlistFilter,
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func playlistFilter(field string, value interface{}) Sqlizer {
|
||||
return Or{
|
||||
substringFilter("name", value),
|
||||
substringFilter("comment", value),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *playlistRepository) userFilter() Sqlizer {
|
||||
user := loggedUser(r.ctx)
|
||||
if user.IsAdmin {
|
||||
|
@ -68,6 +68,15 @@ func fullTextFilter(field string, value interface{}) Sqlizer {
|
||||
return fullTextExpr(value.(string))
|
||||
}
|
||||
|
||||
func substringFilter(field string, value interface{}) Sqlizer {
|
||||
parts := strings.Split(value.(string), " ")
|
||||
filters := And{}
|
||||
for _, part := range parts {
|
||||
filters = append(filters, Like{field: "%" + part + "%"})
|
||||
}
|
||||
return filters
|
||||
}
|
||||
|
||||
func idFilter(tableName string) func(string, interface{}) Sqlizer {
|
||||
return func(field string, value interface{}) Sqlizer {
|
||||
return Eq{tableName + ".id": value}
|
||||
|
@ -26,7 +26,7 @@ import PlaylistListActions from './PlaylistListActions'
|
||||
|
||||
const PlaylistFilter = (props) => (
|
||||
<Filter {...props} variant={'outlined'}>
|
||||
<SearchInput source="name" alwaysOn />
|
||||
<SearchInput source="q" alwaysOn />
|
||||
</Filter>
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user