commit 0d3fb1b72ee6f4b3b370bff48bae5a8881990373
parent d4531c10c90c300d8e19b3e69b398dfa54561ff4
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 12 Sep 2026 01:26:24 +0530
parent d4531c10c90c300d8e19b3e69b398dfa54561ff4
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 12 Sep 2026 01:26:24 +0530
Share page header rendering
1 file changed, 57 insertions(+), 76 deletions(-)
diff --git a/main.c b/main.c @@ -241,6 +241,18 @@ view_jobs(void) } static void +get_html_crumb(struct khtmlreq *req, const char *href, const char *text) +{ + + if (href != NULL) + khtml_attr(req, KELEM_A, KATTR_HREF, href, KATTR__MAX); + else + khtml_elem(req, KELEM_SPAN); + khtml_puts(req, text); + khtml_closeelem(req, 1); +} + +static void get_view_switch(struct khtmlreq *req, const char *runs, const char *jobs) { @@ -265,6 +277,31 @@ get_view_switch(struct khtmlreq *req, const char *runs, const char *jobs) } static void +get_html_header(struct khtmlreq *req, const char *classes, + const char *href1, const char *text1, + const char *href2, const char *text2, + const char *href3, const char *text3, + const char *runs, const char *jobs) +{ + + khtml_elem(req, KELEM_HEADER); + khtml_attr(req, KELEM_H1, KATTR_CLASS, classes, KATTR__MAX); + get_html_crumb(req, href1, text1); + if (text2 != NULL) { + khtml_ncr(req, 0x203a); + get_html_crumb(req, href2, text2); + } + if (text3 != NULL) { + khtml_ncr(req, 0x203a); + get_html_crumb(req, href3, text3); + } + khtml_closeelem(req, 1); /* h1 */ + if (runs != NULL && jobs != NULL) + get_view_switch(req, runs, jobs); + khtml_closeelem(req, 1); /* header */ +} + +static void get_html_artifact(const struct artifact *p, void *arg) { struct khtmlreq *req = arg; @@ -899,17 +936,8 @@ get_run_html(struct kreq *r, const struct run *p) kcgi_writer_disable(r); html_open(&req.html, "Run"); req.r = r; - khtml_elem(&req.html, KELEM_HEADER); - khtml_attr(&req.html, KELEM_H1, KATTR_CLASS, "singleton", KATTR__MAX); - khtml_attr(&req.html, KELEM_A, KATTR_HREF, "index.html", KATTR__MAX); - khtml_puts(&req.html, "Dashboard"); - khtml_closeelem(&req.html, 1); - khtml_ncr(&req.html, 0x203a); - khtml_attr(&req.html, KELEM_A, KATTR_HREF, urlproj, KATTR__MAX); - khtml_puts(&req.html, p->project.name); - khtml_closeelem(&req.html, 1); - khtml_closeelem(&req.html, 1); - khtml_closeelem(&req.html, 1); + get_html_header(&req.html, "table", "index.html", "Dashboard", + urlproj, p->project.name, NULL, NULL, NULL, NULL); khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, "table alltable", KATTR__MAX); get_html_job_header(&req.html); @@ -957,7 +985,7 @@ static void get_job_html(struct kreq *r, const struct job *p) { struct khtmlreq req; - char buf[64], *urlrun; + char buf[64], *runbuf, *urlrun; size_t artc = 0; urlrun = khttp_urlpartx(r->pname, ksuffixes[KMIME_TEXT_HTML], @@ -966,21 +994,9 @@ get_job_html(struct kreq *r, const struct job *p) khtml_open(&req, r, 0); kcgi_writer_disable(r); html_open(&req, "Job"); - khtml_elem(&req, KELEM_HEADER); - khtml_attr(&req, KELEM_H1, KATTR_CLASS, "singleton", KATTR__MAX); - khtml_attr(&req, KELEM_A, KATTR_HREF, "index.html", KATTR__MAX); - khtml_puts(&req, "Dashboard"); - khtml_closeelem(&req, 1); - khtml_ncr(&req, 0x203a); - khtml_attr(&req, KELEM_A, KATTR_HREF, urlrun, KATTR__MAX); - khtml_puts(&req, p->run.project.name); - khtml_closeelem(&req, 1); - khtml_ncr(&req, 0x203a); - khtml_elem(&req, KELEM_SPAN); - khtml_puts(&req, p->name); - khtml_closeelem(&req, 1); - khtml_closeelem(&req, 1); - khtml_closeelem(&req, 1); + kasprintf(&runbuf, "Run #%" PRId64, p->runid); + get_html_header(&req, "table", "index.html", "Dashboard", + urlrun, runbuf, NULL, p->name, NULL, NULL); khtml_attr(&req, KELEM_DIV, KATTR_CLASS, "singleton", KATTR__MAX); khtml_attr(&req, KELEM_SPAN, KATTR_CLASS, @@ -1026,6 +1042,7 @@ get_job_html(struct kreq *r, const struct job *p) khtml_closeelem(&req, 1); khtml_closeelem(&req, 1); khtml_close(&req); + free(runbuf); free(urlrun); } @@ -1118,20 +1135,8 @@ get_dash(struct kreq *r, time_t mtime) /* Output header. */ - khtml_elem(&req, KELEM_HEADER); - khtml_attr(&req, KELEM_H1, - KATTR_CLASS, "table", KATTR__MAX); - - khtml_elem(&req, KELEM_SPAN); - khtml_puts(&req, "Dashboard"); - khtml_closeelem(&req, 1); /* span */ - khtml_ncr(&req, 0x203a); - khtml_elem(&req, KELEM_SPAN); - khtml_puts(&req, "All"); - khtml_closeelem(&req, 1); /* span */ - khtml_closeelem(&req, 1); /* h1 */ - get_view_switch(&req, "index.html", "index.html?view=jobs"); - khtml_closeelem(&req, 1); /* header */ + get_html_header(&req, "table", NULL, "Dashboard", NULL, "All", + NULL, NULL, "index.html", "index.html?view=jobs"); /* Output data. */ @@ -1380,52 +1385,28 @@ get_last(struct kreq *r, time_t mtime) /* Output header. */ - khtml_elem(&req.html, KELEM_HEADER); - khtml_attr(&req.html, KELEM_H1, - KATTR_CLASS, "table", KATTR__MAX); - if (kpn != NULL) { - khtml_attr(&req.html, KELEM_A, - KATTR_HREF, "index.html", KATTR__MAX); - khtml_puts(&req.html, "Dashboard"); - khtml_closeelem(&req.html, 1); /* a */ - khtml_ncr(&req.html, 0x203a); - khtml_elem(&req.html, KELEM_SPAN); - khtml_puts(&req.html, kpn->parsed.s); - khtml_closeelem(&req.html, 1); /* span */ kasprintf(&urlruns, "index.html?project-name=%s", kpn->parsed.s); kasprintf(&urljobs, "index.html?project-name=%s&view=jobs", kpn->parsed.s); + get_html_header(&req.html, "table", "index.html", + "Dashboard", NULL, kpn->parsed.s, NULL, NULL, + urlruns, urljobs); req.checkhash = 1; - } else if (kph != NULL) { - khtml_attr(&req.html, KELEM_A, - KATTR_HREF, "index.html", KATTR__MAX); - khtml_puts(&req.html, "Dashboard"); - khtml_closeelem(&req.html, 1); /* a */ - khtml_ncr(&req.html, 0x203a); - khtml_elem(&req.html, KELEM_SPAN); - khtml_puts(&req.html, "Machine Dashboard"); - khtml_closeelem(&req.html, 1); /* span */ - } else { - khtml_attr(&req.html, KELEM_A, - KATTR_HREF, "index.html", KATTR__MAX); - khtml_puts(&req.html, "Dashboard"); - khtml_closeelem(&req.html, 1); /* a */ - khtml_ncr(&req.html, 0x203a); - khtml_elem(&req.html, KELEM_SPAN); + } else if (kph != NULL) + get_html_header(&req.html, "table", "index.html", + "Dashboard", NULL, "Machine Dashboard", NULL, NULL, + NULL, NULL); + else { t = kpd->parsed.i; gmtime_r(&t, &tm); strftime(datebuf, sizeof(datebuf), "%F", &tm); - khtml_puts(&req.html, datebuf); - khtml_closeelem(&req.html, 1); /* span */ + get_html_header(&req.html, "table", "index.html", + "Dashboard", NULL, datebuf, NULL, NULL, + NULL, NULL); } - khtml_closeelem(&req.html, 1); /* h1 */ - if (kpn != NULL) - get_view_switch(&req.html, urlruns, urljobs); - khtml_closeelem(&req.html, 1); /* header */ - /* Output data. */ if (kpn != NULL && view_jobs()) {
: nply/minci