Skip to content

Commit

Permalink
Left Menu 'Select All' created
Browse files Browse the repository at this point in the history
Merged all call for activities and presiders into a single BE call
  • Loading branch information
Timaqt authored and Timaqt committed Nov 22, 2024
1 parent 7944f22 commit b38207a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 145 deletions.
103 changes: 32 additions & 71 deletions api/Controllers/DashboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public DashboardController(LocationService locationService, JudicialCalendarServ
// [HttpGet("monthly-schedule/{year}/{month}")]
[HttpGet]
[Route("monthly-schedule/{year}/{month}")]
public async Task<ActionResult<IEnumerable<CalendarDay>>> GetMonthlySchedule(int year, int month, [FromQuery] string locationId = "")
public async Task<ActionResult<CalendarSchedule>> GetMonthlySchedule(int year, int month, [FromQuery] string locationId = "")
{
try
{
Expand All @@ -55,12 +55,41 @@ public async Task<ActionResult<IEnumerable<CalendarDay>>> GetMonthlySchedule(int
// last day of the month and a week after the last day of the month
var endDate = startDate.AddMonths(1).AddDays(-1).AddDays(7);
var calendars = await _judicialCalendarService.JudicialCalendarsGetAsync(locationId, startDate, endDate);
CalendarSchedule calendarSchedule = new CalendarSchedule();

var calendarDays = MapperHelper.CalendarToDays(calendars.ToList());
if (calendarDays == null)
{
return Ok(new List<CalendarDay>());
calendarSchedule.Schedule = new List<CalendarDay>();
}
return Ok(calendarDays);
else
calendarSchedule.Schedule = calendarDays;

calendarSchedule.Presiders = calendars.Where(t => t.IsPresider).Select(presider => new FilterCode
{
Text = $"{presider.RotaInitials} - {presider.Name}",
Value = $"{presider.ParticipantId}",
}).ToList().DistinctBy(t => t.Value).OrderBy(x => x.Value).ToList();

var assignmentsList = calendars.Where(t => t.IsPresider)
.Where(t => t.Days?.Count > 0)
.SelectMany(t => t.Days).Where(day => day.Assignment != null && (day.Assignment.ActivityAm !=null || day.Assignment.ActivityPm != null))
.Select(day => day.Assignment)
.ToList();
var activitiesList = assignmentsList
.SelectMany(t => new[] { t.ActivityAm, t.ActivityPm })
.Where(activity => activity != null)
.Select(activity => new FilterCode
{
Text = activity.ActivityDescription,
Value = activity.ActivityCode
})
.DistinctBy(t => t.Value)
.OrderBy(x => x.Text)
.ToList();
calendarSchedule.Activities = activitiesList;

return Ok(calendarSchedule);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -121,74 +150,6 @@ public async Task<ActionResult<IEnumerable<FilterCode>>> LocationList()
return StatusCode(500, "Internal server error" + ex.Message);
}
}

/// <summary>
/// Provides presiders.
/// </summary>
/// <returns>IEnumerable{FilterCode}</returns>
[HttpGet]
[Route("presiders/{year}/{month}")]
public async Task<ActionResult<IEnumerable<FilterCode>>> PresidersList(int year, int month, [FromQuery] string locationId = "")
{
if (string.IsNullOrWhiteSpace(locationId))
{
return Ok(new List<FilterCode>());
}
var locationIds = locationId.Split(',').ToList();

// first day of the month and a week before the first day of the month
var startDate = new DateTime(year, month, 1).AddDays(-7);
// last day of the month and a week after the last day of the month
var endDate = startDate.AddMonths(1).AddDays(-1).AddDays(7);

var calendars = await _judicialCalendarService.JudicialCalendarsGetAsync(locationId, startDate, endDate);

var presidersList = calendars.Where(t => t.IsPresider).Select(presider => new FilterCode
{
Text = $"{presider.RotaInitials} - {presider.Name}",
Value = $"{presider.ParticipantId}",
}).ToList().DistinctBy(t => t.Value).OrderBy(x => x.Value);

return Ok(presidersList);
}
/// <summary>
/// Provides activities.
/// </summary>
/// <returns>IEnumerable{FilterCode}</returns>
[HttpGet]
[Route("activities/{year}/{month}")]
public async Task<ActionResult<IEnumerable<FilterCode>>> ActivitiesList(int year, int month, [FromQuery] string locationId = "")
{
if (string.IsNullOrWhiteSpace(locationId))
{
return Ok(new List<FilterCode>());
}

// first day of the month and a week before the first day of the month
var startDate = new DateTime(year, month, 1).AddDays(-7);
// last day of the month and a week after the last day of the month
var endDate = startDate.AddMonths(1).AddDays(-1).AddDays(7);

var calendars = await _judicialCalendarService.JudicialCalendarsGetAsync(locationId, startDate, endDate);
var assignmentsList = calendars.Where(t => t.IsPresider)
.Where(t => t.Days?.Count > 0)
.SelectMany(t => t.Days).Where(day => day.Assignment != null && (day.Assignment.ActivityAm !=null || day.Assignment.ActivityPm != null))
.Select(day => day.Assignment)
.ToList();
var activitiesList = assignmentsList
.SelectMany(t => new[] { t.ActivityAm, t.ActivityPm })
.Where(activity => activity != null)
.Select(activity => new FilterCode
{
Text = activity.ActivityDescription,
Value = activity.ActivityCode
})
.DistinctBy(t => t.Value)
.OrderBy(x => x.Text)
.ToList();

return Ok(activitiesList);
}
}


Expand Down
12 changes: 12 additions & 0 deletions api/Models/Calendar/CalendarSchedule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Scv.Api.Models.Lookup;
using System.Collections.Generic;

namespace Scv.Api.Models.Calendar
{
public class CalendarSchedule
{
public List<CalendarDay> Schedule { get; set; }
public List<FilterCode> Activities { get; set; }
public List<FilterCode> Presiders { get; set; }
}
}
2 changes: 1 addition & 1 deletion web/src/components/NavigationTopbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div style="width: 80%;">
<ul>
<li>
<a class="nav-link" href="/Home">Dashboard</a>
<a class="nav-link" href="/Dashboard">Dashboard</a>
</li>
<li>
<a class="nav-link">Court Calendar</a>
Expand Down
105 changes: 32 additions & 73 deletions web/src/components/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
:options="locations.length > 7 ? locations.slice(0, 7) : locations"
name="locations-filter" @change="onCheckboxChange"></b-form-checkbox-group>
</b-card>
<button v-if="locations.length > 1" class="moreItems" @click="showAllLocations()">
<button v-if="locations.length > 0" class="moreItems" @click="showAllLocations()">
<span>See all locations</span>
</button>
</b-collapse>
Expand All @@ -61,7 +61,7 @@
:options="presiders.length > 7 ? presiders.slice(0, 7) : presiders"
name="presiders-filter" @change="onCheckboxPresidersChange"></b-form-checkbox-group>
</b-card>
<button v-if="presiders.length > 1" class="moreItems" @click="showAllPresiders()">
<button v-if="presiders.length > 0" class="moreItems" @click="showAllPresiders()">
<span>See all presiders</span>
</button>
</b-collapse>
Expand Down Expand Up @@ -536,46 +536,25 @@ export default class Dashboard extends Vue {
this.arEvents = [...this.ar];
(this.$refs.locationsModal as any).hide();
this.loadActivities(this.currentCalendarDate);
this.loadPresiders(this.currentCalendarDate);
this.getMonthlySchedule(this.currentCalendarDate);
}
loadPresiders(currentMonth) {
let locationId = "";
if (this.selectedLocations.length > 0) {
locationId = this.selectedLocations.join(',');
}
else {
loadPresiders(data) {
if (this.selectedLocations.length == 0) {
this.presiders = [];
this.selectedPresiders = [];
this.selectAllPresiders = false;
return;
}
else {
this.selectAllPresiders = true;
}
this.presiders = [...data];
this.selectedPresiders = this.presiders.map((x) => {
return x.value
});
//calendarStartDate, calendarEndDate
this.$http
.get("api/dashboard/presiders/" +
`${currentMonth.getFullYear()}/${String(currentMonth.getMonth() + 1).padStart(2, '0')}` +
`?locationId=${locationId}`)
.then(
(Response) => Response.json(),
(err) => {
this.$bvToast.toast(`Error - ${err.url} - ${err.status} - ${err.statusText}`, {
title: "An error has occured.",
variant: "danger",
autoHideDelay: 10000,
});
console.log(err);
}
)
.then((data) => {
if (data) {
this.presiders = [...data];
this.selectedPresiders = this.presiders.map((x) => {
return x.value
});
} else {
window.alert("bad data!");
}
});
}
showAllPresiders() {
Expand All @@ -584,45 +563,28 @@ export default class Dashboard extends Vue {
resetPresiders() {
this.selectedPresiders = [];
}
loadActivities(currentMonth) {
let locationId = "";
if (this.selectedLocations.length > 0) {
locationId = this.selectedLocations.join(',');
}
else {
loadActivities(data) {
if (this.selectedLocations.length == 0) {
this.activities = [];
this.selectedActivities = [];
this.selectAllActivities = false;
return;
}
this.$http
.get("api/dashboard/activities/" +
`${currentMonth.getFullYear()}/${String(currentMonth.getMonth() + 1).padStart(2, '0')}` +
`?locationId=${locationId}`)
.then(
(Response) => Response.json(),
(err) => {
this.$bvToast.toast(`Error - ${err.url} - ${err.status} - ${err.statusText}`, {
title: "An error has occured.",
variant: "danger",
autoHideDelay: 10000,
});
console.log(err);
}
)
.then((data) => {
if (data) {
this.activities = [...data];
this.selectedActivities = this.activities.map((x) => {
return x.value;
});
} else {
window.alert("bad data!");
}
});
else {
this.selectAllActivities = true;
}
this.activities = [...data];
this.selectedActivities = this.activities.map((x) => {
return x.value;
});
}
showAllActivities() {
this.showActivitiesModal = true;
}
resetActivities() {
this.selectedActivities = [];
}
Expand All @@ -646,8 +608,6 @@ export default class Dashboard extends Vue {
this.ar = [];
this.currentCalendarDate = currentMonth;
//loadActivities();
//loadpresired()
let locations = "";
if (this.selectedLocations.length > 0) {
const locationIds = this.selectedLocations.join(',');
Expand All @@ -673,11 +633,13 @@ export default class Dashboard extends Vue {
)
.then((data) => {
if (data) {
// this.ar = JSON.parse(JSON.stringify(data, null, 2));
this.ar = [...JSON.parse(JSON.stringify(data))];
this.ar = [...data.schedule];
//this.ar = data;
this.arEvents = [...this.ar];
this.loadActivities(data.activities);
this.loadPresiders(data.presiders);
} else {
window.alert("bad data!");
}
Expand All @@ -692,9 +654,6 @@ export default class Dashboard extends Vue {
} else {
this.isMySchedule = true;
}
this.loadActivities(this.currentCalendarDate);
this.loadPresiders(this.currentCalendarDate);
this.getMonthlySchedule(this.currentCalendarDate);
}
Expand Down

0 comments on commit b38207a

Please sign in to comment.