svg + responsive
This commit is contained in:
+28
-6
@@ -295,8 +295,8 @@ document
|
|||||||
const loader =
|
const loader =
|
||||||
document.querySelector(".loader");
|
document.querySelector(".loader");
|
||||||
|
|
||||||
const iframe =
|
const frame =
|
||||||
document.getElementById("pdf_iframe");
|
document.getElementById("img_svg");
|
||||||
|
|
||||||
const pdflink =
|
const pdflink =
|
||||||
document.getElementById("pdf_link");
|
document.getElementById("pdf_link");
|
||||||
@@ -304,9 +304,33 @@ document
|
|||||||
|
|
||||||
submitButton.disabled = true;
|
submitButton.disabled = true;
|
||||||
loader.style.display = "block";
|
loader.style.display = "block";
|
||||||
|
pdflink.disabled = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
const response_svg =
|
||||||
|
await fetch("/edt.svg", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ cours })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response_svg.ok)
|
||||||
|
throw new Error("Erreur lors de la génération du SVG.");
|
||||||
|
|
||||||
|
const blob_svg =
|
||||||
|
await response_svg.blob();
|
||||||
|
|
||||||
|
const url_svg =
|
||||||
|
URL.createObjectURL(blob_svg);
|
||||||
|
|
||||||
|
|
||||||
|
frame.src = url_svg;
|
||||||
|
frame.style.display = "block";
|
||||||
|
|
||||||
|
|
||||||
const response =
|
const response =
|
||||||
await fetch("/edt.pdf", {
|
await fetch("/edt.pdf", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -325,9 +349,6 @@ document
|
|||||||
const url =
|
const url =
|
||||||
URL.createObjectURL(blob);
|
URL.createObjectURL(blob);
|
||||||
|
|
||||||
iframe.src = url;
|
|
||||||
iframe.style.display = "block";
|
|
||||||
|
|
||||||
pdflink.href = url;
|
pdflink.href = url;
|
||||||
pdflink.style.display = "block";
|
pdflink.style.display = "block";
|
||||||
|
|
||||||
@@ -340,6 +361,7 @@ document
|
|||||||
|
|
||||||
loader.style.display = "none";
|
loader.style.display = "none";
|
||||||
submitButton.disabled = false;
|
submitButton.disabled = false;
|
||||||
|
pdflink.disabled = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,4 +394,4 @@ if (selectAll) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-4
@@ -169,9 +169,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pdf_iframe {
|
.container {
|
||||||
width: min(100%, 1400px);
|
height: 100%;
|
||||||
aspect-ratio: 297 / 210;
|
overflow-x: scroll;
|
||||||
|
white-space: nowrap;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#img_svg {
|
||||||
|
width: max(800px, 70%);
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
margin: 1rem auto;
|
margin: 1rem auto;
|
||||||
}
|
}
|
||||||
@@ -179,4 +185,4 @@
|
|||||||
footer {
|
footer {
|
||||||
margin-top: 2em;
|
margin-top: 2em;
|
||||||
text-align: center
|
text-align: center
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,7 +244,10 @@ Générer PDF
|
|||||||
<div class="loader" style="margin: auto; display: none"></div>
|
<div class="loader" style="margin: auto; display: none"></div>
|
||||||
|
|
||||||
<a id="pdf_link" target="_blank" style="display: none;margin-top: 2em;">Ouvrir dans une nouvelle fenêtre</a>
|
<a id="pdf_link" target="_blank" style="display: none;margin-top: 2em;">Ouvrir dans une nouvelle fenêtre</a>
|
||||||
<iframe id="pdf_iframe" style="display: none"></iframe>
|
|
||||||
|
<div class="container">
|
||||||
|
<img src="" alt="Emploi du temps" id="img_svg" style="display: none">
|
||||||
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@@ -255,4 +258,4 @@ Générer PDF
|
|||||||
<footer>Valentin Moguérou 2026 - Licence AGPL 3.0 - <a href="https://git.kaz.bzh/valentin/edt_maker_m1orsay" target="_blank">code source</a></footer>
|
<footer>Valentin Moguérou 2026 - Licence AGPL 3.0 - <a href="https://git.kaz.bzh/valentin/edt_maker_m1orsay" target="_blank">code source</a></footer>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ from pprint import pprint
|
|||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
compiler = typst.Compiler()
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
cours_base = [
|
cours_base = [
|
||||||
@@ -211,32 +213,25 @@ def index():
|
|||||||
def favicon():
|
def favicon():
|
||||||
return send_file("favicon.ico")
|
return send_file("favicon.ico")
|
||||||
|
|
||||||
@app.route('/edt.pdf', methods=["GET", "POST"])
|
@app.route('/edt.pdf', methods=["POST"])
|
||||||
def generate_pdf():
|
def generate_pdf():
|
||||||
if request.method != "POST":
|
data = json.loads(request.data)
|
||||||
data = {
|
pprint(data)
|
||||||
"cours": [
|
|
||||||
{"day": 0, "start": "08:15", "end": "10:xx", "name": "Algèbre (CM)", "prof": "Jean-Benoît Bost", "room": "OA1", "color": "#ff80b3"},
|
|
||||||
{"day": 0, "start": "10:30", "end": "13:00", "name": "Algèbre (TD)", "prof": "x", "room": "OA1", "color": "#ff80b3"},
|
|
||||||
{"day": 3, "start": "14:00", "end": "16:00", "name": "Algèbre (CM)", "prof": "Jean-Benoît Bost", "room": "OA1", "color": "#ff80b3"},
|
|
||||||
{"day": 3, "start": "16:15", "end": "18:45", "name": "Algèbre (TD)", "prof": "x", "room": "OA1", "color": "#ff80b3"},
|
|
||||||
|
|
||||||
{"day": 0, "start": "14:00", "end": "16:00", "name": "Analyse (CM)", "prof": "Blanche Buet", "room": "OA1", "color": "#80ffcc"},
|
|
||||||
{"day": 0, "start": "16:15", "end": "18:45", "name": "Analyse (TD)", "prof": "x", "room": "OA1", "color": "#80ffcc"},
|
|
||||||
{"day": 2, "start": "08:15", "end": "10:15", "name": "Analyse (CM)", "prof": "Blanche Buet", "room": "OA1", "color": "#80ffcc"},
|
|
||||||
{"day": 2, "start": "10:30", "end": "13:00", "name": "Analyse (TD)", "prof": "x", "room": "OA1", "color": "#80ffcc"},
|
|
||||||
|
|
||||||
{"day": 1, "start": "14:00", "end": "16:00", "name": "Cryptographie (CM)", "prof": "Stéphane Fischler","room": "OA1", "color": "#e6b3ff"},
|
|
||||||
{"day": 4, "start": "10:30", "end": "12:30", "name": "Cryptographie (TP)", "prof": "Chimène Fischler", "room": "OA1", "color": "#e6b3ff"},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
print(data)
|
|
||||||
else:
|
|
||||||
data = json.loads(request.data)
|
|
||||||
pprint(data)
|
|
||||||
|
|
||||||
sys_inputs = {"data": json.dumps(data)}
|
sys_inputs = {"data": json.dumps(data)}
|
||||||
|
|
||||||
pdf_file = BytesIO(typst.compile(input="templates/edt.typ", sys_inputs=sys_inputs))
|
pdf_file = BytesIO(compiler.compile(input="templates/edt.typ", sys_inputs=sys_inputs))
|
||||||
|
|
||||||
|
return send_file(pdf_file, download_name="edt.pdf")
|
||||||
|
|
||||||
|
@app.route('/edt.svg', methods=["POST"])
|
||||||
|
def generate_svg():
|
||||||
|
data = json.loads(request.data)
|
||||||
|
pprint(data)
|
||||||
|
|
||||||
|
sys_inputs = {"data": json.dumps(data)}
|
||||||
|
|
||||||
|
pdf_file = BytesIO(compiler.compile(input="templates/edt.typ", sys_inputs=sys_inputs, format="svg"))
|
||||||
|
|
||||||
|
return send_file(pdf_file, download_name="edt.svg")
|
||||||
|
|
||||||
return send_file(pdf_file, download_name="edt.pdf")
|
|
||||||
Reference in New Issue
Block a user