Commit df739040 authored by berumuron's avatar berumuron
Browse files

add: #15 Provide projects deletion

parent 22c7854f
......@@ -258,3 +258,12 @@ class Project:
database.commit()
return cls.find_by_id(cursor.lastrowid)
def delete(self):
try:
database = db.get_db()
database.execute("DELETE FROM projects WHERE id = ?", (self.id,))
database.commit()
return True
except sqlite3.DatabaseError:
return False
......@@ -35,3 +35,17 @@ def create():
return redirect(url_for("projects.index"))
return render_template("projects/create.html")
@bp.route("/delete/<project_id>", methods=["DELETE"])
@login_required
def delete(project_id):
project = Project.find_by_id(project_id)
if not project:
flash("Le projet n’existe pas.")
elif not project.delete():
flash("Le projet n’a pas pu être supprimé.")
else:
flash("Le projet a été correctement supprimé.", "success")
return redirect(url_for("projects.index"))
......@@ -400,6 +400,8 @@ button.button-ghost {
}
.project .project-header {
position: relative;
display: flex;
align-items: baseline;
......@@ -424,6 +426,23 @@ button.button-ghost {
content: "👤";
}
.project .project-header .project-delete {
position: absolute;
top: -1.75rem;
left: 0;
opacity: 0;
visibility: hidden;
transition: opacity .2s ease-out;
}
.project .project-header:hover .project-delete {
opacity: 1;
visibility: visible;
}
.project .project-header .project-delete::before {
content: "🗑";
}
.project .project-description {
margin-top: 1rem;
}
......
......@@ -23,36 +23,39 @@
id="{{ project.name|slugify }}"
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">
<header class="project-header">
<h2 class="project-name">
{% if project.description %}
<button class="folder-toggle">
{{ project.name }}
</button>
</h2>
{% if project.responsible %}
<span class="project-responsible">
{{ project.responsible }}
</span>
{% else %}
{{ project.name }}
{% endif %}
</header>
</h2>
{% if g.current_user %}
<button
class="button-ghost project-delete"
data-confirm="Êtes-vous certain·e de vouloir supprimer ce projet ?"
data-action="{{ url_for('projects.delete', project_id=project.id ) }}"
data-method="delete"
>
Supprimer
</button>
{% endif %}
{% if project.responsible %}
<span class="project-responsible">
{{ project.responsible }}
</span>
{% endif %}
</header>
{% if project.description %}
<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 %}
<ul class="events">
......
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