Skip to content

Commit

Permalink
CONCD-996 'All' option in the Campaign status dropdown to allow users…
Browse files Browse the repository at this point in the history
… to get back to that option after selecting others.
  • Loading branch information
rasarkar committed Jan 7, 2025
1 parent 181339b commit 4c01b3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ <h1>Completed Campaigns</h1>
<div class="d-flex align-items-center ms-3 mt-2">
<label for="campaign-type" class="pe-1">Campaign Status</label>
<select id="campaign-type">
<option value="completed"{% if request.GET.type != 'retired' %} selected{% endif %}>Completed</option>
<option value="all"{% if 'type' not in request.GET %} selected{%endif %}>All</option>
<option value="completed"{% if request.GET.type == 'completed' %} selected{% endif %}>Completed</option>
<option value="retired"{% if request.GET.type == 'retired' %} selected{% endif %}>Retired</option>
</select>
<a class="btn btn-primary" onclick="toggleCampaignType();" type="submit">Go</a>
Expand Down Expand Up @@ -125,7 +126,11 @@ <h1>Completed Campaigns</h1>
var toggleCampaignType = function(form) {
let url = new URL(window.location.href);
let typeValue = document.getElementById('campaign-type').value;
url.searchParams.set("type", encodeURIComponent(typeValue));
if (typeValue == "all") {
url.searchParams.delete("type");
} else {
url.searchParams.set("type", encodeURIComponent(typeValue));
}
window.location.href = url;
}

Expand Down
9 changes: 7 additions & 2 deletions concordia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,16 @@ class CompletedCampaignListView(APIListView):
template_name = "transcriptions/campaign_list_small_blocks.html"

def _get_all_campaigns(self):
if self.request.GET.get("type", "completed") == "retired":
campaignType = self.request.GET.get("type", None)
campaigns = Campaign.objects.published().listed()
if campaignType is None:
return campaigns
elif campaignType == "retired":
status = Campaign.Status.RETIRED
else:
status = Campaign.Status.COMPLETED
return Campaign.objects.published().listed().filter(status=status)

return campaigns.filter(status=status)

def get_queryset(self):
campaigns = self._get_all_campaigns()
Expand Down

0 comments on commit 4c01b3f

Please sign in to comment.