# HG changeset patch # User David Demelier # Date 1659854612 -7200 # Node ID 752bb1cd2dd87d1932cb1792ddce1024ef7334ae # Parent 27f039a790f401739476672d1f484626fa572b67 themes: improve status page diff -r 27f039a790f4 -r 752bb1cd2dd8 scid/page-index.c --- a/scid/page-index.c Sun Aug 07 08:42:04 2022 +0200 +++ b/scid/page-index.c Sun Aug 07 08:43:32 2022 +0200 @@ -119,7 +119,6 @@ pageutil_render(req, KHTTP_200, KMIME_TEXT_HTML, data); free(data); json_decref(root); - json_decref(projects); } else pageutil_status(req, KHTTP_500); } diff -r 27f039a790f4 -r 752bb1cd2dd8 scid/pageutil.c --- a/scid/pageutil.c Sun Aug 07 08:42:04 2022 +0200 +++ b/scid/pageutil.c Sun Aug 07 08:43:32 2022 +0200 @@ -41,6 +41,20 @@ khttp_free(req); } +static const int statustab[] = { + [KHTTP_200] = 200, + [KHTTP_400] = 400, + [KHTTP_404] = 404, + [KHTTP_500] = 500 +}; + +static const char * const statusmsg[] = { + [KHTTP_200] = "OK", + [KHTTP_400] = "Bad Request", + [KHTTP_404] = "Not Found", + [KHTTP_500] = "Internal Server Error" +}; + void pageutil_status(struct kreq *req, enum khttp status) { @@ -48,7 +62,11 @@ char *body; - body = theme_page_status(status); + /* + * KHTTP_ are numbered like a standard enum, the Javascript code must + * get the appropriate HTTP code instead. + */ + body = theme_page_status(statustab[status], statusmsg[status]); pageutil_render(req, status, KMIME_TEXT_HTML, body); free(body); } diff -r 27f039a790f4 -r 752bb1cd2dd8 scid/theme.c --- a/scid/theme.c Sun Aug 07 08:42:04 2022 +0200 +++ b/scid/theme.c Sun Aug 07 08:43:32 2022 +0200 @@ -360,12 +360,12 @@ } char * -theme_page_status(enum khttp status) +theme_page_status(int status, const char *message) { json_t *doc; char *ret; - doc = util_json_pack("{si}", "status", status); + doc = util_json_pack("{si ss}", "status", status, "message", message); ret = call(doc, "onPageStatus"); json_decref(doc); diff -r 27f039a790f4 -r 752bb1cd2dd8 scid/theme.h --- a/scid/theme.h Sun Aug 07 08:42:04 2022 +0200 +++ b/scid/theme.h Sun Aug 07 08:43:32 2022 +0200 @@ -109,12 +109,13 @@ * } * ``` * - * \param status the status code + * \param status the status code (e.g. 404) + * \param message the status message (e.g. Not found) * \return a newly allocated rendered string * \note You must free the return value */ char * -theme_page_status(enum khttp status); +theme_page_status(int status, const char *msg); /** * Cleanup theme resources. diff -r 27f039a790f4 -r 752bb1cd2dd8 themes/bulma/index.mustache --- a/themes/bulma/index.mustache Sun Aug 07 08:42:04 2022 +0200 +++ b/themes/bulma/index.mustache Sun Aug 07 08:43:32 2022 +0200 @@ -1,45 +1,45 @@ -
- {{#projects}} -
-
-
-
-
-

{{name}}

-

{{desc}}

-
-
+
+ {{#projects}} +
+
+
+
+
+

{{name}}

+

{{desc}}

+
+
-
- {{#jobs}} - - - - - - - - - {{#jobs}} - - - - - - {{/jobs}} -
jobtagstatus
{{id}}{{tag}}{{status}}
- {{/jobs}} +
+ {{#jobs}} + + + + + + + + + {{#jobs}} + + + + + + {{/jobs}} +
jobtagstatus
{{id}}{{tag}}{{status}}
+ {{/jobs}} -
- {{#jobs}} -

{{n-success}} successful jobs, {{n-failed}} failed jobs

- {{/jobs}} - {{^jobs}} -

no jobs yet.

- {{/jobs}} +
+ {{#jobs}} +

{{n-success}} successful jobs, {{n-failed}} failed jobs

+ {{/jobs}} + {{^jobs}} +

no jobs yet.

+ {{/jobs}} +
+
+
+
+ {{/projects}}
-
-
-
- {{/projects}} -
diff -r 27f039a790f4 -r 752bb1cd2dd8 themes/bulma/status.mustache --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/bulma/status.mustache Sun Aug 07 08:43:32 2022 +0200 @@ -0,0 +1,1 @@ +

{{status}} - {{message}}

diff -r 27f039a790f4 -r 752bb1cd2dd8 themes/bulma/theme.js --- a/themes/bulma/theme.js Sun Aug 07 08:42:04 2022 +0200 +++ b/themes/bulma/theme.js Sun Aug 07 08:43:32 2022 +0200 @@ -16,12 +16,18 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -function onPageIndex(rdr, data) +function render(rdr, page, title, data) { Scid.render(rdr, "header.mustache", { - title: "sci -- index page" + title: title }); + Scid.render(rdr, page, data); + Scid.render(rdr, "footer.mustache"); +} + +function onPageIndex(rdr, data) +{ /* * Add is-danger/is-success for every job depending on their success * status, this is required to show the appropriate tag. @@ -35,6 +41,11 @@ } } - Scid.render(rdr, "index.mustache", data); - Scid.render(rdr, "footer.mustache"); + render(rdr, "index.mustache", "sci -- index page", data); } + +function onPageStatus(rdr, data) +{ + Scid.print(JSON.stringify(data)); + render(rdr, "status.mustache", "sci -- " + data.status, data); +}