data_tool / templates /index.html
Swapnilbpatil's picture
Update templates/index.html
3301cc2 verified
Raw History Blame Contribute Delete
7.73 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enter gandi gali (शिव्या)</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gradient-to-br from-blue-50 to-indigo-100 min-h-screen flex items-center justify-center p-4">
<div class="bg-white rounded-lg shadow-2xl p-8 w-full max-w-md">
<h1 class="text-3xl font-bold text-gray-800 mb-8 text-center">Enter gandi gali (शिव्या)</h1>
<!-- Input Form -->
<div id="formContainer" class="space-y-5 mb-8">
<div>
<label class="block text-sm font-semibold text-gray-700 mb-2">Human</label>
<input
type="text"
id="person1"
placeholder="Enter human name"
class="w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-indigo-500 transition"
>
</div>
<div>
<label class="block text-sm font-semibold text-gray-700 mb-2">AI</label>
<input
type="text"
id="person2"
placeholder="Enter AI name"
class="w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-indigo-500 transition"
>
</div>
<button
onclick="addData()"
class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-lg transition duration-200 ease-in-out transform hover:scale-105"
>
ADD
</button>
</div>
<!-- Status Message -->
<div id="statusMessage" class="mb-6 text-center"></div>
<!-- Download Button -->
<button
onclick="openPasswordModal()"
class="w-full bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded-lg transition duration-200 ease-in-out transform hover:scale-105"
>
Download Data
</button>
</div>
<!-- Password Modal -->
<div id="passwordModal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
<div class="bg-white rounded-lg p-8 max-w-sm w-full mx-4 shadow-2xl">
<h2 class="text-2xl font-bold text-gray-800 mb-6">Enter Password</h2>
<input
type="password"
id="passwordInput"
placeholder="Enter password"
class="w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-indigo-500 transition mb-6"
>
<div id="passwordError" class="text-red-600 text-sm mb-4 text-center hidden"></div>
<div class="flex gap-3">
<button
onclick="closePasswordModal()"
class="flex-1 bg-gray-400 hover:bg-gray-500 text-white font-bold py-2 px-4 rounded-lg transition"
>
Cancel
</button>
<button
onclick="verifyPassword()"
class="flex-1 bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-lg transition"
>
Submit
</button>
</div>
</div>
</div>
<script>
function addData() {
const person1 = document.getElementById('person1').value;
const person2 = document.getElementById('person2').value;
const statusMsg = document.getElementById('statusMessage');
if (!person1 || !person2) {
showStatus('Please fill in both fields', 'error');
return;
}
fetch('/add_data', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
person1: person1,
person2: person2
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
showStatus('✓ Data added successfully', 'success');
document.getElementById('person1').value = '';
document.getElementById('person2').value = '';
document.getElementById('person1').focus();
} else {
showStatus('✗ ' + data.message, 'error');
}
})
.catch(error => {
showStatus('✗ Error: ' + error, 'error');
});
}
function openPasswordModal() {
document.getElementById('passwordModal').classList.remove('hidden');
document.getElementById('passwordInput').value = '';
document.getElementById('passwordError').classList.add('hidden');
document.getElementById('passwordInput').focus();
}
function closePasswordModal() {
document.getElementById('passwordModal').classList.add('hidden');
}
function verifyPassword() {
const password = document.getElementById('passwordInput').value;
const errorMsg = document.getElementById('passwordError');
if (!password) {
errorMsg.textContent = 'Please enter a password';
errorMsg.classList.remove('hidden');
return;
}
fetch('/verify_password', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
password: password
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
closePasswordModal();
window.location.href = '/download_csv';
} else {
errorMsg.textContent = 'Incorrect password';
errorMsg.classList.remove('hidden');
}
})
.catch(error => {
errorMsg.textContent = 'Error: ' + error;
errorMsg.classList.remove('hidden');
});
}
function showStatus(message, type) {
const statusMsg = document.getElementById('statusMessage');
statusMsg.textContent = message;
statusMsg.className = 'text-center font-semibold text-sm p-3 rounded-lg';
if (type === 'success') {
statusMsg.classList.add('bg-green-100', 'text-green-700');
} else {
statusMsg.classList.add('bg-red-100', 'text-red-700');
}
setTimeout(() => {
statusMsg.textContent = '';
statusMsg.className = 'text-center';
}, 3000);
}
// Allow Enter key to submit
document.getElementById('person2').addEventListener('keypress', function(e) {
if (e.key === 'Enter') addData();
});
document.getElementById('passwordInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') verifyPassword();
});
</script>
</body>
</html>