Add support for filtering domains by 'available' and 'error' status

Extended the domain filtering logic and UI to allow filtering by 'available' and 'error' statuses. Updated the Domain model to handle these new filters and adjusted the dashboard to include global stats, including inactive domains.
This commit is contained in:
Hosteroid
2025-10-20 12:43:51 +03:00
parent 5281cec031
commit 6b9e4b1d23
3 changed files with 23 additions and 0 deletions

View File

@@ -43,9 +43,13 @@ class DashboardController extends Controller
// Format domains for display
$formattedRecentDomains = \App\Helpers\DomainHelper::formatMultiple($recentDomains);
$formattedExpiringDomains = \App\Helpers\DomainHelper::formatMultiple($expiringThisMonth);
// Get global stats for dashboard cards
$globalStats = \App\Helpers\LayoutHelper::getGlobalStats();
$this->view('dashboard/index', [
'stats' => $stats,
'globalStats' => $globalStats,
'recentDomains' => $formattedRecentDomains,
'expiringThisMonth' => $formattedExpiringDomains,
'expiringCount' => count($allExpiringDomains),

View File

@@ -127,6 +127,7 @@ class Domain extends Model
'inactive' => 0,
];
// Get status counts for active domains only
$sql = "SELECT status, COUNT(*) as count FROM domains WHERE is_active = 1 GROUP BY status";
$stmt = $this->db->query($sql);
$results = $stmt->fetchAll();
@@ -137,6 +138,14 @@ class Domain extends Model
$stats[strtolower($row['status'])] = $row['count'];
}
// Get count of inactive domains (is_active = 0)
$inactiveStmt = $this->db->query("SELECT COUNT(*) as count FROM domains WHERE is_active = 0");
$inactiveResult = $inactiveStmt->fetch();
$stats['inactive'] = $inactiveResult['count'] ?? 0;
// Add inactive count to total
$stats['total'] += $stats['inactive'];
return $stats;
}
@@ -167,6 +176,14 @@ class Domain extends Model
}
return false;
}
// Handle inactive filter (based on is_active field)
if ($filters['status'] === 'inactive') {
return $domain['is_active'] == 0;
}
// Handle available and error status filters
if ($filters['status'] === 'available' || $filters['status'] === 'error') {
return $domain['status'] === $filters['status'];
}
return $domain['status'] === $filters['status'];
});
}

View File

@@ -68,6 +68,8 @@ $currentFilters = $filters ?? ['search' => '', 'status' => '', 'group' => '', 's
<option value="">All Statuses</option>
<option value="active" <?= $currentFilters['status'] === 'active' ? 'selected' : '' ?>>Active</option>
<option value="expiring_soon" <?= $currentFilters['status'] === 'expiring_soon' ? 'selected' : '' ?>>Expiring Soon</option>
<option value="available" <?= $currentFilters['status'] === 'available' ? 'selected' : '' ?>>Available</option>
<option value="error" <?= $currentFilters['status'] === 'error' ? 'selected' : '' ?>>Error</option>
<option value="inactive" <?= $currentFilters['status'] === 'inactive' ? 'selected' : '' ?>>Inactive</option>
</select>
</div>