Utopia-Canteen-System/MEAL_SCHEDULE_VIEW_ONLY_CHA...

9.7 KiB

Meal Schedule View-Only Mode Changes

Summary

Converted the Meal Schedule management screen from full CRUD (Create, Read, Update, Delete) to view-only mode. Users can now only view existing meal schedules without any ability to create, edit, or delete them.


Changes Made

1. ViewModel Changes (MealSchedulesViewModel.cs)

Removed Properties (No longer needed for forms)

// REMOVED:
private string_locationSiteId = string.Empty;
private string _mealName = string.Empty;
private string _startTime = "06:00:00";
private string _endTime = "09:00:00";

Removed Commands (All CRUD operations)

// REMOVED:
[RelayCommand] private void AddNew()        // Form preparation
[RelayCommand] private async Task Save()    // Create/Update logic
[RelayCommand] private void SelectSchedule() // Edit selection
[RelayCommand] private async Task Delete()   // Delete operation

Removed Callbacks

// REMOVED:
partial void OnSelectedScheduleChanged(MealSchedule? value)
{
    // This used to populate form fields when editing
    // No longer needed in view-only mode
}

Updated Class Summary

/// <summary>
/// View-only display of meal schedules from production (hrms.meal_schedule). 
/// No CRUD operations.
/// Loads all schedules on open; optional Site filter (local).
/// </summary>
public partial class MealSchedulesViewModel : ObservableObject
{
    // Only these properties remain:
    [ObservableProperty] private ObservableCollection<MealSchedule> _schedules;
    [ObservableProperty] private string_selectedSiteFilter = "All";
    [ObservableProperty] private MealSchedule? _selectedSchedule;
    [ObservableProperty] private string _message = string.Empty;
    [ObservableProperty] private bool_isError;
    [ObservableProperty] private bool _isLoading;
    
    // Only one command remains:
    [RelayCommand] private void Back(); // Navigate back to Settings
}

2. View Changes (MealSchedulesView.xaml)

Removed UI Elements

  1. "Add New" Button (was in top-right corner)
<!-- REMOVED: -->
<Button Grid.Column="3"
        Command="{Binding AddNewCommand}"
        Content="+ Add New"/>
  1. Actions Column in DataGrid (Edit/Delete icons)
<!-- REMOVED: -->
<DataGridTemplateColumn Header="Actions" Width="100">
    <DataGridTemplateColumn.CellTemplate>
        <Button Style="{StaticResource GridActionEditButton}" ... />
        <Button Style="{StaticResource GridActionDeleteButton}" ... />
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
  1. Entire Add/Edit Form Card
<!-- REMOVED: Complete "Add or Edit Meal Schedule" card with:
     - Location Site ID input
     - Meal Session input
     - Start Time input
     - End Time input
     - Add New / Save / Delete buttons
-->

Updated DataGrid Columns

<!-- BEFORE (with Actions column): -->
<DataGridTextColumn Header="Site" Binding="{Binding LocationSiteId}" Width="*" />
<DataGridTextColumn Header="Session" Binding="{Binding MealName}" Width="*" />
<DataGridTextColumn Header="Start" Binding="{Binding StartTime}" Width="*" />
<DataGridTextColumn Header="End" Binding="{Binding EndTime}" Width="*" />
<DataGridTemplateColumn Header="Actions" Width="100">...edit/delete buttons...</DataGridTemplateColumn>

<!-- AFTER (no Actions column): -->
<DataGridTextColumn Header="Site" Binding="{Binding LocationSiteId}" Width="*" />
<DataGridTextColumn Header="Session" Binding="{Binding MealName}" Width="*" />
<DataGridTextColumn Header="Start Time" Binding="{Binding StartTime}" Width="*" />
<DataGridTextColumn Header="End Time" Binding="{Binding EndTime}" Width="*" />

Updated Header Text

<!-- BEFORE: -->
<TextBlock Text="Meal Schedules" ... />

<!-- AFTER: -->
<TextBlock Text="Meal Schedules" ... />
<TextBlock Text="View-only mode - configured meal windows per site" ... />

Updated Empty State Message

// BEFORE:
Message = "No schedules in production. Add one below (HRMS MySQL must be configured).";

// AFTER:
Message = "No schedules configured in production.";

3. Styles Cleanup

Marked as Removed (but kept for Back button compatibility)

<!-- Kept but noted as potentially removable: -->
- PrimaryButton style (used by Back button)
- SecondaryButton style (used by Back button)  
- DangerButton style (no longer used)
- GridActionButton styles (no longer used)
- GridActionEditButton style (no longer used)
- GridActionDeleteButton style (no longer used)
- ModernTextBox style (no longer used - no forms)
- ModernComboBox style (still used for Site filter)

