Добавил возможность удаления услуг в БД и UI панели администратора
This commit is contained in:
@@ -263,3 +263,11 @@ class DatabaseManager:
|
|||||||
""", (name.strip(), price.strip(), float(price_numeric), description.strip(), int(is_active), service_id.strip()))
|
""", (name.strip(), price.strip(), float(price_numeric), description.strip(), int(is_active), service_id.strip()))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return cursor.rowcount > 0
|
return cursor.rowcount > 0
|
||||||
|
|
||||||
|
def delete_service(self, service_id: str) -> bool:
|
||||||
|
"""Удалить услугу из базы данных."""
|
||||||
|
with self._get_connection() as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("DELETE FROM services WHERE id = ?", (service_id.strip(),))
|
||||||
|
conn.commit()
|
||||||
|
return cursor.rowcount > 0
|
||||||
|
|||||||
@@ -915,11 +915,15 @@ DASHBOARD_TEMPLATE = """
|
|||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="p-4 text-center">
|
<td class="p-4 text-center space-x-2">
|
||||||
<button onclick="openEditModal('{{ svc.id }}', '{{ svc.name | replace("'", "\\'") }}', '{{ svc.price | replace("'", "\\'") }}', '{{ svc.price_numeric }}', '{{ svc.description | replace("'", "\\'") | replace("\n", " ") }}', {{ svc.is_active }})"
|
<button onclick="openEditModal('{{ svc.id }}', '{{ svc.name | replace("'", "\\'") }}', '{{ svc.price | replace("'", "\\'") }}', '{{ svc.price_numeric }}', '{{ svc.description | replace("'", "\\'") | replace("\n", " ") }}', {{ svc.is_active }})"
|
||||||
class="inline-flex items-center gap-1 px-3 py-1.5 bg-blue-950/30 hover:bg-blue-900/50 border border-blue-900/40 hover:border-blue-500/50 text-blue-300 text-xs font-bold uppercase tracking-wider rounded-lg transition">
|
class="inline-flex items-center gap-1 px-3 py-1.5 bg-blue-950/30 hover:bg-blue-900/50 border border-blue-900/40 hover:border-blue-500/50 text-blue-300 text-xs font-bold uppercase tracking-wider rounded-lg transition">
|
||||||
✏️ Ред.
|
✏️ Ред.
|
||||||
</button>
|
</button>
|
||||||
|
<button onclick="deleteService('{{ svc.id }}', '{{ svc.name | replace("'", "\\'") }}')"
|
||||||
|
class="inline-flex items-center gap-1 px-3 py-1.5 bg-red-950/30 hover:bg-red-900/50 border border-red-900/40 hover:border-red-500/50 text-red-300 text-xs font-bold uppercase tracking-wider rounded-lg transition">
|
||||||
|
🗑️ Удал.
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -1127,6 +1131,30 @@ DASHBOARD_TEMPLATE = """
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteService(id, name) {
|
||||||
|
if (!confirm(`Вы действительно хотите безвозвратно удалить услугу "${name}" (ID: ${id})?`)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch(`/admin/services/delete/${id}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
})
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.status === 'success') {
|
||||||
|
alert('Услуга успешно удалена!');
|
||||||
|
window.location.reload();
|
||||||
|
} else {
|
||||||
|
alert('Ошибка: ' + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
alert('Не удалось связаться с сервером');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function filterStatus(status) {
|
function filterStatus(status) {
|
||||||
currentFilter = status;
|
currentFilter = status;
|
||||||
|
|
||||||
@@ -1377,6 +1405,20 @@ def admin_edit_service(service_id):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"status": "error", "message": str(e)}), 500
|
return jsonify({"status": "error", "message": str(e)}), 500
|
||||||
|
|
||||||
|
@app.route('/admin/services/delete/<service_id>', methods=['POST'])
|
||||||
|
def admin_delete_service(service_id):
|
||||||
|
if not session.get('logged_in'):
|
||||||
|
return jsonify({"status": "error", "message": "Не авторизован"}), 403
|
||||||
|
|
||||||
|
try:
|
||||||
|
success = db.delete_service(service_id)
|
||||||
|
if success:
|
||||||
|
return jsonify({"status": "success", "message": "Услуга успешно удалена"})
|
||||||
|
else:
|
||||||
|
return jsonify({"status": "error", "message": "Не удалось удалить услугу (возможно, она не найдена)"}), 404
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"status": "error", "message": str(e)}), 500
|
||||||
|
|
||||||
@app.route('/admin/check-payment/<reg_id>', methods=['POST'])
|
@app.route('/admin/check-payment/<reg_id>', methods=['POST'])
|
||||||
def admin_check_payment(reg_id):
|
def admin_check_payment(reg_id):
|
||||||
if not session.get('logged_in'):
|
if not session.get('logged_in'):
|
||||||
|
|||||||
Reference in New Issue
Block a user