commit ecbf63356f29f223b3a83deb50c60a721814b1d8
parent 10e89d975acdef99f89a202e1bbe7e8963190ed0
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Mon, 11 Mar 2024 20:09:40 -0700
Add reference to total element at the top of table
I ended up reworking some of the backend so that printduration now
just allows specifying an id instead of the final argument. I also
replaced the text "Reload" with '↻' and used a down arrow for the
Diffstat:
M | pages/main.c | | | 45 | +++++++++++++++++++++++++++------------------ |
1 file changed, 27 insertions(+), 18 deletions(-)
diff --git a/pages/main.c b/pages/main.c
@@ -25,7 +25,7 @@
static char *datetime_fmt = "%FT%T+0000";
enum kcgi_err
-printduration(struct pagedata *pd, time_t duration, int final)
+printduration(struct pagedata *pd, time_t duration, char *id)
{
enum kcgi_err status;
time_t hr, mn, sc;
@@ -43,30 +43,18 @@ printduration(struct pagedata *pd, time_t duration, int final)
err(1, "snprintf (%lldh %lldm %llds)", hr, mn, sc);
}
- if (!final)
+ if (id)
status = khtml_attr(&pd->html, KELEM_TIME,
- KATTR_ID, "counter", KATTR_DATETIME, datetime, KATTR__MAX);
+ KATTR_ID, id, KATTR_DATETIME, datetime, KATTR__MAX);
else
status = khtml_attr(&pd->html, KELEM_TIME,
KATTR_DATETIME, datetime, KATTR__MAX);
- if (status)
- return status;
- if ((status =
+ if (status != KCGI_OK || (status =
khtml_printf(&pd->html, "%.2lld:%.2lld:%.2lld", hr, mn, sc)) != KCGI_OK ||
(status = khtml_closeelem(&pd->html, 1)) != KCGI_OK)
return status;
- if (!final) {
- if ((status = khtml_elem(&pd->html, KELEM_NOSCRIPT)) != KCGI_OK ||
- (status = khtml_attr(&pd->html, KELEM_A,
- KATTR_HREF, pd->pages[PageMain], KATTR__MAX)) != KCGI_OK ||
- (status = khtml_putc(&pd->html, ' ')) != KCGI_OK ||
- (status = htmlwithin(pd, KELEM_BUTTON, "Reload")) != KCGI_OK ||
- (status = khtml_closeelem(&pd->html, 2)) != KCGI_OK)
- return status;
- }
-
return KCGI_OK;
}
@@ -74,12 +62,28 @@ enum kcgi_err
printhours(struct pagedata *pd, struct timesheet *ts)
{
int final;
+ enum kcgi_err status;
assert(ts->set & StartTimeFlag);
final = (ts->set & EndTimeFlag ||
(ts->set & BreakStartTimeFlag && !(ts->set & BreakEndTimeFlag)));
- return printduration(pd, getduration(ts), final);
+
+ status = printduration(pd, getduration(ts), final ? NULL : "counter");
+ if (status != KCGI_OK)
+ return status;
+
+ if (!final) {
+ if ((status = khtml_elem(&pd->html, KELEM_NOSCRIPT)) != KCGI_OK ||
+ (status = khtml_attr(&pd->html, KELEM_A,
+ KATTR_HREF, pd->pages[PageMain], KATTR__MAX)) != KCGI_OK ||
+ (status = khtml_elem(&pd->html, KELEM_BUTTON)) != KCGI_OK ||
+ (status = khtml_ncr(&pd->html, 0x21BB)) != KCGI_OK ||
+ (status = khtml_closeelem(&pd->html, 3)) != KCGI_OK)
+ return status;
+ }
+
+ return KCGI_OK;
}
enum kcgi_err
@@ -102,7 +106,7 @@ printtotal(struct pagedata *pd, struct timesheet *ts)
for (i = StartTime; i <= EndTime + 1; ++i)
if ((status = khtml_elem(&pd->html, KELEM_TD)) != KCGI_OK ||
- (i > EndTime && (status = printduration(pd, t, 1)) != KCGI_OK) ||
+ (i > EndTime && (status = printduration(pd, t, "total")) != KCGI_OK) ||
(status = khtml_closeelem(&pd->html, 1)) != KCGI_OK)
return status;
return KCGI_OK;
@@ -243,6 +247,11 @@ printtimes(struct pagedata *pd, struct timesheet *times)
if ((status = khtml_attr(&pd->html, KELEM_TH,
KATTR_SCOPE, "col", KATTR__MAX)) != KCGI_OK ||
(status = khtml_puts(&pd->html, headers[i])) != KCGI_OK ||
+ (i == Len(headers) - 1 && (
+ (status = khtml_attr(&pd->html, KELEM_A,
+ KATTR_HREF, "#total", KATTR__MAX)) != KCGI_OK ||
+ (status = khtml_ncr(&pd->html, 0x2193)) != KCGI_OK ||
+ (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK)) ||
(status = khtml_closeelem(&pd->html, 1)) != KCGI_OK)
return status;
}