- 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.
205 lines
6.0 KiB
HTML
205 lines
6.0 KiB
HTML
{% extends "base.html" %} {% block title %}Production · CalMiner{% endblock %}
|
|
{% block content %}
|
|
<section class="panel">
|
|
<h2>Production Output</h2>
|
|
{% if scenarios %}
|
|
<div class="form-grid">
|
|
<label for="production-scenario-filter">
|
|
Scenario filter
|
|
<select id="production-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 production output data.</p>
|
|
{% endif %}
|
|
<div id="production-empty" class="empty-state">
|
|
Choose a scenario to review its production output.
|
|
</div>
|
|
<div id="production-table-wrapper" class="table-container hidden">
|
|
<table aria-label="Scenario production records">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">Amount</th>
|
|
<th scope="col">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="production-table-body"></tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="panel">
|
|
<h2>Add Production Output</h2>
|
|
{% if scenarios %}
|
|
<form id="production-form" class="form-grid">
|
|
<label for="production-form-scenario">
|
|
Scenario
|
|
<select id="production-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="production-form-amount">
|
|
Amount
|
|
<input
|
|
id="production-form-amount"
|
|
type="number"
|
|
name="amount"
|
|
min="0"
|
|
step="0.01"
|
|
required
|
|
/>
|
|
</label>
|
|
<label for="production-form-description">
|
|
Description (optional)
|
|
<textarea
|
|
id="production-form-description"
|
|
name="description"
|
|
rows="3"
|
|
></textarea>
|
|
</label>
|
|
<button type="submit" class="btn primary">Add Record</button>
|
|
</form>
|
|
<p id="production-feedback" class="feedback hidden" role="status"></p>
|
|
{% else %}
|
|
<p class="empty-state">Create a scenario before adding production output.</p>
|
|
{% endif %}
|
|
</section>
|
|
|
|
<script>
|
|
const scenarios = {{ scenarios | tojson | safe }};
|
|
const productionByScenario = {{ production_by_scenario | tojson | safe }};
|
|
|
|
const filterSelect = document.getElementById("production-scenario-filter");
|
|
const tableWrapper = document.getElementById("production-table-wrapper");
|
|
const tableBody = document.getElementById("production-table-body");
|
|
const emptyState = document.getElementById("production-empty");
|
|
const form = document.getElementById("production-form");
|
|
const feedbackEl = document.getElementById("production-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 formatAmount(value) {
|
|
return Number(value).toLocaleString(undefined, {
|
|
minimumFractionDigits: 2,
|
|
maximumFractionDigits: 2,
|
|
});
|
|
}
|
|
|
|
function renderProductionRows(scenarioId) {
|
|
const key = String(scenarioId);
|
|
const records = productionByScenario[key] || [];
|
|
|
|
tableBody.innerHTML = "";
|
|
|
|
if (!records.length) {
|
|
emptyState.textContent = "No production output 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>${formatAmount(record.amount)}</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 its production output.";
|
|
emptyState.classList.remove("hidden");
|
|
tableWrapper.classList.add("hidden");
|
|
tableBody.innerHTML = "";
|
|
return;
|
|
}
|
|
renderProductionRows(value);
|
|
});
|
|
}
|
|
|
|
async function submitProduction(event) {
|
|
event.preventDefault();
|
|
hideFeedback();
|
|
|
|
const formData = new FormData(form);
|
|
const scenarioId = formData.get("scenario_id");
|
|
const payload = {
|
|
scenario_id: scenarioId ? Number(scenarioId) : null,
|
|
amount: Number(formData.get("amount")),
|
|
description: formData.get("description") || null,
|
|
};
|
|
|
|
try {
|
|
const response = await fetch("/api/production/", {
|
|
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 production output record.");
|
|
}
|
|
|
|
const result = await response.json();
|
|
const mapKey = String(result.scenario_id);
|
|
|
|
if (!Array.isArray(productionByScenario[mapKey])) {
|
|
productionByScenario[mapKey] = [];
|
|
}
|
|
productionByScenario[mapKey].push(result);
|
|
|
|
form.reset();
|
|
showFeedback("Production output saved.", "success");
|
|
|
|
if (filterSelect && filterSelect.value === String(result.scenario_id)) {
|
|
renderProductionRows(filterSelect.value);
|
|
}
|
|
} catch (error) {
|
|
showFeedback(error.message || "An unexpected error occurred.", "error");
|
|
}
|
|
}
|
|
|
|
if (form) {
|
|
form.addEventListener("submit", submitProduction);
|
|
}
|
|
|
|
if (filterSelect && filterSelect.value) {
|
|
renderProductionRows(filterSelect.value);
|
|
}
|
|
</script>
|
|
{% endblock %}
|