diff options
author | June McEnroe <june@causal.agency> | 2020-07-11 14:04:25 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-11 14:04:25 -0400 |
commit | 24c7965d9d0aaf27985d29c5cbb12a4e08ac7d9c (patch) | |
tree | 2a9e3955d59c375edb7d02ae0bd195bf966d57ea /events.c | |
parent | Implement basic search page (diff) | |
download | scooper-24c7965d9d0aaf27985d29c5cbb12a4e08ac7d9c.tar.gz scooper-24c7965d9d0aaf27985d29c5cbb12a4e08ac7d9c.zip |
Factor out "scope" of pages
Use this to keep the search query around and hide network and context from the search results if the scope is already limited.
Diffstat (limited to '')
-rw-r--r-- | events.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/events.c b/events.c index 32e94c2..5e332a3 100644 --- a/events.c +++ b/events.c @@ -70,11 +70,8 @@ const char *EventsBeforeQuery = SQL( ); enum kcgi_err pageEvents(struct kreq *req) { - if (!req->fieldmap[Network] || !req->fieldmap[Context]) { - return httpFail(req, KHTTP_400); - } - const char *network = req->fieldmap[Network]->parsed.s; - const char *context = req->fieldmap[Context]->parsed.s; + struct Scope scope = htmlScope(req); + if (!scope.network || !scope.context) return httpFail(req, KHTTP_400); if (!req->fieldmap[After] && !req->fieldmap[Before]) { struct tm *tm = gmtime(&(time_t) { time(NULL) }); @@ -85,8 +82,8 @@ enum kcgi_err pageEvents(struct kreq *req) { char *url = khttp_urlpart( NULL, NULL, Pages[Events], - Keys[Network].name, network, - Keys[Context].name, context, + Keys[Network].name, scope.network, + Keys[Context].name, scope.context, Keys[Before].name, time, NULL ); @@ -106,16 +103,16 @@ enum kcgi_err pageEvents(struct kreq *req) { error = error || khttp_body(req) || khtml_open(&html, req, KHTML_PRETTY) - || htmlHead(&html, context) - || htmlNav(&html, network, context) + || htmlHead(&html, scope.context) + || htmlNav(&html, scope) || khtml_elem(&html, KELEM_TABLE); if (error) return error; sqlite3_stmt *events = stmt.eventsAfter; if (req->fieldmap[Before]) events = stmt.eventsBefore; - dbBindText(events, ":network", network); - dbBindText(events, ":context", context); + dbBindText(events, ":network", scope.network); + dbBindText(events, ":context", scope.context); if (pagePublic) dbBindInt(events, ":query", false); dbBindText(events, ":time", time); dbBindInt(events, ":limit", pageLimit); @@ -132,7 +129,7 @@ enum kcgi_err pageEvents(struct kreq *req) { .target = (const char *)sqlite3_column_text(events, 6), .message = (const char *)sqlite3_column_text(events, 7), }; - error = htmlEvent(&html, event); + error = htmlEvent(&html, scope, event); if (error) break; } if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db)); |