|
|
@ -17,6 +17,7 @@ struct ObjectModelDisplay<'a> { |
|
|
|
name : &'a str, |
|
|
|
name : &'a str, |
|
|
|
properties: Vec<&'a PropertyModel>, |
|
|
|
properties: Vec<&'a PropertyModel>, |
|
|
|
relations: Vec<RelationModelDisplay<'a>>, |
|
|
|
relations: Vec<RelationModelDisplay<'a>>, |
|
|
|
|
|
|
|
reciprocal_relations: Vec<RelationModelDisplay<'a>>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Debug)] |
|
|
|
#[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_props = rg.get_grouped_prop_models(); |
|
|
|
|
|
|
|
|
|
|
|
let mut model_relations = rg.get_grouped_relation_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![]; |
|
|
|
let mut models = vec![]; |
|
|
|
for om in models_iter { |
|
|
|
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 mut relations = model_relations.remove(&om.id).unwrap_or_default(); |
|
|
|
|
|
|
|
let mut relations = relations.into_iter().map(|rm| { |
|
|
|
let rel_displays = relations.into_iter().map(|rm| { |
|
|
|
let mut rprops = model_props.get(&rm.id).cloned().unwrap_or_default(); |
|
|
|
let mut rprops = model_props.remove(&rm.id).unwrap_or_default(); |
|
|
|
|
|
|
|
rprops.sort_by_key(|m| &m.name); |
|
|
|
rprops.sort_by_key(|m| &m.name); |
|
|
|
|
|
|
|
|
|
|
|
RelationModelDisplay { |
|
|
|
RelationModelDisplay { |
|
|
@ -88,16 +88,32 @@ pub(crate) async fn index(session : Session, store : crate::YopaStoreWrapper) -> |
|
|
|
related_name: rg.get_model_name(rm.related), |
|
|
|
related_name: rg.get_model_name(rm.related), |
|
|
|
properties: rprops |
|
|
|
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<_>>(); |
|
|
|
}).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 { |
|
|
|
models.push(ObjectModelDisplay { |
|
|
|
id: om.id, |
|
|
|
id: om.id, |
|
|
|
name: &om.name, |
|
|
|
name: &om.name, |
|
|
|
properties: oprops, |
|
|
|
properties, |
|
|
|
relations: rel_displays, |
|
|
|
relations, |
|
|
|
|
|
|
|
reciprocal_relations |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|