|
|
|
@ -17,6 +17,7 @@ struct ObjectModelDisplay<'a> { |
|
|
|
|
name : &'a str, |
|
|
|
|
properties: Vec<&'a PropertyModel>, |
|
|
|
|
relations: Vec<RelationModelDisplay<'a>>, |
|
|
|
|
reciprocal_relations: Vec<RelationModelDisplay<'a>>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Debug)] |
|
|
|
@ -73,14 +74,13 @@ pub(crate) async fn index(session : Session, store : crate::YopaStoreWrapper) -> |
|
|
|
|
let mut model_props = rg.get_grouped_prop_models(); |
|
|
|
|
|
|
|
|
|
let mut model_relations = rg.get_grouped_relation_models(); |
|
|
|
|
let mut model_rec_relations = rg.get_grouped_reciprocal_relation_models(); |
|
|
|
|
|
|
|
|
|
let mut models = vec![]; |
|
|
|
|
for om in models_iter { |
|
|
|
|
let mut oprops = model_props.remove(&om.id).unwrap_or_default(); |
|
|
|
|
let mut relations = model_relations.remove(&om.id).unwrap_or_default(); |
|
|
|
|
|
|
|
|
|
let rel_displays = relations.into_iter().map(|rm| { |
|
|
|
|
let mut rprops = model_props.remove(&rm.id).unwrap_or_default(); |
|
|
|
|
let mut relations = relations.into_iter().map(|rm| { |
|
|
|
|
let mut rprops = model_props.get(&rm.id).cloned().unwrap_or_default(); |
|
|
|
|
rprops.sort_by_key(|m| &m.name); |
|
|
|
|
|
|
|
|
|
RelationModelDisplay { |
|
|
|
@ -88,16 +88,32 @@ pub(crate) async fn index(session : Session, store : crate::YopaStoreWrapper) -> |
|
|
|
|
related_name: rg.get_model_name(rm.related), |
|
|
|
|
properties: rprops |
|
|
|
|
} |
|
|
|
|
}).collect::<Vec<_>>(); |
|
|
|
|
relations.sort_by_key(|d| &d.model.name); |
|
|
|
|
|
|
|
|
|
// Relations coming INTO this model
|
|
|
|
|
let mut reciprocal_relations = model_rec_relations.remove(&om.id).unwrap_or_default(); |
|
|
|
|
let mut reciprocal_relations = reciprocal_relations.into_iter().map(|rm| { |
|
|
|
|
let mut rprops = model_props.get(&rm.id).cloned().unwrap_or_default(); |
|
|
|
|
rprops.sort_by_key(|m| &m.name); |
|
|
|
|
|
|
|
|
|
RelationModelDisplay { |
|
|
|
|
model: rm, |
|
|
|
|
related_name: rg.get_model_name(rm.object), |
|
|
|
|
properties: rprops |
|
|
|
|
} |
|
|
|
|
}).collect::<Vec<_>>(); |
|
|
|
|
reciprocal_relations.sort_by_key(|d| &d.model.reciprocal_name); |
|
|
|
|
|
|
|
|
|
oprops.sort_by_key(|m| &m.name); |
|
|
|
|
let mut properties = model_props.remove(&om.id).unwrap_or_default(); |
|
|
|
|
properties.sort_by_key(|m| &m.name); |
|
|
|
|
|
|
|
|
|
models.push(ObjectModelDisplay { |
|
|
|
|
id: om.id, |
|
|
|
|
name: &om.name, |
|
|
|
|
properties: oprops, |
|
|
|
|
relations: rel_displays, |
|
|
|
|
properties, |
|
|
|
|
relations, |
|
|
|
|
reciprocal_relations |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|