Commit 127e8c2f authored by berumuron's avatar berumuron
Browse files

add: #16 Display the projects

parent 35a737b1
......@@ -143,6 +143,42 @@ class Project:
self.responsible = responsible
self.description = description
@classmethod
def items(cls):
database = db.get_db()
cursor = database.execute("SELECT * FROM projects")
project = cursor.fetchone()
while project:
yield cls(
project["id"],
project["name"],
project["is_private"],
project["responsible"],
project["description"],
)
project = cursor.fetchone()
@classmethod
def items_where(cls, is_private):
database = db.get_db()
cursor = database.execute(
"SELECT * FROM projects WHERE is_private = ?", (is_private,)
)
project = cursor.fetchone()
while project:
yield cls(
project["id"],
project["name"],
project["is_private"],
project["responsible"],
project["description"],
)
project = cursor.fetchone()
@classmethod
def find_by_id(cls, project_id):
database = db.get_db()
......
from flask import Blueprint, request, redirect, url_for, flash, render_template
from flask import Blueprint, request, redirect, url_for, flash, render_template, g
from .auth import login_required
from .models import Project
......@@ -9,7 +9,12 @@ bp = Blueprint("projects", __name__, url_prefix="/projects")
@bp.route("/")
def index():
return render_template("projects/index.html")
if g.current_user is None:
projects = Project.items_where(is_private=False)
else:
projects = Project.items()
return render_template("projects/index.html", projects=projects)
@bp.route("/create", methods=("GET", "POST"))
......
......@@ -377,6 +377,41 @@ button.button-ghost {
content: "🗑";
}
/* Projects structure */
.project {
margin-bottom: 3rem;
padding: 1rem;
}
.project .project-header {
display: flex;
align-items: baseline;
justify-content: space-between;
}
.project .project-header .project-name {
margin-bottom: 0;
}
.project.project-private .project-name::before {
content: "🔒";
}
.project .project-header .project-responsible {
padding-left: 1rem;
padding-right: 1rem;
color: var(--main-color-muted);
}
.project .project-header .project-responsible::before {
content: "👤";
}
.project .project-description {
margin-top: 1rem;
}
/* Folder system */
.folder.folder-folded .folder-container {
display: none;
......
......@@ -17,5 +17,41 @@
</div>
{% include "alerts.html" %}
{% for project in projects|sort(attribute="name") %}
<section class="project {{ 'project-private' if project.is_private }} {{ 'folder folder-folded' if project.description }}">
{% if project.description %}
<header class="project-header">
<h2 class="project-name">
<button class="folder-toggle">
{{ project.name }}
</button>
</h2>
{% if project.responsible %}
<span class="project-responsible">
{{ project.responsible }}
</span>
{% endif %}
</header>
<div class="project-description folder-container">
{{ project.description|markdown }}
</div>
{% else %}
<header class="project-header">
<h2 class="project-name">
{{ project.name }}
</h2>
{% if project.responsible %}
<span class="project-responsible">
{{ project.responsible }}
</span>
{% endif %}
</header>
{% endif %}
</section>
{% endfor %}
</div>
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment