Skip to content

Commit defeab3

Browse files
Instead of showing "calls made", display "Unlimited"
Now when any field in the `RedisCallLimitJson` case class is missing (e.g., `per_month: None`): 1. **Instead of showing "calls made"**, it will display **"Unlimited"** 2. **Instead of showing "Resets in X seconds"**, that line will be **completely omitted** 3. The auto-refresh functionality will also properly handle missing fields This works for both the initial page load and the AJAX-based auto-refresh functionality, ensuring consistent behavior across the entire user interface.
1 parent e8c09f0 commit defeab3

1 file changed

Lines changed: 31 additions & 26 deletions

File tree

apimanager/consumers/templates/consumers/detail.html

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -194,33 +194,33 @@ <h2>{% trans "Current Usage" %}
194194
<div class="row" id="usageStatsRow">
195195
<div class="col-xs-6 col-sm-2" data-period="per_second">
196196
<strong>{% trans "Per Second" %}</strong><br>
197-
<span class="text-info usage-calls">{% if current_usage.per_second.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_second.calls_made }} calls made{% endif %}</span><br>
198-
<small class="text-muted usage-reset">{% if current_usage.per_second.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_second.reset_in_seconds }} seconds{% endif %}</small>
197+
<span class="text-info usage-calls">{% if not current_usage.per_second %}Unlimited{% elif current_usage.per_second.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_second.calls_made }} calls made{% endif %}</span><br>
198+
{% if current_usage.per_second %}<small class="text-muted usage-reset">{% if current_usage.per_second.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_second.reset_in_seconds }} seconds{% endif %}</small>{% endif %}
199199
</div>
200200
<div class="col-xs-6 col-sm-2" data-period="per_minute">
201201
<strong>{% trans "Per Minute" %}</strong><br>
202-
<span class="text-info usage-calls">{% if current_usage.per_minute.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_minute.calls_made }} calls made{% endif %}</span><br>
203-
<small class="text-muted usage-reset">{% if current_usage.per_minute.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_minute.reset_in_seconds }} seconds{% endif %}</small>
202+
<span class="text-info usage-calls">{% if not current_usage.per_minute %}Unlimited{% elif current_usage.per_minute.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_minute.calls_made }} calls made{% endif %}</span><br>
203+
{% if current_usage.per_minute %}<small class="text-muted usage-reset">{% if current_usage.per_minute.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_minute.reset_in_seconds }} seconds{% endif %}</small>{% endif %}
204204
</div>
205205
<div class="col-xs-6 col-sm-2" data-period="per_hour">
206206
<strong>{% trans "Per Hour" %}</strong><br>
207-
<span class="text-info usage-calls">{% if current_usage.per_hour.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_hour.calls_made }} calls made{% endif %}</span><br>
208-
<small class="text-muted usage-reset">{% if current_usage.per_hour.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_hour.reset_in_seconds }} seconds{% endif %}</small>
207+
<span class="text-info usage-calls">{% if not current_usage.per_hour %}Unlimited{% elif current_usage.per_hour.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_hour.calls_made }} calls made{% endif %}</span><br>
208+
{% if current_usage.per_hour %}<small class="text-muted usage-reset">{% if current_usage.per_hour.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_hour.reset_in_seconds }} seconds{% endif %}</small>{% endif %}
209209
</div>
210210
<div class="col-xs-6 col-sm-2" data-period="per_day">
211211
<strong>{% trans "Per Day" %}</strong><br>
212-
<span class="text-info usage-calls">{% if current_usage.per_day.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_day.calls_made }} calls made{% endif %}</span><br>
213-
<small class="text-muted usage-reset">{% if current_usage.per_day.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_day.reset_in_seconds }} seconds{% endif %}</small>
212+
<span class="text-info usage-calls">{% if not current_usage.per_day %}Unlimited{% elif current_usage.per_day.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_day.calls_made }} calls made{% endif %}</span><br>
213+
{% if current_usage.per_day %}<small class="text-muted usage-reset">{% if current_usage.per_day.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_day.reset_in_seconds }} seconds{% endif %}</small>{% endif %}
214214
</div>
215215
<div class="col-xs-6 col-sm-2" data-period="per_week">
216216
<strong>{% trans "Per Week" %}</strong><br>
217-
<span class="text-info usage-calls">{% if current_usage.per_week.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_week.calls_made }} calls made{% endif %}</span><br>
218-
<small class="text-muted usage-reset">{% if current_usage.per_week.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_week.reset_in_seconds }} seconds{% endif %}</small>
217+
<span class="text-info usage-calls">{% if not current_usage.per_week %}Unlimited{% elif current_usage.per_week.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_week.calls_made }} calls made{% endif %}</span><br>
218+
{% if current_usage.per_week %}<small class="text-muted usage-reset">{% if current_usage.per_week.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_week.reset_in_seconds }} seconds{% endif %}</small>{% endif %}
219219
</div>
220220
<div class="col-xs-6 col-sm-2" data-period="per_month">
221221
<strong>{% trans "Per Month" %}</strong><br>
222-
<span class="text-info usage-calls">{% if current_usage.per_month.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_month.calls_made }} calls made{% endif %}</span><br>
223-
<small class="text-muted usage-reset">{% if current_usage.per_month.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_month.reset_in_seconds }} seconds{% endif %}</small>
222+
<span class="text-info usage-calls">{% if not current_usage.per_month %}Unlimited{% elif current_usage.per_month.calls_made|add:"0" == -1 %}Not tracked{% else %}{{ current_usage.per_month.calls_made }} calls made{% endif %}</span><br>
223+
{% if current_usage.per_month %}<small class="text-muted usage-reset">{% if current_usage.per_month.reset_in_seconds|add:"0" == -1 %}Not tracked{% else %}Resets in {{ current_usage.per_month.reset_in_seconds }} seconds{% endif %}</small>{% endif %}
224224
</div>
225225
</div>
226226
<div id="refreshProgress" class="progress" style="display: none; margin-top: 15px;">
@@ -572,23 +572,23 @@ <h2>{% trans "Current Usage" %}
572572

