diff scid/page-index.c @ 30:43333d18e4b8

scid: document theme
author David Demelier <markand@malikania.fr>
date Thu, 04 Aug 2022 14:54:43 +0200
parents 695637f1d8a7
children 8c2087e7d381
line wrap: on
line diff
--- a/scid/page-index.c	Thu Aug 04 14:13:58 2022 +0200
+++ b/scid/page-index.c	Thu Aug 04 14:54:43 2022 +0200
@@ -27,35 +27,8 @@
 #include "theme.h"
 #include "util.h"
 
-#if 0
-
-/*
- * Document we create for templatize.
- *
- * {
- *   "projects: [
- *     {
- *       "name": "project name",
- *       "desc": "project short description",
- *       "url": "project URL or homepage",
- *       "jobs": [
- *         {
- *           "job": job-id,
- *           "tag": "job tag / revision",
- *           "status": "failed / success"        // failed if at least one has failed
- *         }
- *       ]
- *       "n-failed": number of failed jobs
- *       "n-succes": number of successful jobs
- *     }
- *   ]
- * }
- */
-
-#endif
-
 static void
-fill_jobresults(json_t *project, json_t *job, json_t *jobresults)
+set_job_status(json_t *project, json_t *job, json_t *jobresults)
 {
 	json_t *iter, *status;
 	int exitcode, sigcode;
@@ -81,13 +54,17 @@
 }
 
 static void
-fill_jobs(json_t *project, json_t *jobs)
+set_project_jobs(json_t *project, json_t *jobs)
 {
 	json_t *iter, *jobresults;
 	json_int_t job_id;
 	size_t i;
 
 	json_array_foreach(jobs, i, iter) {
+		/* Don't populate too much. */
+		if (i + 1 >= 10)
+			break;
+
 		/*
 		 * For this job, find all jobresult to check how many have
 		 * failed or not.
@@ -100,15 +77,18 @@
 		if (!(jobresults = db_jobresult_list_by_job_group(job_id)))
 			continue;
 
-		fill_jobresults(project, iter, jobresults);
+		set_job_status(project, iter, jobresults);
 		json_decref(jobresults);
 	}
 
 	json_object_set_new(project, "jobs", jobs);
 }
 
+/*
+ * For every projects, find their jobs and add them as 'jobs' property.
+ */
 static void
-fill_projects(json_t *projects)
+update_projects(json_t *projects)
 {
 	json_t *jobs, *iter;
 	const char *name;
@@ -123,7 +103,7 @@
 		if (!(jobs = db_job_list(name)))
 			continue;
 
-		fill_jobs(iter, jobs);
+		set_project_jobs(iter, jobs);
 	}
 }
 
@@ -135,12 +115,12 @@
 
 	/* First, fetch all projects. */
 	if ((projects = db_project_list())) {
-		fill_projects(projects);
-
+		update_projects(projects);
 		root = json_pack("{so}", "projects", projects);
-		printf("===\n%s\n===\n", json_dumps(root, JSON_INDENT(4)));
-		data = theme_page_index(scid.theme, root);
+		data = theme_page_index(root);
 		pageutil_render(req, KHTTP_200, KMIME_TEXT_HTML, data);
+		free(data);
+		json_decref(root);
 		json_decref(projects);
 	} else
 		pageutil_status(req, KHTTP_500);