fix some bugs

master
Ondřej Hruška 4 years ago
parent 7ab333515d
commit 6561da7e99
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 9188
      yopa-web/resources/static/bundle.js
  2. 2
      yopa-web/resources/static/bundle.js.map
  3. 56
      yopa-web/src/main.rs
  4. 34
      yopa-web/src/routes/objects.rs

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -26,6 +26,7 @@ use tera::Tera;
use yopa::{Storage, TypedValue}; use yopa::{Storage, TypedValue};
use crate::tera_ext::TeraExt; use crate::tera_ext::TeraExt;
use yopa::insert::{InsertObj, InsertValue, InsertRel};
mod utils; mod utils;
mod tera_ext; mod tera_ext;
@ -189,26 +190,16 @@ fn init_yopa() -> YopaStoreWrapper {
name: "Ingredient".to_string(), name: "Ingredient".to_string(),
}).unwrap(); }).unwrap();
store.define_property(model::PropertyModel { let val_descr = store.define_property(model::PropertyModel {
id: Default::default(), id: Default::default(),
object: id_recipe, object: id_recipe,
name: "name".to_string(), name: "description".to_string(),
optional: false, optional: true,
multiple: true, multiple: true,
data_type: DataType::String, data_type: DataType::String,
default: TypedValue::String("".into()), default: TypedValue::String("".into()),
}).unwrap(); }).unwrap();
store.define_property(model::PropertyModel {
id: Default::default(),
object: id_book,
name: "title".to_string(),
optional: false,
multiple: false,
data_type: DataType::String,
default: TypedValue::String("".into()),
}).unwrap();
store.define_property(model::PropertyModel { store.define_property(model::PropertyModel {
id: Default::default(), id: Default::default(),
object: id_book, object: id_book,
@ -229,7 +220,7 @@ fn init_yopa() -> YopaStoreWrapper {
related: id_book, related: id_book,
}).unwrap(); }).unwrap();
store.define_property(model::PropertyModel { let page = store.define_property(model::PropertyModel {
id: Default::default(), id: Default::default(),
object: rel_book_id, object: rel_book_id,
name: "page".to_string(), name: "page".to_string(),
@ -249,5 +240,42 @@ fn init_yopa() -> YopaStoreWrapper {
related: id_recipe, related: id_recipe,
}).unwrap(); }).unwrap();
let book1 = store.insert_object(InsertObj {
model_id: id_book,
name: "Book 1".to_string(),
values: vec![],
relations: vec![]
}).unwrap();
store.insert_object(InsertObj {
model_id: id_book,
name: "Book 2".to_string(),
values: vec![],
relations: vec![]
}).unwrap();
store.insert_object(InsertObj {
model_id: id_recipe,
name: "Recipe1".to_string(),
values: vec![
InsertValue {
model_id: val_descr,
value: TypedValue::String("Bla bla bla".into())
}
],
relations: vec![
InsertRel {
model_id: rel_book_id,
related_id: book1,
values: vec![
InsertValue {
model_id: page,
value: TypedValue::Integer(15)
}
]
}
]
}).unwrap();
web::Data::new(tokio::sync::RwLock::new(store)) web::Data::new(tokio::sync::RwLock::new(store))
} }

@ -280,7 +280,7 @@ struct EnrichedRelation<'a> {
values: HashMap<String /* ID */, Vec<&'a data::Value>>, values: HashMap<String /* ID */, Vec<&'a data::Value>>,
} }
// FIXME relation values are now showing in the edit form! // FIXME relation values are not showing in the edit form!
// TODO save handling // TODO save handling
#[get("/object/update/{id}")] #[get("/object/update/{id}")]
@ -322,41 +322,44 @@ pub(crate) async fn update_form(
{ {
// Some properties may have no values, so we first check what IDs to expect // Some properties may have no values, so we first check what IDs to expect
let rel_ids = create_data.schema.rel_models.iter() let relation_model_ids = create_data.schema.rel_models.iter()
.filter(|p| p.object == model.id).map(|p| p.id).collect_vec(); .filter(|p| p.object == model.id)
.map(|p| p.id).collect_vec();
let relations = rg.get_relations_for_object(*id).collect_vec(); let relations = rg.get_relations_for_object(*id).collect_vec();
let grouped_relations = relations.iter() let relation_ids = relations.iter().map(|r| r.id).collect_vec();
let mut relations_grouped_by_model = relations.iter()
.into_group_map_by(|relation| relation.model); .into_group_map_by(|relation| relation.model);
let mut relation_properties = rg.get_grouped_prop_models_for_parents(rel_ids.clone()); let mut property_models_grouped_by_parent = rg.get_grouped_prop_models_for_parents(relation_model_ids.clone());
let mut relation_values_grouped_by_instance = rg.get_grouped_values_for_objects(relation_ids);
let mut relation_values = rg.get_grouped_values_for_objects(rel_ids.clone()); for rel_model_id in relation_model_ids {
let relations = relations_grouped_by_model.remove(&rel_model_id).unwrap_or_default();
for (rel_model_id, relations) in grouped_relations {
let mut instances = vec![]; let mut instances = vec![];
let props_for_rel = relation_properties.remove(&rel_model_id).unwrap_or_default(); let prop_models_for_relation = property_models_grouped_by_parent.remove(&rel_model_id).unwrap_or_default();
for rel in relations { for rel in relations {
let mut relation_values_map = HashMap::new(); let mut relation_values_map = HashMap::new();
// values keyed by model // values keyed by model
let mut rel_values = relation_values.remove(&rel.id).unwrap_or_default().into_iter() let mut rel_values = relation_values_grouped_by_instance.remove(&rel.id).unwrap_or_default().into_iter()
.into_group_map_by(|relation| relation.model); .into_group_map_by(|relation| relation.model);
props_for_rel.iter().for_each(|prop_model| { prop_models_for_relation.iter().for_each(|prop_model| {
relation_values_map.insert(prop_model.id.to_string(), rel_values.remove(&prop_model.id).unwrap_or_default()); relation_values_map.insert(prop_model.id.to_string(), rel_values.remove(&prop_model.id).unwrap_or_default());
}); });
let enriched = EnrichedRelation { instances.push(EnrichedRelation {
id: rel.id, id: rel.id,
object: rel.object, object: rel.object,
model: rel.model, model: rel.model,
related: rel.related, related: rel.related,
values: relation_values_map values: relation_values_map
}; });
instances.push(enriched);
} }
relation_map.insert(rel_model_id.to_string(), instances); relation_map.insert(rel_model_id.to_string(), instances);
@ -366,13 +369,14 @@ pub(crate) async fn update_form(
let mut form = serde_json::to_value(create_data)?; let mut form = serde_json::to_value(create_data)?;
let object = EnrichedObject { let object = EnrichedObject {
id: object.id , id: object.id,
model: object.model, model: object.model,
name: object.name.clone(), name: object.name.clone(),
values: value_map, values: value_map,
relations: relation_map relations: relation_map
}; };
let _ = form.dot_remove("model_id");
form.dot_set("object", object); form.dot_set("object", object);
context.insert("form_data", &form); context.insert("form_data", &form);

Loading…
Cancel
Save