573573
periods.forEach(function(period) {
574574
const periodData = data[period];
575-
if (periodData) {
576-
const periodDiv = document.querySelector('[data-period="' + period + '"]');
577-
if (periodDiv) {
578-
const callsSpan = periodDiv.querySelector('.usage-calls');
579-
const resetSpan = periodDiv.querySelector('.usage-reset');
575+
const periodDiv = document.querySelector('[data-period="' + period + '"]');
576+
if (periodDiv) {
577+
const callsSpan = periodDiv.querySelector('.usage-calls');
578+
const resetSpan = periodDiv.querySelector('.usage-reset');
580579

581-
if (callsSpan) {
582-
const oldCalls = callsSpan.textContent.match(/-?\d+/);
583-
const newCalls = periodData.calls_made;
584-
const displayCalls = newCalls === -1 ? 'Not tracked' : newCalls + ' calls made';
580+
if (callsSpan) {
581+
const oldCalls = callsSpan.textContent.match(/-?\d+/);
582+
const newCalls = periodData ? periodData.calls_made : null;
583+
const displayCalls = !periodData ? 'Unlimited' : (newCalls === -1 ? 'Not tracked' : newCalls + ' calls made');
585584

586-
// Check if calls increased
587-
const callsIncreased = oldCalls && parseInt(oldCalls[0]) < newCalls && newCalls !== -1;
585+
// Check if calls increased (only if periodData exists)
586+
const callsIncreased = periodData && oldCalls && parseInt(oldCalls[0]) < newCalls && newCalls !== -1;
588587

589-
callsSpan.textContent = displayCalls;
588+
callsSpan.textContent = displayCalls;
590589

591-
// Add visual feedback
590+
// Add visual feedback only if data is tracked
591+
if (periodData) {
592592
callsSpan.classList.add('updating');
593593
if (callsIncreased) {
594594
periodDiv.classList.add('data-updated');
@@ -607,15 +607,20 @@ <h2>{% trans "Current Usage" %}
607607
callsSpan.style.backgroundColor = '';
608608
}, 1000);
609609
}
610+
}
610611

611-
if (resetSpan) {
612+
if (resetSpan) {
613+
if (periodData) {
612614
const resetText = periodData.reset_in_seconds === -1 ? 'Not tracked' : 'Resets in ' + periodData.reset_in_seconds + ' seconds';
613615
resetSpan.textContent = resetText;
616+
resetSpan.style.display = 'block';
614617
// Add subtle animation to reset timer
615618
resetSpan.style.opacity = '0.7';
616619
setTimeout(function() {
617620
resetSpan.style.opacity = '1';
618621
}, 300);
622+
} else {
623+
resetSpan.style.display = 'none';
619624
}
620625
}
621626
}

0 commit comments

Comments
 (0)