|
|
@ -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); |
|
|
|
|
|
|
|
|
|
|
|