What Still Works

Functional Features:

  1. Load all schedules from production database
  2. Site filter dropdown - Filter schedules by site
  3. Auto-refresh on page load
  4. Error handling with detailed messages
  5. Empty state messaging
  6. Back navigation to Settings page
  7. Read-only DataGrid with hover/selection effects

Data Display:

  • Site ID
  • Meal Session name
  • Start time
  • End time

What No Longer Works

Removed Features:

  1. Add New - Cannot create new meal schedules
  2. Edit - Cannot modify existing schedules
  3. Delete - Cannot remove schedules
  4. Form inputs - No textboxes for entering schedule data
  5. Save - No save functionality
  6. Actions column - No edit/delete buttons in grid

Backend Service Layer

No Changes to Service Implementation

The ProductionMealScheduleService still has full CRUD methods:

public Task<long> CreateAsync(...)      // Still exists but not called from UI
public Task UpdateAsync(...)            // Still exists but not called from UI  
public Task DeleteAsync(...)            // Still exists but not called from UI
public Task<IReadOnlyList<MealSchedule>> GetAllSchedulesAsync() // ✅ Still used

Why keep them?

  • Service layer is generic and could be reused if admin features are re-enabled
  • Other parts of the system might use these methods
  • No harm in keeping them available

What Changed:

The ViewModel no longer calls Create/Update/Delete methods. It only calls:

await _mealScheduleService.GetAllSchedulesAsync();

User Experience Impact

Before (Full CRUD):

User Flow:
1. Click "Add New" → Form appears
2. Fill in Site, Session, Times
3. Click "Save" → Record created
4. Click ✎ Edit icon → Form populates
5. Modify fields
6. Click "Save" → Record updated
7. Click 🗑 Delete icon → Record deleted

After (View-Only):

User Flow:
1. Open Meal Schedules page
2. See list of all schedules
3. Optionally filter by Site
4. Click "Back" to return to Settings

Testing Checklist

Test Scenarios:

  1. Initial Load

    • Navigate to Meal Schedules page
    • Verify schedules load from production database
    • Verify no "Add New" button visible
    • Verify no edit/delete icons in grid
  2. Site Filtering

    • Change Site filter dropdown
    • Verify grid filters correctly
    • Select "All" to see all schedules
  3. Empty State

    • If no schedules exist, verify message: "No schedules configured in production."
    • Verify no error shown (just informational message)
  4. Error Handling

    • If production DB unavailable, verify error message shown
    • Verify detailed error in MessageBox
  5. Navigation

    • Click "Back" button
    • Verify returns to Settings page
  6. Data Integrity

    • Verify cannot add rows via UI
    • Verify cannot edit rows via UI
    • Verify cannot delete rows via UI
    • Verify DataGrid is read-only (IsReadOnly=True)

Files Modified

File Lines Changed Description
ViewModels/MealSchedulesViewModel.cs ~135 removed Removed all CRUD commands, form properties, callbacks
Views/MealSchedulesView.xaml ~160 removed Removed Add New button, Actions column, entire form card

Total: ~295 lines removed, minimal additions (comments)


Security Note

⚠️ Important: This change only removes UI elements. The backend API/service methods still exist and could be called directly if someone has database access. For true security, also restrict database permissions at the MySQL user level.


Future Considerations

If Admin Features Need to be Re-enabled:

  1. Restore the removed ViewModel commands (AddNew, Save, Delete, SelectSchedule)
  2. Restore form properties (_locationSiteId, _mealName, _startTime, _endTime)
  3. Restore OnSelectedScheduleChanged callback
  4. Restore XAML form card and Actions column
  5. Re-add "Add New" button to header

Alternative Approach:

Consider role-based access control where:

  • Regular users see view-only mode
  • Admin users see full CRUD mode
  • Toggle visibility based on user role

Commit Message

feat: Convert Meal Schedule management to view-only mode

Changes:
- Remove all CRUD operations (Create, Update, Delete) from MealSchedulesViewModel
- Remove Add New button, Edit/Delete action icons from UI
- Remove form input fields and related properties
- Keep only Load/Display functionality with Site filtering
- Update empty state message to reflect view-only mode
- Retain Back navigation command

Impact:
Users can now only view existing meal schedules without ability to modify them.
Backend service methods still exist but are not called from UI.

This view-only mode complements the earlier fix that switched ProductionMealScheduleService to use the production MySQL connection string instead of the local HRMS lookup connection string, ensuring data consistency across the application.