parent
4108506fc5
commit
afaf36ba01
After Width: | Height: | Size: 183 KiB |
@ -0,0 +1,37 @@ |
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
x:Class="Justice.Views.AuthorityReportsPage" |
||||
Title="Authority Reports"> |
||||
|
||||
<StackLayout Padding="20"> |
||||
<Label Text="Submitted Reports" FontSize="Large" HorizontalOptions="Center" /> |
||||
|
||||
<!-- List of Reports --> |
||||
<ListView x:Name="ReportsListView" HasUnevenRows="True"> |
||||
<ListView.ItemTemplate> |
||||
<DataTemplate> |
||||
<ViewCell> |
||||
<StackLayout Padding="10"> |
||||
<Label Text="{Binding IncidentType}" FontSize="Medium" FontAttributes="Bold" /> |
||||
<Label Text="{Binding Address}" FontSize="Small" TextColor="Gray" /> |
||||
<Label Text="{Binding DateTime, StringFormat='Submitted on: {0:MMM dd, yyyy HH:mm}'}" |
||||
FontSize="Small" /> |
||||
<Label Text="{Binding Description}" FontSize="Small" /> |
||||
|
||||
<!-- Attachment Section --> |
||||
<Button Text="View Attachment" |
||||
IsVisible="{Binding AttachmentPath, Converter={StaticResource NullToVisibilityConverter}}" |
||||
Clicked="OnViewAttachmentClicked" |
||||
CommandParameter="{Binding .}" CornerRadius="80" Margin="5"/> |
||||
|
||||
<!-- Update Status Button --> |
||||
<Button Text="Mark as Resolved" |
||||
Clicked="OnUpdateStatusClicked" |
||||
CommandParameter="{Binding .}" CornerRadius="80" /> |
||||
</StackLayout> |
||||
</ViewCell> |
||||
</DataTemplate> |
||||
</ListView.ItemTemplate> |
||||
</ListView> |
||||
</StackLayout> |
||||
</ContentPage> |
@ -0,0 +1,93 @@ |
||||
using Justice.Helpers; |
||||
using Justice.Models; |
||||
using System.Collections.ObjectModel; |
||||
using Justice.Services; |
||||
|
||||
namespace Justice.Views |
||||
{ |
||||
public partial class AuthorityReportsPage : ContentPage |
||||
{ |
||||
private readonly DatabaseHelper _dbHelper; |
||||
public ObservableCollection<IncidentReport> Reports { get; set; } |
||||
|
||||
public AuthorityReportsPage() |
||||
{ |
||||
InitializeComponent(); |
||||
_dbHelper = new DatabaseHelper(); |
||||
Reports = new ObservableCollection<IncidentReport>(); |
||||
ReportsListView.ItemsSource = Reports; |
||||
} |
||||
|
||||
protected override async void OnAppearing() |
||||
{ |
||||
base.OnAppearing(); |
||||
await LoadReportsAsync(); |
||||
} |
||||
|
||||
private async Task LoadReportsAsync() |
||||
{ |
||||
try |
||||
{ |
||||
Reports.Clear(); |
||||
var reportsFromDb = await _dbHelper.GetAllAsync<IncidentReport>(); |
||||
foreach (var report in reportsFromDb) |
||||
{ |
||||
Reports.Add(report); |
||||
} |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
await DisplayAlert("Error", $"Failed to load reports: {ex.Message}", "OK"); |
||||
} |
||||
} |
||||
|
||||
private async void OnUpdateStatusClicked(object sender, EventArgs e) |
||||
{ |
||||
var button = sender as Button; |
||||
if (button?.CommandParameter is IncidentReport selectedReport) |
||||
{ |
||||
selectedReport.Status = "Resolved"; |
||||
|
||||
try |
||||
{ |
||||
await _dbHelper.UpdateAsync(selectedReport); |
||||
await DisplayAlert("Success", "Status updated to Resolved.", "OK"); |
||||
|
||||
// Push notification to end user (dummy logic) |
||||
await DisplayAlert("Notification", $"Notification sent to {selectedReport.ReporterName}.", "OK"); |
||||
await LoadReportsAsync(); |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
await DisplayAlert("Error", $"Failed to update status: {ex.Message}", "OK"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private async void OnViewAttachmentClicked(object sender, EventArgs e) |
||||
{ |
||||
var button = sender as Button; |
||||
if (button?.CommandParameter is IncidentReport selectedReport) |
||||
{ |
||||
if (!string.IsNullOrEmpty(selectedReport.AttachmentPath)) |
||||
{ |
||||
try |
||||
{ |
||||
await Launcher.OpenAsync(new OpenFileRequest |
||||
{ |
||||
File = new ReadOnlyFile(selectedReport.AttachmentPath) |
||||
}); |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
await DisplayAlert("Error", $"Failed to open attachment: {ex.Message}", "OK"); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
await DisplayAlert("Error", "No attachment found for this report.", "OK"); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
x:Class="Justice.Views.EndUserReportsPage" |
||||
Title="My Reports"> |
||||
|
||||
<StackLayout Padding="20"> |
||||
<Label Text="My Submitted Reports" FontSize="Large" HorizontalOptions="Center" /> |
||||
|
||||
<!-- List of Submitted Reports --> |
||||
<ListView x:Name="ReportsListView" HasUnevenRows="True"> |
||||
<ListView.ItemTemplate> |
||||
<DataTemplate> |
||||
<ViewCell> |
||||
<StackLayout Padding="10"> |
||||
<Label Text="{Binding IncidentType}" FontSize="Medium" FontAttributes="Bold" /> |
||||
<Label Text="{Binding Address}" FontSize="Small" TextColor="Gray" /> |
||||
<Label Text="{Binding DateTime, StringFormat='Submitted on: {0:MMM dd, yyyy HH:mm}'}" FontSize="Small" /> |
||||
<Label Text="{Binding Description}" FontSize="Small" /> |
||||
<Label Text="{Binding Status}" FontSize="Small" FontAttributes="Bold" /> |
||||
</StackLayout> |
||||
</ViewCell> |
||||
</DataTemplate> |
||||
</ListView.ItemTemplate> |
||||
</ListView> |
||||
</StackLayout> |
||||
</ContentPage> |
@ -0,0 +1,43 @@ |
||||
using Justice.Helpers; |
||||
using Justice.Models; |
||||
using System.Collections.ObjectModel; |
||||
|
||||
namespace Justice.Views |
||||
{ |
||||
public partial class EndUserReportsPage : ContentPage |
||||
{ |
||||
private readonly DatabaseHelper _dbHelper; |
||||
public ObservableCollection<IncidentReport> Reports { get; set; } |
||||
|
||||
public EndUserReportsPage() |
||||
{ |
||||
InitializeComponent(); |
||||
_dbHelper = new DatabaseHelper(); |
||||
Reports = new ObservableCollection<IncidentReport>(); |
||||
ReportsListView.ItemsSource = Reports; |
||||
} |
||||
|
||||
protected override async void OnAppearing() |
||||
{ |
||||
base.OnAppearing(); |
||||
await LoadReportsAsync(); |
||||
} |
||||
|
||||
private async Task LoadReportsAsync() |
||||
{ |
||||
try |
||||
{ |
||||
Reports.Clear(); |
||||
var reportsFromDb = await _dbHelper.GetAllAsync<IncidentReport>(); |
||||
foreach (var report in reportsFromDb) |
||||
{ |
||||
Reports.Add(report); |
||||
} |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
await DisplayAlert("Error", $"Failed to load reports: {ex.Message}", "OK"); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,33 +0,0 @@ |
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
x:Class="Justice.Views.ViewReportsPage" |
||||
Title="View Reports"> |
||||
|
||||
<StackLayout Padding="20"> |
||||
<Label Text="Submitted Reports" FontSize="Large" HorizontalOptions="Center" /> |
||||
<!-- List of Reports --> |
||||
<ListView x:Name="ReportsListView" |
||||
HasUnevenRows="True" |
||||
ItemSelected="OnReportSelected"> |
||||
<ListView.ItemTemplate> |
||||
<DataTemplate> |
||||
<ViewCell> |
||||
<StackLayout Padding="10" Orientation="Horizontal"> |
||||
<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand"> |
||||
<Label Text="{Binding IncidentType}" FontSize="Medium" FontAttributes="Bold" /> |
||||
<Label Text="{Binding Address}" FontSize="Small" TextColor="Gray" /> |
||||
<Label Text="{Binding DateTime, StringFormat='Submitted on: {0:MMM dd, yyyy HH:mm}'}" |
||||
FontSize="Small" /> |
||||
<Label Text="{Binding Description}" FontSize="Small" /> |
||||
</StackLayout> |
||||
<Button x:Name="DeleteName" Text="Delete" |
||||
Clicked="OnDeleteReportClicked" |
||||
CommandParameter="{Binding .}" HeightRequest="10" IsVisible="True"/> |
||||
</StackLayout> |
||||
</ViewCell> |
||||
</DataTemplate> |
||||
</ListView.ItemTemplate> |
||||
|
||||
</ListView> |
||||
</StackLayout> |
||||
</ContentPage> |
@ -1,102 +0,0 @@ |
||||
using Justice.Helpers; |
||||
using Justice.Models; |
||||
using System; |
||||
using System.Collections.ObjectModel; |
||||
using System.Threading.Tasks; |
||||
using Justice.Services; |
||||
|
||||
namespace Justice.Views |
||||
{ |
||||
public partial class ViewReportsPage : ContentPage |
||||
{ |
||||
private readonly DatabaseHelper _databaseHelper; |
||||
public ObservableCollection<IncidentReport> Reports { get; set; } |
||||
|
||||
public ViewReportsPage() |
||||
{ |
||||
InitializeComponent(); |
||||
_databaseHelper = new DatabaseHelper(); |
||||
Reports = new ObservableCollection<IncidentReport>(); |
||||
ReportsListView.ItemsSource = Reports; |
||||
} |
||||
|
||||
protected override async void OnAppearing() |
||||
{ |
||||
base.OnAppearing(); |
||||
await LoadReportsAsync(); |
||||
} |
||||
|
||||
private async Task LoadReportsAsync() |
||||
{ |
||||
try |
||||
{ |
||||
var reportsFromDb = await _databaseHelper.GetAllAsync<IncidentReport>(); |
||||
Reports.Clear(); |
||||
|
||||
foreach (var report in reportsFromDb) |
||||
{ |
||||
Reports.Add(report); |
||||
} |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
await DisplayAlert("Error", $"Failed to load reports: {ex.Message}", "OK"); |
||||
} |
||||
} |
||||
|
||||
private async void OnReportSelected(object sender, SelectedItemChangedEventArgs e) |
||||
{ |
||||
if (e.SelectedItem is IncidentReport selectedReport) |
||||
{ |
||||
await DisplayAlert("Report Details", |
||||
$"Type: {selectedReport.IncidentType}\n" + |
||||
$"Description: {selectedReport.Description}\n" + |
||||
$"Address: {selectedReport.Address}\n" + |
||||
$"Submitted on: {selectedReport.DateTime:MMM dd, yyyy HH:mm}\n" + |
||||
$"Attachment: {(string.IsNullOrWhiteSpace(selectedReport.AttachmentPath) ? "None" : "Attached")}", |
||||
"OK"); |
||||
|
||||
// Deselect the item |
||||
ReportsListView.SelectedItem = null; |
||||
} |
||||
} |
||||
private async void OnDeleteReportClicked(object sender, EventArgs e) |
||||
{ |
||||
// Get the button's binding context |
||||
if (sender is Button deleteButton && deleteButton.CommandParameter is IncidentReport reportToDelete) |
||||
{ |
||||
bool confirm = await DisplayAlert("Delete Report", "Are you sure you want to delete this report?", "Yes", "No"); |
||||
if (confirm) |
||||
{ |
||||
try |
||||
{ |
||||
// Delete the report from the database |
||||
await _databaseHelper.DeleteAsync(reportToDelete); |
||||
|
||||
// Remove the report from the ObservableCollection |
||||
Reports.Remove(reportToDelete); |
||||
|
||||
await DisplayAlert("Success", "Report deleted successfully.", "OK"); |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
await DisplayAlert("Error", $"Failed to delete report: {ex.Message}", "OK"); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
private async void OnLogoutClicked(object sender, EventArgs e) |
||||
{ |
||||
bool confirm = await DisplayAlert("Logout", "Are you sure you want to log out?", "Yes", "No"); |
||||
if (confirm) |
||||
{ |
||||
// Redirect to Login Page |
||||
await Shell.Current.GoToAsync("//LoginPage"); |
||||
} |
||||
} |
||||
private void MenuItem_Clicked(object sender, EventArgs e) |
||||
{ |
||||
|
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue