Add IDs to entries on edit page, set fragment when modifying entry
This commit is contained in:
parent
425569fc5e
commit
6c08946354
55
src/lib.rs
55
src/lib.rs
|
@ -173,12 +173,21 @@ impl State {
|
||||||
self.scoped("")
|
self.scoped("")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edit_collection_path(&self, id: Uuid, token: &ValidToken) -> String {
|
fn edit_collection_path(
|
||||||
self.scoped(&format!("{id}?token={}", token.token))
|
&self,
|
||||||
|
collection_id: Uuid,
|
||||||
|
entry_id: Option<Uuid>,
|
||||||
|
token: &ValidToken,
|
||||||
|
) -> String {
|
||||||
|
if let Some(entry_id) = entry_id {
|
||||||
|
self.scoped(&format!("{collection_id}?token={}#{entry_id}", token.token))
|
||||||
|
} else {
|
||||||
|
self.scoped(&format!("{collection_id}?token={}", token.token))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_collection_path(&self, id: Uuid, token: &ValidToken) -> String {
|
fn update_collection_path(&self, collection_id: Uuid, token: &ValidToken) -> String {
|
||||||
self.scoped(&format!("{id}?token={}", token.token))
|
self.scoped(&format!("{collection_id}?token={}", token.token))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_collection_path(&self, id: Uuid, token: &ValidToken, confirmed: bool) -> String {
|
fn delete_collection_path(&self, id: Uuid, token: &ValidToken, confirmed: bool) -> String {
|
||||||
|
@ -314,9 +323,17 @@ pub fn configure(cfg: &mut web::ServiceConfig, state: State, client: Client) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_edit_page(id: Uuid, token: &ValidToken, state: &State) -> HttpResponse {
|
fn to_edit_page(
|
||||||
|
collection_id: Uuid,
|
||||||
|
entry_id: Option<Uuid>,
|
||||||
|
token: &ValidToken,
|
||||||
|
state: &State,
|
||||||
|
) -> HttpResponse {
|
||||||
HttpResponse::SeeOther()
|
HttpResponse::SeeOther()
|
||||||
.insert_header((LOCATION, state.edit_collection_path(id, token)))
|
.insert_header((
|
||||||
|
LOCATION,
|
||||||
|
state.edit_collection_path(collection_id, entry_id, token),
|
||||||
|
))
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,7 +713,12 @@ async fn upload(
|
||||||
.await
|
.await
|
||||||
.stateful(&state)?;
|
.stateful(&state)?;
|
||||||
|
|
||||||
Ok(to_edit_page(path.collection, &token, &state))
|
Ok(to_edit_page(
|
||||||
|
path.collection,
|
||||||
|
Some(entry_path.entry),
|
||||||
|
&token,
|
||||||
|
&state,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize)]
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
@ -845,6 +867,7 @@ async fn create_collection(
|
||||||
|
|
||||||
Ok(to_edit_page(
|
Ok(to_edit_page(
|
||||||
collection_path.collection,
|
collection_path.collection,
|
||||||
|
None,
|
||||||
&ValidToken { token: token.token },
|
&ValidToken { token: token.token },
|
||||||
&state,
|
&state,
|
||||||
))
|
))
|
||||||
|
@ -865,7 +888,7 @@ async fn update_collection(
|
||||||
.await
|
.await
|
||||||
.stateful(&state)?;
|
.stateful(&state)?;
|
||||||
|
|
||||||
Ok(to_edit_page(path.collection, &token, &state))
|
Ok(to_edit_page(path.collection, None, &token, &state))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn move_entry(
|
async fn move_entry(
|
||||||
|
@ -880,7 +903,12 @@ async fn move_entry(
|
||||||
.await
|
.await
|
||||||
.stateful(&state)?;
|
.stateful(&state)?;
|
||||||
|
|
||||||
Ok(to_edit_page(path.collection, &token, &state))
|
Ok(to_edit_page(
|
||||||
|
path.collection,
|
||||||
|
Some(path.entry),
|
||||||
|
&token,
|
||||||
|
&state,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(name = "Update Entry")]
|
#[tracing::instrument(name = "Update Entry")]
|
||||||
|
@ -898,7 +926,12 @@ async fn update_entry(
|
||||||
.await
|
.await
|
||||||
.stateful(&state)?;
|
.stateful(&state)?;
|
||||||
|
|
||||||
Ok(to_edit_page(entry_path.collection, &token, &state))
|
Ok(to_edit_page(
|
||||||
|
entry_path.collection,
|
||||||
|
Some(entry_path.entry),
|
||||||
|
&token,
|
||||||
|
&state,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize)]
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
@ -953,7 +986,7 @@ async fn delete_entry(
|
||||||
.await
|
.await
|
||||||
.stateful(&state)?;
|
.stateful(&state)?;
|
||||||
|
|
||||||
Ok(to_edit_page(entry_path.collection, &token, &state))
|
Ok(to_edit_page(entry_path.collection, None, &token, &state))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn qr(req: &HttpRequest, path: &web::Path<CollectionPath>, state: &web::Data<State>) -> String {
|
fn qr(req: &HttpRequest, path: &web::Path<CollectionPath>, state: &web::Data<State>) -> String {
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<div class="content-group">
|
<div class="content-group">
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
@:button_link_html("Delete Collection", &state.delete_collection_path(id, token, true), ButtonKind::Submit)
|
@:button_link_html("Delete Collection", &state.delete_collection_path(id, token, true), ButtonKind::Submit)
|
||||||
@:button_link_html("Cancel", &state.edit_collection_path(id, token), ButtonKind::Outline)
|
@:button_link_html("Cancel", &state.edit_collection_path(id, None, token), ButtonKind::Outline)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<p class="delete-confirmation">Are you sure you want to delete this image?</p>
|
<p class="delete-confirmation">Are you sure you want to delete this image?</p>
|
||||||
<div class="button-group button-space">
|
<div class="button-group button-space">
|
||||||
@:button_link_html("Delete Image", &state.delete_entry_path(collection_id, id, token, true), ButtonKind::Submit)
|
@:button_link_html("Delete Image", &state.delete_entry_path(collection_id, id, token, true), ButtonKind::Submit)
|
||||||
@:button_link_html("Cancel", &state.edit_collection_path(collection_id, token), ButtonKind::Outline)
|
@:button_link_html("Cancel", &state.edit_collection_path(collection_id, Some(id), token), ButtonKind::Outline)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
@use crate::{ui::ButtonKind, Collection, Direction, Entry, State, ValidToken};
|
@use crate::{ui::ButtonKind, Collection, Direction, Entry, State, ValidToken};
|
||||||
@use super::{button_html, button_link_html, image_html, file_input_html, layout_html, return_home_html, text_area_html, text_input_html,
|
@use super::{button_html, button_link_html, image_html, file_input_html, layout_html, return_home_html, text_area_html,
|
||||||
statics::file_upload_js};
|
text_input_html, statics::file_upload_js};
|
||||||
@use uuid::Uuid;
|
@use uuid::Uuid;
|
||||||
|
|
||||||
@(collection: &Collection, collection_id: Uuid, entries: &[(Uuid, Entry)], token: &ValidToken, state: &State, qr: &str)
|
@(collection: &Collection, collection_id: Uuid, entries: &[(Uuid, Entry)], token: &ValidToken, state: &State, qr: &str)
|
||||||
|
@ -29,7 +29,7 @@ statics::file_upload_js};
|
||||||
<h3>Edit Collection</h3>
|
<h3>Edit Collection</h3>
|
||||||
</article>
|
</article>
|
||||||
<article class="content-group">
|
<article class="content-group">
|
||||||
<p class="subtitle"><a href="@state.edit_collection_path(collection_id, token)">Do not lose this link</a></p>
|
<p class="subtitle"><a href="@state.edit_collection_path(collection_id, None, token)">Do not lose this link</a></p>
|
||||||
</article>
|
</article>
|
||||||
<article class="content-group">
|
<article class="content-group">
|
||||||
<form method="POST" action="@state.update_collection_path(collection_id, token)">
|
<form method="POST" action="@state.update_collection_path(collection_id, token)">
|
||||||
|
@ -44,7 +44,7 @@ statics::file_upload_js};
|
||||||
</article>
|
</article>
|
||||||
<ul>
|
<ul>
|
||||||
@for (i, (id, entry)) in entries.iter().enumerate() {
|
@for (i, (id, entry)) in entries.iter().enumerate() {
|
||||||
<li class="content-group">
|
<li class="content-group" id="@id">
|
||||||
<article>
|
<article>
|
||||||
<div class="edit-row">
|
<div class="edit-row">
|
||||||
<div class="edit-item">
|
<div class="edit-item">
|
||||||
|
@ -61,7 +61,8 @@ statics::file_upload_js};
|
||||||
<div class="button-group button-space">
|
<div class="button-group button-space">
|
||||||
@if let Some(upload_id) = entry.upload_id() {
|
@if let Some(upload_id) = entry.upload_id() {
|
||||||
<input type="hidden" name="upload_id" value="@upload_id" />
|
<input type="hidden" name="upload_id" value="@upload_id" />
|
||||||
@:button_link_html("Refresh", &state.edit_collection_path(collection_id, token), ButtonKind::Submit)
|
@:button_link_html("Refresh", &state.edit_collection_path(collection_id, Some(*id), token),
|
||||||
|
ButtonKind::Submit)
|
||||||
}
|
}
|
||||||
@if let Some((filename, delete_token)) = entry.file_parts() {
|
@if let Some((filename, delete_token)) = entry.file_parts() {
|
||||||
<input type="hidden" name="filename" value="@filename" />
|
<input type="hidden" name="filename" value="@filename" />
|
||||||
|
|
Loading…
Reference in a new issue