feat: Add 'Day Usage' column to user table
This commit is contained in:
@ -9,6 +9,7 @@ class User(BaseModel):
|
||||
traffic_used: str
|
||||
expiry_date: str
|
||||
expiry_days: str
|
||||
day_usage: str
|
||||
enable: bool
|
||||
unlimited_ip: bool
|
||||
online_count: int = 0
|
||||
@ -36,6 +37,7 @@ class User(BaseModel):
|
||||
'traffic_used': 'N/A',
|
||||
'expiry_date': 'N/A',
|
||||
'expiry_days': 'N/A',
|
||||
'day_usage': 'N/A',
|
||||
'enable': False,
|
||||
'unlimited_ip': False,
|
||||
'online_count': 0
|
||||
@ -44,20 +46,25 @@ class User(BaseModel):
|
||||
expiration_days = user_data.get('expiration_days', 0)
|
||||
creation_date_str = user_data.get("account_creation_date")
|
||||
|
||||
if not creation_date_str:
|
||||
display_expiry_days = "On-hold"
|
||||
display_expiry_date = "On-hold"
|
||||
elif expiration_days <= 0:
|
||||
display_expiry_days = "Unlimited"
|
||||
display_expiry_date = "Unlimited"
|
||||
else:
|
||||
display_expiry_days = str(expiration_days)
|
||||
day_usage = "On-hold"
|
||||
display_expiry_days = "On-hold"
|
||||
display_expiry_date = "On-hold"
|
||||
|
||||
if creation_date_str:
|
||||
try:
|
||||
creation_date = datetime.strptime(creation_date_str, "%Y-%m-%d")
|
||||
expiry_dt_obj = creation_date + timedelta(days=expiration_days)
|
||||
display_expiry_date = expiry_dt_obj.strftime("%Y-%m-%d")
|
||||
day_usage = str((datetime.now() - creation_date).days)
|
||||
|
||||
if expiration_days <= 0:
|
||||
display_expiry_days = "Unlimited"
|
||||
display_expiry_date = "Unlimited"
|
||||
else:
|
||||
display_expiry_days = str(expiration_days)
|
||||
expiry_dt_obj = creation_date + timedelta(days=expiration_days)
|
||||
display_expiry_date = expiry_dt_obj.strftime("%Y-%m-%d")
|
||||
except (ValueError, TypeError):
|
||||
display_expiry_date = "Error"
|
||||
day_usage = "Error"
|
||||
|
||||
used_bytes = user_data.get("download_bytes", 0) + user_data.get("upload_bytes", 0)
|
||||
quota_bytes = user_data.get('max_download_bytes', 0)
|
||||
@ -78,6 +85,7 @@ class User(BaseModel):
|
||||
'traffic_used': traffic_used_display,
|
||||
'expiry_date': display_expiry_date,
|
||||
'expiry_days': display_expiry_days,
|
||||
'day_usage': day_usage,
|
||||
'enable': not user_data.get('blocked', False),
|
||||
'unlimited_ip': user_data.get('unlimited_user', False),
|
||||
'online_count': user_data.get('online_count', 0)
|
||||
|
||||
@ -83,6 +83,7 @@
|
||||
<th>Traffic Usage</th>
|
||||
<th class="text-nowrap">Expiry Date</th>
|
||||
<th class="text-nowrap">Expiry Days</th>
|
||||
<th class="text-nowrap">Day Usage</th>
|
||||
<th>Enable</th>
|
||||
<th class="text-nowrap requires-iplimit-service" style="display: none;">Unlimited IP</th>
|
||||
<th class="text-nowrap">Configs</th>
|
||||
@ -116,6 +117,7 @@
|
||||
<td>{{ user.traffic_used }}</td>
|
||||
<td>{{ user.expiry_date }}</td>
|
||||
<td>{{ user.expiry_days }}</td>
|
||||
<td>{{ user.day_usage }}</td>
|
||||
<td>
|
||||
{% if user.enable %}
|
||||
<i class="fas fa-check-circle text-success"></i>
|
||||
@ -381,8 +383,8 @@
|
||||
switch (filter) {
|
||||
case "on-hold": showRow = $(this).find("td:eq(2) i").hasClass("text-warning"); break;
|
||||
case "online": showRow = $(this).find("td:eq(2) i").hasClass("text-success"); break;
|
||||
case "enable": showRow = $(this).find("td:eq(7) i").hasClass("text-success"); break;
|
||||
case "disable": showRow = $(this).find("td:eq(7) i").hasClass("text-danger"); break;
|
||||
case "enable": showRow = $(this).find("td:eq(8) i").hasClass("text-success"); break;
|
||||
case "disable": showRow = $(this).find("td:eq(8) i").hasClass("text-danger"); break;
|
||||
default: showRow = true;
|
||||
}
|
||||
$(this).toggle(showRow).find(".user-checkbox").prop("checked", false);
|
||||
@ -463,7 +465,7 @@
|
||||
$("#editUsername").val(user);
|
||||
$("#editTrafficLimit").val(parseFloat(trafficText.split('/')[1]) || 0);
|
||||
$("#editExpirationDays").val(parseInt(expiryText) || 0);
|
||||
$("#editBlocked").prop("checked", !row.find("td:eq(7) i").hasClass("text-success"));
|
||||
$("#editBlocked").prop("checked", !row.find("td:eq(8) i").hasClass("text-success"));
|
||||
$("#editUnlimitedIp").prop("checked", row.find(".unlimited-ip-cell i").hasClass("text-primary"));
|
||||
validateUsername('#editUsername', '#editUsernameError');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user