Skip to content

Commit

Permalink
Fixed data acquisition #55 (#76)
Browse files Browse the repository at this point in the history
* Initial schedule UI work

* Revert "Initial schedule UI"

* Issue #8 - domain object validation (#34)

* issue #8 inital commit

* Issue #8 Cron validation in RecurringSchedule.cs

* more validation rules issue #8

* validation rules for default datetimes issue #8

* WIP - Fetching timeslot data from the server

* Fixing datetime data entry on the availability page  #63

* WIP - Trying to get timeslots shown

* Migrating the Availability page to CSS grid

* Fixed data acquisition #55
  • Loading branch information
csharpfritz authored Aug 11, 2019
1 parent 468e813 commit c3f6d3a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
<div id="MySchedule">
<h2 class="h3">My Schedule</h2>

<DayPicker />

<DayView DayViewStart="Model.DayViewStart" DayViewEnd="Model.DayViewEnd" MyScheduleState="Model.MyScheduleState" />
<DayPicker />

<DayView DayViewStart="Model.DayViewStart" DayViewEnd="Model.DayViewEnd" MyScheduleState="Model.MyScheduleState" />

</div>

<div id="ScheduleList">
Expand Down
21 changes: 10 additions & 11 deletions src/Fritz.ResourceManagement.WebClient/Pages/DayPicker.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@inject ViewModels.DayPickerViewModel Model
@inherits ViewModels.DayPickerViewModel
<div class="monthpicker">

<button id="prevMonth" @onclick="Model.PrevMonth">&lt;</button>
<div id="name">@Model.SelectedDate.ToString("MMMM yyyy")</div>
<button id="nextMonth" @onclick="Model.NextMonth">&gt;</button>
<button id="prevMonth" @onclick="PrevMonth">&lt;</button>
<div id="name">@SelectedDate.ToString("MMMM yyyy")</div>
<button id="nextMonth" @onclick="NextMonth">&gt;</button>

<span class="dow">Su</span>
<span class="dow">M</span>
Expand All @@ -13,20 +13,19 @@
<span class="dow">F</span>
<span class="dow">Sa</span>

@for (var i = 0; i < Model.FirstDayOfMonthDoW; i++)
@for (var i = 0; i < FirstDayOfMonthDoW; i++)
{
<span></span>
}

@for (var i = 1; i <= Model.LastDayOfMonth; i++)
@for (var i = 1; i <= LastDayOfMonth; i++)
{
// TODO: Simon G - Should be able to replace this loop with a ForEach over a new method Model.GetDaysOfMonthToRender() that returns List<DayOfMonthDisplayInfo> - Should wait for app UI running again to dev test before attempting.
var displayInfo = this.Model.DisplayDayOfMonth(i);
<span class="@displayInfo.Today @displayInfo.HasAppointment @displayInfo.IsSelected day" title="@displayInfo.Title" @onclick="() => Model.MyScheduleState.SelectDate(displayInfo.ThisDay)">@i</span>
var displayInfo = this.DisplayDayOfMonth(i);
<span class="@displayInfo.Today @displayInfo.HasAppointment @displayInfo.IsSelected day" title="@displayInfo.Title" @onclick="() => MyScheduleState.SelectDate(displayInfo.ThisDay)">@i</span>
}

</div>
<button id="gotoToday" @onclick="Model.GotoToday">Today</button>

<span>Selected Date is: @Model.SelectedDate.ToShortDateString()</span>
<button id="gotoToday" @onclick="GotoToday">Today</button>

