Implement client authentication and admin clinics panel
This commit is contained in:
@@ -0,0 +1,616 @@
|
||||
:root {
|
||||
--primary: #4361ee;
|
||||
--primary-hover: #3a56d4;
|
||||
--primary-light: rgba(67, 97, 238, 0.1);
|
||||
--success: #2ec4b6;
|
||||
--success-light: rgba(46, 196, 182, 0.15);
|
||||
--danger: #ef476f;
|
||||
--danger-light: rgba(239, 71, 111, 0.15);
|
||||
--warning: #ff9f1c;
|
||||
--dark: #0b132b;
|
||||
--gray-900: #1c2541;
|
||||
--gray-800: #2b3a67;
|
||||
--gray-200: #e2e8f0;
|
||||
--light: #f8f9fa;
|
||||
--white: #ffffff;
|
||||
|
||||
--glass-bg: rgba(255, 255, 255, 0.05);
|
||||
--glass-border: rgba(255, 255, 255, 0.1);
|
||||
--glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
|
||||
|
||||
--font-heading: 'Outfit', sans-serif;
|
||||
--font-body: 'Inter', sans-serif;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-body);
|
||||
background: linear-gradient(135deg, var(--dark) 0%, var(--gray-900) 100%);
|
||||
color: var(--light);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
/* Glassmorphism Classes */
|
||||
.glass-card {
|
||||
background: var(--glass-bg);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
border: 1px solid var(--glass-border);
|
||||
border-radius: 16px;
|
||||
box-shadow: var(--glass-shadow);
|
||||
}
|
||||
|
||||
/* Animations */
|
||||
@keyframes pulse {
|
||||
0% { box-shadow: 0 0 0 0 rgba(67, 97, 238, 0.4); }
|
||||
70% { box-shadow: 0 0 0 10px rgba(67, 97, 238, 0); }
|
||||
100% { box-shadow: 0 0 0 0 rgba(67, 97, 238, 0); }
|
||||
}
|
||||
|
||||
.pulse-animation {
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(10px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
/* Sidebar */
|
||||
.sidebar {
|
||||
width: 260px;
|
||||
background: rgba(11, 19, 43, 0.8);
|
||||
border-right: 1px solid var(--glass-border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 24px 0;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 0 24px 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.logo-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: linear-gradient(135deg, #4cc9f0, var(--primary));
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 20px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.sidebar-header h2 {
|
||||
font-family: var(--font-heading);
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 0 16px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
padding: 12px 16px;
|
||||
border-radius: 10px;
|
||||
color: #a0aec0;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.nav-item i {
|
||||
font-size: 18px;
|
||||
width: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.nav-item:hover {
|
||||
background: var(--glass-bg);
|
||||
color: var(--white);
|
||||
transform: translateX(4px);
|
||||
}
|
||||
|
||||
.nav-item.active {
|
||||
background: var(--primary-light);
|
||||
color: #4cc9f0;
|
||||
border-left: 3px solid #4cc9f0;
|
||||
}
|
||||
|
||||
.sidebar-footer {
|
||||
padding: 0 24px;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
background: transparent;
|
||||
border: 1px solid var(--glass-border);
|
||||
color: #a0aec0;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
font-family: var(--font-body);
|
||||
font-weight: 500;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.logout-btn:hover {
|
||||
background: var(--danger-light);
|
||||
color: var(--danger);
|
||||
border-color: var(--danger);
|
||||
}
|
||||
|
||||
/* Main Content */
|
||||
.main-content {
|
||||
flex: 1;
|
||||
padding: 32px 40px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.top-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 40px;
|
||||
animation: fadeIn 0.5s ease-out;
|
||||
}
|
||||
|
||||
.header-title h1 {
|
||||
font-family: var(--font-heading);
|
||||
font-size: 32px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.header-title p {
|
||||
color: #a0aec0;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.primary-btn {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
border-radius: 10px;
|
||||
font-family: var(--font-body);
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 15px rgba(67, 97, 238, 0.3);
|
||||
}
|
||||
|
||||
.primary-btn:hover {
|
||||
background: var(--primary-hover);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(67, 97, 238, 0.4);
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
background: transparent;
|
||||
color: var(--white);
|
||||
border: 1px solid var(--glass-border);
|
||||
padding: 12px 24px;
|
||||
border-radius: 10px;
|
||||
font-family: var(--font-body);
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.secondary-btn:hover {
|
||||
background: var(--glass-bg);
|
||||
}
|
||||
|
||||
.icon-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: #a0aec0;
|
||||
cursor: pointer;
|
||||
padding: 6px;
|
||||
border-radius: 6px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.icon-btn:hover {
|
||||
color: var(--white);
|
||||
background: var(--glass-bg);
|
||||
}
|
||||
|
||||
.icon-btn.delete:hover {
|
||||
color: var(--danger);
|
||||
background: var(--danger-light);
|
||||
}
|
||||
|
||||
/* Stats */
|
||||
.dashboard-stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 24px;
|
||||
margin-bottom: 40px;
|
||||
animation: fadeIn 0.6s ease-out;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
padding: 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.bg-blue { background: rgba(67, 97, 238, 0.15); color: #4cc9f0; }
|
||||
.bg-green { background: var(--success-light); color: var(--success); }
|
||||
.bg-red { background: var(--danger-light); color: var(--danger); }
|
||||
|
||||
.stat-info h3 {
|
||||
font-size: 14px;
|
||||
color: #a0aec0;
|
||||
font-weight: 500;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.stat-info p {
|
||||
font-family: var(--font-heading);
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* Table */
|
||||
.data-section {
|
||||
padding: 24px;
|
||||
animation: fadeIn 0.7s ease-out;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.modern-table {
|
||||
width: 100%;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0 8px;
|
||||
}
|
||||
|
||||
.modern-table th {
|
||||
text-align: left;
|
||||
padding: 0 16px 12px;
|
||||
color: #a0aec0;
|
||||
font-weight: 500;
|
||||
font-size: 13px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.modern-table td {
|
||||
padding: 16px;
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
|
||||
.modern-table tr td:first-child {
|
||||
border-radius: 10px 0 0 10px;
|
||||
}
|
||||
|
||||
.modern-table tr td:last-child {
|
||||
border-radius: 0 10px 10px 0;
|
||||
}
|
||||
|
||||
.modern-table tbody tr {
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.modern-table tbody tr:hover td {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
/* Status Badge */
|
||||
.status-badge {
|
||||
padding: 6px 12px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.status-active {
|
||||
background: var(--success-light);
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
.status-inactive {
|
||||
background: var(--danger-light);
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.token-blur {
|
||||
filter: blur(4px);
|
||||
transition: filter 0.3s;
|
||||
cursor: pointer;
|
||||
font-family: monospace;
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.token-blur:hover {
|
||||
filter: blur(0);
|
||||
}
|
||||
|
||||
/* Modals */
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
backdrop-filter: blur(5px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 100;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-overlay.active {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
padding: 32px;
|
||||
transform: scale(0.9);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-overlay.active .modal-content {
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
font-family: var(--font-heading);
|
||||
}
|
||||
|
||||
/* Forms */
|
||||
.modern-form .form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.modern-form label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
color: #a0aec0;
|
||||
}
|
||||
|
||||
.input-with-icon {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.input-with-icon i {
|
||||
position: absolute;
|
||||
left: 16px;
|
||||
color: #a0aec0;
|
||||
}
|
||||
|
||||
.input-with-icon input {
|
||||
width: 100%;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border: 1px solid var(--glass-border);
|
||||
color: white;
|
||||
padding: 14px 16px 14px 45px;
|
||||
border-radius: 10px;
|
||||
font-family: var(--font-body);
|
||||
font-size: 15px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.input-with-icon input:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary);
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.form-group small {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
color: #718096;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 16px;
|
||||
margin-top: 32px;
|
||||
}
|
||||
|
||||
/* Success Modal */
|
||||
.success-modal {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.success-icon {
|
||||
font-size: 64px;
|
||||
color: var(--success);
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.success-modal h2 {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.success-modal p {
|
||||
color: #a0aec0;
|
||||
margin-bottom: 24px;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.token-container {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
padding: 16px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
border: 1px solid var(--primary-light);
|
||||
}
|
||||
|
||||
.token-container code {
|
||||
font-family: monospace;
|
||||
font-size: 16px;
|
||||
color: #4cc9f0;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* Toast */
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 24px;
|
||||
right: 24px;
|
||||
padding: 16px 24px;
|
||||
background: var(--glass-bg);
|
||||
backdrop-filter: blur(12px);
|
||||
border-left: 4px solid var(--primary);
|
||||
color: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
||||
transform: translateX(120%);
|
||||
transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.toast.error {
|
||||
border-left-color: var(--danger);
|
||||
}
|
||||
|
||||
.toast.success {
|
||||
border-left-color: var(--success);
|
||||
}
|
||||
|
||||
.loading-cell {
|
||||
text-align: center;
|
||||
padding: 40px !important;
|
||||
color: #a0aec0;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 3px solid rgba(255,255,255,0.1);
|
||||
border-top-color: var(--primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 0 auto 16px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* Custom Switch Toggle */
|
||||
.toggle-switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 44px;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
.toggle-switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0; left: 0; right: 0; bottom: 0;
|
||||
background-color: rgba(255,255,255,0.1);
|
||||
transition: .4s;
|
||||
border-radius: 34px;
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
left: 3px;
|
||||
bottom: 3px;
|
||||
background-color: #a0aec0;
|
||||
transition: .4s;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
input:checked + .slider {
|
||||
background-color: var(--success);
|
||||
}
|
||||
|
||||
input:checked + .slider:before {
|
||||
transform: translateX(20px);
|
||||
background-color: white;
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-BR">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Gerenciamento de Clínicas - RF Dental</title>
|
||||
|
||||
<!-- Fontes -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
||||
|
||||
<!-- Ícones -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
|
||||
<!-- Estilos -->
|
||||
<link rel="stylesheet" href="admin-clinics.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<aside class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<div class="logo-icon">
|
||||
<i class="fa-solid fa-tooth"></i>
|
||||
</div>
|
||||
<h2>RF Dental</h2>
|
||||
</div>
|
||||
|
||||
<nav class="sidebar-nav">
|
||||
<a href="/" class="nav-item">
|
||||
<i class="fa-solid fa-chart-line"></i> Dashboard
|
||||
</a>
|
||||
<a href="/clients" class="nav-item">
|
||||
<i class="fa-solid fa-network-wired"></i> Conexões
|
||||
</a>
|
||||
<a href="/admin-clinics" class="nav-item active">
|
||||
<i class="fa-solid fa-hospital"></i> Clínicas e Acessos
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<div class="sidebar-footer">
|
||||
<button id="logoutBtn" class="logout-btn">
|
||||
<i class="fa-solid fa-arrow-right-from-bracket"></i> Sair
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="main-content">
|
||||
|
||||
<header class="top-header">
|
||||
<div class="header-title">
|
||||
<h1>Dispositivos e Clínicas</h1>
|
||||
<p>Gerencie o acesso do Aplicativo Desktop aos computadores das clínicas.</p>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<button id="addClinicBtn" class="primary-btn pulse-animation">
|
||||
<i class="fa-solid fa-plus"></i> Novo Acesso
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="dashboard-stats">
|
||||
<div class="stat-card glass-card">
|
||||
<div class="stat-icon bg-blue">
|
||||
<i class="fa-solid fa-desktop"></i>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<h3>Total de Dispositivos</h3>
|
||||
<p id="totalDevices">0</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card glass-card">
|
||||
<div class="stat-icon bg-green">
|
||||
<i class="fa-solid fa-check-circle"></i>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<h3>Ativos</h3>
|
||||
<p id="activeDevices">0</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card glass-card">
|
||||
<div class="stat-icon bg-red">
|
||||
<i class="fa-solid fa-ban"></i>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<h3>Bloqueados</h3>
|
||||
<p id="blockedDevices">0</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="data-section glass-card">
|
||||
<div class="table-container">
|
||||
<table class="modern-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Status</th>
|
||||
<th>Clínica</th>
|
||||
<th>Computador</th>
|
||||
<th>Email de Acesso</th>
|
||||
<th>Último IP</th>
|
||||
<th>Token de Autenticação</th>
|
||||
<th>Ações</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="clinicsTableBody">
|
||||
<!-- Loading state -->
|
||||
<tr>
|
||||
<td colspan="7" class="loading-cell">
|
||||
<div class="spinner"></div>
|
||||
<p>Carregando dispositivos...</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
<!-- Modal Cadastro -->
|
||||
<div id="clinicModal" class="modal-overlay">
|
||||
<div class="modal-content glass-card">
|
||||
<div class="modal-header">
|
||||
<h2>Adicionar Novo Dispositivo</h2>
|
||||
<button class="close-modal"><i class="fa-solid fa-xmark"></i></button>
|
||||
</div>
|
||||
|
||||
<form id="clinicForm" class="modern-form">
|
||||
<div class="form-group">
|
||||
<label for="clinic_name">Nome da Clínica</label>
|
||||
<div class="input-with-icon">
|
||||
<i class="fa-solid fa-hospital"></i>
|
||||
<input type="text" id="clinic_name" name="clinic_name" placeholder="Ex: Odonto Mais Centro" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="pc_name">Identificação do Computador</label>
|
||||
<div class="input-with-icon">
|
||||
<i class="fa-solid fa-desktop"></i>
|
||||
<input type="text" id="pc_name" name="pc_name" placeholder="Ex: Recepção 01" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">E-mail de Login</label>
|
||||
<div class="input-with-icon">
|
||||
<i class="fa-solid fa-envelope"></i>
|
||||
<input type="email" id="email" name="email" placeholder="recepcao@odontomais.com" required>
|
||||
</div>
|
||||
<small>O email que o usuário usará no aplicativo Desktop.</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Senha de Acesso</label>
|
||||
<div class="input-with-icon">
|
||||
<i class="fa-solid fa-lock"></i>
|
||||
<input type="password" id="password" name="password" placeholder="Mínimo 6 caracteres" required minlength="6">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="button" class="secondary-btn close-modal">Cancelar</button>
|
||||
<button type="submit" class="primary-btn" id="submitBtn">
|
||||
<i class="fa-solid fa-check"></i> Salvar e Gerar Token
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Token Gerado -->
|
||||
<div id="tokenModal" class="modal-overlay">
|
||||
<div class="modal-content glass-card success-modal">
|
||||
<div class="success-icon pulse-animation">
|
||||
<i class="fa-solid fa-check-circle"></i>
|
||||
</div>
|
||||
<h2>Dispositivo Cadastrado!</h2>
|
||||
<p>Copie o token abaixo e cole-o no Aplicativo Desktop junto com o email e senha para liberar o envio de raios-x.</p>
|
||||
|
||||
<div class="token-container">
|
||||
<code id="generatedToken">8f8a3b20-1d8c-4b3f-9e7b...</code>
|
||||
<button id="copyTokenBtn" class="icon-btn" title="Copiar Token">
|
||||
<i class="fa-regular fa-copy"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button class="primary-btn close-token-modal" style="width: 100%; margin-top: 20px;">
|
||||
Entendido
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="toast" class="toast">Notificação</div>
|
||||
|
||||
<script src="admin-clinics.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,238 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Configurações
|
||||
const API_URL = '/api/admin/clinics';
|
||||
|
||||
// Pegar Token JWT do Admin (salvo no localStorage ou cookies)
|
||||
// Assumindo que a sessão já está lidada por cookies ou podemos buscar da rota,
|
||||
// mas usaremos credenciais padrão do fetch se usar cookie de sessão.
|
||||
// Se usar JWT localStorage:
|
||||
const token = localStorage.getItem('token') || '';
|
||||
|
||||
const fetchOptions = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
};
|
||||
|
||||
// Elementos UI
|
||||
const clinicsTableBody = document.getElementById('clinicsTableBody');
|
||||
const addClinicBtn = document.getElementById('addClinicBtn');
|
||||
const clinicModal = document.getElementById('clinicModal');
|
||||
const tokenModal = document.getElementById('tokenModal');
|
||||
const closeModals = document.querySelectorAll('.close-modal');
|
||||
const closeTokenModal = document.querySelector('.close-token-modal');
|
||||
const clinicForm = document.getElementById('clinicForm');
|
||||
const generatedTokenElem = document.getElementById('generatedToken');
|
||||
const copyTokenBtn = document.getElementById('copyTokenBtn');
|
||||
|
||||
// Stats
|
||||
const totalDevicesElem = document.getElementById('totalDevices');
|
||||
const activeDevicesElem = document.getElementById('activeDevices');
|
||||
const blockedDevicesElem = document.getElementById('blockedDevices');
|
||||
|
||||
// Inicializar
|
||||
loadClinics();
|
||||
|
||||
// ==========================================
|
||||
// Carregar Clínicas
|
||||
// ==========================================
|
||||
async function loadClinics() {
|
||||
try {
|
||||
const response = await fetch(API_URL, fetchOptions);
|
||||
if (!response.ok) {
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
window.location.href = '/login';
|
||||
return;
|
||||
}
|
||||
throw new Error('Falha ao buscar clínicas');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
if (data.success) {
|
||||
renderClinics(data.clinics);
|
||||
updateStats(data.clinics);
|
||||
} else {
|
||||
showToast(data.message, 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
clinicsTableBody.innerHTML = `<tr><td colspan="7" style="text-align:center;color:red;">Erro ao carregar dados.</td></tr>`;
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// Renderizar Tabela
|
||||
// ==========================================
|
||||
function renderClinics(clinics) {
|
||||
if (clinics.length === 0) {
|
||||
clinicsTableBody.innerHTML = `<tr><td colspan="7" style="text-align:center;padding:30px;color:#a0aec0;">Nenhum dispositivo cadastrado.</td></tr>`;
|
||||
return;
|
||||
}
|
||||
|
||||
clinicsTableBody.innerHTML = '';
|
||||
clinics.forEach(c => {
|
||||
const isAct = c.is_active;
|
||||
const statusClass = isAct ? 'status-active' : 'status-inactive';
|
||||
const statusIcon = isAct ? 'fa-check' : 'fa-ban';
|
||||
const statusText = isAct ? 'Ativo' : 'Bloqueado';
|
||||
|
||||
const tr = document.createElement('tr');
|
||||
tr.innerHTML = `
|
||||
<td><span class="status-badge ${statusClass}"><i class="fa-solid ${statusIcon}"></i> ${statusText}</span></td>
|
||||
<td><strong>${c.clinic_name}</strong></td>
|
||||
<td><i class="fa-solid fa-desktop" style="color:#a0aec0;margin-right:6px"></i>${c.pc_name || '-'}</td>
|
||||
<td>${c.email}</td>
|
||||
<td>${c.last_ip || 'Nunca conectou'}</td>
|
||||
<td><span class="token-blur" title="Clique para copiar" onclick="navigator.clipboard.writeText('${c.machine_token}');showToast('Token copiado!')">${c.machine_token.split('-')[0]}...</span></td>
|
||||
<td>
|
||||
<div style="display:flex;gap:12px;align-items:center;">
|
||||
<label class="toggle-switch" title="${isAct ? 'Bloquear Acesso' : 'Ativar Acesso'}">
|
||||
<input type="checkbox" ${isAct ? 'checked' : ''} onchange="toggleStatus(${c.id}, this.checked)">
|
||||
<span class="slider"></span>
|
||||
</label>
|
||||
<button class="icon-btn delete" onclick="deleteClinic(${c.id})" title="Excluir">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
`;
|
||||
clinicsTableBody.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
function updateStats(clinics) {
|
||||
const total = clinics.length;
|
||||
const active = clinics.filter(c => c.is_active).length;
|
||||
const blocked = total - active;
|
||||
|
||||
totalDevicesElem.textContent = total;
|
||||
activeDevicesElem.textContent = active;
|
||||
blockedDevicesElem.textContent = blocked;
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// Cadastrar Clínica
|
||||
// ==========================================
|
||||
clinicForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Salvando...';
|
||||
|
||||
const formData = new FormData(clinicForm);
|
||||
const bodyData = Object.fromEntries(formData.entries());
|
||||
|
||||
try {
|
||||
const response = await fetch(API_URL, {
|
||||
method: 'POST',
|
||||
headers: fetchOptions.headers,
|
||||
body: JSON.stringify(bodyData)
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
clinicModal.classList.remove('active');
|
||||
clinicForm.reset();
|
||||
loadClinics();
|
||||
|
||||
// Show Token Modal
|
||||
generatedTokenElem.textContent = data.machine_token;
|
||||
tokenModal.classList.add('active');
|
||||
} else {
|
||||
showToast(data.message, 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showToast('Erro de conexão ao salvar', 'error');
|
||||
} finally {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.innerHTML = '<i class="fa-solid fa-check"></i> Salvar e Gerar Token';
|
||||
}
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
// Toggle Status
|
||||
// ==========================================
|
||||
window.toggleStatus = async (id, isActive) => {
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/${id}/status`, {
|
||||
method: 'PUT',
|
||||
headers: fetchOptions.headers,
|
||||
body: JSON.stringify({ is_active: isActive })
|
||||
});
|
||||
const data = await response.json();
|
||||
if(data.success) {
|
||||
showToast(isActive ? 'Dispositivo Ativado' : 'Dispositivo Bloqueado', 'success');
|
||||
loadClinics();
|
||||
} else {
|
||||
showToast(data.message, 'error');
|
||||
loadClinics(); // revert UI
|
||||
}
|
||||
} catch (error) {
|
||||
showToast('Erro ao alterar status', 'error');
|
||||
loadClinics();
|
||||
}
|
||||
};
|
||||
|
||||
// ==========================================
|
||||
// Deletar
|
||||
// ==========================================
|
||||
window.deleteClinic = async (id) => {
|
||||
if(!confirm('Tem certeza que deseja excluir este dispositivo permanentemente? O Desktop perderá acesso instantaneamente.')) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: fetchOptions.headers
|
||||
});
|
||||
const data = await response.json();
|
||||
if(data.success) {
|
||||
showToast('Dispositivo removido', 'success');
|
||||
loadClinics();
|
||||
} else {
|
||||
showToast(data.message, 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showToast('Erro ao excluir', 'error');
|
||||
}
|
||||
};
|
||||
|
||||
// ==========================================
|
||||
// UI Actions (Modals, Copy, Logout)
|
||||
// ==========================================
|
||||
addClinicBtn.addEventListener('click', () => clinicModal.classList.add('active'));
|
||||
|
||||
closeModals.forEach(btn => btn.addEventListener('click', () => {
|
||||
clinicModal.classList.remove('active');
|
||||
}));
|
||||
|
||||
closeTokenModal.addEventListener('click', () => {
|
||||
tokenModal.classList.remove('active');
|
||||
});
|
||||
|
||||
copyTokenBtn.addEventListener('click', () => {
|
||||
navigator.clipboard.writeText(generatedTokenElem.textContent).then(() => {
|
||||
showToast('Token copiado com sucesso!', 'success');
|
||||
copyTokenBtn.innerHTML = '<i class="fa-solid fa-check" style="color:var(--success)"></i>';
|
||||
setTimeout(() => {
|
||||
copyTokenBtn.innerHTML = '<i class="fa-regular fa-copy"></i>';
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('logoutBtn').addEventListener('click', () => {
|
||||
localStorage.removeItem('token');
|
||||
window.location.href = '/login';
|
||||
});
|
||||
|
||||
function showToast(message, type = 'success') {
|
||||
const toast = document.getElementById('toast');
|
||||
toast.textContent = message;
|
||||
toast.className = `toast show ${type}`;
|
||||
|
||||
setTimeout(() => {
|
||||
toast.className = 'toast';
|
||||
}, 3000);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user