forked from enviPath/enviPy
[Feature] Modern UI roll out (#236)
This PR moves all the collection pages into the new UI in a rough push. I did not put the same amount of care into these as into search, index, and predict. ## Major changes - All modals are now migrated to a state based alpine.js implementation. - jQuery is no longer present in the base layout; ajax is replace by native fetch api - most of the pps.js is now obsolte (as I understand it; the code is not referenced any more @jebus please double check) - in-memory pagination for large result lists (set to 50; we can make that configurable later; performance degrades at around 1k) stukk a bit rough tracked in #235 ## Minor things - Sarch and index also use alpine now - The loading spinner is now CSS animated (not sure if it currently gets correctly called) ## Not done - Ihave not even cheked the admin pages. Not sure If these need migrations - The temporary migration pages still use the old template. Not sure what is supposed to happen with those? @jebus ## What I did to test - opend all pages in browse, and user ; plus all pages reachable from there. - Interacted and tested the functionality of each modal superfically with exception of the API key modal (no functional test). --- This PR is massive sorry for that; just did not want to push half-brokenn state. @jebus @liambrydon I would be glad if you could click around and try to break it :) Finally closes #133 Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#236 Co-authored-by: Tobias O <tobias.olenyi@envipath.com> Co-committed-by: Tobias O <tobias.olenyi@envipath.com>
This commit is contained in:
@ -1,112 +1,142 @@
|
||||
{% load static %}
|
||||
<div
|
||||
class="modal fade bs-modal-lg"
|
||||
<dialog
|
||||
id="set_scenario_modal"
|
||||
tabindex="-1"
|
||||
aria-labelledby="set_scenario_modal"
|
||||
aria-modal="true"
|
||||
role="dialog"
|
||||
class="modal"
|
||||
x-data="{
|
||||
isSubmitting: false,
|
||||
isLoading: false,
|
||||
loaded: false,
|
||||
scenarios: [],
|
||||
attachedScenarios: [{% for scen in current_object.scenarios.all %}'{{ scen.url }}'{% if not forloop.last %},{% endif %}{% endfor %}],
|
||||
|
||||
reset() {
|
||||
this.isSubmitting = false;
|
||||
},
|
||||
|
||||
async loadScenarios() {
|
||||
if (this.loaded) return;
|
||||
|
||||
this.isLoading = true;
|
||||
try {
|
||||
const response = await fetch('{% url "package scenario list" meta.current_package.uuid %}');
|
||||
const data = await response.json();
|
||||
this.scenarios = data;
|
||||
this.loaded = true;
|
||||
} catch (error) {
|
||||
console.error('Error loading scenarios:', error);
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
|
||||
isSelected(url) {
|
||||
return this.attachedScenarios.includes(url);
|
||||
},
|
||||
|
||||
submit() {
|
||||
this.isSubmitting = true;
|
||||
const select = document.getElementById('scenario-select');
|
||||
if (select.selectedOptions.length === 0) {
|
||||
// Add hidden empty option to indicate clearing all scenarios
|
||||
const emptyOption = document.createElement('option');
|
||||
emptyOption.value = '';
|
||||
emptyOption.selected = true;
|
||||
select.appendChild(emptyOption);
|
||||
}
|
||||
document.getElementById('set_scenario_modal_form').submit();
|
||||
}
|
||||
}"
|
||||
@close="reset()"
|
||||
x-init="$watch('$el.open', value => { if (value) loadScenarios(); })"
|
||||
>
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button
|
||||
type="button"
|
||||
class="close"
|
||||
data-dismiss="modal"
|
||||
aria-label="Close"
|
||||
>
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<h4 class="modal-title">
|
||||
Set Scenarios for {{ current_object.name|safe }}
|
||||
</h4>
|
||||
<div class="modal-box max-w-4xl">
|
||||
<!-- Header -->
|
||||
<h3 class="text-lg font-bold">
|
||||
Set Scenarios for {{ current_object.name|safe }}
|
||||
</h3>
|
||||
|
||||
<!-- Close button (X) -->
|
||||
<form method="dialog">
|
||||
<button
|
||||
class="btn btn-sm btn-circle btn-ghost absolute top-2 right-2"
|
||||
:disabled="isSubmitting"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- Body -->
|
||||
<div class="py-4">
|
||||
<!-- Loading indicator -->
|
||||
<div x-show="isLoading" x-cloak class="mb-4 text-center">
|
||||
<span class="loading loading-spinner loading-lg"></span>
|
||||
<div class="alert alert-info mt-2">Loading Scenarios...</div>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div id="loading_scenario_div" class="text-center"></div>
|
||||
<form
|
||||
id="set_scenario_modal_form"
|
||||
accept-charset="UTF-8"
|
||||
action="{{ current_object.url }}"
|
||||
data-remote="true"
|
||||
method="post"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<label for="scenario-select">Scenarios</label>
|
||||
|
||||
<form
|
||||
id="set_scenario_modal_form"
|
||||
accept-charset="UTF-8"
|
||||
action="{{ current_object.url }}"
|
||||
data-remote="true"
|
||||
method="post"
|
||||
x-show="!isLoading"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<div class="form-control">
|
||||
<label class="label" for="scenario-select">
|
||||
<span class="label-text">Scenarios</span>
|
||||
</label>
|
||||
<select
|
||||
id="scenario-select"
|
||||
name="selected-scenarios"
|
||||
data-actions-box="true"
|
||||
class="form-control"
|
||||
class="select select-bordered h-48 w-full"
|
||||
multiple
|
||||
data-width="100%"
|
||||
>
|
||||
<option disabled>Select Scenarios</option>
|
||||
<option value="" hidden></option>
|
||||
<template x-for="scenario in scenarios" :key="scenario.url">
|
||||
<option
|
||||
:value="scenario.url"
|
||||
:selected="isSelected(scenario.url)"
|
||||
x-text="scenario.name"
|
||||
></option>
|
||||
</template>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-secondary pull-left"
|
||||
data-dismiss="modal"
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
id="set_scenario_modal_form_submit"
|
||||
>
|
||||
Submit
|
||||
</button>
|
||||
</div>
|
||||
<label class="label">
|
||||
<span class="label-text-alt"
|
||||
>Hold Ctrl/Cmd to select multiple scenarios</span
|
||||
>
|
||||
</label>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="modal-action">
|
||||
<button
|
||||
type="button"
|
||||
class="btn"
|
||||
onclick="this.closest('dialog').close()"
|
||||
:disabled="isSubmitting"
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
@click="submit()"
|
||||
:disabled="isSubmitting || isLoading"
|
||||
>
|
||||
<span x-show="!isSubmitting">Submit</span>
|
||||
<span
|
||||
x-show="isSubmitting"
|
||||
class="loading loading-spinner loading-sm"
|
||||
></span>
|
||||
<span x-show="isSubmitting">Submitting...</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{# prettier-ignore-start #}
|
||||
<script>
|
||||
|
||||
$(function () {
|
||||
var loaded = false;
|
||||
|
||||
var attachedScenarios = []
|
||||
{% if current_object.scenarios.all %}
|
||||
{% for scen in current_object.scenarios.all %}
|
||||
attachedScenarios.push('{{ scen.url }}')
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
$('#scenario-select').selectpicker();
|
||||
|
||||
$('#set_scenario_modal').on('shown.bs.modal', function () {
|
||||
|
||||
if (!loaded) {
|
||||
makeLoadingGif("#loading_scenario_div", "{% static '/images/wait.gif' %}");
|
||||
$('#loading_scenario_div').append("<p></p><div class='alert alert-info'>Loading Scenarios...</div>");
|
||||
|
||||
$.getJSON("{% url 'package scenario list' meta.current_package.uuid %}").then(function (data) {
|
||||
for(s in data) {
|
||||
scenario = data[s]
|
||||
var selected = attachedScenarios.includes(scenario.url);
|
||||
$('#scenario-select').append(`<option value="${scenario.url}" ${selected ? 'selected' : ''}>${scenario.name}</option>`);
|
||||
}
|
||||
$('#scenario-select').selectpicker('refresh');
|
||||
$("#loading_scenario_div").empty();
|
||||
});
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
$('#set_scenario_modal_form_submit').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
if ($('#scenario-select').val().length == 0) {
|
||||
$('#scenario-select').val("")
|
||||
}
|
||||
$('#set_scenario_modal_form').submit();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
{# prettier-ignore-end #}
|
||||
<!-- Backdrop -->
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button :disabled="isSubmitting">close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
Reference in New Issue
Block a user