<span>Selected Date is: @SelectedDate.ToShortDateString()</span>
9 changes: 7 additions & 2 deletions src/Fritz.ResourceManagement.WebClient/Pages/DayView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@if (Model.MyScheduleState != null)
{
foreach (var item in Model.MyScheduleState.TimeSlots.Where(s => s.StartDateTime.Date == Model.SelectedDate.Date))
foreach (var item in TimeSlots.Where(s => s.StartDateTime.Date == Model.SelectedDate.Date))
{
if (Model.DisplayItem(item.StartDateTime, item.EndDateTime))
{
Expand Down Expand Up @@ -60,6 +60,8 @@
set { Model.MyScheduleState = value; }
}

[CascadingParameter(Name = "Timeslots")] protected List<TimeSlot> TimeSlots { get; set; }


[Parameter]
DateTime DayViewStart
Expand Down Expand Up @@ -95,7 +97,10 @@
{
if (Model.MyScheduleState != null)
{
Model.MyScheduleState.OnSelectedDateChanged += (o, args) => { Invoke(StateHasChanged); };
Model.MyScheduleState.OnSelectedDateChanged += (o, args) => {
Console.WriteLine($"Timeslots: {Model.MyScheduleState.TimeSlots.Count} -- Parm: {TimeSlots.Count}");

};
}
base.OnInit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>

<div id="MyScheduleContainer">
<DayView DayCount="7" DayDisplay="true" MyScheduleState="Model.MyScheduleState"></DayView>
<DayView DayCount="7" DayDisplay="true"></DayView>
</div>

@code {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ public AvailabilityViewModel(
{
//this.CurrentUser = currentUser;

// TODO: Remove mocked schedulestate
//this.MyScheduleState = myScheduleState;
this.MyScheduleState = myScheduleState;
this.httpClient = httpClient;
}

public async Task OnInitAsync(ClaimsPrincipal user)
{

_User = user;
this.MyScheduleState = new ScheduleState { ScheduleId = _User.GetClaimValueAsInt(UserInfo.Claims.SCHEDULEID).Value };
this.MyScheduleState.ScheduleId = _User.GetClaimValueAsInt(UserInfo.Claims.SCHEDULEID).Value;

this.ResetScheduleItem();
this.MySchedule = await GetMyAvailability();
Expand All @@ -75,6 +74,7 @@ private async Task ExpandSchedule()
var fetchedTimeslots = await httpClient.GetJsonAsync<TimeSlot[]>($"api/timeslot/{MyScheduleState.ScheduleId}/{DateTime.Today.AddMonths(-1).ToString("MM.dd.yyyy")}/{DateTime.Today.AddMonths(2).ToString("MM.dd.yyyy")}");
Console.WriteLine($"Fetched {fetchedTimeslots.Length} timeslots");
MyScheduleState.TimeSlots.AddRange(fetchedTimeslots);
Console.WriteLine($"MyScheduleState: {MyScheduleState.GetHashCode()}");


}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Fritz.ResourceManagement.Domain;
using Fritz.ResourceManagement.WebClient.Data;
using Microsoft.AspNetCore.Components;

namespace Fritz.ResourceManagement.WebClient.ViewModels
{
public class DayPickerViewModel
public class DayPickerViewModel : ComponentBase
{

protected override void OnInit()
{
Console.WriteLine($"MyScheduleState: {MyScheduleState.GetHashCode()}");
base.OnInit();
}

public DateTime SelectedDate
{
get { return this.MyScheduleState.SelectedDate; }
Expand Down Expand Up @@ -34,8 +43,7 @@ public DayOfMonthDisplayInfo DisplayDayOfMonth(int dayOfMonth)
var thisDay = new DateTime(this.SelectedDate.Year, this.SelectedDate.Month, dayOfMonth);
var today = (thisDay.Date == DateTime.Today.Date) ? "today" : null;

var hasAppt = this.MyScheduleState.TimeSlots.Any(x => x.StartDateTime.Date == thisDay.Date) ? "appt" : null;
Console.WriteLine($"{MyScheduleState.TimeSlots.Count}");
var hasAppt = MyScheduleState.TimeSlots.Any(x => x.StartDateTime.Date == thisDay.Date) ? "appt" : null;

return new DayOfMonthDisplayInfo()
{
Expand All @@ -47,13 +55,9 @@ public DayOfMonthDisplayInfo DisplayDayOfMonth(int dayOfMonth)
};
}

[Inject]
public ScheduleState MyScheduleState { get; private set; }

public DayPickerViewModel(ScheduleState myScheduleState)
{
this.MyScheduleState = myScheduleState;
}

public void GotoToday()
{
this.SelectedDate = DateTime.Today;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public DateTime SelectedDate
get { return this.MyScheduleState.SelectedDate; }
set { this.MyScheduleState.SelectDate(value); }
}

public ScheduleState MyScheduleState { get; private set; }

private readonly HttpClient HttpClient;
Expand All @@ -33,6 +34,7 @@ public void OnChangeDate(int daysToChange)

public async Task OnParametersSetAsync()
{

this.MyScheduleState.DisplayBeginDate = this.SelectedDate.Subtract(TimeSpan.FromDays((int)this.SelectedDate.DayOfWeek));
this.MyScheduleState.DisplayEndDate = this.MyScheduleState.DisplayBeginDate.AddDays(7);

Expand Down

0 comments on commit c3f6d3a

Please sign in to comment.