Skip to content

Commit

Permalink
Merge pull request #1310 from ucdavis/JCS/GroupReport20230914
Browse files Browse the repository at this point in the history
Jcs/group report20230914
  • Loading branch information
jSylvestre authored Sep 14, 2023
2 parents 3abbf2c + 6df6382 commit ff14e04
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 15 deletions.
12 changes: 11 additions & 1 deletion Keas.Core/Domain/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ public string Name {
get {
return FirstName + " " + LastName;
}
}
}

[StringLength(256)]
[Display(Name = "Name")]
public string NameV2
{
get
{
return $"{LastName}, {FirstName}";
}
}

[Required]
[StringLength(256)]
Expand Down
14 changes: 14 additions & 0 deletions Keas.Mvc/Controllers/GroupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ public async Task<IActionResult> IncompleteDocumentsReport(int id)
return View(model);
}

public async Task<IActionResult> CompletedDocumentsReport(int id, DateTime? start = null, DateTime? end = null)
{
var group = await GetGroup(id);

if (group == null)
{
ErrorMessage = "Group not found or no access to Group";
return RedirectToAction("NoAccess", "Home");
}

var model = await _reportService.CompletedDocuments(group, start, end);
return View(model);
}

public async Task<IActionResult> PeopleLeavingWithAssets(int id)
{
var group = await GetGroup(id);
Expand Down
19 changes: 18 additions & 1 deletion Keas.Mvc/Models/ReportModels/CompletedDocsReportModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ public class CompletedDocsReportModel
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Display(Name = "End Created Date")]
public DateTime End { get; set; }
public List<Document> Docs {get;set;}

public Group Group { get; set; }

public CompletedDocsReportModelItem[] Items { get; set; }
}

public class CompletedDocsReportModelItem
{
public string PersonName { get; set; }
public string DocName { get; set; }
[DisplayFormat(DataFormatString = "{0:d}")]
public DateTime CreatedAt { get; set; }
[DisplayFormat(DataFormatString = "{0:d}")]
public DateTime? CompletedAt { get; set; }
public string TeamSlug { get; set; }
public string TeamName { get; set; }
public string DetailsLink { get; set; }

}
}
62 changes: 60 additions & 2 deletions Keas.Mvc/Services/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public interface IReportService
Task<List<InactiveSpaceReportModel>> InactiveSpaces(string teamSlug); //Not sure if this one can be done with a group

Task<CompletedDocsReportModel> CompletedDocuments(Team team, string teamSlug, DateTime? start, DateTime? end);
Task<CompletedDocsReportModel> CompletedDocuments(Group group, DateTime? start = null, DateTime? end = null);
}


Expand Down Expand Up @@ -412,9 +413,52 @@ public async Task<CompletedDocsReportModel> CompletedDocuments(Team team, string
end = end.Value.FromPacificTime().Date;
}

var docs = await _context.Documents.AsNoTracking().Include(a => a.Person).Where(a => a.TeamId == team.Id && a.Active && a.Person.Active && a.CreatedAt >= start && a.CreatedAt <= end && a.Status == "Completed").ToListAsync();

var model = new CompletedDocsReportModel { Start = start.Value.ToPacificTime().Date, End = end.Value.ToPacificTime().Date, Docs = docs };
var model = new CompletedDocsReportModel
{
Start = start.Value.ToPacificTime().Date,
End = end.Value.ToPacificTime().Date,
Items = await _context.Documents.AsNoTracking()
.Include(a => a.Person)
.Where(a => a.TeamId == team.Id && a.Active && a.Person.Active && a.CreatedAt >= start && a.CreatedAt <= end && a.Status == "Completed")
.Select(CompletedDocsProjection())
.ToArrayAsync()
};

return model;
}

public async Task<CompletedDocsReportModel> CompletedDocuments(Group group, DateTime? start = null, DateTime? end = null)
{
if (!start.HasValue)
{
start = DateTime.UtcNow.AddDays(-30).Date;
}
else
{
start = start.Value.FromPacificTime().Date;
}
if (!end.HasValue)
{
end = DateTime.UtcNow.AddDays(1).Date;
}
else
{
end = end.Value.FromPacificTime().Date;
}


var model = new CompletedDocsReportModel
{
Group = group,
Start = start.Value.ToPacificTime().Date,
End = end.Value.ToPacificTime().Date,
Items = await _context.Documents.AsNoTracking()
.Include(a => a.Team).Include(a => a.Person)
.Where(a => a.Team.Groups.Any(g => g.GroupId == group.Id) && a.Active && a.Person.Active && a.CreatedAt >= start && a.CreatedAt <= end && a.Status == "Completed")
.Select(CompletedDocsProjection())
.ToArrayAsync()
};

return model;
}
Expand Down Expand Up @@ -652,5 +696,19 @@ public Expression<Func<Workstation, ExpiringItemReportModel>> ExpiringWorkstatio
DetailsLink = $"/{a.Team.Slug}/spaces/details/{a.SpaceId}", //This is really only needed for the non group one?
};
}

public Expression<Func<Document, CompletedDocsReportModelItem>> CompletedDocsProjection()
{
return a => new CompletedDocsReportModelItem
{
PersonName = a.Person.NameV2,
DocName = a.Name,
CreatedAt = a.CreatedAt.ToPacificTime(),
CompletedAt = a.CompletedAt.ToPacificTime(),
TeamSlug = a.Team.Slug,
TeamName = a.Team.Name,
DetailsLink = $"/{a.Team.Slug}/people/details/{a.PersonId}",
};
}
}
}
107 changes: 107 additions & 0 deletions Keas.Mvc/Views/Group/CompletedDocumentsReport.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
@model Keas.Mvc.Models.ReportModels.CompletedDocsReportModel

