From: Christian Heller <c.heller@plomlompom.de> Date: Sat, 18 May 2024 01:34:44 +0000 (+0200) Subject: Refactor templates. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/calendar?a=commitdiff_plain;h=2ca0045683f74254fd0e248c2567fa2efa358c08;p=taskplom Refactor templates. --- diff --git a/templates/_base.html b/templates/_base.html new file mode 100644 index 0000000..0070630 --- /dev/null +++ b/templates/_base.html @@ -0,0 +1,36 @@ +<!DOCTYPE html> +<html> +<meta charset="UTF-8"> +<style> +body { + font-family: monospace; + text-align: left; + padding: 0; +} +input.btn-harmless { + color: green; +} +input.btn-dangerous { + color: red; +} +div.btn-to-right { + float: right; + text-align: right; +} +td, th, tr, table { + vertical-align: top; + padding: 0; +} +{% block css %} +{% endblock %} +</style> +<body> +<a href="processes">processes</a> +<a href="conditions">conditions</a> +<a href="day">today</a> +<a href="calendar">calendar</a> +<hr> +{% block content %} +{% endblock %} +</body> +</html> diff --git a/templates/base.html b/templates/base.html deleted file mode 100644 index 0070630..0000000 --- a/templates/base.html +++ /dev/null @@ -1,36 +0,0 @@ -<!DOCTYPE html> -<html> -<meta charset="UTF-8"> -<style> -body { - font-family: monospace; - text-align: left; - padding: 0; -} -input.btn-harmless { - color: green; -} -input.btn-dangerous { - color: red; -} -div.btn-to-right { - float: right; - text-align: right; -} -td, th, tr, table { - vertical-align: top; - padding: 0; -} -{% block css %} -{% endblock %} -</style> -<body> -<a href="processes">processes</a> -<a href="conditions">conditions</a> -<a href="day">today</a> -<a href="calendar">calendar</a> -<hr> -{% block content %} -{% endblock %} -</body> -</html> diff --git a/templates/calendar.html b/templates/calendar.html index eae103d..f6208bb 100644 --- a/templates/calendar.html +++ b/templates/calendar.html @@ -1,4 +1,6 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} + + {% block css %} tr.week_row td { diff --git a/templates/condition.html b/templates/condition.html index 00aeedb..8e73e5e 100644 --- a/templates/condition.html +++ b/templates/condition.html @@ -1,4 +1,5 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} +{% import '_macros.html' as macros %} @@ -23,9 +24,6 @@ <tr/> </table> -<input class="btn-harmless" type="submit" name="update" value="update" /> -<div class="btn-to-right"> -<input class="btn-dangerous" type="submit" name="delete" value="delete" /> -</div> +{{ macros.edit_buttons() }} {% endblock %} diff --git a/templates/conditions.html b/templates/conditions.html index a717bf0..e2c4ec1 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} {% block content %} <a href="condition">add</a> diff --git a/templates/day.html b/templates/day.html index a0823f3..da5e17a 100644 --- a/templates/day.html +++ b/templates/day.html @@ -1,4 +1,5 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} +{% import '_macros.html' as macros %} @@ -106,11 +107,6 @@ td.todo_line { comment: <input name="day_comment" value="{{day.comment|e}}" /> <input type="submit" value="OK" /><br /> add todo: <input name="new_todo" list="processes" autocomplete="off" /> -<datalist id="processes"> -{% for process in processes %} -<option value="{{process.id_}}">{{process.title.newest|e}}</option> -{% endfor %} -</datalist> <h4>todo</h4> @@ -148,13 +144,9 @@ add todo: <input name="new_todo" list="processes" autocomplete="off" /> <td class="cond_line_{{(conditions_present|length - loop.index) % 3}}"> {% endif %} {% endfor %} - -<td><input name="new_todo" list="todos_for_{{condition.id_}}" autocomplete="off" /></td> -<datalist name="new_todo" id="todos_for_{{condition.id_}}" /> -{% for process in enablers_for[condition.id_] %} -<option value="{{process.id_}}">{{process.title.newest|e}}</option> -{% endfor %} -</datalist /> +{% set list_name = "todos_for_%s"|format(condition.id_) %} +<td><input name="new_todo" list="{{list_name}}" autocomplete="off" /></td> +{{ macros.datalist_of_direct_titles(list_name, enablers_for[condition.id_]) }} </td> </tr> {% endfor %} @@ -184,5 +176,6 @@ add todo: <input name="new_todo" list="processes" autocomplete="off" /> </table> </form> -{% endblock %} +{{ macros.datalist_of_direct_titles("processes", processes) }} +{% endblock %} diff --git a/templates/msg.html b/templates/msg.html index 90cd61c..3672f21 100644 --- a/templates/msg.html +++ b/templates/msg.html @@ -1,4 +1,6 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} + + {% block content %} <p>{{msg}}</p> diff --git a/templates/process.html b/templates/process.html index 10442cf..41f8117 100644 --- a/templates/process.html +++ b/templates/process.html @@ -1,4 +1,5 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} +{% import '_macros.html' as macros %} @@ -56,59 +57,17 @@ add: <input name="new_step_to_{{step_id}}" list="candidates" autocomplete="off" <tr> <th>conditions</th> -<td> -<table> -{% for condition in process.conditions %} -<tr> -<td> -<input type="checkbox" name="condition" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="condition" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("condition", process.conditions, "condition", "condition_candidates") }}</td> </tr> <tr> <th>enables</th> -<td> -<table> -{% for condition in process.enables %} -<tr> -<td> -<input type="checkbox" name="enables" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="enables" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("enables", process.enables, "condition", "condition_candidates") }}</td> </tr> <tr> <th>disables</th> -<td> -<table> -{% for condition in process.disables %} -<tr> -<td> -<input type="checkbox" name="disables" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="disables" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("disables", process.disables, "condition", "condition_candidates") }}</td> </tr> <tr> @@ -133,20 +92,9 @@ add: <input name="new_top_step" list="step_candidates" autocomplete="off" /> <tr> </table> -<datalist id="condition_candidates"> -{% for condition_candidate in condition_candidates %} -<option value="{{condition_candidate.id_}}">{{condition_candidate.title.newest|e}}</option> -{% endfor %} -</datalist> -<datalist id="step_candidates"> -{% for candidate in step_candidates %} -<option value="{{candidate.id_}}">{{candidate.title.newest|e}}</option> -{% endfor %} -</datalist> - -<input class="btn-harmless" type="submit" name="update" value="update" /> -<div class="btn-to-right"> -<input class="btn-dangerous" type="submit" name="delete" value="delete" /> -</div> +{{ macros.edit_buttons() }} </form> + +{{ macros.datalist_of_direct_titles("condition_candidates", condition_candidates) }} +{{ macros.datalist_of_direct_titles("step_candidates", step_candidates) }} {% endblock %} diff --git a/templates/processes.html b/templates/processes.html index 6dc3e85..6c3c64b 100644 --- a/templates/processes.html +++ b/templates/processes.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} {% block content %} <a href="process">add</a> diff --git a/templates/todo.html b/templates/todo.html index 44cdfa7..d3957af 100644 --- a/templates/todo.html +++ b/templates/todo.html @@ -1,4 +1,5 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} +{% import '_macros.html' as macros %} @@ -29,59 +30,17 @@ <tr> <th>conditions</th> -<td> -<table> -{% for condition in todo.conditions %} -<tr> -<td> -<input type="checkbox" name="condition" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="condition" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("condition", todo.conditions, "condition", "condition_candidates") }}</td> </tr> <tr> <th>enables</th> -<td> -<table> -{% for condition in todo.enables %} -<tr> -<td> -<input type="checkbox" name="enables" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="enables" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("enables", todo.enables, "condition", "condition_candidates") }}</td> </tr> <tr> <th>disables</th> -<td> -<table> -{% for condition in todo.disables%} -<tr> -<td> -<input type="checkbox" name="disables" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="disables" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("disables", todo.disables, "condition", "condition_candidates") }}</td> </tr> <tr> @@ -109,20 +68,9 @@ adopt: <input name="adopt" list="todo_candidates" autocomplete="off" /> </tr> </table> -<input class="btn-harmless" type="submit" name="update" value="update" /> -<div class="btn-to-right"> -<input class="btn-dangerous" type="submit" name="delete" value="delete" /> -</div> +{{ macros.edit_buttons() }} </form> -<datalist id="condition_candidates"> -{% for condition_candidate in condition_candidates %} -<option value="{{condition_candidate.id_}}">{{condition_candidate.title.newest|e}}</option> -{% endfor %} -</datalist> -<datalist id="todo_candidates"> -{% for candidate in todo_candidates %} -<option value="{{candidate.id_}}">{{candidate.process.title.newest|e}} ({{candidate.id_}})</option> -{% endfor %} -</datalist> +{{ macros.datalist_of_direct_titles("condition_candidates", condition_candidates) }} +{{ macros.datalist_of_indirect_titles("todo_candidates", todo_candidates) }} {% endblock %}