Added UI to create, build and delete documents

This commit is contained in:
Youen 2022-08-13 19:54:20 +02:00
parent 3a3edd3651
commit df476d9865
13 changed files with 140 additions and 36 deletions

View File

@ -12,10 +12,13 @@ def create_app():
from api import api_document from api import api_document
app.register_blueprint(api_document.bp) app.register_blueprint(api_document.bp)
from web import web_admin
app.register_blueprint(web_admin.bp)
from web import web_document from web import web_document
app.register_blueprint(web_document.bp) app.register_blueprint(web_document.bp)
from web.admin import admin
app.register_blueprint(admin.bp)
from web.admin import admin_document
app.register_blueprint(admin_document.bp)
return app return app

View File

@ -52,6 +52,13 @@ class Document:
def pull(self): def pull(self):
return run("cd \"" + self.doc_path + "/repo\" && git pull") return run("cd \"" + self.doc_path + "/repo\" && git pull")
def delete(self):
shutil.rmtree(self.doc_path)
def delete_folder(self):
doc_path = Document.make_doc_path(self.doc_name, self.branch)
shutil.rmtree(doc_path)
def get_url(self): def get_url(self):
return "/doc/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/index.html" return "/doc/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/index.html"

8
src/static/app.js Normal file
View File

@ -0,0 +1,8 @@
var confirm_elements = document.querySelectorAll('a[data-confirm]');
for (let elt of confirm_elements)
{
elt.addEventListener('click', (e) => {
if(!confirm(elt.getAttribute('data-confirm')))
e.preventDefault();
}, false);
}

0
src/static/style.css Normal file
View File

View File

@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% block title %}Exécution...{% endblock %}
{% block content %}
<pre>{{ output }}</pre>
<a href="{{ next }}" class="button">OK</a>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html' %}
{% block title %}{{ doc.doc_name }} / {{ doc.branch }} (admin){% endblock %}
{% block content %}
<h1>Gestion de {{ doc.doc_name }} / {{ doc.branch }}</h1>
<a href="{{doc.get_url()}}" class="button">Consulter</a><br/>
<a href="{{ url_for('api_document.build', doc = doc.doc_name, branch = doc.branch) }}" class="button">Compiler</a><br/>
<br/>
<a href="{{ url_for('admin_document.delete', doc_name = doc.doc_name, branch = doc.branch) }}" class="button danger" data-confirm="Êtes-vous sûr de vouloir supprimer le document {{ doc.doc_name }} / {{ doc.branch }} ?">Supprimer</a>
{% endblock %}

View File

@ -0,0 +1,14 @@
{% extends 'base.html' %}
{% block title %}Nouveau document{% endblock %}
{% block content %}
<form method="POST">
<label for="repo">Dépôt git :</label> <input type="text" id="repo" name="repo"><br/>
<label for="branch">Branche :</label> <input type="text" id="branch" name="branch" value="master"><br/>
<label for="doc">Nom :</label> <input type="text" id="doc" name="doc"> (laisser vide pour utiliser le nom du dépôt)<br/>
<label for="source">Dossier source :</label> <input type="text" id="source" name="source" value="source"> (chemin dans le dépôt du dossier contenant les sources du document)<br/>
<input type="submit" value="Créer le document"/>
</form>
{% endblock %}

View File

@ -0,0 +1,22 @@
{% extends 'base.html' %}
{% block title %}Documentation (admin){% endblock %}
{% block content %}
<h1>Administration des documents</h1>
<a href="{{ url_for('admin_document.new') }}">Nouveau document...</a>
<h2>Liste des documents</h2>
{% if documents|length > 0 %}
<ul>
{% for doc in documents %}
{% if doc.valid %}
<li>{{ doc.doc_name }} / {{ doc.branch }} <a href="{{ doc.get_url() }}">Consulter</a> <a href="{{ url_for('admin_document.manage', doc_name = doc.doc_name, branch = doc.branch) }}" class="button">Gérer</a></li>
{% else %}
<li>{{ doc.doc_name }} / {{ doc.branch }} (document invalide) <a href="{{ url_for('admin_document.delete_invalid', doc_name = doc.doc_name, branch = doc.branch) }}" class="confirm danger">Supprimer le dossier</a></li>
{% endif %}
{% endfor %}
</ul>
{% else %}
<p>Aucun document</p>
{% endif %}
{% endblock %}

14
src/templates/base.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
{% block content %}{% endblock %}
<script type="text/javascript" src="{{ url_for('static', filename='app.js') }}"></script>
</body>

View File

@ -1,24 +0,0 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Documentation (admin)</title>
</head>
<body>
<h1>Administration des documents</h1>
<a href="">Nouveau document...</a>
<h2>Liste des documents</h2>
<ul>
{% for doc in documents %}
{% if doc.valid %}
<li>{{ doc.doc_name }} / {{ doc.branch }} <a href="{{ doc.get_url() }}">Consulter</a></li>
{% else %}
<li>{{ doc.doc_name }} / {{ doc.branch }} (document invalide)</li>
{% endif %}
{% endfor %}
</ul>
<script type="text/javascript" src="/static/index.js"></script>
</body>

9
src/web/admin/admin.py Normal file
View File

@ -0,0 +1,9 @@
from flask import Blueprint, render_template
from data.document import Document
bp = Blueprint('admin', __name__, url_prefix='/admin')
@bp.route('/')
def index():
return render_template("admin/index.html", documents=Document.list())

View File

@ -0,0 +1,41 @@
import os
from flask import Blueprint, render_template, redirect, url_for, request
from web_utils.get_arg import get_arg
from data.document import Document
bp = Blueprint('admin_document', __name__, url_prefix='/admin/doc')
@bp.route('/new', methods=['GET', 'POST'])
def new():
if request.method == 'POST':
repo = request.form.get('repo')
doc_name = request.form.get('doc')
branch = request.form.get('branch')
source_dir = request.form.get('source')
if doc_name == "":
doc_name = os.path.splitext(os.path.basename(repo))[0]
output = Document.clone(repo, branch, doc_name, source_dir)
return render_template("admin/command_output.html", output = output, next = url_for('admin_document.manage', doc_name = doc_name, branch = branch))
else:
return render_template("admin/document/new.html")
@bp.route('/manage/<doc_name>/<branch>')
def manage(doc_name, branch):
return render_template("admin/document/manage.html", doc=Document(doc_name, branch))
@bp.route('/delete/<doc_name>/<branch>')
def delete(doc_name, branch):
doc = Document(doc_name, branch)
doc.delete()
return redirect(url_for('admin.index'), code=302)
@bp.route('/delete_invalid/<doc_name>/<branch>')
def delete_invalid(doc_name, branch):
doc = Document(doc_name, branch, allow_invalid = True)
doc.delete_folder()
return redirect(url_for('admin.index'), code=302)

View File

@ -1,9 +0,0 @@
from flask import Blueprint, render_template
from data.document import Document
bp = Blueprint('web_admin', __name__, url_prefix='/admin')
@bp.route('/')
def index():
return render_template("index.html", documents=Document.list())