changeset 2677:fe93c48f76c9 import-overview-rework

Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 15 Mar 2019 12:04:52 +0100
parents 43e1abaf9ee3
children b7995ab49ec5
files pkg/controllers/importqueue.go
diffstat 1 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/importqueue.go	Fri Mar 15 10:18:49 2019 +0100
+++ b/pkg/controllers/importqueue.go	Fri Mar 15 12:04:52 2019 +0100
@@ -163,25 +163,32 @@
 	a.stmt.WriteString(selectAfterSQL)
 	b.stmt.WriteString(selectBeforeSQL)
 
+	cond := func(format string, v ...interface{}) {
+		l.cond(format, v...)
+		a.cond(format, v...)
+		b.cond(format, v...)
+	}
+
+	if query := req.FormValue("query"); query != "" {
+		query = "%" + query + "%"
+		cond(` (kind ILIKE $%d OR username ILIKE $%d OR signer ILIKE $%d OR `+
+			`id IN (SELECT import_id FROM import.import_logs WHERE msg ILIKE $%d)) `,
+			query, query, query, query)
+	}
+
 	if st := req.FormValue("states"); st != "" {
 		states := toTextArray(st, imports.ImportStateNames)
-		l.cond(" state = ANY($%d) ", states)
-		a.cond(" state = ANY($%d) ", states)
-		b.cond(" state = ANY($%d) ", states)
+		cond(" state = ANY($%d) ", states)
 	}
 
 	if ks := req.FormValue("kinds"); ks != "" {
 		kinds := toTextArray(ks, imports.ImportKindNames())
-		l.cond(" kind = ANY($%d) ", kinds)
-		a.cond(" kind = ANY($%d) ", kinds)
-		b.cond(" kind = ANY($%d) ", kinds)
+		cond(" kind = ANY($%d) ", kinds)
 	}
 
 	if idss := req.FormValue("ids"); idss != "" {
 		ids := toInt8Array(idss)
-		l.cond(" id = ANY($%d) ", ids)
-		a.cond(" id = ANY($%d) ", ids)
-		b.cond(" id = ANY($%d) ", ids)
+		cond(" id = ANY($%d) ", ids)
 	}
 
 	if from := req.FormValue("from"); from != "" {
@@ -208,9 +215,7 @@
 
 	switch warn := strings.ToLower(req.FormValue("warnings")); warn {
 	case "1", "t", "true":
-		l.cond(" id IN (SELECT id FROM warned) ")
-		a.cond(" id IN (SELECT id FROM warned) ")
-		b.cond(" id IN (SELECT id FROM warned) ")
+		cond(" id IN (SELECT id FROM warned) ")
 	}
 
 	if !l.hasCond {
@@ -227,6 +232,8 @@
 	a.stmt.WriteString(" ORDER BY enqueued LIMIT 1")
 	b.stmt.WriteString(" ORDER BY enqueued LIMIT 1")
 
+	log.Println(l.stmt.String())
+
 	if noBefore {
 		b = nil
 	}