Spaces:
Sleeping
Sleeping
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>CSV Upload</title> | |
<!-- Подключение стилей Notyf --> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notyf/notyf.min.css"> | |
<!-- Подключение стилей Bootstrap --> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
text-align: center; | |
background-color: #f0f0f0; | |
margin: 0; | |
padding: 0; | |
} | |
h1 { | |
background-color: #4CAF50; | |
color: white; | |
padding: 20px; | |
margin: 0; | |
border-bottom: 2px solid #388E3C; | |
} | |
.input-row { | |
display: flex; | |
justify-content: center; | |
gap: 10px; | |
margin-top: 20px; | |
} | |
.input-row input[type="file"] { | |
padding: 10px; | |
font-size: 16px; | |
border: 1px solid #ccc; | |
border-radius: 5px; | |
} | |
.input-row input[type="checkbox"] { | |
margin-top: 5px; | |
} | |
.input-row label { | |
display: flex; | |
align-items: center; | |
color: #4CAF50; | |
font-size: 16px; | |
} | |
#uploadButton { | |
color: white; | |
background-color: #4CAF50; | |
border: none; | |
cursor: pointer; | |
padding: 10px 20px; | |
font-size: 16px; | |
border-radius: 5px; | |
margin-top: 20px; | |
} | |
#uploadButton:hover { | |
background-color: #388E3C; | |
} | |
.center-spinner { | |
position: fixed; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
z-index: 1000; | |
} | |
.loader { | |
--b: 10px; /* border thickness */ | |
--n: 10; /* number of dashes*/ | |
--g: 10deg; /* gap between dashes*/ | |
--c: green; /* the color */ | |
width: 100px; /* size */ | |
aspect-ratio: 1; | |
border-radius: 50%; | |
padding: 1px; /* get rid of bad outlines */ | |
background: conic-gradient(#0000, var(--c)) content-box; | |
--_m: /* we use +/-1deg between colors to avoid jagged edges */ | |
repeating-conic-gradient(#0000 0deg, | |
#000 1deg calc(360deg/var(--n) - var(--g) - 1deg), | |
#0000 calc(360deg/var(--n) - var(--g)) calc(360deg/var(--n))), | |
radial-gradient(farthest-side, #0000 calc(98% - var(--b)), #000 calc(100% - var(--b))); | |
-webkit-mask: var(--_m); | |
mask: var(--_m); | |
-webkit-mask-composite: destination-in; | |
mask-composite: intersect; | |
animation: load 1s infinite steps(var(--n)); | |
display: none; | |
} | |
@keyframes load { | |
to { transform: rotate(1turn); } | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Upload CSV File</h1> | |
<form id="uploadForm" enctype="multipart/form-data" method="post"> | |
<div class="input-row"> | |
<input type="file" name="file" accept=".csv"> | |
</div> | |
<div class="input-row"> | |
<label> | |
<input type="checkbox" name="verify_phone" value="1"> Verify Phone | |
</label> | |
<label> | |
<input type="checkbox" name="add_curator" value="1"> Add Curator | |
</label> | |
</div> | |
<input id="uploadButton" type="submit" value="Upload"> | |
</form> | |
<div id="result"></div> | |
<div class="loader center-spinner"></div> | |
<!-- Подключение скрипта Notyf --> | |
<script src="https://cdn.jsdelivr.net/npm/notyf/notyf.min.js"></script> | |
<!-- Подключение скриптов Bootstrap --> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | |
<script> | |
document.getElementById('uploadForm').addEventListener('submit', function(event) { | |
event.preventDefault(); | |
const form = new FormData(this); | |
const loader = document.querySelector('.loader'); | |
loader.style.display = 'block'; // Показываем спиннер | |
fetch('/upload_csv', { | |
method: 'POST', | |
body: form | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
loader.style.display = 'none'; // Скрываем спиннер после завершения | |
const notyf = new Notyf({ | |
duration: 5000, // Длительность показа уведомления | |
position: { | |
x: 'right', | |
y: 'bottom' | |
}, | |
types: [ | |
{ | |
type: 'success', | |
background: 'green', | |
icon: { | |
className: 'notyf__icon--success', | |
tagName: 'span', | |
text: '' | |
} | |
} | |
] | |
}); | |
notyf.success(data.message); // Показываем уведомление с сообщением от сервера | |
}) | |
.catch(error => { | |
console.error('Error:', error); | |
loader.style.display = 'none'; // Скрываем спиннер в случае ошибки | |
const notyf = new Notyf({ | |
duration: 5000, // Длительность показа уведомления | |
position: { | |
x: 'right', | |
y: 'bottom' | |
}, | |
types: [ | |
{ | |
type: 'error', | |
background: 'red', | |
icon: { | |
className: 'notyf__icon--error', | |
tagName: 'span', | |
text: '' | |
} | |
} | |
] | |
}); | |
notyf.error('An error occurred while uploading the file.'); // Показываем уведомление об ошибке | |
}); | |
}); | |
</script> | |
</body> | |
</html> |