forked from bcgov/supreme-court-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial calendar implementation (#29)
* Initial calendar setup completed, including the interface and frontend connection to the backend, along with a basic template for the assignment reader. The full integration with PCSS will come later. Features like Jump To Date, assignment displays inside the calendar cells and popups will also be added in the next phase. * Initial Daashboard page implementation - Calendar UI updated as per wireframes - Events were Added - Side panels behavior - Locations, Activities and Presiders Load - Events Filtering added * pcss-client added - New Dashboard Structure; - Initial PCSS Integration; * Update package-lock.json using centos7 nodejs12 --------- Co-authored-by: Timaqt <TimA@QL023547701657> Co-authored-by: Ronaldo Macapobre <[email protected]> Co-authored-by: Wade Barnes <[email protected]>
- Loading branch information
1 parent
7c6710a
commit 52cde11
Showing
54 changed files
with
4,969 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Scv.Api.Helpers.Extensions; | ||
using Scv.Api.Infrastructure.Authorization; | ||
using Scv.Api.Services; | ||
using Scv.Api.Models.Lookup; | ||
using PCSS.Models.REST.JudicialCalendar; | ||
using Scv.Api.Helpers; | ||
using Scv.Api.Models.Calendar; | ||
|
||
namespace Scv.Api.Controllers | ||
{ | ||
[Authorize(AuthenticationSchemes = "SiteMinder, OpenIdConnect", Policy = nameof(ProviderAuthorizationHandler))] | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class DashboardController : ControllerBase | ||
{ | ||
#region Variables | ||
private readonly LocationService _locationService; | ||
private readonly JudicialCalendarService _judicialCalendarService; | ||
|
||
#endregion Variables | ||
|
||
#region Constructor | ||
public DashboardController(LocationService locationService, JudicialCalendarService judicialCalendarService) | ||
{ | ||
_locationService = locationService; | ||
_judicialCalendarService = judicialCalendarService; | ||
} | ||
#endregion Constructor | ||
|
||
/// <summary> | ||
/// Returns list of assignemnts for a given month and year for current user. | ||
/// </summary> | ||
/// <param name="year">selected year</param> | ||
/// <param name="month">selected month</param> | ||
/// <param name="locationId">selected month</param> | ||
/// <returns></returns> | ||
// [HttpGet("monthly-schedule/{year}/{month}")] | ||
[HttpGet] | ||
[Route("monthly-schedule/{year}/{month}")] | ||
public async Task<ActionResult<CalendarSchedule>> GetMonthlySchedule(int year, int month, [FromQuery] string locationId = "") | ||
{ | ||
try | ||
{ | ||
// 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); | ||
CalendarSchedule calendarSchedule = new CalendarSchedule(); | ||
|
||
var calendarDays = MapperHelper.CalendarToDays(calendars.ToList()); | ||
if (calendarDays == null) | ||
{ | ||
calendarSchedule.Schedule = new List<CalendarDay>(); | ||
} | ||
else | ||
calendarSchedule.Schedule = calendarDays; | ||
|
||
calendarSchedule.Presiders = calendars.Where(t => t.IsPresider).Select(presider => new FilterCode | ||
{ | ||
Text = $"{presider.RotaInitials} - {presider.Name}", | ||
Value = $"{presider.ParticipantId}", | ||
}).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) | ||
{ | ||
// Log the exception | ||
return StatusCode(500, "Internal server error"); | ||
} | ||
} | ||
|
||
//public async Task<ActionResult<List<FilterCode>>> LocationList(int a) | ||
/// <summary> | ||
/// Provides locations. | ||
/// </summary> | ||
/// <returns>IEnumerable{FilterCode}</returns> | ||
[HttpGet] | ||
[Route("locations")] | ||
public async Task<ActionResult<IEnumerable<FilterCode>>> LocationList() | ||
{ | ||
try | ||
{ | ||
var locations = await _locationService.GetLocations(); | ||
var locationList = locations.Where(t => t.Flex?.Equals("Y") == true).Select(location => new FilterCode | ||
{ | ||
Text = location.LongDesc, | ||
Value = location.ShortDesc | ||
}).OrderBy(x => x.Text); | ||
|
||
return Ok(locationList); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Log the exception | ||
return StatusCode(500, "Internal server error" + ex.Message); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using AutoMapper; | ||
using System.Collections.Generic; | ||
using Scv.Api.Models.Calendar; | ||
using Scv.Api.Mappers; | ||
using PCSS.Models.REST.JudicialCalendar; | ||
using System.Linq; | ||
|
||
namespace Scv.Api.Helpers | ||
{ | ||
public static class MapperHelper | ||
{ | ||
// Usage | ||
public static List<CalendarDay> CalendarToDays(List<JudicialCalendar> listOfCalendars) | ||
{ | ||
var config = new MapperConfiguration(cfg => cfg.AddProfile<MappingProfile>()); | ||
var mapper = new Mapper(config); | ||
|
||
return listOfCalendars.SelectMany(calendarDays => mapper.Map<List<CalendarDay>>(calendarDays)).ToList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using Scv.Api.Controllers; | ||
using Scv.Api.Services; | ||
using Scv.Api.Models; | ||
using static System.Runtime.InteropServices.JavaScript.JSType; | ||
using System.Collections.Generic; | ||
using PCSS.Models.REST.JudicialCalendar; | ||
using Scv.Api.Models.Calendar; | ||
using System.Linq; | ||
|
||
namespace Scv.Api.Mappers | ||
{ | ||
public class MappingProfile : AutoMapper.Profile | ||
{ | ||
public MappingProfile() | ||
{ | ||
CreateMap<JudicialCalendarDay, CalendarDay>(); | ||
|
||
|
||
CreateMap<JudicialCalendar, List<CalendarDay>>() | ||
.ConvertUsing((src, dest, context) => | ||
src.Days.Select(b => { | ||
var c = context.Mapper.Map<CalendarDay>(b); | ||
c.RotaInitials = src.RotaInitials; | ||
return c; | ||
}).ToList()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using PCSS.Models.REST.JudicialCalendar; | ||
using System; | ||
|
||
namespace Scv.Api.Models.Calendar | ||
{ | ||
public class CalendarDay : JudicialCalendarDay | ||
{ | ||
public string RotaInitials { get; set; } | ||
public DateTime Start | ||
{ | ||
get | ||
{ | ||
return DateTime.ParseExact(base.Date, "dd-MMM-yyyy", null).AddHours(8); | ||
} | ||
} | ||
|
||
public bool showAM | ||
{ | ||
get | ||
{ | ||
return showPM; | ||
} | ||
} | ||
public bool showPM | ||
{ | ||
get | ||
{ | ||
if(showPMLocation || (this.Assignment?.ActivityAm?.CourtRoomCode != this.Assignment?.ActivityPm?.CourtRoomCode) | ||
|| (this.Assignment?.ActivityAm?.ActivityDescription != this.Assignment?.ActivityPm?.ActivityDescription)) | ||
return true; | ||
else | ||
return false; | ||
} | ||
} | ||
public bool showPMLocation | ||
{ | ||
get | ||
{ | ||
if (this.Assignment?.ActivityPm != null && this.Assignment?.ActivityAm?.LocationName != this.Assignment?.ActivityPm?.LocationName) | ||
return true; | ||
else | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Scv.Api.Models.Lookup | ||
{ | ||
public class FilterCode | ||
{ | ||
public string Text { get; set; } | ||
public string Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using JCCommon.Clients.LocationServices; | ||
using LazyCache; | ||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json.Serialization; | ||
using PCSSClient.Clients.JudicialCalendarsServices; | ||
using Scv.Api.Helpers; | ||
using Scv.Api.Helpers.ContractResolver; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using PCSS.Models.REST.JudicialCalendar; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
|
||
namespace Scv.Api.Services | ||
{ | ||
/// <summary> | ||
/// This should handle caching and JudicialCalendarsServicesClient. | ||
/// </summary> | ||
public class JudicialCalendarService | ||
{ | ||
#region Variables | ||
|
||
private readonly IAppCache _cache; | ||
private readonly IConfiguration _configuration; | ||
private JudicialCalendarsServicesClient _judicialCalendarsClient { get; } | ||
|
||
#endregion Variables | ||
|
||
#region Properties | ||
|
||
#endregion Properties | ||
|
||
#region Constructor | ||
|
||
public JudicialCalendarService(IConfiguration configuration, JudicialCalendarsServicesClient judicialCalendarsClient, | ||
IAppCache cache) | ||
{ | ||
_configuration = configuration; | ||
_judicialCalendarsClient = judicialCalendarsClient; | ||
_cache = cache; | ||
_cache.DefaultCachePolicy.DefaultCacheDurationSeconds = int.Parse(configuration.GetNonEmptyValue("Caching:LocationExpiryMinutes")) * 60; | ||
SetupLocationServicesClient(); | ||
} | ||
|
||
#endregion Constructor | ||
|
||
#region Collection Methods | ||
|
||
public async Task<ICollection<JudicialCalendar>> JudicialCalendarsGetAsync(string locationId, DateTime startDate, DateTime endDate) | ||
{ | ||
var judicialCalendars = await _judicialCalendarsClient.JudicialCalendarsGetAsync(locationId, startDate, endDate, CancellationToken.None); | ||
|
||
return judicialCalendars; | ||
} | ||
|
||
|
||
#endregion Collection Methods | ||
|
||
#region Lookup Methods | ||
|
||
|
||
#endregion Lookup Methods | ||
|
||
#region Helpers | ||
private void SetupLocationServicesClient() | ||
{ | ||
_judicialCalendarsClient.JsonSerializerSettings.ContractResolver = new SafeContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }; | ||
} | ||
|
||
#endregion Helpers | ||
} | ||
} |
Oops, something went wrong.