- Updated equipment.html to include scenario filtering, equipment addition form, and dynamic equipment listing. - Enhanced maintenance.html with scenario filtering, maintenance entry form, and dynamic equipment selection. - Improved production.html to allow scenario filtering and production output entry. - Revamped reporting.html to display scenario KPI summaries with refresh functionality. - Expanded simulations.html to support scenario selection, simulation run history, and detailed results display. - Refactored base_header.html for improved navigation structure and active link highlighting.
191 lines
5.6 KiB
HTML
191 lines
5.6 KiB
HTML
{% extends "base.html" %} {% block title %}Equipment · CalMiner{% endblock %} {%
|
|
block content %}
|
|
<section class="panel">
|
|
<h2>Equipment Inventory</h2>
|
|
{% if scenarios %}
|
|
<div class="form-grid">
|
|
<label for="equipment-scenario-filter">
|
|
Scenario filter
|
|
<select id="equipment-scenario-filter">
|
|
<option value="">Select a scenario</option>
|
|
{% for scenario in scenarios %}
|
|
<option value="{{ scenario.id }}">{{ scenario.name }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</label>
|
|
</div>
|
|
{% else %}
|
|
<p class="empty-state">Create a scenario to view equipment inventory.</p>
|
|
{% endif %}
|
|
<div id="equipment-empty" class="empty-state">
|
|
Choose a scenario to review the equipment list.
|
|
</div>
|
|
<div id="equipment-table-wrapper" class="table-container hidden">
|
|
<table aria-label="Scenario equipment inventory">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">Name</th>
|
|
<th scope="col">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="equipment-table-body"></tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="panel">
|
|
<h2>Add Equipment</h2>
|
|
{% if scenarios %}
|
|
<form id="equipment-form" class="form-grid">
|
|
<label for="equipment-form-scenario">
|
|
Scenario
|
|
<select id="equipment-form-scenario" name="scenario_id" required>
|
|
<option value="" disabled selected>Select a scenario</option>
|
|
{% for scenario in scenarios %}
|
|
<option value="{{ scenario.id }}">{{ scenario.name }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</label>
|
|
<label for="equipment-form-name">
|
|
Equipment name
|
|
<input id="equipment-form-name" type="text" name="name" required />
|
|
</label>
|
|
<label for="equipment-form-description">
|
|
Description (optional)
|
|
<textarea
|
|
id="equipment-form-description"
|
|
name="description"
|
|
rows="3"
|
|
></textarea>
|
|
</label>
|
|
<button type="submit" class="btn primary">Add Equipment</button>
|
|
</form>
|
|
<p id="equipment-feedback" class="feedback hidden" role="status"></p>
|
|
{% else %}
|
|
<p class="empty-state">Create a scenario before managing equipment.</p>
|
|
{% endif %}
|
|
</section>
|
|
|
|
<script>
|
|
const scenarios = {{ scenarios | tojson | safe }};
|
|
const equipmentByScenario = {{ equipment_by_scenario | tojson | safe }};
|
|
|
|
const filterSelect = document.getElementById("equipment-scenario-filter");
|
|
const tableWrapper = document.getElementById("equipment-table-wrapper");
|
|
const tableBody = document.getElementById("equipment-table-body");
|
|
const emptyState = document.getElementById("equipment-empty");
|
|
const form = document.getElementById("equipment-form");
|
|
const feedbackEl = document.getElementById("equipment-feedback");
|
|
|
|
function showFeedback(message, type = "success") {
|
|
if (!feedbackEl) {
|
|
return;
|
|
}
|
|
feedbackEl.textContent = message;
|
|
feedbackEl.classList.remove("hidden", "success", "error");
|
|
feedbackEl.classList.add(type);
|
|
}
|
|
|
|
function hideFeedback() {
|
|
if (!feedbackEl) {
|
|
return;
|
|
}
|
|
feedbackEl.classList.add("hidden");
|
|
feedbackEl.textContent = "";
|
|
}
|
|
|
|
function renderEquipmentRows(scenarioId) {
|
|
const key = String(scenarioId);
|
|
const records = equipmentByScenario[key] || [];
|
|
|
|
tableBody.innerHTML = "";
|
|
|
|
if (!records.length) {
|
|
emptyState.textContent = "No equipment recorded for this scenario yet.";
|
|
emptyState.classList.remove("hidden");
|
|
tableWrapper.classList.add("hidden");
|
|
return;
|
|
}
|
|
|
|
emptyState.classList.add("hidden");
|
|
tableWrapper.classList.remove("hidden");
|
|
|
|
records.forEach((record) => {
|
|
const row = document.createElement("tr");
|
|
row.innerHTML = `
|
|
<td>${record.name || "—"}</td>
|
|
<td>${record.description || "—"}</td>
|
|
`;
|
|
tableBody.appendChild(row);
|
|
});
|
|
}
|
|
|
|
if (filterSelect) {
|
|
filterSelect.addEventListener("change", (event) => {
|
|
const value = event.target.value;
|
|
if (!value) {
|
|
emptyState.textContent = "Choose a scenario to review the equipment list.";
|
|
emptyState.classList.remove("hidden");
|
|
tableWrapper.classList.add("hidden");
|
|
tableBody.innerHTML = "";
|
|
return;
|
|
}
|
|
renderEquipmentRows(value);
|
|
});
|
|
}
|
|
|
|
async function submitEquipment(event) {
|
|
event.preventDefault();
|
|
hideFeedback();
|
|
|
|
const formData = new FormData(form);
|
|
const scenarioId = formData.get("scenario_id");
|
|
const payload = {
|
|
scenario_id: scenarioId ? Number(scenarioId) : null,
|
|
name: formData.get("name"),
|
|
description: formData.get("description") || null,
|
|
};
|
|
|
|
try {
|
|
const response = await fetch("/api/equipment/", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(payload),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorDetail = await response.json().catch(() => ({}));
|
|
throw new Error(errorDetail.detail || "Unable to add equipment record.");
|
|
}
|
|
|
|
const result = await response.json();
|
|
const mapKey = String(result.scenario_id);
|
|
|
|
if (!Array.isArray(equipmentByScenario[mapKey])) {
|
|
equipmentByScenario[mapKey] = [];
|
|
}
|
|
equipmentByScenario[mapKey].push(result);
|
|
|
|
form.reset();
|
|
showFeedback("Equipment saved.", "success");
|
|
|
|
if (filterSelect && filterSelect.value === String(result.scenario_id)) {
|
|
renderEquipmentRows(filterSelect.value);
|
|
}
|
|
} catch (error) {
|
|
showFeedback(error.message || "An unexpected error occurred.", "error");
|
|
}
|
|
}
|
|
|
|
if (form) {
|
|
form.addEventListener("submit", submitEquipment);
|
|
}
|
|
|
|
if (filterSelect && filterSelect.value) {
|
|
renderEquipmentRows(filterSelect.value);
|
|
}
|
|
</script>
|
|
{% endblock %}
|