changeset 82:44713c475974

scid: fix index page
author David Demelier <markand@malikania.fr>
date Tue, 28 Feb 2023 16:21:37 +0100
parents 377ea81b4ecf
children 28fd8b5247f0
files scid/page-index.c themes/bulma/index.mustache
diffstat 2 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/scid/page-index.c	Tue Feb 28 16:21:23 2023 +0100
+++ b/scid/page-index.c	Tue Feb 28 16:21:37 2023 +0100
@@ -31,16 +31,16 @@
 	const char *status;
 	json_t *iter;
 	int exitcode, sigcode;
-	size_t i;
+	size_t i, rs = 0, rf = 0;
 
 	/* Compute number of failures and number of success. */
 	json_array_foreach(jobresults, i, iter) {
 		json_unpack(iter, "{si si}", "exitcode", &exitcode, "sigcode", &sigcode);
 
 		if (exitcode == 0 && sigcode == 0)
-			(*ns)++;
+			rs++;
 		else
-			(*nf)++;
+			rf++;
 	}
 
 	/*
@@ -50,26 +50,34 @@
 	 * - success: all results were successful,
 	 * - failed: at least one has failed.
 	 */
-	if (*nf == 0 && *ns == 0)
+	if (rs == 0 && rf == 0)
 		status = "unknown";
-	else if (*nf > 0)
+	else if (rf > 0)
 		status = "failed";
 	else
 		status = "success";
 
+	/* Append to the total. */
+	*ns += rs;
+	*nf += rf;
+
 	json_object_set_new(job, "status", json_string(status));
 }
 
 static void
 set_project_jobs(json_t *project, json_t *jobs)
 {
-	json_t *iter, *jobresults;
+	json_t *iter, *jobresults, *list;
 	json_int_t job_id;
 	size_t i, ns = 0, nf = 0;
 
+	/*
+	 * This is the actual list of jobs that we will put into the list card
+	 * because the jobs argument may be greater than the limit.
+	 */
+	list = json_array();
+
 	json_array_foreach(jobs, i, iter) {
-		ns = nf = 0;
-
 		/* Don't populate too much. */
 		if (i + 1 >= 10)
 			break;
@@ -88,11 +96,13 @@
 
 		set_job_status(project, iter, jobresults, &ns, &nf);
 		json_decref(jobresults);
+		json_array_append(list, iter);
 	}
 
-	json_object_set_new(project, "jobs", jobs);
+	json_object_set_new(project, "jobs", list);
 	json_object_set_new(project, "n-failed", json_integer(nf));
 	json_object_set_new(project, "n-success", json_integer(ns));
+	json_decref(jobs);
 }
 
 /*
--- a/themes/bulma/index.mustache	Tue Feb 28 16:21:23 2023 +0100
+++ b/themes/bulma/index.mustache	Tue Feb 28 16:21:37 2023 +0100
@@ -1,6 +1,6 @@
 				<div class="columns is-multiline">
 					{{#projects}}
-					<div class="column is-4">
+					<div class="column">
 						<div class="card">
 							<div class="card-content">
 								<div class="media">