crud with conditions

This commit is contained in:
null 2024-02-28 21:02:23 +01:00
parent 99b78c9bd1
commit a56cf12c2a
6 changed files with 82 additions and 35 deletions

17
app.py
View File

@ -13,26 +13,13 @@ r = RethinkDB()
conn = r.connect(rethinkUrl, rethinkPort, db='finfree') conn = r.connect(rethinkUrl, rethinkPort, db='finfree')
create_conditions_routes(app, r, conn) create_conditions_routes(app, r, conn)
conditionModel = {
"id": {
"type": "readonly",
"name": "ID"
},
"itemDescription": {
"type": "string",
"name": "Beschreibung"
},
"itemName": {
"type": "string",
"name": "Name"
}
}
@app.route('/') @app.route('/')
def index(): def index():
cursor = r.table("conditions").run(conn) cursor = r.table("conditions").run(conn)
conditions = list(cursor) conditions = list(cursor)
return render_template('index.html', data={"conditions": { "data": conditions, "model": conditionModel }}) return render_template('index.html', data={"conditions": conditions })
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True) app.run(host='0.0.0.0', port=8080, debug=True)

View File

@ -38,10 +38,32 @@ td {
text-align: left; text-align: left;
} }
td div {
max-width: 6ch;
white-space: nowrap;
overflow: hidden;
display: block;
}
thead td:first-child {
border: none;
}
th.nodata {
text-align: center;
}
tfoot td { tfoot td {
border: none; border: none;
} }
tbody td:first-child {
max-width: 1ch;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
button { button {
background-color: #4CAF50; background-color: #4CAF50;
color: white; color: white;
@ -67,13 +89,20 @@ fieldset {
/* Dialog box */ /* Dialog box */
dialog { dialog {
width: 400px; width: 400px;
height: 420px;
padding: 20px; padding: 20px;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 5px; border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
overflow: hidden; overflow: hidden;
} }
dialog.create {
height: 320px;
}
dialog.update {
height: 500px;
}
/* Labels */ /* Labels */
label { label {
@ -84,7 +113,7 @@ label {
} }
/* Text inputs */ /* Text inputs */
input, form div { input, select, form div {
padding: 8px; padding: 8px;
margin-bottom: 10px; margin-bottom: 10px;
border: 1px solid #ccc; border: 1px solid #ccc;
@ -93,7 +122,7 @@ input, form div {
font-size: 16; font-size: 16;
} }
input { input, select {
width: 100%; width: 100%;
} }

View File

@ -13,7 +13,14 @@ function documentReady() {
openDialog.close(); openDialog.close();
window.location.reload(); window.location.reload();
} else { } else {
document.querySelector("dialog").showModal() const dialog = document.querySelector("dialog")
if (iframe.contentWindow.location.href.split("/").pop() === "create") {
dialog.className = 'create';
} else {
dialog.className = 'update';
}
dialog.showModal()
} }
} }
} }

View File

@ -14,12 +14,19 @@
<h2>Create a condition</h2> <h2>Create a condition</h2>
<form method="POST" action="/conditions"> <form method="POST" action="/conditions">
<fieldset> <fieldset>
<label for="itemDescription">Beschreibung</label> <label for="symbol">Symbol</label>
<input type="text" name="itemDescription"> <input type="text" name="symbol">
<label for="itemName">Name</label> <label for="condition">Condition</label>
<input type="text" name="itemName"> <select name="condition">
<option value="gt">Greater than</option>
<option value="lt">Lower than</option>
</select>
<label for="value">Value</label>
<input type="number" step="any" name="value">
</fieldset> </fieldset>
<fieldset> <fieldset>
<button value="cancel" formmethod="dialog" onclick="window.top.postMessage('close', '*')">Cancel</button> <button value="cancel" formmethod="dialog" onclick="window.top.postMessage('close', '*')">Cancel</button>
<button type="submit">Submit</button> <button type="submit">Submit</button>

View File

@ -17,11 +17,17 @@
<label>ID</label> <label>ID</label>
<div>{{ data.id }}</div> <div>{{ data.id }}</div>
<label for="itemDescription">Beschreibung</label> <label for="symbol">Symbol</label>
<input type="text" name="itemDescription" value="{{ data.itemDescription }}"> <input type="text" name="symbol" value="{{ data.symbol }}">
<label for="itemName">Name</label> <label for="condition">Condition</label>
<input type="text" name="itemName" value="{{ data.itemName }}"> <select name="condition">
<option value="gt" {% if data.condition == "gt" %}selected{% endif %}>Greater than</option>
<option value="lt" {% if data.condition == "lt" %}selected{% endif %}>Lower than</option>
</select>
<label for="value">Value</label>
<input type="number" step="any" name="value" value="{{ data.value }}">
</fieldset> </fieldset>
<fieldset> <fieldset>
<button value="cancel" formmethod="dialog" onclick="window.top.postMessage('close', '*')">Cancel</button> <button value="cancel" formmethod="dialog" onclick="window.top.postMessage('close', '*')">Cancel</button>

View File

@ -11,30 +11,41 @@
<body> <body>
<div class="container"> <div class="container">
<h1>Conditions</h1>
<dialog> <dialog>
<iframe frameborder="0"></iframe> <iframe frameborder="0"></iframe>
</dialog> </dialog>
<table id="conditionTable"> <table id="conditionTable">
<thead> <thead>
<tr> <tr>
{% for key, value in data.conditions.model.items() %} <td colspan="5"><h2>Conditions</h2></td>
<th>{{ value.name }}</th>
{% endfor %}
</tr> </tr>
{% if data.conditions %}
<tr>
<th>ID</th>
<th>Symbol</th>
<th>Condition</th>
<th>Value</th>
</tr>
{% else %}
<tr>
<th class="nodata">No Data</th>
</tr>
{% endif %}
</thead> </thead>
<tbody> <tbody>
{% for item in data.conditions.data %} {% for item in data.conditions %}
<tr onclick="document.querySelector('dialog iframe').contentWindow.location='/conditions/{{ item.id }}'"> <tr onclick="document.querySelector('dialog iframe').contentWindow.location='/conditions/{{ item.id }}'">
{% for key, value in item.items() %}
<td>{{ value }}</td> {% set order = ["id", "symbol", "condition", "value"] %}
{% for key in order %}
<td>{{ item[key] }}</td>
{% endfor %} {% endfor %}
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr>
<td colspan="3" style="text-align: right;"> <!-- Adjust colspan as per your total columns --> <td colspan="5" style="text-align: right;"> <!-- Adjust colspan as per your total columns -->
<button onclick="document.querySelector('dialog iframe').contentWindow.location='/conditions/create'">Add Item</button> <button onclick="document.querySelector('dialog iframe').contentWindow.location='/conditions/create'">Add Item</button>
</td> </td>
</tr> </tr>