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