Completato form attività e filtri
This commit is contained in:
@@ -4,13 +4,14 @@
|
||||
@using Template.Shared.Components.Layout
|
||||
@using Template.Shared.Components.SingleElements
|
||||
@using Template.Shared.Components.Layout.Spinner
|
||||
@inject IManageDataService manageData
|
||||
@inject IDialogService Dialog
|
||||
@using Template.Shared.Components.Layout.BottomSheet
|
||||
@inject IManageDataService ManageData
|
||||
@inject IJSRuntime JS
|
||||
|
||||
<HeaderLayout Title="@CurrentMonth.ToString("MMMM yyyy", new System.Globalization.CultureInfo("it-IT")).FirstCharToUpper()"
|
||||
ShowFilter="true"
|
||||
ShowCalendarToggle="true"
|
||||
OnFilterToggle="ToggleFilter"
|
||||
OnCalendarToggle="ToggleExpanded"/>
|
||||
|
||||
<div @ref="weekSliderRef" class="container week-slider @(Expanded ? "expanded" : "") @(SliderAnimation)">
|
||||
@@ -34,7 +35,7 @@
|
||||
var day = new DateTime(CurrentMonth.Year, CurrentMonth.Month, d);
|
||||
var isSelected = IsSameDay(day, SelectedDate);
|
||||
var isToday = IsSameDay(day, DateTime.Today);
|
||||
var events = GetEventsForDay(day);
|
||||
var events = ReturnFilteredActivity(day);
|
||||
|
||||
<div class="day @(isSelected ? "selected" : (isToday ? "today" : ""))"
|
||||
@onclick="() => SelezionaDataDalMese(day)">
|
||||
@@ -69,10 +70,10 @@
|
||||
<div class="day @(isSelected ? "selected" : (isToday ? "today" : ""))"
|
||||
@onclick="() => SelezionaData(day)">
|
||||
<div>@day.Day</div>
|
||||
@if (GetEventsForDay(day).Any())
|
||||
@if (ReturnFilteredActivity(day).Any())
|
||||
{
|
||||
<div class="event-dot-container" style="margin-top: 2px;">
|
||||
@foreach (var cat in GetEventsForDay(day).Select(x => x.Category).Distinct())
|
||||
@foreach (var cat in ReturnFilteredActivity(day).Select(x => x.Category).Distinct())
|
||||
{
|
||||
<div class="event-dot @cat.ConvertToHumanReadable()" title="@cat.ConvertToHumanReadable()"></div>
|
||||
}
|
||||
@@ -92,7 +93,7 @@
|
||||
else if (FilteredActivities is { Count: > 0 })
|
||||
{
|
||||
<Virtualize Items="FilteredActivities" Context="activity">
|
||||
<ActivityCard Activity="activity" />
|
||||
<ActivityCard Activity="activity" ActivityChanged="OnActivityChanged"/>
|
||||
</Virtualize>
|
||||
}
|
||||
else
|
||||
@@ -101,6 +102,8 @@
|
||||
}
|
||||
</div>
|
||||
|
||||
<FilterActivity @bind-IsSheetVisible="OpenFilter" @bind-Filter="Filter" @bind-Filter:after="ApplyFilter"/>
|
||||
|
||||
@code {
|
||||
|
||||
// Stato UI
|
||||
@@ -124,6 +127,10 @@
|
||||
private int DaysInMonth => DateTime.DaysInMonth(CurrentMonth.Year, CurrentMonth.Month);
|
||||
private int StartOffset => (int)CurrentMonth.DayOfWeek == 0 ? 6 : (int)CurrentMonth.DayOfWeek - 1;
|
||||
|
||||
//Filtri
|
||||
private bool OpenFilter { get; set; }
|
||||
private FilterActivityDTO Filter { get; set; } = new();
|
||||
|
||||
private int EndOffset
|
||||
{
|
||||
get
|
||||
@@ -147,10 +154,17 @@
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
Filter.User = new HashSet<string> { UserSession.User.Username };
|
||||
|
||||
dotNetHelper = DotNetObjectReference.Create(this);
|
||||
await JS.InvokeVoidAsync("calendarSwipe.register", weekSliderRef, dotNetHelper);
|
||||
_internalMonth = new DateTime(SelectedDate.Year, SelectedDate.Month, 1);
|
||||
await LoadMonthData();
|
||||
|
||||
if (!Expanded)
|
||||
ApplyFilter();
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +263,7 @@
|
||||
// Carica tutte le attività del mese corrente visualizzato
|
||||
var start = CurrentMonth;
|
||||
var end = start.AddDays(DaysInMonth - 1);
|
||||
var activities = await manageData.GetActivity(x =>
|
||||
var activities = await ManageData.GetActivity(x =>
|
||||
(x.EffectiveDate == null && x.EstimatedDate >= start && x.EstimatedDate <= end) ||
|
||||
(x.EffectiveDate >= start && x.EffectiveDate <= end));
|
||||
MonthActivities = activities.OrderBy(x => x.EffectiveDate ?? x.EstimatedDate).ToList();
|
||||
@@ -272,7 +286,7 @@
|
||||
await LoadMonthData();
|
||||
}
|
||||
|
||||
FilteredActivities = GetEventsForDay(day);
|
||||
ApplyFilter();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
@@ -280,7 +294,7 @@
|
||||
private async Task SelezionaDataDalMese(DateTime day)
|
||||
{
|
||||
SelectedDate = day;
|
||||
FilteredActivities = GetEventsForDay(day);
|
||||
ApplyFilter();
|
||||
// Chiudi la vista mese e passa alla settimana, con animazione
|
||||
SliderAnimation = "collapse-animation";
|
||||
StateHasChanged();
|
||||
@@ -306,4 +320,63 @@
|
||||
{
|
||||
dotNetHelper?.Dispose();
|
||||
}
|
||||
|
||||
private async Task OnActivityChanged(string activityId)
|
||||
{
|
||||
var newActivity = await ManageData.GetActivity(x => x.ActivityId.Equals(activityId));
|
||||
var indexActivity = MonthActivities?.FindIndex(x => x.ActivityId.Equals(activityId));
|
||||
|
||||
if (indexActivity != null && !newActivity.IsNullOrEmpty())
|
||||
{
|
||||
MonthActivities![indexActivity.Value] = newActivity[0];
|
||||
}
|
||||
|
||||
ApplyFilter();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void ToggleFilter()
|
||||
{
|
||||
OpenFilter = !OpenFilter;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void ApplyFilter()
|
||||
{
|
||||
FilteredActivities = GetEventsForDay(SelectedDate);
|
||||
|
||||
if (!Filter.ClearFilter)
|
||||
{
|
||||
FilteredActivities = GetEventsForDay(SelectedDate)?
|
||||
.Where(x =>
|
||||
(!Filter.Text.IsNullOrEmpty() && x.ActivityDescription != null && x.ActivityDescription.ContainsIgnoreCase(Filter.Text!)) ||
|
||||
(x.ActivityTypeId != null && !Filter.Type.IsNullOrEmpty() && x.ActivityTypeId.Equals(Filter.Type)) ||
|
||||
(x.ActivityResultId != null && !Filter.Result.IsNullOrEmpty() && x.ActivityResultId.Equals(Filter.Result)) ||
|
||||
(x.UserName != null && !Filter.User.IsNullOrEmpty() && Filter.User!.Contains(x.UserName)) ||
|
||||
(Filter.Category != null && x.Category.Equals(Filter.Category))
|
||||
)
|
||||
.ToList() ?? [];
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private List<ActivityDTO> ReturnFilteredActivity(DateTime day)
|
||||
{
|
||||
if (!Filter.ClearFilter)
|
||||
{
|
||||
return GetEventsForDay(day)?
|
||||
.Where(x =>
|
||||
(!Filter.Text.IsNullOrEmpty() && x.ActivityDescription != null && x.ActivityDescription.ContainsIgnoreCase(Filter.Text!)) ||
|
||||
(x.ActivityTypeId != null && !Filter.Type.IsNullOrEmpty() && x.ActivityTypeId.Equals(Filter.Type)) ||
|
||||
(x.ActivityResultId != null && !Filter.Result.IsNullOrEmpty() && x.ActivityResultId.Equals(Filter.Result)) ||
|
||||
(x.UserName != null && !Filter.User.IsNullOrEmpty() && Filter.User!.Contains(x.UserName)) ||
|
||||
(Filter.Category != null && x.Category.Equals(Filter.Category))
|
||||
)
|
||||
.ToList() ?? [];
|
||||
}
|
||||
|
||||
return GetEventsForDay(day);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user