mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-02 15:06:23 -07:00
Show filters in descending order on manage page
This commit is contained in:
parent
4cca346f47
commit
363e8914b3
2 changed files with 18 additions and 7 deletions
|
@ -74,11 +74,15 @@ func GetFilterByID(id int) (*Filter, error) {
|
||||||
|
|
||||||
// GetAllFilters returns an array of all post filters, and an error if one occured. It can optionally return only the active or
|
// GetAllFilters returns an array of all post filters, and an error if one occured. It can optionally return only the active or
|
||||||
// only the inactive filters (or return all)
|
// only the inactive filters (or return all)
|
||||||
func GetAllFilters(activeFilter BooleanFilter) ([]Filter, error) {
|
func GetAllFilters(activeFilter BooleanFilter, desc ...bool) ([]Filter, error) {
|
||||||
return queryFilters(` WHERE match_action <> 'replace'` + activeFilter.whereClause("is_active", true))
|
queryAdd := " WHERE match_action <> 'replace' " + activeFilter.whereClause("is_active", true)
|
||||||
|
if len(desc) > 0 && desc[0] {
|
||||||
|
queryAdd += " ORDER BY id DESC"
|
||||||
|
}
|
||||||
|
return queryFilters(queryAdd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFiltersByBoardDirHelper(dir string, includeAllBoards bool, activeFilter BooleanFilter, useWordFilters bool) ([]Filter, error) {
|
func getFiltersByBoardDirHelper(dir string, includeAllBoards bool, activeFilter BooleanFilter, useWordFilters bool, desc bool) ([]Filter, error) {
|
||||||
query := `LEFT JOIN DBPREFIXfilter_boards ON filter_id = f.id
|
query := `LEFT JOIN DBPREFIXfilter_boards ON filter_id = f.id
|
||||||
LEFT JOIN DBPREFIXboards ON DBPREFIXboards.id = board_id`
|
LEFT JOIN DBPREFIXboards ON DBPREFIXboards.id = board_id`
|
||||||
|
|
||||||
|
@ -101,14 +105,21 @@ func getFiltersByBoardDirHelper(dir string, includeAllBoards bool, activeFilter
|
||||||
query += activeFilter.whereClause("is_active", true)
|
query += activeFilter.whereClause("is_active", true)
|
||||||
params = []any{dir}
|
params = []any{dir}
|
||||||
}
|
}
|
||||||
|
if desc {
|
||||||
|
query += " ORDER BY id DESC"
|
||||||
|
}
|
||||||
return queryFilters(query, params...)
|
return queryFilters(query, params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFiltersByBoardDir returns the filters associated with the given board dir, optionally including filters
|
// GetFiltersByBoardDir returns the filters associated with the given board dir, optionally including filters
|
||||||
// not associated with a specific board. It can optionally return only the active or only the inactive filters
|
// not associated with a specific board. It can optionally return only the active or only the inactive filters
|
||||||
// (or return all)
|
// (or return all)
|
||||||
func GetFiltersByBoardDir(dir string, includeAllBoards bool, show BooleanFilter) ([]Filter, error) {
|
func GetFiltersByBoardDir(dir string, includeAllBoards bool, show BooleanFilter, desc ...bool) ([]Filter, error) {
|
||||||
return getFiltersByBoardDirHelper(dir, includeAllBoards, show, false)
|
descParam := false
|
||||||
|
if len(desc) > 0 {
|
||||||
|
descParam = desc[0]
|
||||||
|
}
|
||||||
|
return getFiltersByBoardDirHelper(dir, includeAllBoards, show, false, descParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFiltersByBoardID returns an array of post filters associated to the given board ID, including
|
// GetFiltersByBoardID returns an array of post filters associated to the given board ID, including
|
||||||
|
|
|
@ -267,9 +267,9 @@ func filtersCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
||||||
var filters []gcsql.Filter
|
var filters []gcsql.Filter
|
||||||
boardSearch := request.FormValue("boardsearch")
|
boardSearch := request.FormValue("boardsearch")
|
||||||
if boardSearch == "" {
|
if boardSearch == "" {
|
||||||
filters, err = gcsql.GetAllFilters(show)
|
filters, err = gcsql.GetAllFilters(show, true)
|
||||||
} else {
|
} else {
|
||||||
filters, err = gcsql.GetFiltersByBoardDir(boardSearch, false, show)
|
filters, err = gcsql.GetFiltersByBoardDir(boardSearch, false, show, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue