Text search for the change log
This commit is contained in:
parent
268a177412
commit
763b9e4404
|
@ -31,6 +31,8 @@ func ChangeLog() http.HandlerFunc {
|
||||||
adminUser = r.FormValue("admin_user_id")
|
adminUser = r.FormValue("admin_user_id")
|
||||||
event = r.FormValue("event")
|
event = r.FormValue("event")
|
||||||
sort = r.FormValue("sort")
|
sort = r.FormValue("sort")
|
||||||
|
searchQuery = r.FormValue("search")
|
||||||
|
search = models.ParseSearchString(searchQuery)
|
||||||
sortOK bool
|
sortOK bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,7 +82,7 @@ func ChangeLog() http.HandlerFunc {
|
||||||
}
|
}
|
||||||
pager.ParsePage(r)
|
pager.ParsePage(r)
|
||||||
|
|
||||||
cl, err := models.PaginateChangeLog(tableName, tableID, aboutUserID, adminUserID, event, pager)
|
cl, err := models.PaginateChangeLog(tableName, tableID, aboutUserID, adminUserID, event, search, pager)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
session.FlashError(w, r, "Error paginating the change log: %s", err)
|
session.FlashError(w, r, "Error paginating the change log: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -115,6 +117,7 @@ func ChangeLog() http.HandlerFunc {
|
||||||
"AboutUserID": aboutUser,
|
"AboutUserID": aboutUser,
|
||||||
"AdminUserID": adminUser,
|
"AdminUserID": adminUser,
|
||||||
"Event": event,
|
"Event": event,
|
||||||
|
"SearchQuery": searchQuery,
|
||||||
"Sort": sort,
|
"Sort": sort,
|
||||||
}
|
}
|
||||||
if err := tmpl.Execute(w, r, vars); err != nil {
|
if err := tmpl.Execute(w, r, vars); err != nil {
|
||||||
|
|
|
@ -52,7 +52,7 @@ var ChangeLogEventTypes = []string{
|
||||||
}
|
}
|
||||||
|
|
||||||
// PaginateChangeLog lists the change logs.
|
// PaginateChangeLog lists the change logs.
|
||||||
func PaginateChangeLog(tableName string, tableID, aboutUserID, adminUserID uint64, event string, pager *Pagination) ([]*ChangeLog, error) {
|
func PaginateChangeLog(tableName string, tableID, aboutUserID, adminUserID uint64, event string, search *Search, pager *Pagination) ([]*ChangeLog, error) {
|
||||||
var (
|
var (
|
||||||
cl = []*ChangeLog{}
|
cl = []*ChangeLog{}
|
||||||
where = []string{}
|
where = []string{}
|
||||||
|
@ -84,6 +84,18 @@ func PaginateChangeLog(tableName string, tableID, aboutUserID, adminUserID uint6
|
||||||
placeholders = append(placeholders, event)
|
placeholders = append(placeholders, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Text search terms
|
||||||
|
for _, term := range search.Includes {
|
||||||
|
var ilike = "%" + strings.ToLower(term) + "%"
|
||||||
|
where = append(where, "change_logs.message ILIKE ?")
|
||||||
|
placeholders = append(placeholders, ilike)
|
||||||
|
}
|
||||||
|
for _, term := range search.Excludes {
|
||||||
|
var ilike = "%" + strings.ToLower(term) + "%"
|
||||||
|
where = append(where, "change_logs.message NOT ILIKE ?")
|
||||||
|
placeholders = append(placeholders, ilike)
|
||||||
|
}
|
||||||
|
|
||||||
query := DB.Model(&ChangeLog{}).Where(
|
query := DB.Model(&ChangeLog{}).Where(
|
||||||
strings.Join(where, " AND "),
|
strings.Join(where, " AND "),
|
||||||
placeholders...,
|
placeholders...,
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="column px-1">
|
<div class="column pl-1">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">Admin User:</label>
|
<label class="label">Admin User:</label>
|
||||||
<input type="text" class="input"
|
<input type="text" class="input"
|
||||||
|
@ -87,7 +87,9 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="columns">
|
||||||
<div class="column px-1">
|
<div class="column px-1">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">Event Type:</label>
|
<label class="label">Event Type:</label>
|
||||||
|
@ -102,6 +104,16 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="column is-narrow">
|
||||||
|
<label class="label">Search query:</label>
|
||||||
|
<input type="text" class="input" name="search" value="{{$Root.SearchQuery}}">
|
||||||
|
<p class="help">
|
||||||
|
Tip: you can <span class="has-text-success">"quote exact phrases"</span> and
|
||||||
|
<span class="has-text-success">-exclude</span> words (or
|
||||||
|
<span class="has-text-success">-"exclude phrases"</span>) from your search.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="column px-1">
|
<div class="column px-1">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">Sort:</label>
|
<label class="label">Sort:</label>
|
||||||
|
@ -113,15 +125,15 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="has-text-centered">
|
<div class="column has-text-right">
|
||||||
<a href="{{.Request.URL.Path}}" class="button">Reset</a>
|
<br>
|
||||||
<button type="submit" class="button is-success">
|
<a href="{{.Request.URL.Path}}" class="button">Reset</a>
|
||||||
<span>Search</span>
|
<button type="submit" class="button is-success">
|
||||||
<span class="icon"><i class="fa fa-search"></i></span>
|
<span>Search</span>
|
||||||
</button>
|
<span class="icon"><i class="fa fa-search"></i></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user