|
|
|
@ -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); |
|
|
|
@ -366,13 +369,14 @@ pub(crate) async fn update_form( |
|
|
|
|
let mut form = serde_json::to_value(create_data)?; |
|
|
|
|
|
|
|
|
|
let object = EnrichedObject { |
|
|
|
|
id: object.id , |
|
|
|
|
id: object.id, |
|
|
|
|
model: object.model, |
|
|
|
|
name: object.name.clone(), |
|
|
|
|
values: value_map, |
|
|
|
|
relations: relation_map |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let _ = form.dot_remove("model_id"); |
|
|
|
|
form.dot_set("object", object); |
|
|
|
|
context.insert("form_data", &form); |
|
|
|
|
|
|
|
|
|