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,118 +1,174 @@
|
||||
<div
|
||||
class="modal fade"
|
||||
tabindex="-1"
|
||||
<dialog
|
||||
id="manage_api_token_modal"
|
||||
role="dialog"
|
||||
aria-labelledby="manage_api_token_modal"
|
||||
aria-hidden="true"
|
||||
class="modal"
|
||||
x-data="{
|
||||
isSubmitting: false,
|
||||
newToken: '',
|
||||
tokens: [],
|
||||
|
||||
reset() {
|
||||
this.isSubmitting = false;
|
||||
this.newToken = '';
|
||||
},
|
||||
|
||||
async requestToken() {
|
||||
this.isSubmitting = true;
|
||||
const form = document.getElementById('request_api_token_form');
|
||||
const formData = new FormData(form);
|
||||
|
||||
try {
|
||||
const response = await fetch('{{ meta.user.url }}', {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams(formData)
|
||||
});
|
||||
const data = await response.json();
|
||||
this.newToken = data.raw_token;
|
||||
} catch (error) {
|
||||
console.error('Error requesting token:', error);
|
||||
} finally {
|
||||
this.isSubmitting = false;
|
||||
}
|
||||
},
|
||||
|
||||
async deleteToken(form) {
|
||||
const formData = new FormData(form);
|
||||
try {
|
||||
await fetch(form.action, {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams(formData)
|
||||
});
|
||||
form.closest('.token-item').remove();
|
||||
} catch (error) {
|
||||
console.error('Error deleting token:', error);
|
||||
}
|
||||
}
|
||||
}"
|
||||
@close="reset()"
|
||||
>
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
<span aria-hidden="true">×</span>
|
||||
<span class="sr-only">Close</span>
|
||||
</button>
|
||||
<h3 class="modal-title">Manage API Token</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
Requesting a Token will invalidate all potential existing tokens. The
|
||||
new token will only be shown once, so ensure to store it in secure
|
||||
place
|
||||
</p>
|
||||
<form
|
||||
id="request_api_token_form"
|
||||
accept-charset="UTF-8"
|
||||
action=""
|
||||
data-remote="true"
|
||||
method="post"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<p>
|
||||
<label for="token-name">Name</label>
|
||||
<input
|
||||
type="text"
|
||||
id="token-name"
|
||||
class="form-control"
|
||||
name="name"
|
||||
placeholder="Generic Token for {{ meta.user.username }}"
|
||||
/>
|
||||
<label for="valid-for">Valid for (in days)</label>
|
||||
<input
|
||||
type="number"
|
||||
id="valid-for"
|
||||
class="form-control"
|
||||
name="valid-for"
|
||||
value="90"
|
||||
/>
|
||||
<input type="hidden" name="hidden" value="request-api-token" />
|
||||
</p>
|
||||
</form>
|
||||
<div id="new-token">
|
||||
<pre id="new-token-pre"></pre>
|
||||
<div class="modal-box">
|
||||
<!-- Header -->
|
||||
<h3 class="text-lg font-bold">Manage API Token</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">
|
||||
<p class="mb-4">
|
||||
Requesting a Token will invalidate all potential existing tokens. The
|
||||
new token will only be shown once, so ensure to store it in a secure
|
||||
place.
|
||||
</p>
|
||||
|
||||
<form id="request_api_token_form" accept-charset="UTF-8" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="form-control mb-3">
|
||||
<label class="label" for="token-name">
|
||||
<span class="label-text">Name</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="token-name"
|
||||
class="input input-bordered w-full"
|
||||
name="name"
|
||||
placeholder="Generic Token for {{ meta.user.username }}"
|
||||
/>
|
||||
</div>
|
||||
<div id="existing-tokens">
|
||||
{% for t in tokens %}
|
||||
<div class="form-control mb-3">
|
||||
<label class="label" for="valid-for">
|
||||
<span class="label-text">Valid for (in days)</span>
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
id="valid-for"
|
||||
class="input input-bordered w-full"
|
||||
name="valid-for"
|
||||
value="90"
|
||||
/>
|
||||
</div>
|
||||
<input type="hidden" name="hidden" value="request-api-token" />
|
||||
</form>
|
||||
|
||||
<!-- New Token Display -->
|
||||
<div x-show="newToken" x-cloak class="alert alert-success mb-4">
|
||||
<div class="w-full">
|
||||
<span class="font-bold">New Token:</span>
|
||||
<pre
|
||||
class="mt-2 p-2 bg-base-200 rounded overflow-x-auto"
|
||||
x-text="newToken"
|
||||
></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Existing Tokens -->
|
||||
<div class="space-y-2">
|
||||
{% for t in tokens %}
|
||||
<div class="token-item">
|
||||
<form
|
||||
id="delete-token-{{ forloop.counter0 }}"
|
||||
accept-charset="UTF-8"
|
||||
action="{{ meta.user.url }}"
|
||||
data-remote="true"
|
||||
method="post"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<div class="input-group">
|
||||
<div class="join w-full">
|
||||
<input type="hidden" name="hidden" value="delete" />
|
||||
<input type="hidden" name="token-id" value="{{ t.pk }}" />
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
class="input input-bordered join-item w-full"
|
||||
value="{{ t.name|safe }}"
|
||||
disabled
|
||||
/>
|
||||
<span class="input-group-btn">
|
||||
<button type="submit" class="btn btn-danger">Delete</button>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-error join-item"
|
||||
@click="deleteToken($el.closest('form'))"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a id="manage_api_token_form_submit" class="btn btn-primary" href="#"
|
||||
>Submit</a
|
||||
>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="modal-action">
|
||||
<button
|
||||
type="button"
|
||||
class="btn"
|
||||
onclick="this.closest('dialog').close()"
|
||||
:disabled="isSubmitting"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
@click="requestToken()"
|
||||
:disabled="isSubmitting"
|
||||
>
|
||||
<span x-show="!isSubmitting">Request Token</span>
|
||||
<span
|
||||
x-show="isSubmitting"
|
||||
class="loading loading-spinner loading-sm"
|
||||
></span>
|
||||
<span x-show="isSubmitting">Requesting...</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(function () {
|
||||
$("#new-token").hide();
|
||||
|
||||
$("#manage_api_token_form_submit").on("click", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const formData = $("#request_api_token_form").serialize();
|
||||
$.post("", formData, function (response) {
|
||||
$("#new-token-pre").text(response.raw_token);
|
||||
$("#new-token").show();
|
||||
});
|
||||
});
|
||||
|
||||
// Select all elements that start with 'delete-token-'
|
||||
$("[id^='delete-token-']").on("submit", function (e) {
|
||||
e.preventDefault();
|
||||
const formData = $(this).serialize();
|
||||
const form = $(this);
|
||||
$.post(this.action, formData, function (response) {
|
||||
console.log(this);
|
||||
form.remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<!-- Backdrop -->
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button :disabled="isSubmitting">close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
Reference in New Issue
Block a user