about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--events.c66
-rw-r--r--server.h1
2 files changed, 64 insertions, 3 deletions
diff --git a/events.c b/events.c
index 2816baa..51e56de 100644
--- a/events.c
+++ b/events.c
@@ -34,10 +34,23 @@ static const char *timestamp(time_t time) {
 	return stamp;
 }
 
+static enum kcgi_err tidyField(struct kreq *req, struct khtmlreq *html) {
+	if (!req->fieldmap[Tidy]) return KCGI_OK;
+	return khtml_attr(
+		html, KELEM_INPUT,
+		KATTR_TYPE, "hidden",
+		KATTR_NAME, Keys[Tidy].name,
+		KATTR_VALUE, req->fieldmap[Tidy]->parsed.s,
+		KATTR__MAX
+	);
+}
+
 static enum kcgi_err
-dateForm(struct khtmlreq *html, struct Scope scope, const char *_time) {
+dateForm(struct kreq *req, struct khtmlreq *html, struct Scope scope) {
+	struct kpair *field = req->fieldmap[After];
+	if (!field) field = req->fieldmap[Before];
 	struct tm tm = {0};
-	if (!strptime(_time, "%F", &tm)) {
+	if (!strptime(field->parsed.s, "%F", &tm)) {
 		tm = *gmtime(&(time_t) { time(NULL) });
 	}
 	char date[sizeof("0000-00-00")];
@@ -57,6 +70,7 @@ dateForm(struct khtmlreq *html, struct Scope scope, const char *_time) {
 			KATTR_VALUE, date,
 			KATTR__MAX
 		)
+		|| tidyField(req, html)
 		|| khtml_attr(
 			html, KELEM_INPUT,
 			KATTR_TYPE, "submit",
@@ -66,6 +80,46 @@ dateForm(struct khtmlreq *html, struct Scope scope, const char *_time) {
 		|| khtml_closeelem(html, 1);
 }
 
+static enum kcgi_err
+displayForm(struct kreq *req, struct khtmlreq *html, struct Scope scope) {
+	struct kpair *time = req->fieldmap[After];
+	if (!time) time = req->fieldmap[Before];
+	return 0
+		|| khtml_attr(
+			html, KELEM_FORM,
+			KATTR_METHOD, "get",
+			KATTR_ACTION, Pages[Events],
+			KATTR__MAX
+		)
+		|| htmlScopeFields(html, scope)
+		|| khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "hidden",
+			KATTR_NAME, time->key,
+			KATTR_VALUE, time->parsed.s,
+			KATTR__MAX
+		)
+		|| khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "checkbox",
+			KATTR_ID, Keys[Tidy].name,
+			KATTR_NAME, Keys[Tidy].name,
+			KATTR_VALUE, "1",
+			(req->fieldmap[Tidy] ? KATTR_CHECKED : KATTR__MAX), "checked",
+			KATTR__MAX
+		)
+		|| khtml_attr(html, KELEM_LABEL, KATTR_FOR, Keys[Tidy].name, KATTR__MAX)
+		|| khtml_puts(html, "Hide general events")
+		|| khtml_closeelem(html, 1)
+		|| khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "submit",
+			KATTR_VALUE, "Apply",
+			KATTR__MAX
+		)
+		|| khtml_closeelem(html, 1);
+}
+
 const char *EventsTopicQuery = SQL(
 	SELECT topics.topic
 	FROM topics
@@ -94,6 +148,7 @@ const char *EventsAfterQuery = SQL(
 	WHERE contexts.network = :network
 		AND contexts.name = :context
 		AND contexts.query <= NOT :public
+		AND events.type < :tidy
 		AND events.time >= strftime('%s', :time)
 	ORDER BY events.time, events.event
 	LIMIT :limit;
@@ -116,6 +171,7 @@ const char *EventsBeforeQuery = SQL(
 		WHERE contexts.network = :network
 			AND contexts.name = :context
 			AND contexts.query <= NOT :public
+			AND events.type < :tidy
 			AND events.time < strftime('%s', :time)
 		ORDER BY events.time DESC
 		LIMIT :limit
@@ -155,7 +211,8 @@ enum kcgi_err eventsPage(struct kreq *req) {
 		|| khtml_open(&html, req, 0)
 		|| htmlHead(&html, scope.context)
 		|| htmlNav(&html, scope)
-		|| dateForm(&html, scope, time)
+		|| dateForm(req, &html, scope)
+		|| displayForm(req, &html, scope)
 		|| khtml_elem(&html, KELEM_TABLE);
 	if (error) return error;
 
@@ -185,6 +242,7 @@ enum kcgi_err eventsPage(struct kreq *req) {
 	dbBindText(events, ":network", scope.network);
 	dbBindText(events, ":context", scope.context);
 	dbBindText(events, ":time", time);
+	dbBindInt(events, ":tidy", (req->fieldmap[Tidy] ? Join : TypesLen));
 	dbBindInt(events, ":public", contextsPublic);
 	dbBindInt(events, ":limit", eventsLimit);
 
@@ -209,6 +267,7 @@ enum kcgi_err eventsPage(struct kreq *req) {
 				Keys[Network].name, scope.network,
 				Keys[Context].name, scope.context,
 				Keys[Before].name, timestamp(event.time + eventsOverlap),
+				(req->fieldmap[Tidy] ? Keys[Tidy].name : NULL), "1",
 				NULL
 			);
 			if (!base) err(EX_OSERR, "khttp_urlpart");
@@ -250,6 +309,7 @@ enum kcgi_err eventsPage(struct kreq *req) {
 			Keys[Network].name, scope.network,
 			Keys[Context].name, scope.context,
 			Keys[After].name, timestamp(prevTime - eventsOverlap),
+			(req->fieldmap[Tidy] ? Keys[Tidy].name : NULL), "1",
 			NULL
 		);
 		if (!href) err(EX_OSERR, "khttp_urlpart");
diff --git a/server.h b/server.h
index f8b7126..1177871 100644
--- a/server.h
+++ b/server.h
@@ -55,6 +55,7 @@ extern const char *Pages[PagesLen];
 	X(Context, "context", kvalid_stringne) \
 	X(After, "after", kvalid_stringne) \
 	X(Before, "before", kvalid_stringne) \
+	X(Tidy, "tidy", kvalid_stringne) \
 	X(Query, "query", kvalid_stringne) \
 	X(Offset, "offset", kvalid_int)