add bucket quota
This commit is contained in:
@@ -135,6 +135,7 @@ templ S3Buckets(data dash.S3BucketsData) {
|
||||
<th>Created</th>
|
||||
<th>Objects</th>
|
||||
<th>Size</th>
|
||||
<th>Quota</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
@@ -152,6 +153,24 @@ templ S3Buckets(data dash.S3BucketsData) {
|
||||
<td>{bucket.CreatedAt.Format("2006-01-02 15:04")}</td>
|
||||
<td>{fmt.Sprintf("%d", bucket.ObjectCount)}</td>
|
||||
<td>{formatBytes(bucket.Size)}</td>
|
||||
<td>
|
||||
if bucket.Quota > 0 {
|
||||
<div>
|
||||
<span class={fmt.Sprintf("badge bg-%s", getQuotaStatusColor(bucket.Size, bucket.Quota, bucket.QuotaEnabled))}>
|
||||
{formatBytes(bucket.Quota)}
|
||||
</span>
|
||||
if bucket.QuotaEnabled {
|
||||
<div class="small text-muted">
|
||||
{fmt.Sprintf("%.1f%% used", float64(bucket.Size)/float64(bucket.Quota)*100)}
|
||||
</div>
|
||||
} else {
|
||||
<div class="small text-muted">Disabled</div>
|
||||
}
|
||||
</div>
|
||||
} else {
|
||||
<span class="text-muted">No quota</span>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<span class={fmt.Sprintf("badge bg-%s", getBucketStatusColor(bucket.Status))}>
|
||||
{bucket.Status}
|
||||
@@ -169,6 +188,14 @@ templ S3Buckets(data dash.S3BucketsData) {
|
||||
title="View Details">
|
||||
<i class="fas fa-eye"></i>
|
||||
</a>
|
||||
<button type="button"
|
||||
class="btn btn-outline-warning btn-sm quota-btn"
|
||||
data-bucket-name={bucket.Name}
|
||||
data-current-quota={fmt.Sprintf("%d", getQuotaInMB(bucket.Quota))}
|
||||
data-quota-enabled={fmt.Sprintf("%t", bucket.QuotaEnabled)}
|
||||
title="Manage Quota">
|
||||
<i class="fas fa-tachometer-alt"></i>
|
||||
</button>
|
||||
<button type="button"
|
||||
class="btn btn-outline-danger btn-sm delete-bucket-btn"
|
||||
data-bucket-name={bucket.Name}
|
||||
@@ -181,7 +208,7 @@ templ S3Buckets(data dash.S3BucketsData) {
|
||||
}
|
||||
if len(data.Buckets) == 0 {
|
||||
<tr>
|
||||
<td colspan="6" class="text-center text-muted py-4">
|
||||
<td colspan="7" class="text-center text-muted py-4">
|
||||
<i class="fas fa-cube fa-3x mb-3 text-muted"></i>
|
||||
<div>
|
||||
<h5>No Object Store buckets found</h5>
|
||||
@@ -236,6 +263,36 @@ templ S3Buckets(data dash.S3BucketsData) {
|
||||
Bucket names must be between 3 and 63 characters, contain only lowercase letters, numbers, dots, and hyphens.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="enableQuota" name="quota_enabled">
|
||||
<label class="form-check-label" for="enableQuota">
|
||||
Enable Storage Quota
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3" id="quotaSettings" style="display: none;">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<label for="quotaSize" class="form-label">Quota Size</label>
|
||||
<input type="number" class="form-control" id="quotaSize" name="quota_size"
|
||||
placeholder="1024" min="1" step="1">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label for="quotaUnit" class="form-label">Unit</label>
|
||||
<select class="form-select" id="quotaUnit" name="quota_unit">
|
||||
<option value="MB" selected>MB</option>
|
||||
<option value="GB">GB</option>
|
||||
<option value="TB">TB</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-text">
|
||||
Set the maximum storage size for this bucket.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -275,6 +332,64 @@ templ S3Buckets(data dash.S3BucketsData) {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Manage Quota Modal -->
|
||||
<div class="modal fade" id="manageQuotaModal" tabindex="-1" aria-labelledby="manageQuotaModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="manageQuotaModalLabel">
|
||||
<i class="fas fa-tachometer-alt me-2"></i>Manage Bucket Quota
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form id="quotaForm">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Bucket Name</label>
|
||||
<input type="text" class="form-control" id="quotaBucketName" readonly>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="quotaEnabled" name="quota_enabled">
|
||||
<label class="form-check-label" for="quotaEnabled">
|
||||
Enable Storage Quota
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3" id="quotaSizeSettings">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<label for="quotaSizeMB" class="form-label">Quota Size</label>
|
||||
<input type="number" class="form-control" id="quotaSizeMB" name="quota_size"
|
||||
placeholder="1024" min="0" step="1">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label for="quotaUnitMB" class="form-label">Unit</label>
|
||||
<select class="form-select" id="quotaUnitMB" name="quota_unit">
|
||||
<option value="MB" selected>MB</option>
|
||||
<option value="GB">GB</option>
|
||||
<option value="TB">TB</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-text">
|
||||
Set the maximum storage size for this bucket. Set to 0 to remove quota.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-warning">
|
||||
<i class="fas fa-save me-1"></i>Update Quota
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
// Helper functions for template
|
||||
@@ -299,4 +414,26 @@ func countActiveBuckets(buckets []dash.S3Bucket) int {
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func getQuotaStatusColor(used, quota int64, enabled bool) string {
|
||||
if !enabled || quota <= 0 {
|
||||
return "secondary"
|
||||
}
|
||||
|
||||
percentage := float64(used) / float64(quota) * 100
|
||||
if percentage >= 90 {
|
||||
return "danger"
|
||||
} else if percentage >= 75 {
|
||||
return "warning"
|
||||
} else {
|
||||
return "success"
|
||||
}
|
||||
}
|
||||
|
||||
func getQuotaInMB(quotaBytes int64) int64 {
|
||||
if quotaBytes < 0 {
|
||||
quotaBytes = -quotaBytes // Handle disabled quotas (negative values)
|
||||
}
|
||||
return quotaBytes / (1024 * 1024)
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user