@{
ViewData["Title"] = "Completed Documents";
}

<a asp-action="Index" asp-route-id="@Model.Group.Id" class="btn btn-link">Back to Group Home</a>

<div class="card documents-color">
<div class="card-header-documents">
<div class="card-head">
<h2>Group: @Model.Group.Name</h2>
<h3>Completed Documents</h3>
</div>
</div>
<div class="card-content">

<form asp-action="CompletedDocumentsReport" method="get">

<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="row align-items-end">
<div class="col-sm-4">
<h3>Filters</h3>
<div class="form-group">
<label asp-for="Start" class="control-label"></label>
<input asp-for="Start" class="form-control datepicker" />
<span asp-validation-for="Start" class="text-danger"></span>
<label asp-for="End" class="control-label"></label>
<input asp-for="End" class="form-control datepicker" />
<span asp-validation-for="End" class="text-danger"></span>
<div class="form-group">
<i class="fas fa-sync-alt fa-sm"></i><input type="submit" value="Refresh Report" class="btn btn-link" />
</div>
</div>
</div>
</div>

</form>

<br>
<br>

<table id="dtDocuments" class="table dataTable">
<thead>
<tr>
<th>
Person
</th>
<th>
Doc Name
</th>
<th>
Created
</th>
<th>
Completed
</th>
<th>
Team
</th>
<th>
Link
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Items)
{
<tr>
<td>@item.PersonName</td>
<td>@item.DocName</td>
<td>@Html.DisplayFor(a => item.CreatedAt)</td>
<td>@Html.DisplayFor(a => item.CompletedAt)</td>
<td>@item.TeamName</td>
<td>
<a href='@item.DetailsLink' target="_blank">Details</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>

@section Styles {
@await Html.PartialAsync("_ReportStylePartial")
}
@section Scripts {
@{
await Html.RenderPartialAsync("_ImportJS");
}

<script type="text/javascript">
$('.dataTable').DataTable({
"dom": 'lBfrtip',
"buttons": [
{ extend: 'copyHtml5' },
{ extend: 'excelHtml5' },
{ extend: 'csvHtml5' },
{ extend: 'print' },
],
"columnDefs": [
{ "type": "date", "targets": [2,3] }
]
});
</script>
}
5 changes: 4 additions & 1 deletion Keas.Mvc/Views/Group/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@
</div>

<div class="report-list documents-color col-md-3">
<h3><i class="fas fa-file-alt fa-xs"></i> Incomplete Documents Reports</h3>
<h3><i class="fas fa-file-alt fa-xs"></i> Documents Reports</h3>
<ul>
<li>
<a asp-action="IncompleteDocumentsReport" asp-route-id="@Model.Group.Id">View All Incomplete Docs <i class="fas fa-chevron-right fa-sm" aria-hidden="true"></i></a>
</li>
<li>
<a asp-action="CompletedDocumentsReport" asp-route-id="@Model.Group.Id">Completed Documents <i class="fas fa-chevron-right fa-sm" aria-hidden="true"></i></a>
</li>
</ul>
</div>

Expand Down
16 changes: 6 additions & 10 deletions Keas.Mvc/Views/Report/CompletedDocuments.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,15 @@
</tr>
</thead>
<tbody>
@foreach (var item in Model.Docs)
@foreach (var item in Model.Items)
{
<tr>
<td>@Html.DisplayFor(a=> item.Person.LastName), @Html.DisplayFor(a => item.Person.FirstName)</td>
<td>@Html.DisplayFor(a=> item.Name)</td>
<td>@item.PersonName</td>
<td>@item.DocName</td>
<td>@Html.DisplayFor(a => item.CreatedAt)</td>
<td>@Html.DisplayFor(a => item.CompletedAt)</td>
<td>
@item.CreatedAt.ToPacificTime().ToString("d")
</td>
<td>
@(item.CompletedAt.HasValue ? item.CompletedAt.Value.ToPacificTime().ToString("d") : null)
</td>
<td>
<a href='@string.Format("/{0}/{1}/details/{2}", TempData["TeamName"], "people", item.PersonId)' >Details</a>
<a href='@item.DetailsLink' target="_blank">Details</a>
</td>
</tr>
}
Expand Down
5 changes: 5 additions & 0 deletions Test/TestsDatabase/PersonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public void TestDatabaseFieldAttributes()
"[System.ComponentModel.DataAnnotations.DisplayAttribute(Name = \"Name\")]",
"[System.ComponentModel.DataAnnotations.StringLengthAttribute((Int32)256)]",
}));
expectedFields.Add(new NameAndType("NameV2", "System.String", new List<string>
{
"[System.ComponentModel.DataAnnotations.DisplayAttribute(Name = \"Name\")]",
"[System.ComponentModel.DataAnnotations.StringLengthAttribute((Int32)256)]",
}));
expectedFields.Add(new NameAndType("Notes", "System.String", new List<string>
{
"[System.ComponentModel.DataAnnotations.DataTypeAttribute((System.ComponentModel.DataAnnotations.DataType)9)]",
Expand Down

0 comments on commit ff14e04

Please sign in to comment.