Skip to content

Commit

Permalink
Improve calendar list display
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidier committed Aug 2, 2023
1 parent e7af0f4 commit b0b5ab5
Showing 1 changed file with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using SSW.SophieBot.HttpClientComponents.PersonQuery.Models;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -68,17 +69,7 @@ private EmployeeProfileWithStatusModel ConvertToProfile(GetEmployeeModel employe
LastName = employee.LastName,
BillableRate = employee.BillableRate,
BookedDays = EmployeesHelper.GetBookedDays(employee, date),
Appointments = EmployeesHelper.GetAppointments(employee.NormalizedAppointments, date, 10)
.Select(a => new EmployeeProfileAppointment
{
Start = a.Start.DateTime.ToUserFriendlyDate(date),
End = a.End.DateTime.ToUserFriendlyDate(date),
Duration = (a.End - a.Start).ToUserFriendlyDuration(),
BookingStatus = EmployeesHelper.GetBookingStatus(a),
Subject = a.Subject.Trim(),
Regarding = a.Regarding.Trim()
})
.ToList()
Appointments = GetDisplayAppointments(EmployeesHelper.GetAppointments(employee.NormalizedAppointments, date, 10), date)
};

if (profile.BookingStatus == BookingStatus.Leave)
Expand All @@ -100,5 +91,40 @@ private EmployeeProfileWithStatusModel ConvertToProfile(GetEmployeeModel employe

return profile;
}

private List<EmployeeProfileAppointment> GetDisplayAppointments(IEnumerable<GetAppointmentModel> sourceAppointments, DateTime date)
{
var result = new List<EmployeeProfileAppointment>();
var appointment = new EmployeeProfileAppointment();
if (!sourceAppointments.Any())
{
return result;
}

foreach (var sourceAppointment in sourceAppointments.OrderBy(sa => sa.Start.DateTime))
{
if (appointment.Subject != sourceAppointment.Subject)
{
appointment = new EmployeeProfileAppointment
{
Start = sourceAppointment.Start.DateTime.ToUserFriendlyDate(date),
End = sourceAppointment.End.DateTime.ToUserFriendlyDate(date),
Duration = (sourceAppointment.End - sourceAppointment.Start).ToUserFriendlyDuration(),
BookingStatus = EmployeesHelper.GetBookingStatus(sourceAppointment),
Subject = sourceAppointment.Subject.Trim(),
Regarding = sourceAppointment.Regarding.Trim()
};

result.Add(appointment);
}
else
{
appointment.End = sourceAppointment.End.DateTime.ToUserFriendlyDate(date);
appointment.Duration = (sourceAppointment.End - sourceAppointment.Start).ToUserFriendlyDuration();
}
}

return result;
}
}
}

0 comments on commit b0b5ab5

Please sign in to comment.