Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@using CulinaryCommand.Data.Entities
@inject ILocationService LocationService
@inject AuthService Auth
@rendermode InteractiveServer

<div class="tag-picker">
Expand Down Expand Up @@ -52,7 +53,7 @@

protected override async Task OnInitializedAsync()
{
AllLocations = await LocationService.GetAllLocationsAsync();
AllLocations = await LocationService.GetLocationsByCompanyAsync(Auth.CurrentUser?.CompanyId);
RefreshLists();
}

Expand Down
3 changes: 3 additions & 0 deletions CulinaryCommandApp/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@using CulinaryCommand.Services
@inject CulinaryCommand.Services.AuthService Auth
@inject NavigationManager Nav
@inject LocationState LocationState
@using System.Threading.Tasks
@rendermode InteractiveServer

Expand Down Expand Up @@ -30,6 +31,8 @@
if (!firstRender || _hydrated)
return;

await LocationState.HydrateAsync();

var path = Nav.Uri.ToLowerInvariant();
if (!path.Contains("/signin") && !path.Contains("/signup") && !path.Contains("/adminsignup"))
{
Expand Down
63 changes: 13 additions & 50 deletions CulinaryCommandApp/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,62 +27,20 @@
</NavLink>
</div>

@* <div class="nav-item px-3">
<NavLink class="nav-link" href="signin">
<span class="bi bi-box-arrow-in-right nav-icon" aria-hidden="true"></span> Sign In
</NavLink>
</div> *@


@* <div class="nav-item px-3">
<NavLink class="nav-link" href="signup">
<span class="bi bi-box-arrow-in-right nav-icon" aria-hidden="true"></span> Sign Up
</NavLink>
</div> *@


@if (Auth.UserRole == "Employee")
{
<div class="nav-item px-3">
<NavLink class="nav-link" href="/tasks">
<span class="bi bi-list-nested nav-icon" aria-hidden="true"></span> My Tasks
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="/inventory-management">
<span class="bi bi-box-seam nav-icon" aria-hidden="true"></span> Inventory
</NavLink>
</div>

@if (Auth.UserRole == "Admin")
{
<div class="nav-item px-3">
<NavLink class="nav-link" href="recipes">
<span class="bi bi-journal-text nav-icon"></span> Recipes
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="ingredients">
<span class="bi bi-basket3 nav-icon"></span> Ingredients
</NavLink>
</div>
}
else { @* admin or manager *@
<div class="nav-item px-3">
<NavLink class="nav-link" href="/assign-tasks">
<span class="bi bi-clipboard-check nav-icon" aria-hidden="true"></span> Assign Tasks
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="/purchase-orders">
<span class="bi bi-cart3 nav-icon" aria-hidden="true"></span> Purchase Orders
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="users">
<span class="bi bi-people nav-icon"></span> Manage Users
</NavLink>
</div>
}
else if (Auth.UserRole == "Manager")
{
<div class="nav-item px-3">
<NavLink class="nav-link" href="recipes">
<span class="bi bi-journal-text nav-icon"></span>Recipes
Expand All @@ -94,18 +52,23 @@
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="/assign-tasks">
<span class="bi bi-clipboard-check nav-icon" aria-hidden="true"></span> Assign Tasks
<NavLink class="nav-link" href="/inventory-management">
<span class="bi bi-box-seam nav-icon"></span> Inventory
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="/purchase-orders">
<span class="bi bi-cart3 nav-icon" aria-hidden="true"></span> Purchase Orders
</NavLink>
</div>


}
@if (Auth.UserRole == "Admin")
{
<div class="nav-item px-3">
<NavLink class="nav-link" href="/inventory">
<span class="bi bi-box-seam nav-icon"></span> Inventory
<NavLink class="nav-link" href="users">
<span class="bi bi-people nav-icon"></span> Manage Users
</NavLink>
</div>
}
Expand Down
2 changes: 1 addition & 1 deletion CulinaryCommandApp/Components/Pages/AdminView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<DashboardCard Title="Active Tasks by Employee" Value="6 tasks" Color="#3662e3" IconClass="bi bi-people"
Link="/tasks" />
<DashboardCard Title="Low Stock Ingredients" Value="2" Color="#ca3a31" IconClass="bi bi-box-seam"
Link="/inventory" />
Link="/inventory-management" />
<DashboardCard Title="Manage Employees" Value="35" Color="#e28743" IconClass="bi bi-person-gear"
Link="/employees" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ else

selectedLocationId = LocationState.CurrentLocation?.Id;

LocationState.OnChange -= HandleLocationStateChanged;
LocationState.OnChange += HandleLocationStateChanged;

await LoadTasksAsync();
Expand All @@ -104,10 +105,11 @@ else
allTasks = await TaskService.GetForUserAsync(Auth.UserId.Value, selectedLocationId);

prepTasks = allTasks
.Where(t => t.Kind == WorkTaskKind.PrepFromRecipe)
@* .Where(t => t.Kind == WorkTaskKind.PrepFromRecipe) *@
.Where(t => !string.Equals(t.Status, "Completed", StringComparison.OrdinalIgnoreCase))
.OrderBy(t => t.DueDate)
.ToList();

}
finally
{
Expand Down
32 changes: 18 additions & 14 deletions CulinaryCommandApp/Components/Pages/Dashboard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -149,38 +149,42 @@ else

protected override async Task OnAfterRenderAsync(bool firstRender)
{

if (!firstRender) return;
await Auth.EnsureHydratedAsync(); // safe here (interactive)
_ready = true;
StateHasChanged();

if (!_aiLoadedOnce)
if (!_aiLoadedOnce && Auth.IsSignedIn)
{
_aiLoadedOnce = true;
_aiLoading = true;
StateHasChanged();

// Get analysis:

var csvPath = Path.Combine(Env.ContentRootPath, "AIDashboard", "Services", "Reporting", "test_data.csv");
_aiAnalysis = await ReportingService.AnalyzeCsvAsync(csvPath);

// Try to deserialize the returned JSON into the DTO so we can render structured cards UI.
if (!string.IsNullOrWhiteSpace(_aiAnalysis))
try
{
try
var csvPath = Path.Combine(Env.ContentRootPath, "AIDashboard", "Services", "Reporting", "test_data.csv");
_aiAnalysis = await ReportingService.AnalyzeCsvAsync(csvPath);

// Try to deserialize the returned JSON into the DTO so we can render structured cards UI.
if (!string.IsNullOrWhiteSpace(_aiAnalysis))
{
var options = new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true };
_aiAnalysisObj = System.Text.Json.JsonSerializer.Deserialize<AIAnalysisResultDTO>(_aiAnalysis, options);
}
catch
{
_aiAnalysisObj = null;
}
}
catch(Exception e)
{
Console.WriteLine($"AI Analysis failed: {e.Message}");
_aiAnalysisObj = null;
_aiAnalysis = null;

_aiLoading = false;
StateHasChanged();
}
finally {
_aiLoading = false;
StateHasChanged();
}
}

}
Expand Down
25 changes: 22 additions & 3 deletions CulinaryCommandApp/Components/Pages/EmployeeView.razor
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
@rendermode InteractiveServer
@implements IDisposable
<div class="employee-dashboard">
<h2 class="mb-4 text-warning">Employee Dashboard</h2>
<p>Welcome, @Auth.CurrentUser.Name!</p>
<p>Welcome, @(Auth.CurrentUser?.Name ?? "User")!</p>

<ul>
<li>View your active tasks and prep items</li>
<li>Check your assigned location: @LocationState.CurrentLocation</li>
<li>Check your assigned location: @(LocationState.CurrentLocation?.Name ?? "Not assigned")</li>
<li>Submit updates to your manager</li>
</ul>
</div>

@code {
[Inject] private CulinaryCommand.Services.AuthService Auth { get; set; } = default!;
[Inject] private CulinaryCommand.Services.LocationState LocationState { get; set; } = default!;
[Inject] private CulinaryCommand.Services.LocationState LocationState { get; set; } = default!;

private async void HandleLocationStateChanged()
{
await InvokeAsync(async () =>
{
StateHasChanged();
});
}

protected override void OnInitialized()
{
// Subscribe to the change event
LocationState.OnChange += HandleLocationStateChanged;
}

public void Dispose()
{
LocationState.OnChange -= HandleLocationStateChanged;
}
}
2 changes: 1 addition & 1 deletion CulinaryCommandApp/Components/Pages/ManagerView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<DashboardCard Title="Active Tasks by Employee" Value="6 tasks" Color="#3662e3" IconClass="bi bi-people"
Link="/tasks" />
<DashboardCard Title="Low Stock Ingredients" Value="2" Color="#ca3a31" IconClass="bi bi-box-seam"
Link="/inventory" />
Link="/inventory-management" />
<DashboardCard Title="Manage Employees" Value="35" Color="#e28743" IconClass="bi bi-person-gear"
Link="/employees" />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
@using CulinaryCommand.Data.Entities
@inject AuthService Auth
<div class="card shadow-sm p-3">

@foreach (var loc in Locations)
{
<div class="card shadow-sm p-3 mb-3">
<div class="d-flex justify-content-between">
<div>
<h5>@loc.Name</h5>
<p class="text-muted mb-1">@loc.Address</p>
<small>@loc.City, @loc.State @loc.ZipCode</small>
</div>
</div>
</div>
}

@* <div class="card shadow-sm p-3">

<h4>@Auth.Company</h4>

Expand All @@ -15,8 +29,8 @@
<p class="mb-1">@Location.City, @Location.State @Location.ZipCode</p>
}

