add simple input form

This commit is contained in:
null 2024-02-17 11:19:10 +01:00
parent 17b3c46960
commit 8d4c29451e
5 changed files with 195 additions and 3 deletions

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM python:latest
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./app.py" ]

6
app.py
View File

@ -1,10 +1,10 @@
from flask import Flask from flask import Flask, render_template
app = Flask(__name__) app = Flask(__name__)
@app.route('/') @app.route('/')
def hello_world(): def index():
return 'Hello World!' return render_template('index.html')
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080) app.run(host='0.0.0.0', port=8080)

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
flask

88
static/css/styles.css Normal file
View File

@ -0,0 +1,88 @@
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}
.container {
max-width: 800px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
position: relative;
}
h1 {
margin-top: 0;
font-size: 24px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table,
th,
td {
border: 1px solid #ddd;
}
th,
td {
padding: 12px;
text-align: left;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
padding-top: 60px;
}
.modal-content {
background-color: #fefefe;
margin: 5% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
border-radius: 8px;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}

93
templates/index.html Normal file
View File

@ -0,0 +1,93 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paper-Like Website</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/styles.css') }}">
</head>
<body>
<div class="container">
<h1>Conditions</h1>
<button onclick="openModal()">Add Item</button>
<table id="dataTable">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<!-- Data will be inserted here dynamically -->
</tbody>
</table>
</div>
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal()">&times;</span>
<h2>Add Item</h2>
<form id="addItemForm">
<label for="itemName">Name:</label><br>
<input type="text" id="itemName" name="itemName" required><br>
<label for="itemDescription">Description:</label><br>
<textarea id="itemDescription" name="itemDescription" required></textarea><br><br>
<button type="submit">Submit</button>
</form>
</div>
</div>
<script>
// Sample data to populate the table
const sampleData = [
{ id: 1, name: 'Item 1', description: 'Description for Item 1' },
{ id: 2, name: 'Item 2', description: 'Description for Item 2' },
{ id: 3, name: 'Item 3', description: 'Description for Item 3' }
];
// Function to populate the table with data
function populateTable(data) {
const tableBody = document.querySelector('#dataTable tbody');
tableBody.innerHTML = '';
data.forEach(item => {
const row = `<tr>
<td>${item.id}</td>
<td>${item.name}</td>
<td>${item.description}</td>
</tr>`;
tableBody.insertAdjacentHTML('beforeend', row);
});
}
// Open modal function
function openModal() {
document.getElementById('myModal').style.display = 'block';
}
// Close modal function
function closeModal() {
document.getElementById('myModal').style.display = 'none';
}
// Handle form submission
document.getElementById('addItemForm').addEventListener('submit', function (event) {
event.preventDefault();
const itemName = document.getElementById('itemName').value;
const itemDescription = document.getElementById('itemDescription').value;
// Here you would typically send this data to the backend
// For simplicity, let's just log it for now
console.log('Submitted:', itemName, itemDescription);
closeModal();
});
// Initially populate the table with sample data
populateTable(sampleData);
</script>
</body>
</html>