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. 32
      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 crate::tera_ext::TeraExt;
use yopa::insert::{InsertObj, InsertValue, InsertRel};
mod utils;
mod tera_ext;
@ -189,26 +190,16 @@ fn init_yopa() -> YopaStoreWrapper {
name: "Ingredient".to_string(),
}).unwrap();
store.define_property(model::PropertyModel {
let val_descr = store.define_property(model::PropertyModel {
id: Default::default(),
object: id_recipe,
name: "name".to_string(),
optional: false,
name: "description".to_string(),
optional: true,
multiple: true,
data_type: DataType::String,
default: TypedValue::String("".into()),
}).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 {
id: Default::default(),
object: id_book,
@ -229,7 +220,7 @@ fn init_yopa() -> YopaStoreWrapper {
related: id_book,
}).unwrap();
store.define_property(model::PropertyModel {
let page = store.define_property(model::PropertyModel {
id: Default::default(),
object: rel_book_id,
name: "page".to_string(),
@ -249,5 +240,42 @@ fn init_yopa() -> YopaStoreWrapper {
related: id_recipe,
}).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))
}

@ -280,7 +280,7 @@ struct EnrichedRelation<'a> {
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
#[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
let rel_ids = create_data.schema.rel_models.iter()
.filter(|p| p.object == model.id).map(|p| p.id).collect_vec();
let relation_model_ids = create_data.schema.rel_models.iter()
.filter(|p| p.object == model.id)
.map(|p| p.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);
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 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 {
let mut relation_values_map = HashMap::new();
// 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);
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());
});
let enriched = EnrichedRelation {
instances.push(EnrichedRelation {
id: rel.id,
object: rel.object,
model: rel.model,
related: rel.related,
values: relation_values_map
};
instances.push(enriched);
});
}
relation_map.insert(rel_model_id.to_string(), instances);
@ -373,6 +376,7 @@ pub(crate) async fn update_form(
relations: relation_map
};
let _ = form.dot_remove("model_id");
form.dot_set("object", object);
context.insert("form_data", &form);

Loading…
Cancel
Save