|
{% extends "base.html" %} |
|
|
|
{% block title %}Run Impact Analysis - PoliSage{% endblock %} |
|
|
|
{% block content %} |
|
<div class="container mt-4"> |
|
<h2>Run New Impact Analysis</h2> |
|
|
|
{% with messages = get_flashed_messages(with_categories=true) %} |
|
{% if messages %} |
|
{% for category, message in messages %} |
|
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert"> |
|
{{ message }} |
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> |
|
</div> |
|
{% endfor %} |
|
{% endif %} |
|
{% endwith %} |
|
|
|
<form method="POST" action="{{ url_for("analysis.run_analysis") }}"> |
|
<div class="mb-3"> |
|
<label for="document_type" class="form-label">Document Type <span class="text-danger">*</span></label> |
|
<select class="form-select" id="document_type" name="document_type" required onchange="updateDocumentList()"> |
|
<option value="" disabled {% if not document_type %}selected{% endif %}>Select Type...</option> |
|
<option value="Legislation" {% if document_type == "Legislation" %}selected{% endif %}>Legislation</option> |
|
<option value="Draft" {% if document_type == "Draft" %}selected{% endif %}>Draft</option> |
|
<option value="Amendment" {% if document_type == "Amendment" %}selected{% endif %}>Amendment</option> |
|
</select> |
|
</div> |
|
|
|
<div class="mb-3"> |
|
<label for="document_id" class="form-label">Document <span class="text-danger">*</span></label> |
|
<select class="form-select" id="document_id" name="document_id" required> |
|
<option value="" disabled selected>Select Document Type First...</option> |
|
|
|
</select> |
|
<div class="form-text">Choose the specific document to analyze.</div> |
|
</div> |
|
|
|
<div class="mb-3"> |
|
<label for="analysis_type" class="form-label">Analysis Type <span class="text-danger">*</span></label> |
|
<select class="form-select" id="analysis_type" name="analysis_type" required> |
|
<option value="" disabled {% if not analysis_type %}selected{% endif %}>Select Analysis Type...</option> |
|
<option value="Societal" {% if analysis_type == "Societal" %}selected{% endif %}>Societal Impact</option> |
|
<option value="Economic" {% if analysis_type == "Economic" %}selected{% endif %}>Economic Impact</option> |
|
<option value="Environmental" {% if analysis_type == "Environmental" %}selected{% endif %}>Environmental Impact</option> |
|
<option value="Overall" {% if analysis_type == "Overall" %}selected{% endif %}>Overall Impact</option> |
|
</select> |
|
<div class="form-text">Select the dimension of impact to analyze.</div> |
|
</div> |
|
|
|
<button type="submit" class="btn btn-primary">Run Analysis</button> |
|
<a href="{{ url_for("analysis.list_analyses") }}" class="btn btn-secondary">Cancel</a> |
|
</form> |
|
</div> |
|
{% endblock %} |
|
|
|
{% block scripts_extra %} |
|
<script> |
|
const documents = { |
|
Legislation: [ |
|
{% for leg in legislations %} |
|
{ id: {{ leg.id }}, title: "{{ leg.title | escape | replace("\"", "\\\"") }}" }, |
|
{% endfor %} |
|
], |
|
Draft: [ |
|
{% for draft in drafts %} |
|
{ id: {{ draft.id }}, title: "{{ draft.title | escape | replace("\"", "\\\"") }}" }, |
|
{% endfor %} |
|
], |
|
Amendment: [ |
|
{% for amendment in amendments %} |
|
{ id: {{ amendment.id }}, title: "Amendment #{{ amendment.id }} for {{ (amendment.legislation.title if amendment.legislation else \"Unknown\") | escape | replace("\"", "\\\"") }}" }, |
|
{% endfor %} |
|
] |
|
}; |
|
|
|
const documentTypeSelect = document.getElementById("document_type"); |
|
const documentIdSelect = document.getElementById("document_id"); |
|
const selectedDocumentId = "{{ document_id or \"\" }}"; // Get pre-selected ID if form re-rendered |
|
|
|
function updateDocumentList() { |
|
const selectedType = documentTypeSelect.value; |
|
documentIdSelect.innerHTML = "<option value=\"\" disabled selected>Select Document...</option>"; // Clear and add placeholder |
|
|
|
if (selectedType && documents[selectedType]) { |
|
documents[selectedType].forEach(doc => { |
|
const option = document.createElement("option"); |
|
option.value = doc.id; |
|
option.textContent = `${doc.title} (ID: ${doc.id})`; |
|
// Re-select if it was previously selected |
|
if (selectedDocumentId && doc.id == parseInt(selectedDocumentId)) { |
|
option.selected = true; |
|
} |
|
documentIdSelect.appendChild(option); |
|
}); |
|
} else { |
|
documentIdSelect.innerHTML = "<option value=\"\" disabled selected>Select Document Type First...</option>"; |
|
} |
|
} |
|
|
|
// Initial population if a type is already selected (e.g., on form validation error) |
|
if (documentTypeSelect.value) { |
|
updateDocumentList(); |
|
} |
|
</script> |
|
{% endblock %} |
|
|
|
|