</div>
</div> *@

@code {
[Parameter] public Location? Location { get; set; }
[Parameter] public List<Location> Locations { get; set; } = new List<Location>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,29 @@
<td>@user.Role</td>
<td class="text-end">

@if (user.Role == "Manager")
{
<button class="btn btn-warning btn-sm me-2"
@onclick="() => Demote(user)">
Demote
</button>
}
else
{
<button class="btn btn-primary btn-sm me-2"
@onclick="() => Promote(user)">
Promote
</button>
}

<button class="btn btn-danger btn-sm"
@onclick="() => RemoveUser(user)">
Remove
</button>
<div class="d-flex justify-content-end">
@if (user.Role == "Manager")
{
<button class="btn btn-warning btn-sm me-2"
@onclick="() => Demote(user)">
Demote
</button>
}
else if (user.Role == "Employee")
{
<button class="btn btn-primary btn-sm me-2"
@onclick="() => Promote(user)">
Promote
</button>
}
@if (!(user.Role == "Admin" && user.Id == Auth.CurrentUser?.Id)) {
@* Admins shouldn't be able to remove themselves *@
<button class="btn btn-danger btn-sm"
@onclick="() => RemoveUser(user)">
Remove
</button>
}
</div>
</td>
</tr>
}
Expand Down Expand Up @@ -175,7 +179,17 @@
if (!int.TryParse(selectedUserId, out var userId))
return;

await LocationService.AddUserToLocationAsync(LocationId, userId);
var UserToAdd = AvailableUsers.FirstOrDefault(u => u.Id == userId);

if (UserToAdd != null) {
// add to general user mapping
await LocationService.AddUserToLocationAsync(LocationId, userId);

// add to manager list if user is manager
if (UserToAdd.Role == "Manager") {
await LocationService.AddManagerToLocationAsync(LocationId, userId);
}
}

await ReloadUsers();
HideAddExistingForm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
Locations="locations"
OnEdit="Update" />
}
else
else // Auth.UserRole == "Employee"
{
<LocationEmployeeView Location="employeeLocation" />
<LocationEmployeeView Locations="locations" />
}
}
</div>
Expand Down Expand Up @@ -70,8 +70,8 @@
}
else
{
employeeLocation = (await LocationService.GetLocationsByEmployeeAsync(Auth.UserId!.Value))
.FirstOrDefault();
locations = await LocationService.GetLocationsByEmployeeAsync(Auth.UserId!.Value);

}
}

Expand Down
1 change: 1 addition & 0 deletions CulinaryCommandApp/Components/Pages/Users/Edit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ else
{
await UserService.UpdateUserAsync(u);
await UserService.AssignLocationsAsync(u.Id, u.UserLocations.Select(x => x.LocationId).ToList());

Nav.NavigateTo("/users");
}
}
Loading
Loading