view themes/bulma/theme.js @ 78:26bbca3765dd

misc: update API timeout
author David Demelier <markand@malikania.fr>
date Tue, 31 Jan 2023 22:01:36 +0100
parents 38bdcfb3d4f7
children 71cd8447e3a4
line wrap: on
line source

/*
 * theme.js -- scid bulma theme
 *
 * Copyright (c) 2021-2022 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

function render(rdr, page, title, data)
{
	Scid.render(rdr, "header.mustache", {
		title: title
	});

	Scid.render(rdr, page, data);
	Scid.render(rdr, "footer.mustache");
}

function isFailed(job)
{
	/* Can be failed if there is a property status to false. */
	if (typeof (job.status) === "boolean")
		return job.status === false;

	/* Otherwise, check for exitcode/sigcode that must be present. */
	return job.exitcode !== 0 || job.sigcode !== 0;
}

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.
	 */
	for (var p = 0; p < data.projects.length; ++p) {
		var jobs = data.projects[p].jobs;

		for (var j = 0; j < jobs.length; ++j) {
			switch (jobs[j].status) {
			case "unknown":
				jobs[j].color = "is-warning";
				jobs[j].textcolor = "has-text-warning";
				jobs[j].status = "pending";
				break;
			case "success":
				jobs[j].color = "is-success";
				jobs[j].textcolor = "has-text-success";
				jobs[j].status = "success";
				break;
			case "failed":
				jobs[j].color = "is-danger";
				jobs[j].textcolor = "has-text-danger";
				jobs[j].status = "failed";
				break;
			default:
				break;
			}
		}

		/* Hide card jobs table if empty. */
		if (jobs.length === 0)
			data.projects[p].hidden = "hidden";
	}

	render(rdr, "index.mustache", "sci -- index page", data);
}

function addResultClasses(jobresults)
{
	/* Add a status on failed/successful tasks. */
	for (var i = 0; i < jobresults.length; ++i) {
		var res = jobresults[i];

		if (res.exitcode === 0 && res.sigcode === 0) {
			res.textcolor = "has-text-success";
			res.status = "success";
		} else {
			res.textcolor = "has-text-danger";
			res.status = "failed";
		}
	}
}

function onPageJobresults(rdr, data)
{
	addResultClasses(data.jobresults);
	render(rdr, "jobresults.mustache", "sci -- job results", data);
}

function onPageStatus(rdr, data)
{
	render(rdr, "status.mustache", "sci -- " + data.status, data);
}

function onPageWorker(rdr, data)
{
	/* Similar to index page, add classes. */
	if (typeof (data.jobresults) === "object")
		addResultClasses(data.jobresults);

	render(rdr, "worker.mustache", "sci -- worker", data);
}

function onPageWorkers(rdr, data)
{
	render(rdr, "workers.mustache", "sci -- workers", data);
}

function onPageProjects(rdr, data)
{
	render(rdr, "projects.mustache", "sci -- projects", data);
}

function onPageProject(rdr, data)
{
	render(rdr, "project.mustache", "sci -- project", data);
}