Add support for projects
This commit is contained in:
parent
b7d53c381c
commit
9913c394f3
2
db.py
2
db.py
|
|
@ -241,7 +241,7 @@ class Object:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def all_by_project(db: sqlite3.Connection) -> list[Project]:
|
def all_by_project(db: sqlite3.Connection) -> list[Project]:
|
||||||
objects = Object.all(db)
|
objects = [x.full(db) for x in Object.all(db)]
|
||||||
objects_by_projects = itertools.groupby(objects, lambda x: x.project)
|
objects_by_projects = itertools.groupby(objects, lambda x: x.project)
|
||||||
# print(dict(objects_by_projects))
|
# print(dict(objects_by_projects))
|
||||||
return list(map(lambda x: Project(x[0], list(x[1])), objects_by_projects))
|
return list(map(lambda x: Project(x[0], list(x[1])), objects_by_projects))
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block extracss %}
|
||||||
|
<style>
|
||||||
|
.project {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
@ -7,19 +15,44 @@
|
||||||
{% if projects %}
|
{% if projects %}
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<p>Voici les projets existants dans la base de données :
|
<p>Voici les projets existants dans la base de données :
|
||||||
<ul>
|
<div class="fixed-grid has-6-cols">
|
||||||
|
<div class="grid">
|
||||||
{% for project in projects %}
|
{% for project in projects %}
|
||||||
<li>
|
<a href="#" id="project-{{ loop.index0 }}" class="cell p-2 has-text-centered" style="border: solid; border-width: 1px; border-radius: 5px;">
|
||||||
<h2 class="title mb-0 mt-3">{{ project.name }} <em>({{ project.objects | length }} objets)</em></h2>
|
<div>
|
||||||
|
<strong>{{ project.name }}</strong>
|
||||||
<ul>
|
</div>
|
||||||
|
<div>
|
||||||
|
<em>({{ project.objects | length }} objets)</em>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% for project in projects %}
|
||||||
|
<div class="project project-{{ loop.index0 }}">
|
||||||
|
<h2>{{ project.name }} <em>({{ project.objects | length }} objets)</em></h2>
|
||||||
|
<div class="fixed-grid has-6-cols mb-5">
|
||||||
|
<div class="grid">
|
||||||
{% for object in project.objects %}
|
{% for object in project.objects %}
|
||||||
<li><a href="/object/{{ object.id }}">{{ object.name }}</a></li>
|
<a href="/object/{{ object.id }}" class="cell p-2 has-text-centered" style="border: solid; border-width: 1px; border-radius: 5px;">
|
||||||
|
<div>
|
||||||
|
<strong>{{ object.name }}</strong>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{% if object.acquisitions %}
|
||||||
|
<img src="/data/objects/{{ object.id }}/{{ object.acquisitions[0].id }}/{{ leds[0] }}.jpg">
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<em>Pas d'acquisitions</em>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</div>
|
||||||
</li>
|
</div>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>Il n'y a aucun projet pour le moment...</p>
|
<p>Il n'y a aucun projet pour le moment...</p>
|
||||||
|
|
@ -72,5 +105,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let projects = document.getElementsByClassName('project');
|
||||||
|
for (let i = 0; i < {{ projects | length }}; i++) {
|
||||||
|
document.getElementById('project-' + i).addEventListener('click', () => {
|
||||||
|
for (let p of projects) {
|
||||||
|
if (p.classList.contains('project-' + i)) {
|
||||||
|
p.style.display = "block";
|
||||||
|
} else {
|
||||||
|
p.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
{% endblock extrajs %}
|
{% endblock extrajs %}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue