crates/server: REST API routes; RBAC auth middleware; cookie sessions; dashboard
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I5298a925bd9c11780e49d8b1c98eebd86a6a6964
This commit is contained in:
parent
44d1ee1d6b
commit
235d3d38a6
38 changed files with 6275 additions and 7 deletions
133
crates/server/templates/project.html
Normal file
133
crates/server/templates/project.html
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}{{ project.name }} - FC CI{% endblock %}
|
||||
{% block auth %}
|
||||
{% if !auth_name.is_empty() %}
|
||||
<span class="auth-user">{{ auth_name }}</span>
|
||||
<form method="POST" action="/logout"><button type="submit">Logout</button></form>
|
||||
{% else %}
|
||||
<a href="/login">Login</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block breadcrumbs %}
|
||||
<nav class="breadcrumbs">
|
||||
<a href="/">Home</a> <span class="sep">/</span>
|
||||
<span class="current">{{ project.name }}</span>
|
||||
</nav>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<h1>{{ project.name }}</h1>
|
||||
{% match project.description %}
|
||||
{% when Some with (desc) %}
|
||||
<p>{{ desc }}</p>
|
||||
{% when None %}
|
||||
{% endmatch %}
|
||||
<p><strong>Repository:</strong> {{ project.repository_url }}</p>
|
||||
<p><strong>Created:</strong> {{ project.created_at.format("%Y-%m-%d %H:%M") }}</p>
|
||||
|
||||
{% if is_admin %}
|
||||
<div style="margin-top: 0.5rem;">
|
||||
<button class="btn btn-danger btn-small" onclick="deleteProject()">Delete Project</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<h2>Jobsets</h2>
|
||||
|
||||
{% if is_admin %}
|
||||
<details>
|
||||
<summary>Add Jobset</summary>
|
||||
<div class="form-card">
|
||||
<form id="create-jobset-form">
|
||||
<div class="form-group">
|
||||
<label for="js-name">Name</label>
|
||||
<input type="text" id="js-name" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="js-expr">Nix Expression</label>
|
||||
<input type="text" id="js-expr" value="." required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label><input type="checkbox" id="js-flake" checked> Flake mode</label>
|
||||
</div>
|
||||
<button type="submit" class="btn">Add Jobset</button>
|
||||
</form>
|
||||
<div id="jobset-msg"></div>
|
||||
</div>
|
||||
</details>
|
||||
{% endif %}
|
||||
|
||||
{% if jobsets.is_empty() %}
|
||||
<p class="empty">No jobsets configured.</p>
|
||||
{% else %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>Name</th><th>Expression</th><th>Flake</th><th>Enabled</th><th>Interval</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for j in jobsets %}
|
||||
<tr>
|
||||
<td><a href="/jobset/{{ j.id }}">{{ j.name }}</a></td>
|
||||
<td><code>{{ j.nix_expression }}</code></td>
|
||||
<td>{% if j.flake_mode %}Yes{% else %}No{% endif %}</td>
|
||||
<td>{% if j.enabled %}Yes{% else %}No{% endif %}</td>
|
||||
<td>{{ j.check_interval }}s</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
<h2>Recent Evaluations</h2>
|
||||
{% if recent_evals.is_empty() %}
|
||||
<p class="empty">No evaluations yet.</p>
|
||||
{% else %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>Commit</th><th>Status</th><th>Time</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for e in recent_evals %}
|
||||
<tr>
|
||||
<td><a href="/evaluation/{{ e.id }}">{{ e.commit_short }}</a></td>
|
||||
<td><span class="badge badge-{{ e.status_class }}">{{ e.status_text }}</span></td>
|
||||
<td>{{ e.time }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
{% if is_admin %}
|
||||
<script>
|
||||
document.getElementById('create-jobset-form')?.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const msg = document.getElementById('jobset-msg');
|
||||
try {
|
||||
const res = await fetch('/api/v1/projects/{{ project.id }}/jobsets', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
name: document.getElementById('js-name').value,
|
||||
nix_expression: document.getElementById('js-expr').value,
|
||||
flake_mode: document.getElementById('js-flake').checked,
|
||||
}),
|
||||
});
|
||||
if (res.ok) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
const err = await res.json();
|
||||
msg.innerHTML = '<div class="flash-message flash-error">' + (err.error || 'Error') + '</div>';
|
||||
}
|
||||
} catch(e) {
|
||||
msg.innerHTML = '<div class="flash-message flash-error">Request failed</div>';
|
||||
}
|
||||
});
|
||||
async function deleteProject() {
|
||||
if (!confirm('Delete this project and all its data?')) return;
|
||||
const res = await fetch('/api/v1/projects/{{ project.id }}', { method: 'DELETE' });
|
||||
if (res.ok) window.location.href = '/projects';
|
||||
else alert('Failed to delete project');
|
||||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue