Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kan slette timerater #933

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 61 additions & 29 deletions packages/adminpanel/Client/Pages/Customers/Customer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Icon="@Icons.Material.Filled.ArrowBack"
Color="Color.Secondary"
aria-label="back"
OnClick="@(()=> Navigation.NavigateTo("/kunder"))"/>
OnClick="@(() => Navigation.NavigateTo("/kunder"))"/>

<PageTitle>@Localizer["CustomersPage.Title"]/@_customer.Name</PageTitle>

Expand All @@ -38,8 +38,10 @@
<MudPaper Class="pa-4">
<MudText Class="mb-2" Typo="Typo.h6">@Localizer["Common.ContactInformation"]</MudText>
<MudText>@Localizer["Common.ContactPerson"]: @_customer.ContactPerson</MudText>
<MudText>@Localizer["Common.Email"]: <MudLink Href="@($"mailto:{_customer.ContactEmail}")">@_customer.ContactEmail</MudLink></MudText>
<MudText>@Localizer["Common.Telephone"]: <MudLink Href="@($"tel:{_customer.ContactPhone}")">@_customer.ContactPhone</MudLink></MudText>
<MudText>@Localizer["Common.Email"]: <MudLink Href="@($"mailto:{_customer.ContactEmail}")">@_customer.ContactEmail</MudLink>
</MudText>
<MudText>@Localizer["Common.Telephone"]: <MudLink Href="@($"tel:{_customer.ContactPhone}")">@_customer.ContactPhone</MudLink>
</MudText>
</MudPaper>
</div>

Expand Down Expand Up @@ -213,6 +215,22 @@
OnClick="@EditHourRate"
aria-label="@Localizer["CustomerPage.EditHourRate"]">
</MudIconButton>
<MudIconButton
Icon="@Icons.Material.Filled.Delete"
Color="Color.Secondary"
Disabled="@(_selectedHourRate == null)"
OnClick="@ConfirmDeleteHourRate"
aria-label="@Localizer["CustomerPage.DeleteHourRate"]">
</MudIconButton>
<MudMessageBox @ref="_confirmDeleteHourRateMessageBox" Title="Slette?" CancelText="Avbryt">
<MessageContent>
Er du sikker på at du vil slette timeraten?
</MessageContent>
<YesButton>
<MudButton Variant="Variant.Filled" Color="Color.Error"
StartIcon="@Icons.Material.Filled.DeleteForever" OnClick="@DeleteHourRate">Ja, slett</MudButton>
</YesButton>
</MudMessageBox>
</ToolBarContent>
<Columns>
<SelectColumn
Expand Down Expand Up @@ -273,7 +291,7 @@ else
[Inject] NavigationManager Navigation { get; set; }

[Parameter] public string CustomerId { get; set; }

private CustomerModel? _customer;
private IEnumerable<TaskModel>? _aggregatedTasks;
private IEnumerable<HourRateModel>? _aggregatedHourRates;
Expand All @@ -290,49 +308,51 @@ else
private TaskModel? _selectedTask;
private HourRateModel? _selectedHourRate;

private MudMessageBox _confirmDeleteHourRateMessageBox;

protected override async Task OnInitializedAsync()
{
// Fetch data for customer
Interceptor.RegisterEvent();
await RefreshCustomer();
}

private Func<ProjectModel, bool> QuickFilterProjects => project =>
{
if (string.IsNullOrWhiteSpace(_projectSearchString))
return true;

if (project.Name.Contains(_projectSearchString, StringComparison.OrdinalIgnoreCase))
return true;

return false;
};

private Func<TaskModel, bool> QuickFilterTasks => task =>
{
if (string.IsNullOrWhiteSpace(_taskSearchString))
return true;

if (task.Name.Contains(_taskSearchString, StringComparison.OrdinalIgnoreCase))
return true;

if (task.ProjectName.Contains(_taskSearchString, StringComparison.OrdinalIgnoreCase))
return true;

return false;
};

private Func<HourRateModel, bool> QuickFilterHourRates => hourRate =>
{
if (string.IsNullOrWhiteSpace(_hourRateSearchString))
return true;

if (hourRate.ProjectName.Contains(_hourRateSearchString, StringComparison.OrdinalIgnoreCase))
return true;

if (hourRate.TaskName.Contains(_hourRateSearchString, StringComparison.OrdinalIgnoreCase))
return true;

return false;
};

Expand Down Expand Up @@ -386,14 +406,14 @@ else
MaxWidth = MaxWidth.Small
});
}

private void EditCustomer()
{
if (string.IsNullOrEmpty(CustomerId) || !int.TryParse(CustomerId, out int parsedId))
{
return;
}

DialogService.ShowAsync<CustomerDialog>(Localizer["CustomerPage.EditCustomer"], new DialogParameters
{
["OnCustomerSubmit"] = RefreshAfterDialogAction,
Expand All @@ -414,7 +434,7 @@ else
["OnProjectSubmit"] = RefreshAfterDialogAction,
["SelectedProject"] = _selectedProject
},
new DialogOptions()
new DialogOptions
{
FullWidth = true,
MaxWidth = MaxWidth.Small
Expand All @@ -424,16 +444,16 @@ else
private void EditTask()
{
DialogService.Show<TaskDialog>(Localizer["CustomerPage.EditTask"], new DialogParameters
{
["OnTaskSubmit"] = RefreshAfterDialogAction,
["Projects"] = _customer!.Projects,
["SelectedTask"] = _selectedTask
},
new DialogOptions()
{
FullWidth = true,
MaxWidth = MaxWidth.Small
});
{
["OnTaskSubmit"] = RefreshAfterDialogAction,
["Projects"] = _customer!.Projects,
["SelectedTask"] = _selectedTask
},
new DialogOptions
{
FullWidth = true,
MaxWidth = MaxWidth.Small
});
}

private void EditHourRate()
Expand All @@ -444,11 +464,24 @@ else
["Projects"] = _customer!.Projects,
["SelectedHourRate"] = _selectedHourRate
},
new DialogOptions()
new DialogOptions
{
FullWidth = true,
MaxWidth = MaxWidth.Small
});
});
}

private async Task ConfirmDeleteHourRate()
{
await _confirmDeleteHourRateMessageBox.ShowAsync();
StateHasChanged();
}

private async Task DeleteHourRate()
{
await HttpClient.DeleteAsync(ApiRoutes.DeleteHourRate(_selectedHourRate!.Id));
await RefreshCustomer();
StateHasChanged();
}

private EventCallback RefreshAfterDialogAction => new(this, (Action)(async () =>
Expand Down Expand Up @@ -510,7 +543,7 @@ else
.ThenBy(hr => hr.Rate)
.ToList();
}

/* TODO:
Evaluate current reset of all selections.
It might be that we want to re-evaluate this whole method */
Expand All @@ -520,7 +553,6 @@ else
_selectedProject = null;
_selectedTask = null;
_selectedHourRate = null;

}
else
{
Expand Down
Loading
Loading