Skip to content

Commit c42d4c9

Browse files
committed
Add 'all challenges' option to badges report
1 parent 68e5804 commit c42d4c9

8 files changed

Lines changed: 57 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
3333
- Validation of aria-describedby attributes when using data validation
3434
- JavaScript fix to support improved accessibility for TomSelect
3535
- Color contrast calculations to ensure accessibility compliance
36+
- Option to badge report to just run for all challenges
3637

3738
## Changed
3839

src/GRA.Controllers/MissionControl/ReportingController.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,19 @@ public async Task<IActionResult> Run(ReportCriteriaViewModel viewModel)
383383

384384
var siteId = GetCurrentSiteId();
385385

386+
var challenges = viewModel.ChallengeRequiredList;
387+
388+
if (viewModel.AllChallenges)
389+
{
390+
var challengeIds = await _challengeService.GetAllIdsAsync(siteId);
391+
challenges = string.Join(',', challengeIds);
392+
}
393+
386394
var criterion = new ReportCriterion
387395
{
388396
BadgeRequiredList = viewModel.BadgeRequiredList,
389397
BranchId = viewModel.BranchId,
390-
ChallengeRequiredList = viewModel.ChallengeRequiredList,
398+
ChallengeRequiredList = challenges,
391399
EndDate = viewModel.EndDate,
392400
GroupInfoId = viewModel.GroupInfoId,
393401
IncludeAchieverStatus = viewModel.IncludeAchieverStatus,

src/GRA.Controllers/ViewModel/MissionControl/Reporting/ReportCriteriaViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class ReportCriteriaViewModel
1414
public int? BranchId { get; set; }
1515

1616
public SelectList BranchList { get; set; }
17+
public bool AllChallenges { get; set; }
1718
public string ChallengeRequiredList { get; set; }
1819

1920
[DisplayName("End Date")]

src/GRA.Data/Repository/ChallengeRepository.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ public async Task<Challenge> GetActiveByIdAsync(int id, int? userId = null)
115115
return challenge;
116116
}
117117

118+
public async Task<IEnumerable<int>> GetAllIdsAsync(int siteId)
119+
{
120+
return await DbSet
121+
.AsNoTracking()
122+
.Where(_ => !_.IsDeleted && _.SiteId == siteId)
123+
.Select(_ => _.Id)
124+
.ToListAsync();
125+
}
126+
118127
public new async Task<Challenge> GetByIdAsync(int id)
119128
{
120129
var challenge = await DbSet

src/GRA.Domain.Repository/IChallengeRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Task<List<Challenge>> GetByIdsAsync(int siteId, IEnumerable<int> ids,
1616

1717
Task<int> GetChallengeCountAsync(ChallengeFilter filter);
1818

19+
Task<IEnumerable<int>> GetAllIdsAsync(int siteId);
20+
1921
Task<IEnumerable<ChallengeTask>> GetChallengeTasksAsync(int challengeId, int? userId);
2022

2123
Task<IEnumerable<string>> GetNamesAsync(IEnumerable<int> challengeIds);

src/GRA.Domain.Service/ChallengeService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ public async Task<ChallengeGroup> GetGroupByIdAsync(int id)
473473
return challengeGroup;
474474
}
475475

476+
public async Task<IEnumerable<int>> GetAllIdsAsync(int siteId)
477+
{
478+
return await _challengeRepository.GetAllIdsAsync(siteId);
479+
}
480+
476481
public async Task<ICollection<ChallengeGroup>> GetGroupListAsync()
477482
{
478483
VerifyPermission(Permission.ViewAllChallenges);

src/GRA.Web/Areas/MissionControl/Views/Reporting/BadgeCriteria.cshtml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
<div class="row mt-4">
5454
<div class="col-12">
5555
<div class="card">
56-
<div class="card-header bg-info-subtle">
56+
<div class="card-header bg-info-subtle" id="badgeCardHeader">
5757
<h3 class="card-title">Badges</h3>
5858
</div>
59-
<div class="card-body">
59+
<div class="card-body" id="badgeCardBody">
6060
<table class="table table-sm table-bordered table-striped">
6161
<thead>
6262
<tr>
@@ -118,6 +118,17 @@
118118
</div>
119119
</div>
120120

121+
<div class="row mt-4">
122+
<div class="col-12 lead">
123+
<input asp-for="AllChallenges"
124+
class="form-check-input me-1"
125+
type="checkbox">
126+
<label class="form-check-label" for="AllChallenges">
127+
Report on all Challenges only
128+
</label>
129+
</div>
130+
</div>
131+
121132
<div class="row mt-4">
122133
<div class="col-12">
123134
<button type="submit" class="btn btn-outline-primary">
@@ -208,6 +219,9 @@
208219
@section scripts
209220
{
210221
<script>
222+
const allChallenges = document.getElementById("AllChallenges");
223+
const badgeCardHeader = document.getElementById("badgeCardHeader");
224+
const badgeCardBody = document.getElementById("badgeCardBody");
211225
const badgeIds = $("#BadgeRequiredList").val().split(',').filter(function (x) { return x }).map(Number);
212226
const challengeIds = $("#ChallengeRequiredList").val().split(',').filter(function (x) { return x }).map(Number);
213227
const endDatePicker = graInitalizePickerDatetime(document.getElementById("endDatePicker"));
@@ -343,8 +357,20 @@
343357
defaultDateTime.setDate(defaultDateTime.getDate() - 1);
344358
graPickerSetDate(startDatePicker, defaultDateTime);
345359
360+
allChallenges.addEventListener("input", (event) => {
361+
if(event.target.checked === true) {
362+
badgeCardHeader.classList.add("bg-secondary-subtle");
363+
badgeCardHeader.classList.remove("bg-info-subtle");
364+
badgeCardBody.classList.add("d-none");
365+
} else {
366+
badgeCardHeader.classList.add("bg-info-subtle");
367+
badgeCardHeader.classList.remove("bg-secondary-subtle");
368+
badgeCardBody.classList.remove("d-none");
369+
}
370+
});
371+
346372
$("form").on("submit", function (e) {
347-
if (badgeIds.length == 0 && challengeIds.length == 0) {
373+
if (badgeIds.length == 0 && challengeIds.length == 0 && allChallenges.checked !== true) {
348374
e.preventDefault();
349375
alert("Please select which badges to report on.");
350376
}

src/GRA.Web/GRA.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Company>Maricopa County Library District</Company>
99
<Copyright>Copyright 2017 Maricopa County Library District</Copyright>
1010
<Description>The Great Reading Adventure is an open-source tool for managing dynamic library reading programs.</Description>
11-
<FileVersion>4.6.1.158</FileVersion>
11+
<FileVersion>4.6.1.159</FileVersion>
1212
<OutputType>Exe</OutputType>
1313
<PackageId>GRA.Web</PackageId>
1414
<PackageLicenseUrl>https://github.com/mcld/greatreadingadventure/blob/master/LICENSE</PackageLicenseUrl>

0 commit comments

Comments
 (0)