Rename salesbook
This commit is contained in:
625
salesbook.Shared/Components/Pages/Calendar.razor
Normal file
625
salesbook.Shared/Components/Pages/Calendar.razor
Normal file
@@ -0,0 +1,625 @@
|
||||
@page "/Calendar"
|
||||
@using salesbook.Shared.Core.Dto
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@using salesbook.Shared.Components.Layout
|
||||
@using salesbook.Shared.Components.SingleElements
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Components.SingleElements.BottomSheet
|
||||
@using salesbook.Shared.Core.Entity
|
||||
@using salesbook.Shared.Core.Messages.Activity.New
|
||||
@inject IManageDataService ManageData
|
||||
@inject IJSRuntime JS
|
||||
@inject NewActivityService NewActivity
|
||||
|
||||
<HeaderLayout Title="@_headerTitle"
|
||||
ShowFilter="true"
|
||||
ShowCalendarToggle="true"
|
||||
OnFilterToggle="ToggleFilter"
|
||||
OnCalendarToggle="ToggleExpanded"/>
|
||||
|
||||
<div @ref="_weekSliderRef" class="container week-slider @(Expanded ? "expanded" : "") @(SliderAnimation)">
|
||||
@if (Expanded)
|
||||
{
|
||||
<!-- Vista mensile -->
|
||||
@foreach (var nomeGiorno in GiorniSettimana)
|
||||
{
|
||||
<div class="week-day">
|
||||
<div>@nomeGiorno</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@foreach (var unused in Enumerable.Range(0, StartOffset))
|
||||
{
|
||||
<div class="day" style="visibility: hidden"></div>
|
||||
}
|
||||
|
||||
@if (_isInitialized && _monthDaysData.Length > 0)
|
||||
{
|
||||
@for (var d = 1; d <= DaysInMonth; d++)
|
||||
{
|
||||
var day = new DateTime(CurrentMonth.Year, CurrentMonth.Month, d);
|
||||
var dayData = _monthDaysData[d - 1];
|
||||
|
||||
<div class="day @dayData.CssClass"
|
||||
@onclick="() => SelezionaDataDalMese(day)">
|
||||
<div>@d</div>
|
||||
@if (dayData.HasEvents)
|
||||
{
|
||||
<div class="event-dot-container" style="margin-top: 2px;">
|
||||
@foreach (var cat in dayData.EventCategories)
|
||||
{
|
||||
<div class="event-dot @cat.CssClass" title="@cat.Title"></div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@* Fallback rendering per prima inizializzazione *@
|
||||
@for (var d = 1; d <= DaysInMonth; d++)
|
||||
{
|
||||
var day = new DateTime(CurrentMonth.Year, CurrentMonth.Month, d);
|
||||
var isSelected = IsSameDay(day, SelectedDate);
|
||||
var isToday = IsSameDay(day, DateTime.Today);
|
||||
var events = GetEventsForDay(day);
|
||||
|
||||
<div class="day @(isSelected ? "selected" : (isToday ? "today" : ""))"
|
||||
@onclick="() => SelezionaDataDalMese(day)">
|
||||
<div>@d</div>
|
||||
@if (events.Any())
|
||||
{
|
||||
<div class="event-dot-container" style="margin-top: 2px;">
|
||||
@foreach (var cat in events.Select(x => x.Category).Distinct())
|
||||
{
|
||||
<div class="event-dot @cat.ConvertToHumanReadable()" title="@cat.ConvertToHumanReadable()"></div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@foreach (var unused in Enumerable.Range(0, EndOffset))
|
||||
{
|
||||
<div class="day" style="visibility: hidden"></div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<!-- Vista settimanale -->
|
||||
@if (_isInitialized && _weekDaysData.Length == 7 && _weekDaysData[0].Date != default)
|
||||
{
|
||||
@for (int i = 0; i < 7; i++)
|
||||
{
|
||||
var dayData = _weekDaysData[i];
|
||||
var day = dayData.Date;
|
||||
|
||||
<div class="week-day">
|
||||
<div>@dayData.DayName</div>
|
||||
<div class="day @dayData.CssClass"
|
||||
@onclick="() => SelezionaData(day)">
|
||||
<div>@day.Day</div>
|
||||
@if (dayData.HasEvents)
|
||||
{
|
||||
<div class="event-dot-container" style="margin-top: 2px;">
|
||||
@foreach (var cat in dayData.EventCategories)
|
||||
{
|
||||
<div class="event-dot @cat.CssClass" title="@cat.Title"></div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var start = GetStartOfWeek(SelectedDate);
|
||||
var culture = new System.Globalization.CultureInfo("it-IT");
|
||||
|
||||
|
||||
for (var i = 0; i < 7; i++)
|
||||
{
|
||||
var day = start.AddDays(i);
|
||||
var isSelected = IsSameDay(day, SelectedDate);
|
||||
var isToday = IsSameDay(day, DateTime.Today);
|
||||
var events = GetEventsForDay(day);
|
||||
|
||||
<div class="week-day">
|
||||
<div>@day.ToString("ddd", culture)</div>
|
||||
<div class="day @(isSelected ? "selected" : (isToday ? "today" : ""))"
|
||||
@onclick="() => SelezionaData(day)"
|
||||
aria-label="@day.ToString("dddd d MMMM", culture)">
|
||||
<div>@day.Day</div>
|
||||
@if (events.Any())
|
||||
{
|
||||
<div class="event-dot-container" style="margin-top: 2px;">
|
||||
@foreach (var cat in events.Select(x => x.Category).Distinct())
|
||||
{
|
||||
<div class="event-dot @cat.ConvertToHumanReadable()" title="@cat.ConvertToHumanReadable()"></div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="container appointments">
|
||||
@if (IsLoading)
|
||||
{
|
||||
<SpinnerLayout FullScreen="false"/>
|
||||
}
|
||||
else if (FilteredActivities is { Count: > 0 })
|
||||
{
|
||||
<Virtualize Items="FilteredActivities" Context="activity">
|
||||
<ActivityCard Activity="activity" ActivityChanged="OnActivityChanged" ActivityDeleted="OnActivityDeleted" />
|
||||
</Virtualize>
|
||||
}
|
||||
else
|
||||
{
|
||||
<NoDataAvailable Text="Nessuna attività trovata" ImageSource="_content/salesbook.Shared/images/undraw_file-search_cbur.svg"/>
|
||||
}
|
||||
</div>
|
||||
|
||||
<FilterActivity @bind-IsSheetVisible="OpenFilter" @bind-Filter="Filter" @bind-Filter:after="ApplyFilter"/>
|
||||
|
||||
@code {
|
||||
|
||||
// Modelli per ottimizzazione rendering
|
||||
private record DayData(DateTime Date, string CssClass, bool HasEvents, CategoryData[] EventCategories, string DayName = "");
|
||||
|
||||
private record CategoryData(string CssClass, string Title);
|
||||
|
||||
// Cache per rendering
|
||||
private DayData[] _monthDaysData = [];
|
||||
private readonly DayData[] _weekDaysData = new DayData[7];
|
||||
private string _headerTitle = string.Empty;
|
||||
private readonly Dictionary<DateTime, List<ActivityDTO>> _eventsCache = new();
|
||||
private readonly Dictionary<DateTime, CategoryData[]> _categoriesCache = new();
|
||||
private bool _isInitialized = false;
|
||||
|
||||
// Stato UI
|
||||
private bool Expanded { get; set; }
|
||||
private string SliderAnimation { get; set; } = string.Empty;
|
||||
private ElementReference _weekSliderRef;
|
||||
private DotNetObjectReference<Calendar>? _dotNetHelper;
|
||||
|
||||
// Stato calendario
|
||||
private DateTime SelectedDate { get; set; } = DateTime.Today;
|
||||
private DateTime _internalMonth = DateTime.Today;
|
||||
private DateTime CurrentMonth => new(_internalMonth.Year, _internalMonth.Month, 1);
|
||||
|
||||
// Stato attività
|
||||
private List<ActivityDTO> MonthActivities { get; set; } = [];
|
||||
private List<ActivityDTO> FilteredActivities { get; set; } = [];
|
||||
private bool IsLoading { get; set; } = true;
|
||||
|
||||
// Supporto rendering mese
|
||||
private static readonly string[] GiorniSettimana = ["Lu", "Ma", "Me", "Gi", "Ve", "Sa", "Do"];
|
||||
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
|
||||
{
|
||||
var totalCells = (int)Math.Ceiling((DaysInMonth + StartOffset) / 7.0) * 7;
|
||||
return totalCells - (DaysInMonth + StartOffset);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
PrepareRenderingData();
|
||||
|
||||
NewActivity.OnActivityCreated += async activityId => await OnActivityCreated(activityId);
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
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();
|
||||
|
||||
_isInitialized = true;
|
||||
ApplyFilter();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Metodo per preparare i dati di rendering una sola volta
|
||||
private void PrepareRenderingData()
|
||||
{
|
||||
PrepareHeaderTitle();
|
||||
PrepareEventsCache();
|
||||
|
||||
if (Expanded)
|
||||
{
|
||||
PrepareMonthDaysData();
|
||||
}
|
||||
else
|
||||
{
|
||||
PrepareWeekDaysData();
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareHeaderTitle()
|
||||
{
|
||||
_headerTitle = CurrentMonth.ToString("MMMM yyyy", new System.Globalization.CultureInfo("it-IT")).FirstCharToUpper();
|
||||
}
|
||||
|
||||
private void PrepareEventsCache()
|
||||
{
|
||||
_eventsCache.Clear();
|
||||
_categoriesCache.Clear();
|
||||
|
||||
// Raggruppa le attività per data
|
||||
var activitiesByDate = MonthActivities
|
||||
.GroupBy(x => (x.EffectiveDate ?? x.EstimatedDate!).Value.Date)
|
||||
.ToDictionary(g => g.Key, g => g.ToList());
|
||||
|
||||
foreach (var (date, activities) in activitiesByDate)
|
||||
{
|
||||
_eventsCache[date] = activities;
|
||||
|
||||
// Pre-calcola le categorie per ogni giorno
|
||||
var categories = activities
|
||||
.Select(x => x.Category)
|
||||
.Distinct()
|
||||
.Select(cat => new CategoryData(cat.ConvertToHumanReadable(), cat.ConvertToHumanReadable()))
|
||||
.ToArray();
|
||||
|
||||
_categoriesCache[date] = categories;
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareMonthDaysData()
|
||||
{
|
||||
_monthDaysData = new DayData[DaysInMonth];
|
||||
var today = DateTime.Today;
|
||||
|
||||
for (var d = 1; d <= DaysInMonth; d++)
|
||||
{
|
||||
var day = new DateTime(CurrentMonth.Year, CurrentMonth.Month, d);
|
||||
var isSelected = day.Date == SelectedDate.Date;
|
||||
var isToday = day.Date == today;
|
||||
|
||||
var cssClass = isSelected ? "selected" : (isToday ? "today" : "");
|
||||
var hasEvents = _eventsCache.ContainsKey(day.Date);
|
||||
var eventCategories = hasEvents ? GetFilteredCategoriesForDay(day.Date) : [];
|
||||
|
||||
_monthDaysData[d - 1] = new DayData(day, cssClass, eventCategories.Length > 0, eventCategories);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareWeekDaysData()
|
||||
{
|
||||
var start = GetStartOfWeek(SelectedDate);
|
||||
var today = DateTime.Today;
|
||||
var culture = new System.Globalization.CultureInfo("it-IT");
|
||||
|
||||
for (var i = 0; i < 7; i++)
|
||||
{
|
||||
var day = start.AddDays(i);
|
||||
var isSelected = day.Date == SelectedDate.Date;
|
||||
var isToday = day.Date == today;
|
||||
|
||||
var cssClass = isSelected ? "selected" : (isToday ? "today" : "");
|
||||
var dayName = day.ToString("ddd", culture);
|
||||
var hasEvents = _eventsCache.ContainsKey(day.Date);
|
||||
var eventCategories = hasEvents ? GetFilteredCategoriesForDay(day.Date) : [];
|
||||
|
||||
_weekDaysData[i] = new DayData(day, cssClass, eventCategories.Length > 0, eventCategories, dayName);
|
||||
}
|
||||
}
|
||||
|
||||
private CategoryData[] GetFilteredCategoriesForDay(DateTime date)
|
||||
{
|
||||
if (!_categoriesCache.TryGetValue(date, out var categories))
|
||||
return [];
|
||||
|
||||
if (Filter.ClearFilter)
|
||||
return categories;
|
||||
|
||||
// Applica i filtri alle categorie
|
||||
var filteredActivities = GetFilteredActivitiesForDay(date);
|
||||
if (!filteredActivities.Any())
|
||||
return [];
|
||||
|
||||
return filteredActivities
|
||||
.Select(x => x.Category)
|
||||
.Distinct()
|
||||
.Select(cat => new CategoryData(cat.ConvertToHumanReadable(), cat.ConvertToHumanReadable()))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private List<ActivityDTO> GetFilteredActivitiesForDay(DateTime date)
|
||||
{
|
||||
if (!_eventsCache.TryGetValue(date, out var activities))
|
||||
return [];
|
||||
|
||||
if (Filter.ClearFilter)
|
||||
return activities;
|
||||
|
||||
var filteredActivity = activities.AsQueryable();
|
||||
|
||||
filteredActivity = filteredActivity
|
||||
.Where(x => Filter.Text.IsNullOrEmpty() || (x.ActivityDescription != null && x.ActivityDescription.ContainsIgnoreCase(Filter.Text!)));
|
||||
|
||||
filteredActivity = filteredActivity
|
||||
.Where(x => Filter.Type.IsNullOrEmpty() || (x.ActivityTypeId != null && x.ActivityTypeId.Equals(Filter.Type)));
|
||||
|
||||
filteredActivity = filteredActivity
|
||||
.Where(x => Filter.Result.IsNullOrEmpty() || (x.ActivityResultId != null && x.ActivityResultId.Equals(Filter.Result)));
|
||||
|
||||
filteredActivity = filteredActivity
|
||||
.Where(x => Filter.User.IsNullOrEmpty() || (x.UserName != null && Filter.User!.Contains(x.UserName)));
|
||||
|
||||
filteredActivity = filteredActivity
|
||||
.Where(x => Filter.Category == null || x.Category.Equals(Filter.Category));
|
||||
|
||||
return filteredActivity.ToList();
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task OnSwipeLeft()
|
||||
{
|
||||
await CambiaPeriodo(1);
|
||||
PrepareRenderingData();
|
||||
StateHasChanged();
|
||||
if (Expanded)
|
||||
{
|
||||
await LoadMonthData();
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task OnSwipeRight()
|
||||
{
|
||||
await CambiaPeriodo(-1);
|
||||
PrepareRenderingData();
|
||||
StateHasChanged();
|
||||
if (Expanded)
|
||||
{
|
||||
await LoadMonthData();
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task OnSwipeDown()
|
||||
{
|
||||
if (!Expanded)
|
||||
ToggleExpanded();
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task OnSwipeUp()
|
||||
{
|
||||
if (Expanded)
|
||||
ToggleExpanded();
|
||||
}
|
||||
|
||||
// Cambio periodo mese/settimana
|
||||
private async Task CambiaPeriodo(int direzione)
|
||||
{
|
||||
if (Expanded)
|
||||
{
|
||||
var y = CurrentMonth.Year;
|
||||
var m = CurrentMonth.Month + direzione;
|
||||
if (m < 1)
|
||||
{
|
||||
y--;
|
||||
m = 12;
|
||||
}
|
||||
|
||||
if (m > 12)
|
||||
{
|
||||
y++;
|
||||
m = 1;
|
||||
}
|
||||
|
||||
_internalMonth = new DateTime(y, m, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
await SelezionaData(SelectedDate.AddDays(7 * direzione));
|
||||
_internalMonth = new DateTime(SelectedDate.Year, SelectedDate.Month, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Cambio modalità
|
||||
private void ToggleExpanded()
|
||||
{
|
||||
if (Expanded)
|
||||
{
|
||||
SliderAnimation = "collapse-animation";
|
||||
Expanded = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Expanded = true;
|
||||
SliderAnimation = "expand-animation";
|
||||
}
|
||||
|
||||
PrepareRenderingData();
|
||||
StateHasChanged();
|
||||
|
||||
SliderAnimation = "";
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
// Caricamento attività al cambio mese
|
||||
private async Task LoadMonthData()
|
||||
{
|
||||
IsLoading = true;
|
||||
StateHasChanged();
|
||||
|
||||
var start = CurrentMonth;
|
||||
var end = start.AddDays(DaysInMonth - 1);
|
||||
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();
|
||||
|
||||
PrepareRenderingData();
|
||||
IsLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
// Selezione giorno in settimana
|
||||
private async Task SelezionaData(DateTime day)
|
||||
{
|
||||
SelectedDate = day;
|
||||
|
||||
var cacheInternalMonth = _internalMonth;
|
||||
_internalMonth = new DateTime(day.Year, day.Month, 1);
|
||||
|
||||
if (cacheInternalMonth != _internalMonth)
|
||||
{
|
||||
await LoadMonthData();
|
||||
}
|
||||
else
|
||||
{
|
||||
PrepareRenderingData();
|
||||
}
|
||||
|
||||
ApplyFilter();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
// Selezione giorno dal mese (chiude la vista mese!)
|
||||
private async Task SelezionaDataDalMese(DateTime day)
|
||||
{
|
||||
SelectedDate = day;
|
||||
SliderAnimation = "collapse-animation";
|
||||
Expanded = false;
|
||||
_internalMonth = new DateTime(day.Year, day.Month, 1);
|
||||
|
||||
PrepareRenderingData();
|
||||
ApplyFilter();
|
||||
StateHasChanged();
|
||||
|
||||
SliderAnimation = "";
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
// Utility
|
||||
private static bool IsSameDay(DateTime d1, DateTime d2) => d1.Date == d2.Date;
|
||||
|
||||
private static DateTime GetStartOfWeek(DateTime date)
|
||||
{
|
||||
var day = date.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)date.DayOfWeek;
|
||||
return date.AddDays(-day + 1).Date;
|
||||
}
|
||||
|
||||
private List<ActivityDTO> GetEventsForDay(DateTime day)
|
||||
=> _eventsCache.TryGetValue(day.Date, out var events) ? events : [];
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_dotNetHelper?.Dispose();
|
||||
}
|
||||
|
||||
private async Task OnActivityDeleted(ActivityDTO activity)
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
await ManageData.DeleteActivity(activity);
|
||||
|
||||
var indexActivity = MonthActivities?.FindIndex(x => x.ActivityId.Equals(activity.ActivityId));
|
||||
|
||||
if (indexActivity != null)
|
||||
{
|
||||
MonthActivities?.RemoveAt(indexActivity.Value);
|
||||
PrepareRenderingData();
|
||||
|
||||
ApplyFilter();
|
||||
}
|
||||
|
||||
IsLoading = false;
|
||||
}
|
||||
|
||||
private async Task OnActivityCreated(string activityId)
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
var activity = (await ManageData.GetActivity(x => x.ActivityId.Equals(activityId))).LastOrDefault();
|
||||
|
||||
if (activity == null)
|
||||
{
|
||||
IsLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var date = activity.EffectiveDate ?? activity.EstimatedDate;
|
||||
|
||||
if (CurrentMonth.Month != date!.Value.Month)
|
||||
{
|
||||
IsLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
MonthActivities.Add(activity);
|
||||
PrepareRenderingData();
|
||||
IsLoading = false;
|
||||
|
||||
ApplyFilter();
|
||||
}
|
||||
|
||||
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];
|
||||
PrepareRenderingData(); // Ricalcola i dati di rendering
|
||||
ApplyFilter();
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleFilter()
|
||||
{
|
||||
OpenFilter = !OpenFilter;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void ApplyFilter()
|
||||
{
|
||||
FilteredActivities = GetFilteredActivitiesForDay(SelectedDate);
|
||||
|
||||
// Aggiorna i dati di rendering se il filtro è cambiato
|
||||
if (Expanded)
|
||||
{
|
||||
PrepareMonthDaysData();
|
||||
}
|
||||
else
|
||||
{
|
||||
PrepareWeekDaysData();
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
// Metodo ottimizzato per il rendering dei filtri
|
||||
private List<ActivityDTO> ReturnFilteredActivity(DateTime day)
|
||||
{
|
||||
return GetFilteredActivitiesForDay(day);
|
||||
}
|
||||
|
||||
}
|
||||
167
salesbook.Shared/Components/Pages/Calendar.razor.css
Normal file
167
salesbook.Shared/Components/Pages/Calendar.razor.css
Normal file
@@ -0,0 +1,167 @@
|
||||
.calendar {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.week-slider {
|
||||
width: 100%;
|
||||
transition: all 0.4s ease;
|
||||
transform-origin: center center;
|
||||
transform: scaleY(1);
|
||||
opacity: 1;
|
||||
touch-action: pan-x;
|
||||
user-select: none;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.week-slider:not(.expanded) {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: flex-start;
|
||||
gap: 0.6rem;
|
||||
padding-top: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
overflow-x: hidden;
|
||||
overflow-y: visible;
|
||||
}
|
||||
|
||||
.week-slider.expanded {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
gap: 0.4rem;
|
||||
padding: 1rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.week-slider.expand-animation { animation: expandFromCenter 0.3s ease forwards; }
|
||||
|
||||
.week-slider.collapse-animation { animation: collapseToCenter 0.3s ease forwards; }
|
||||
|
||||
@keyframes expandFromCenter {
|
||||
from {
|
||||
transform: scaleY(0.6);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
to {
|
||||
transform: scaleY(1);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes collapseToCenter {
|
||||
from {
|
||||
transform: scaleY(1);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
to {
|
||||
transform: scaleY(0.6);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.week-day {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
max-width: 60px;
|
||||
flex: 1 1 0;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
|
||||
.week-day > div:first-child {
|
||||
font-size: 0.8rem;
|
||||
color: var(--mud-palette-text-primary);
|
||||
margin-bottom: 0.2rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.day {
|
||||
background: var(--mud-palette-surface);
|
||||
border-radius: 10px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s ease, transform 0.2s ease;
|
||||
font-size: 0.95rem;
|
||||
box-shadow: var(--custom-box-shadow);
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: var(--mud-palette-text-primary);
|
||||
border: 1px solid var(--mud-palette-surface);
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.day:hover { transform: scale(1.08); }
|
||||
|
||||
.week-slider:not(.expanded) .day {
|
||||
padding: 0;
|
||||
min-width: 38px;
|
||||
min-height: 38px;
|
||||
max-width: 48px;
|
||||
max-height: 48px;
|
||||
}
|
||||
|
||||
.day.selected {
|
||||
background: var(--mud-palette-tertiary);
|
||||
border: 1px solid var(--mud-palette-tertiary);
|
||||
color: var(--mud-palette-secondary);
|
||||
}
|
||||
|
||||
.day.today { border: 1px solid var(--mud-palette-primary); }
|
||||
|
||||
.appointments {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
overflow-y: auto;
|
||||
flex-direction: column;
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
padding-bottom: 70px;
|
||||
height: calc(100% - 130px);
|
||||
}
|
||||
|
||||
.appointments.ah-calendar-m { height: calc(100% - 315px) !important; }
|
||||
|
||||
.appointments::-webkit-scrollbar { display: none; }
|
||||
|
||||
.appointment {
|
||||
background: var(--mud-palette-surface);
|
||||
border-radius: 8px;
|
||||
padding: 0.8rem;
|
||||
margin-bottom: 0.5rem;
|
||||
box-shadow: var(--custom-box-shadow);
|
||||
}
|
||||
|
||||
.toggle-month {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--mud-palette-text-primary);
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.event-dot-container {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.event-dot {
|
||||
height: 5px;
|
||||
width: 5px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.event-dot.memo { background-color: var(--mud-palette-info-darken); }
|
||||
|
||||
.event-dot.interna { background-color: var(--mud-palette-success-darken); }
|
||||
|
||||
.event-dot.commessa { background-color: var(--mud-palette-warning); }
|
||||
|
||||
@supports (-webkit-touch-callout: none) { .appointments { padding-bottom: calc(60px + env(safe-area-inset-bottom)) !important; } }
|
||||
22
salesbook.Shared/Components/Pages/Home.razor
Normal file
22
salesbook.Shared/Components/Pages/Home.razor
Normal file
@@ -0,0 +1,22 @@
|
||||
@page "/"
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@attribute [Authorize]
|
||||
@inject IFormFactor FormFactor
|
||||
@inject INetworkService NetworkService
|
||||
|
||||
@code
|
||||
{
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
var lastSyncDate = LocalStorage.Get<DateTime>("last-sync");
|
||||
|
||||
if (!FormFactor.IsWeb() && NetworkService.IsNetworkAvailable() && lastSyncDate.Equals(DateTime.MinValue))
|
||||
{
|
||||
NavigationManager.NavigateTo("/sync");
|
||||
return base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
NavigationManager.NavigateTo("/Calendar");
|
||||
return base.OnInitializedAsync();
|
||||
}
|
||||
}
|
||||
113
salesbook.Shared/Components/Pages/Login.razor
Normal file
113
salesbook.Shared/Components/Pages/Login.razor
Normal file
@@ -0,0 +1,113 @@
|
||||
@page "/login"
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Core.Services
|
||||
@inject IUserAccountService UserAccountService
|
||||
@inject AppAuthenticationStateProvider AuthenticationStateProvider
|
||||
|
||||
@if (Spinner)
|
||||
{
|
||||
<SpinnerLayout/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="login-page">
|
||||
<div class="container container-top-logo">
|
||||
<img src="_content/salesbook.Shared/images/salesbook-marchio_vers.positiva.svg" class="logo" alt="sales book">
|
||||
</div>
|
||||
<div class="container container-login">
|
||||
<div class="login-form-container">
|
||||
<div class="input-group">
|
||||
<MudTextField @bind-Value="UserData.Username" Label="Username" Variant="Variant.Outlined"/>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<MudTextField InputType="@_passwordInput" @bind-Value="UserData.Password" Label="Password" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentIcon="@_passwordInputIcon" OnAdornmentClick="ShowPassword" AdornmentAriaLabel="Show Password"/>
|
||||
</div>
|
||||
<div class="input-group mb-2">
|
||||
<MudTextField @bind-Value="UserData.CodHash" Label="Profilo azienda" Variant="Variant.Outlined"/>
|
||||
</div>
|
||||
|
||||
<MudButton OnClick="SignInUser" Color="Color.Primary" Variant="Variant.Filled">Login</MudButton>
|
||||
@if (_attemptFailed)
|
||||
{
|
||||
<MudAlert Class="my-3" Dense="true" Severity="Severity.Error" Variant="Variant.Filled">@ErrorMessage</MudAlert>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="my-4 login-footer">
|
||||
<span>Powered by</span>
|
||||
<img src="_content/salesbook.Shared/images/logoIntegry.svg" class="img-fluid" alt="Integry">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private SignIn UserData { get; } = new();
|
||||
private bool Spinner { get; set; }
|
||||
private string ErrorMessage { get; set; } = "";
|
||||
private bool _attemptFailed;
|
||||
|
||||
private bool _isShow;
|
||||
private InputType _passwordInput = InputType.Password;
|
||||
private string _passwordInputIcon = Icons.Material.Rounded.VisibilityOff;
|
||||
|
||||
private void ShowPassword()
|
||||
{
|
||||
@if (_isShow)
|
||||
{
|
||||
_isShow = false;
|
||||
_passwordInputIcon = Icons.Material.Rounded.VisibilityOff;
|
||||
_passwordInput = InputType.Password;
|
||||
}
|
||||
else
|
||||
{
|
||||
_isShow = true;
|
||||
_passwordInputIcon = Icons.Material.Rounded.Visibility;
|
||||
_passwordInput = InputType.Text;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
UserData.CodHash = LocalStorage.GetString("codHash");
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task SignInUser()
|
||||
{
|
||||
_attemptFailed = false;
|
||||
if (!string.IsNullOrEmpty(UserData.Username) && !string.IsNullOrEmpty(UserData.Password) && !string.IsNullOrEmpty(UserData.CodHash))
|
||||
{
|
||||
Spinner = true;
|
||||
StateHasChanged();
|
||||
|
||||
try
|
||||
{
|
||||
await UserAccountService.Login(UserData.Username, UserData.Password, UserData.CodHash);
|
||||
AuthenticationStateProvider.NotifyAuthenticationState(); //Chiamato per forzare il refresh
|
||||
|
||||
LocalStorage.SetString("codHash", UserData.CodHash);
|
||||
NavigationManager.NavigateTo("/");
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Spinner = false;
|
||||
StateHasChanged();
|
||||
|
||||
ErrorMessage = e.Message;
|
||||
_attemptFailed = true;
|
||||
Console.WriteLine(e);
|
||||
// Logger<>.LogError(e, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SignIn
|
||||
{
|
||||
public string? Username { get; set; }
|
||||
public string? Password { get; set; }
|
||||
public string? CodHash { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
54
salesbook.Shared/Components/Pages/Login.razor.css
Normal file
54
salesbook.Shared/Components/Pages/Login.razor.css
Normal file
@@ -0,0 +1,54 @@
|
||||
.login-page {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--mud-palette-surface);
|
||||
}
|
||||
|
||||
.container-top-logo > .logo {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.container-login > span {
|
||||
font-size: large;
|
||||
font-weight: 900;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.container-top-logo {
|
||||
height: 35vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.login-form-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.container-login {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 4px 16px 16px;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.login-footer span {
|
||||
font-size: 9px;
|
||||
color: var(--mud-palette-gray-darker);
|
||||
}
|
||||
|
||||
.login-footer img {
|
||||
height: 15px;
|
||||
margin-left: 4px;
|
||||
}
|
||||
14
salesbook.Shared/Components/Pages/Notifications.razor
Normal file
14
salesbook.Shared/Components/Pages/Notifications.razor
Normal file
@@ -0,0 +1,14 @@
|
||||
@page "/Notifications"
|
||||
@attribute [Authorize]
|
||||
@using salesbook.Shared.Components.Layout
|
||||
@using salesbook.Shared.Components.SingleElements
|
||||
|
||||
<HeaderLayout Title="Notifiche" />
|
||||
|
||||
<div class="container">
|
||||
<NoDataAvailable Text="Nessuna notifica meno recente" />
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
}
|
||||
164
salesbook.Shared/Components/Pages/PersonalInfo.razor
Normal file
164
salesbook.Shared/Components/Pages/PersonalInfo.razor
Normal file
@@ -0,0 +1,164 @@
|
||||
@page "/PersonalInfo"
|
||||
@attribute [Authorize]
|
||||
@using salesbook.Shared.Components.Layout
|
||||
@using salesbook.Shared.Core.Authorization.Enum
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@using salesbook.Shared.Core.Services
|
||||
@inject AppAuthenticationStateProvider AuthenticationStateProvider
|
||||
@inject INetworkService NetworkService
|
||||
@inject IFormFactor FormFactor
|
||||
|
||||
<HeaderLayout BackTo="Indietro" Back="true" BackOnTop="true" Title="Profilo" ShowProfile="false"/>
|
||||
|
||||
@if (IsLoggedIn)
|
||||
{
|
||||
<div class="container content">
|
||||
<div class="container-primary-info">
|
||||
<div class="section-primary-info">
|
||||
<MudAvatar Style="height: 70px; width: 70px; font-size: 2rem; font-weight: bold" Color="Color.Secondary">
|
||||
@UtilityString.ExtractInitials(UserSession.User.Fullname)
|
||||
</MudAvatar>
|
||||
|
||||
<div class="personal-info">
|
||||
<span class="info-nome">@UserSession.User.Fullname</span>
|
||||
@if (UserSession.User.KeyGroup is not null)
|
||||
{
|
||||
<span class="info-section">@(((KeyGroupEnum)UserSession.User.KeyGroup).ConvertToHumanReadable())</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="section-info">
|
||||
<div class="section-personal-info">
|
||||
<div>
|
||||
<span class="info-title">Telefono</span>
|
||||
<span class="info-text">000 0000000</span> @*Todo: to implement*@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="info-title">Status</span>
|
||||
@if (NetworkService.IsNetworkAvailable())
|
||||
{
|
||||
<div class="status online">
|
||||
<i class="ri-wifi-line"></i>
|
||||
<span>Online</span>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="status offline">
|
||||
<i class="ri-wifi-off-line"></i>
|
||||
<span>Offline</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-personal-info">
|
||||
<div>
|
||||
<span class="info-title">E-mail</span>
|
||||
<span class="info-text">
|
||||
@if (string.IsNullOrEmpty(UserSession.User.Email))
|
||||
{
|
||||
@("Nessuna mail configurata")
|
||||
}
|
||||
else
|
||||
{
|
||||
@UserSession.User.Email
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="info-title">Ultima sincronizzazione</span>
|
||||
<span class="info-text">@LastSync.ToString("g")</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container-button">
|
||||
<MudButton Class="button-settings green-icon"
|
||||
FullWidth="true"
|
||||
StartIcon="@Icons.Material.Outlined.Sync"
|
||||
Size="Size.Medium"
|
||||
OnClick="() => UpdateDb(true)"
|
||||
Variant="Variant.Outlined">
|
||||
Sincronizza
|
||||
</MudButton>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<MudButton Class="button-settings red-icon"
|
||||
FullWidth="true"
|
||||
StartIcon="@Icons.Material.Outlined.Sync"
|
||||
Size="Size.Medium"
|
||||
OnClick="() => UpdateDb()"
|
||||
Variant="Variant.Outlined">
|
||||
Ripristina dati
|
||||
</MudButton>
|
||||
</div>
|
||||
|
||||
<div class="container-button">
|
||||
<MudButton Class="button-settings exit"
|
||||
FullWidth="true"
|
||||
Color="Color.Error"
|
||||
Size="Size.Medium"
|
||||
OnClick="Logout"
|
||||
Variant="Variant.Outlined">
|
||||
Esci
|
||||
</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private bool Unavailable { get; set; }
|
||||
private bool IsLoggedIn { get; set; }
|
||||
private DateTime LastSync { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
IsLoggedIn = await UserSession.IsLoggedIn();
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Unavailable = FormFactor.IsWeb() || !NetworkService.IsNetworkAvailable();
|
||||
LastSync = LocalStorage.Get<DateTime>("last-sync");
|
||||
});
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void OpenSettings() =>
|
||||
NavigationManager.NavigateTo("/settings/Profilo");
|
||||
|
||||
private async Task Logout()
|
||||
{
|
||||
await AuthenticationStateProvider.SignOut();
|
||||
IsLoggedIn = await UserSession.IsLoggedIn();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void UpdateDb(bool withData = false)
|
||||
{
|
||||
var absoluteUri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
|
||||
var pathAndQuery = absoluteUri.Segments.Length > 1 ? absoluteUri.PathAndQuery : null;
|
||||
|
||||
string path;
|
||||
|
||||
if (withData)
|
||||
path = pathAndQuery == null ? $"/sync/{DateTime.Today:yyyy-MM-dd}" : $"/sync/{DateTime.Today:yyyy-MM-dd}?path=" + System.Web.HttpUtility.UrlEncode(pathAndQuery);
|
||||
else
|
||||
path = pathAndQuery == null ? "/sync" : "/sync?path=" + System.Web.HttpUtility.UrlEncode(pathAndQuery);
|
||||
|
||||
NavigationManager.NavigateTo(path, replace: true);
|
||||
}
|
||||
|
||||
}
|
||||
83
salesbook.Shared/Components/Pages/PersonalInfo.razor.css
Normal file
83
salesbook.Shared/Components/Pages/PersonalInfo.razor.css
Normal file
@@ -0,0 +1,83 @@
|
||||
.container-primary-info {
|
||||
box-shadow: var(--custom-box-shadow);
|
||||
width: 100%;
|
||||
margin-bottom: 2rem;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.container-primary-info .divider {
|
||||
margin: 0 0 0 7rem;
|
||||
width: unset;
|
||||
}
|
||||
|
||||
.section-primary-info {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 1.5rem;
|
||||
padding: .8rem 1.2rem .4rem;
|
||||
}
|
||||
|
||||
.personal-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.info-nome {
|
||||
color: var(--mud-palette-text-primary);
|
||||
font-weight: 800;
|
||||
font-size: x-large;
|
||||
}
|
||||
|
||||
.info-section {
|
||||
color: var(--mud-palette-gray-default);
|
||||
font-size: medium;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.section-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
flex-direction: row;
|
||||
padding: .4rem 1.2rem .8rem;
|
||||
}
|
||||
|
||||
.section-personal-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.section-personal-info > div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
line-height: normal;
|
||||
margin: .25rem 0;
|
||||
}
|
||||
|
||||
.info-title {
|
||||
color: var(--mud-palette-gray-darker);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.info-text {
|
||||
color: var(--mud-palette-text-secondary);
|
||||
font-weight: 700;
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.content ::deep .user-button { border: 1px solid var(--card-border-color) !important; }
|
||||
|
||||
.user-button > i { font-size: large; }
|
||||
|
||||
.user-button > span {
|
||||
font-size: medium;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status { font-weight: 700; }
|
||||
|
||||
.status.online { color: var(--mud-palette-success); }
|
||||
|
||||
.status.offline { color: var(--mud-palette-error); }
|
||||
16
salesbook.Shared/Components/Pages/Settings.razor
Normal file
16
salesbook.Shared/Components/Pages/Settings.razor
Normal file
@@ -0,0 +1,16 @@
|
||||
@page "/settings"
|
||||
@page "/settings/{BackTo}"
|
||||
@using salesbook.Shared.Components.Layout
|
||||
|
||||
<HeaderLayout BackTo="@BackTo" Back="true" Title="Impostazioni"/>
|
||||
|
||||
<div class="content">
|
||||
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter] public string BackTo { get; set; } = "";
|
||||
|
||||
|
||||
|
||||
}
|
||||
105
salesbook.Shared/Components/Pages/SyncPage.razor
Normal file
105
salesbook.Shared/Components/Pages/SyncPage.razor
Normal file
@@ -0,0 +1,105 @@
|
||||
@page "/sync"
|
||||
@page "/sync/{DateFilter}"
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@inject ISyncDbService syncDb
|
||||
@inject IManageDataService manageData
|
||||
|
||||
<SyncSpinner Elements="@Elements"/>
|
||||
|
||||
@code {
|
||||
[Parameter] public string? DateFilter { get; set; }
|
||||
|
||||
private Dictionary<string, bool> Elements { get; set; } = new();
|
||||
|
||||
private bool _hasStarted = false;
|
||||
private int _completedCount = 0;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Elements["Attività"] = false;
|
||||
Elements["Commesse"] = false;
|
||||
Elements["Clienti"] = false;
|
||||
Elements["Prospect"] = false;
|
||||
Elements["Impostazioni"] = false;
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender && !_hasStarted)
|
||||
{
|
||||
_hasStarted = true;
|
||||
|
||||
if (DateFilter is null)
|
||||
{
|
||||
await manageData.ClearDb();
|
||||
}
|
||||
|
||||
await Task.WhenAll(
|
||||
RunAndTrack(SetActivity),
|
||||
RunAndTrack(SetClienti),
|
||||
RunAndTrack(SetProspect),
|
||||
RunAndTrack(SetCommesse),
|
||||
RunAndTrack(SetSettings)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunAndTrack(Func<Task> func)
|
||||
{
|
||||
await func();
|
||||
|
||||
_completedCount++;
|
||||
if (_completedCount == Elements.Count)
|
||||
{
|
||||
LocalStorage.Set("last-sync", DateTime.Now);
|
||||
|
||||
var pathQuery = System.Web.HttpUtility.ParseQueryString(new UriBuilder(NavigationManager.Uri).Query);
|
||||
var originalPath = pathQuery["path"] ?? null;
|
||||
var path = originalPath ?? "/Calendar";
|
||||
|
||||
NavigationManager.NavigateTo(path, replace: true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetActivity()
|
||||
{
|
||||
await Task.Run(async () => { await syncDb.GetAndSaveActivity(DateFilter); });
|
||||
|
||||
Elements["Attività"] = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task SetClienti()
|
||||
{
|
||||
await Task.Run(async () => { await syncDb.GetAndSaveClienti(DateFilter); });
|
||||
|
||||
Elements["Clienti"] = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task SetProspect()
|
||||
{
|
||||
await Task.Run(async () => { await syncDb.GetAndSaveProspect(DateFilter); });
|
||||
|
||||
Elements["Prospect"] = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task SetCommesse()
|
||||
{
|
||||
await Task.Run(async () => { await syncDb.GetAndSaveCommesse(DateFilter); });
|
||||
|
||||
Elements["Commesse"] = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task SetSettings()
|
||||
{
|
||||
await Task.Run(async () => { await syncDb.GetAndSaveSettings(DateFilter); });
|
||||
|
||||
Elements["Impostazioni"] = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
}
|
||||
121
salesbook.Shared/Components/Pages/User.razor
Normal file
121
salesbook.Shared/Components/Pages/User.razor
Normal file
@@ -0,0 +1,121 @@
|
||||
@page "/User/{CodAnag}"
|
||||
@attribute [Authorize]
|
||||
@using salesbook.Shared.Components.Layout
|
||||
@using salesbook.Shared.Core.Entity
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@inject IManageDataService ManageData
|
||||
|
||||
<HeaderLayout BackTo="Indietro" Back="true" BackOnTop="true" Title="" ShowProfile="false"/>
|
||||
|
||||
@if (IsLoading)
|
||||
{
|
||||
<SpinnerLayout FullScreen="true"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="container content">
|
||||
<div class="container-primary-info">
|
||||
<div class="section-primary-info">
|
||||
<MudAvatar Style="height: 70px; width: 70px; font-size: 2rem; font-weight: bold" Color="Color.Secondary">
|
||||
@UtilityString.ExtractInitials(Anag.RagSoc)
|
||||
</MudAvatar>
|
||||
|
||||
<div class="personal-info">
|
||||
<span class="info-nome">@Anag.RagSoc</span>
|
||||
@if (UserSession.User.KeyGroup is not null)
|
||||
{
|
||||
<span class="info-section">@Anag.Indirizzo</span>
|
||||
<span class="info-section">@($"{Anag.Cap} - {Anag.Citta} ({Anag.Prov})")</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="section-info">
|
||||
<div class="section-personal-info">
|
||||
<div>
|
||||
<span class="info-title">Telefono</span>
|
||||
<span class="info-text">
|
||||
@if (string.IsNullOrEmpty(Anag.Telefono))
|
||||
{
|
||||
@("Nessuna mail configurata")
|
||||
}
|
||||
else
|
||||
{
|
||||
@Anag.Telefono
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-personal-info">
|
||||
<div>
|
||||
<span class="info-title">E-mail</span>
|
||||
<span class="info-text">
|
||||
@if (string.IsNullOrEmpty(Anag.EMail))
|
||||
{
|
||||
@("Nessuna mail configurata")
|
||||
}
|
||||
else
|
||||
{
|
||||
@Anag.EMail
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (PersRif is { Count: > 0 })
|
||||
{
|
||||
<div class="container-pers-rif">
|
||||
<Virtualize Items="PersRif" Context="person">
|
||||
@{
|
||||
var index = PersRif.IndexOf(person);
|
||||
var isLast = index == PersRif.Count - 1;
|
||||
}
|
||||
<ContactCard Contact="person" />
|
||||
@if (!isLast)
|
||||
{
|
||||
<div class="divider"></div>
|
||||
}
|
||||
</Virtualize>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="container-button">
|
||||
<MudButton Class="button-settings infoText"
|
||||
FullWidth="true"
|
||||
Size="Size.Medium"
|
||||
Variant="Variant.Outlined">
|
||||
Aggiungi contatto
|
||||
</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public string CodAnag { get; set; }
|
||||
|
||||
private AnagClie Anag { get; set; } = new();
|
||||
private List<VtbCliePersRif>? PersRif { get; set; }
|
||||
|
||||
private bool IsLoading { get; set; } = true;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
Anag = (await ManageData.GetTable<AnagClie>(x => x.CodAnag.Equals(CodAnag))).Last();
|
||||
PersRif = await ManageData.GetTable<VtbCliePersRif>(x => x.CodAnag.Equals(Anag.CodAnag));
|
||||
|
||||
IsLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
}
|
||||
147
salesbook.Shared/Components/Pages/User.razor.css
Normal file
147
salesbook.Shared/Components/Pages/User.razor.css
Normal file
@@ -0,0 +1,147 @@
|
||||
.container-primary-info {
|
||||
box-shadow: var(--custom-box-shadow);
|
||||
width: 100%;
|
||||
margin-bottom: 2rem;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.container-primary-info .divider {
|
||||
margin: 0 0 0 7rem;
|
||||
width: unset;
|
||||
}
|
||||
|
||||
.section-primary-info {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 1.5rem;
|
||||
padding: .8rem 1.2rem .4rem;
|
||||
}
|
||||
|
||||
.personal-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.info-nome {
|
||||
color: var(--mud-palette-text-primary);
|
||||
font-weight: 800;
|
||||
font-size: medium;
|
||||
}
|
||||
|
||||
.info-section {
|
||||
color: var(--mud-palette-gray-default);
|
||||
font-size: small;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.section-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
flex-direction: row;
|
||||
padding: .4rem 1.2rem .8rem;
|
||||
}
|
||||
|
||||
.section-personal-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.section-personal-info > div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
line-height: normal;
|
||||
margin: .25rem 0;
|
||||
}
|
||||
|
||||
.info-title {
|
||||
color: var(--mud-palette-gray-darker);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.info-text {
|
||||
color: var(--mud-palette-text-secondary);
|
||||
font-weight: 700;
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.content ::deep .user-button { border: 1px solid var(--card-border-color) !important; }
|
||||
|
||||
.user-button > i { font-size: large; }
|
||||
|
||||
.user-button > span {
|
||||
font-size: medium;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status { font-weight: 700; }
|
||||
|
||||
.status.online { color: var(--mud-palette-success); }
|
||||
|
||||
.status.offline { color: var(--mud-palette-error); }
|
||||
|
||||
.container-button {
|
||||
width: 100%;
|
||||
box-shadow: var(--custom-box-shadow);
|
||||
padding: .25rem 0;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.container-button .divider {
|
||||
margin: .5rem 0 .5rem 3rem;
|
||||
width: unset;
|
||||
}
|
||||
|
||||
.container-button ::deep .button-settings { border: none !important; }
|
||||
|
||||
.container-button ::deep .button-settings .mud-icon-root {
|
||||
border-radius: 6px;
|
||||
padding: 2px;
|
||||
min-width: 25px;
|
||||
min-height: 25px;
|
||||
}
|
||||
|
||||
.container-button ::deep .button-settings.infoText { color: var(--mud-palette-info); }
|
||||
|
||||
.container-button ::deep .button-settings.green-icon .mud-icon-root {
|
||||
border: 1px solid var(--mud-palette-success);
|
||||
background: hsl(from var(--mud-palette-success-lighten) h s 95%);
|
||||
color: var(--mud-palette-success-darken);
|
||||
}
|
||||
|
||||
.container-button ::deep .button-settings.red-icon .mud-icon-root {
|
||||
border: 1px solid var(--mud-palette-error);
|
||||
background: hsl(from var(--mud-palette-error-lighten) h s 95%);
|
||||
color: var(--mud-palette-error-darken);
|
||||
}
|
||||
|
||||
.container-button ::deep .button-settings .mud-button-label {
|
||||
justify-content: flex-start;
|
||||
text-transform: capitalize;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.container-button ::deep .button-settings.exit { padding: 0; }
|
||||
|
||||
.container-button ::deep .button-settings.exit .mud-button-label {
|
||||
justify-content: center;
|
||||
font-size: 1.1rem;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.container-pers-rif {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
box-shadow: var(--custom-box-shadow);
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.container-pers-rif .divider {
|
||||
margin: 0 0 0 3.5rem;
|
||||
width: unset;
|
||||
}
|
||||
117
salesbook.Shared/Components/Pages/Users.razor
Normal file
117
salesbook.Shared/Components/Pages/Users.razor
Normal file
@@ -0,0 +1,117 @@
|
||||
@page "/Users"
|
||||
@attribute [Authorize]
|
||||
@using salesbook.Shared.Components.Layout
|
||||
@using salesbook.Shared.Core.Entity
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@inject IManageDataService ManageData
|
||||
|
||||
<HeaderLayout Title="Contatti"/>
|
||||
|
||||
<div class="container search-box">
|
||||
<div class="input-card clearButton">
|
||||
<MudTextField T="string?" Placeholder="Cerca..." Variant="Variant.Text" @bind-Value="TextToFilter" OnDebounceIntervalElapsed="FilterUsers" DebounceInterval="500"/>
|
||||
|
||||
@if (!TextToFilter.IsNullOrEmpty())
|
||||
{
|
||||
<MudIconButton Class="closeIcon" Icon="@Icons.Material.Filled.Close" OnClick="() => FilterUsers(true)"/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container users">
|
||||
@if (GroupedUserList?.Count > 0)
|
||||
{
|
||||
<Virtualize Items="FilteredGroupedUserList" Context="item">
|
||||
@if (item.ShowHeader)
|
||||
{
|
||||
<div class="letter-header">@item.HeaderLetter</div>
|
||||
}
|
||||
<UserCard User="item.User"/>
|
||||
</Virtualize>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<UserDisplayItem> GroupedUserList { get; set; } = [];
|
||||
private List<UserDisplayItem> FilteredGroupedUserList { get; set; } = [];
|
||||
private string? TextToFilter { get; set; }
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await LoadData();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
var users = await ManageData.GetTable<AnagClie>(x => x.FlagStato.Equals("A"));
|
||||
|
||||
var sortedUsers = users
|
||||
.Where(u => !string.IsNullOrWhiteSpace(u.RagSoc))
|
||||
.OrderBy(u =>
|
||||
{
|
||||
var firstChar = char.ToUpper(u.RagSoc[0]);
|
||||
return char.IsLetter(firstChar) ? firstChar.ToString() : "ZZZ";
|
||||
})
|
||||
.ThenBy(u => u.RagSoc)
|
||||
.ToList();
|
||||
|
||||
GroupedUserList = [];
|
||||
|
||||
string? lastHeader = null;
|
||||
|
||||
foreach (var user in sortedUsers)
|
||||
{
|
||||
var firstChar = char.ToUpper(user.RagSoc[0]);
|
||||
var currentLetter = char.IsLetter(firstChar) ? firstChar.ToString() : "#";
|
||||
|
||||
var showHeader = currentLetter != lastHeader;
|
||||
lastHeader = currentLetter;
|
||||
|
||||
GroupedUserList.Add(new UserDisplayItem
|
||||
{
|
||||
User = user,
|
||||
ShowHeader = showHeader,
|
||||
HeaderLetter = currentLetter
|
||||
});
|
||||
}
|
||||
|
||||
FilterUsers(true);
|
||||
}
|
||||
|
||||
private class UserDisplayItem
|
||||
{
|
||||
public required AnagClie User { get; set; }
|
||||
public bool ShowHeader { get; set; }
|
||||
public string? HeaderLetter { get; set; }
|
||||
}
|
||||
|
||||
private void FilterUsers() => FilterUsers(false);
|
||||
|
||||
private void FilterUsers(bool clearFilter)
|
||||
{
|
||||
if (clearFilter)
|
||||
{
|
||||
TextToFilter = null;
|
||||
FilteredGroupedUserList = GroupedUserList;
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
if (TextToFilter == null) return;
|
||||
|
||||
FilteredGroupedUserList = GroupedUserList.FindAll(x =>
|
||||
x.User.RagSoc.Contains(TextToFilter, StringComparison.OrdinalIgnoreCase) ||
|
||||
x.User.Indirizzo.Contains(TextToFilter, StringComparison.OrdinalIgnoreCase) ||
|
||||
(x.User.Telefono != null && x.User.Telefono.Contains(TextToFilter, StringComparison.OrdinalIgnoreCase)) ||
|
||||
(x.User.EMail != null && x.User.EMail.Contains(TextToFilter, StringComparison.OrdinalIgnoreCase)) ||
|
||||
x.User.PartIva.Contains(TextToFilter, StringComparison.OrdinalIgnoreCase)
|
||||
);
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
}
|
||||
33
salesbook.Shared/Components/Pages/Users.razor.css
Normal file
33
salesbook.Shared/Components/Pages/Users.razor.css
Normal file
@@ -0,0 +1,33 @@
|
||||
.users {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
overflow-y: auto;
|
||||
flex-direction: column;
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
padding-bottom: 70px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.users .divider {
|
||||
margin: .1rem 0;
|
||||
margin-left: 3rem;
|
||||
}
|
||||
|
||||
.users .input-card { margin: 0 !important; }
|
||||
|
||||
.letter-header {
|
||||
border-bottom: 1px solid var(--card-border-color);
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background: var(--mud-palette-surface);
|
||||
padding-bottom: .5rem;
|
||||
}
|
||||
|
||||
.search-box .input-card {
|
||||
margin: 0 !important;
|
||||
}
|
||||
Reference in New Issue
Block a user