From 780ad36696099bccff7354778ca393b6c795a748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Thu, 11 Feb 2021 21:57:23 +0100 Subject: [PATCH] add old flash to realtion create --- .../templates/property_create.html.tera | 2 -- .../templates/relation_create.html.tera | 12 +++++------- yopa-web/src/routes/relation_model.rs | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/yopa-web/resources/templates/property_create.html.tera b/yopa-web/resources/templates/property_create.html.tera index 69ac221..06e9d3e 100644 --- a/yopa-web/resources/templates/property_create.html.tera +++ b/yopa-web/resources/templates/property_create.html.tera @@ -13,8 +13,6 @@ Define property {# The parent can be either object or relation model #}

Add new property to {{object.describe}}

-{# TODO implement value restoration on error #} -
diff --git a/yopa-web/resources/templates/relation_create.html.tera b/yopa-web/resources/templates/relation_create.html.tera index 181b951..f39c64b 100644 --- a/yopa-web/resources/templates/relation_create.html.tera +++ b/yopa-web/resources/templates/relation_create.html.tera @@ -12,28 +12,26 @@ Define relation

Define new relation from "{{object.name}}"

-{# TODO implement value restoration on error #} - -
+
-
+
- +
-
+

diff --git a/yopa-web/src/routes/relation_model.rs b/yopa-web/src/routes/relation_model.rs index 8c20f64..2217a3d 100644 --- a/yopa-web/src/routes/relation_model.rs +++ b/yopa-web/src/routes/relation_model.rs @@ -30,6 +30,19 @@ pub(crate) async fn create_form( debug!("ID = {}", object_id); + if let Ok(Some(form)) = session.take::("old") { + context.insert("old", &form); + } else { + context.insert("old", &RelationModelCreateForm { + object: Default::default(), + name: "".to_string(), + reciprocal_name: "".to_string(), + optional: false, + multiple: false, + related: Default::default() + }); + } + let object = rg.get_object_model(object_id.parse_or_bad_request()?) .ok_or_else(|| actix_web::error::ErrorNotFound("No such source object"))?; @@ -40,10 +53,12 @@ pub(crate) async fn create_form( context.insert("models", &models); context.insert("object", &object); + + TERA.build_response("relation_create", &context) } -#[derive(Deserialize)] +#[derive(Serialize,Deserialize)] pub(crate) struct RelationModelCreateForm { pub object: ID, pub name: String, @@ -80,6 +95,7 @@ pub(crate) async fn create( Err(e) => { warn!("Error creating relation model: {}", e); session.flash_error(e.to_string()); + session.set("old", &form); redirect(format!("/model/relation/create/{}", form.object)) } }