Skip to content

Commit

Permalink
improve WeekView + #16 +#17
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Peugnet committed Nov 29, 2023
1 parent 252de42 commit a629c1e
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 52 deletions.
21 changes: 14 additions & 7 deletions BlazorCalendar/AnnualView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
tasksCounter = 0;
ondragover = "event.preventDefault();";
borderStyle = "";
if ( TasksList != null )
if ( TasksList is not null )
{
for (var k = 0; k < TasksList.Length; k++)
{
Expand Down Expand Up @@ -135,15 +135,22 @@
}
}

<div class=@($"cellule day-cellule noselect {disabled}") style="@CSSbackground" ondragover="@ondragover" @ondrop="() => HandleDayOnDrop(j)" @ondrop:preventDefault="true">
<div class=@($"cellule day-cellule noselect {disabled}")
style="@CSSbackground"
ondragover="@ondragover"
@ondrop="() => HandleDayOnDrop(j)"
@ondrop:preventDefault="true">
<div class="day" style="@CSSbackground">
@labelDay
</div>
<div id="task-@taskID" class="@($"task{classPin}{classPointer} {borderStyle}")" style="@taskColor" title="@taskComment"
@onclick="e => ClickInternal(e, j)"
@ondragstart="() => HandleDragStart(j, taskID)"
draggable="@draggable.ToString()" >
@taskContent
<div id="task-@taskID"
class="@($"task{classPin}{classPointer} {borderStyle}")"
style="@taskColor"
title="@taskComment"
@onclick="e => ClickInternal(e, j)"
@ondragstart="() => HandleDragStart(j, taskID)"
draggable="@draggable.ToString()" >
@taskContent
</div>
</div>
}
Expand Down
17 changes: 11 additions & 6 deletions BlazorCalendar/AnnualView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ public DateTime FirstDate

