parent
b5a4900209
commit
97af2fd924
@ -0,0 +1,2 @@ |
|||||||
|
assets: |
||||||
|
cd resources && npm run build
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,29 @@ |
|||||||
|
{% extends "_layout" %} |
||||||
|
|
||||||
|
{% block title -%} |
||||||
|
Objects |
||||||
|
{%- endblock %} |
||||||
|
|
||||||
|
{% block nav -%} |
||||||
|
<a href="/models">Edit models</a> |
||||||
|
<a href="/takeout">JSON</a> |
||||||
|
{%- endblock %} |
||||||
|
|
||||||
|
{% block content -%} |
||||||
|
|
||||||
|
<h1>Objects</h1> |
||||||
|
|
||||||
|
{% for table in models %} |
||||||
|
|
||||||
|
<h2>{{ table.model.name }}</h2> |
||||||
|
<a href="/object/create/{{table.model.id}}">Add {{ table.model.name }}</a> |
||||||
|
|
||||||
|
<ul> |
||||||
|
{% for object in table.objects %} |
||||||
|
<li><a href="/object/detail/{{object.id}}">{{object.name}}</a> |
||||||
|
{% endfor %} |
||||||
|
</ul> |
||||||
|
|
||||||
|
{% endfor %} |
||||||
|
|
||||||
|
{%- endblock %} |
@ -0,0 +1,73 @@ |
|||||||
|
use actix_session::Session; |
||||||
|
use actix_web::Responder; |
||||||
|
use crate::routes::models::relation::RelationModelDisplay; |
||||||
|
use crate::routes::models::object::ObjectModelDisplay; |
||||||
|
use crate::session_ext::SessionExt; |
||||||
|
use crate::TERA; |
||||||
|
use crate::tera_ext::TeraExt; |
||||||
|
|
||||||
|
pub(crate) mod object; |
||||||
|
pub(crate) mod relation; |
||||||
|
pub(crate) mod property; |
||||||
|
|
||||||
|
#[get("/models")] |
||||||
|
pub(crate) async fn list(session: Session, store: crate::YopaStoreWrapper) -> actix_web::Result<impl Responder> { |
||||||
|
let rg = store.read().await; |
||||||
|
|
||||||
|
let models_iter = rg.get_object_models(); |
||||||
|
|
||||||
|
// object and relation props
|
||||||
|
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 relations = model_relations.remove(&om.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 { |
||||||
|
model: rm, |
||||||
|
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); |
||||||
|
|
||||||
|
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, |
||||||
|
relations, |
||||||
|
reciprocal_relations, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
models.sort_by_key(|m| m.name); |
||||||
|
|
||||||
|
let mut ctx = tera::Context::new(); |
||||||
|
ctx.insert("models", &models); |
||||||
|
session.render_flash(&mut ctx); |
||||||
|
|
||||||
|
TERA.build_response("models/index", &ctx) |
||||||
|
} |
Loading…
Reference in new issue