private async Task ClickInternal(MouseEventArgs e, DateTime day)
{
if (day == default) return;
if (day == default)
return;

// There can be several tasks in one day :
List<int> listID = new();
if (TasksList != null )

if (TasksList is not null )
{
for (var k = 0; k < TasksList.Length; k++)
{
Expand All @@ -84,7 +86,7 @@ private async Task ClickInternal(MouseEventArgs e, DateTime day)
}
}

if (listID.Count > 0)
if (listID.Any())
{
if (TaskClick.HasDelegate)
{
Expand Down Expand Up @@ -118,7 +120,8 @@ private async Task ClickInternal(MouseEventArgs e, DateTime day)

private async Task HandleDragStart(DateTime day, int taskID)
{
if (taskID < 0) return;
if (taskID < 0)
return;

TaskDragged = new Tasks()
{
Expand All @@ -136,7 +139,8 @@ private async Task HandleDragStart(DateTime day, int taskID)

private async Task HandleDayOnDrop(DateTime day)
{
if (TaskDragged == null) return;
if (TaskDragged is null)
return;

DragDropParameter dragDropParameter = new()
{
Expand All @@ -151,7 +155,8 @@ private async Task HandleDayOnDrop(DateTime day)

private async Task HandleHeaderClick(DateTime month)
{
if (!HeaderClick.HasDelegate) return;
if (!HeaderClick.HasDelegate)
return;

await HeaderClick.InvokeAsync(month);
}
Expand Down
2 changes: 1 addition & 1 deletion BlazorCalendar/BlazorCalendar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<RepositoryType>git</RepositoryType>
<PackageTags>blazor, calendar, schedule, component</PackageTags>
<PackageReleaseNotes>https://github.com/tossnet/Blazor-Calendar#release-notes</PackageReleaseNotes>
<Version>2.6.5</Version>
<Version>2.6.6</Version>
<Authors>Christophe Peugnet</Authors>
<DebugType>embedded</DebugType>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions BlazorCalendar/MonthlyView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
string? CSSToday = null;

// The sorting must be done each time we redraw in case the user moves the spots
if (TasksList != null)
if (TasksList is not null)
{
TasksList = TasksList.OrderBy(x => x.DateStart)
.ThenByDescending(x => x.DateEnd).ToArray();
Expand Down Expand Up @@ -99,7 +99,7 @@
}
}

@if ( TasksList != null )
@if ( TasksList is not null )
{
// occupiedPosition accumulates the number of tasks in a cell
var occupiedPosition = new TaskPosition[32]; // If one day, there are 32 days in a month, it will crash :P
Expand Down Expand Up @@ -168,7 +168,7 @@
{
string row = $"grid-column:{x} / span {s}; grid-row:{y};";

if ( classPosition != null )
if ( classPosition is not null )
{
if ( PriorityDisplay == PriorityLabel.Code )
{
Expand Down Expand Up @@ -234,7 +234,7 @@
Start = t.DateStart.Date < FirstDate ? FirstDate : t.DateStart.Date;
End = t.DateEnd.Date >= LastDay ? LastDay.AddDays(-1) : t.DateEnd.Date;

for (var d = Start.Day; d <= End.Day; d++)
for (int d = Start.Day; d <= End.Day; d++)
{
occupiedPosition[d].Counter++;
}
Expand Down
22 changes: 15 additions & 7 deletions BlazorCalendar/MonthlyView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ private async Task HandleClickOutsideCurrentMonthClick(int AddMonth)

private async Task ClickTaskInternal(MouseEventArgs e, int taskID, DateTime day)
{
if (!TaskClick.HasDelegate) return;
if (!TaskClick.HasDelegate)
return;

List<int> listID = new()
{
Expand All @@ -88,13 +89,16 @@ private async Task ClickTaskInternal(MouseEventArgs e, int taskID, DateTime day)

private async Task ClickAllDayInternal(MouseEventArgs e, DateTime day)
{
if (day == default) return;
if (day == default)
return;

if (!TaskClick.HasDelegate) return;
if (!TaskClick.HasDelegate)
return;

// There can be several tasks in one day :
List<int> listID = new();
if (TasksList != null)

if (TasksList is not null)
{
for (var k = 0; k < TasksList.Length; k++)
{
Expand All @@ -120,7 +124,8 @@ private async Task ClickAllDayInternal(MouseEventArgs e, DateTime day)

private async Task ClickDayInternal(MouseEventArgs e, DateTime day)
{
if (!DayClick.HasDelegate) return;
if (!DayClick.HasDelegate)
return;

ClickEmptyDayParameter clickEmptyDayParameter = new()
{
Expand Down Expand Up @@ -149,8 +154,11 @@ private async Task HandleDragStart(int taskID)

private async Task HandleDayOnDrop(DateTime day)
{
if ( !Draggable ) return;
if ( TaskDragged == null ) return;
if ( !Draggable )
return;

if ( TaskDragged is null )
return;

DragDropParameter dragDropParameter = new()
{
Expand Down
29 changes: 20 additions & 9 deletions BlazorCalendar/WeekView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@

@{
DateTime FirstDateWeek = new DateTime(FirstDate.Year, FirstDate.Month, FirstDate.Day).AddDays(-(Dates.GetNumOfDay((int)FirstDate.Date.DayOfWeek) - 2));

string[] dayNames = CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedDayNames;
string? isHidden = DisplayedView == DisplayedView.Weekly ? null : "hidden-element";
string? CSSbackground = null;
string? taskColor = null;
string? classPin = null;
string? classPointer = null;
string borderStyle = "";

Check warning on line 15 in BlazorCalendar/WeekView.razor

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

The variable 'borderStyle' is assigned but its value is never used

// The sorting must be done each time we redraw in case the user moves the spots
if (TasksList != null)
if (TasksList is not null)
{
TasksList = TasksList.OrderBy(x => x.DateStart)
.ThenByDescending(x => x.DateEnd).ToArray();
.ThenByDescending(x => x.DateEnd)
.ToArray();
}
}

Expand All @@ -32,27 +34,33 @@
CSSbackground = GetBackground(day);
}
<div class="day-header header-name noselect" style="@HeaderStyle @CSSbackground">
@day.ToString("dddd dd.MM")
@dayNames[i] @day.ToString("dd.MM")
</div>

<div class="hours">

@for (var hour = 0; hour < 24; hour++)
@for (int hour = 0; hour < 24; hour++)
{
DateTime hours = day.AddHours(hour);

<div class="hour day-cellule" ondragover="event.preventDefault();" @ondrop:preventDefault="true" @ondrop="() => HandleDayOnDrop(hours)">
<div class="hour day-cellule noselect"
ondragover="event.preventDefault();this.style.fontWeight='600';"
ondragleave="this.style.fontWeight='100';"
@ondrop:preventDefault="true"
@ondrop="() => HandleDayOnDrop(hours)"
@onclick="e => ClickDayInternal(e, hours)">
@hours.ToString("HH:mm")
</div>

@if (TasksList != null)
@if (TasksList is not null)
{
int column = 1;

for (var k = 0; k < TasksList.Length; k++)
{
Tasks t = TasksList[k];


if (t.DateEnd > hours && t.DateStart <= hours)
{
column++;
Expand All @@ -63,8 +71,11 @@
classPin = string.IsNullOrWhiteSpace(t.Comment) ? null : " pin";
classPointer = " cursor-pointer";

<div class="@($"hour-task {classPin}{classPointer}")" style="grid-column-start: @column; @taskColor"
draggable="@Draggable.ToString()" @ondragstart="() => HandleDragStart(t.ID)">
<div class="@($"hour-task {classPin}{classPointer} border-top border-bottom")"
style="grid-column-start: @column; @taskColor"
draggable="@Draggable.ToString()"
@ondragstart="() => HandleDragStart(t.ID)"
@onclick="e => ClickTaskInternal(e, t.ID, day)">
@t.Code
</div>

Expand Down
47 changes: 45 additions & 2 deletions BlazorCalendar/WeekView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public DateTime FirstDate
[Parameter]
public EventCallback<ClickEmptyDayParameter> DayClick { get; set; }

[Parameter]
public EventCallback<ClickEmptyDayParameter> EmptyDayClick { get; set; }

[Parameter]
public EventCallback<ClickTaskParameter> TaskClick { get; set; }

Expand Down Expand Up @@ -66,8 +69,11 @@ private async Task HandleDragStart(int taskID)

private async Task HandleDayOnDrop(DateTime day)
{
if (!Draggable) return;
if (TaskDragged == null) return;
if (!Draggable)
return;

if (TaskDragged is null)
return;

DragDropParameter dragDropParameter = new()
{
Expand Down Expand Up @@ -95,4 +101,41 @@ private string GetBackground(DateTime day)

return $"background:{WeekDaysColor}";
}

private async Task ClickDayInternal(MouseEventArgs e, DateTime day)
{
if (!DayClick.HasDelegate)
return;

ClickEmptyDayParameter clickEmptyDayParameter = new()
{
Day = day,
X = e.ClientX,
Y = e.ClientY
};

await DayClick.InvokeAsync(clickEmptyDayParameter);
}

private async Task ClickTaskInternal(MouseEventArgs e, int taskID, DateTime day)
{
if (!TaskClick.HasDelegate)
return;

List<int> listID = new()
{
taskID
};

ClickTaskParameter clickTaskParameter = new()
{
IDList = listID,
X = e.ClientX,
Y = e.ClientY,
Day = day
};

await TaskClick.InvokeAsync(clickTaskParameter);
}

}
5 changes: 4 additions & 1 deletion BlazorCalendar/WeekView.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

.hour {
grid-column-start: 1;
font-size: 1em;
font-size: 0.8em;
padding-left: 0.5em;
}


.hour-task {
text-align: center;
font-size: 0.8em;
font-weight: 600;
}
12 changes: 0 additions & 12 deletions BlazorCalendar/wwwroot/BlazorCalendar.css
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,6 @@
}
}

/* .monthly-task:after {
content: '';
position: absolute;
width: 0px;
height: 0px;
right: 2px;
top: 28%;
border-style: solid;
border-width: 6px 0 6px 8px;
border-color: transparent transparent transparent #4d4d4d7a;
}*/

.monthly-task-first {
align-self: start;
margin-top: 22px;
Expand Down
2 changes: 1 addition & 1 deletion samples/BlazorServer/BlazorServer.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0; net7.0; net8.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
2 changes: 1 addition & 1 deletion samples/BlazorServer/Pages/Weekly.razor
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

private void DayClick(ClickEmptyDayParameter clickEmptyDayParameter)
{
fakeConsole = "Empty day :" + clickEmptyDayParameter.Day.ToShortDateString();
fakeConsole = $"Empty day :{clickEmptyDayParameter.Day.ToShortDateString()} {clickEmptyDayParameter.Day.ToShortTimeString()}";
}

private void DragStart(DragDropParameter dragDropParameter)
Expand Down
2 changes: 1 addition & 1 deletion samples/BlazorWebAssembly/Pages/Weekly.razor
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

private void DayClick(ClickEmptyDayParameter clickEmptyDayParameter)
{
fakeConsole = "Empty day :" + clickEmptyDayParameter.Day.ToShortDateString();
fakeConsole = $"Empty day :{clickEmptyDayParameter.Day.ToShortDateString()} {clickEmptyDayParameter.Day.ToShortTimeString()}";
}

private void DragStart(DragDropParameter dragDropParameter)
Expand Down

0 comments on commit a629c1e

Please sign in to comment.