Pārlūkot izejas kodu

Added LeaveRequests list

Kenric Nugteren 4 mēneši atpakaļ
vecāks
revīzija
20feb31b9a

+ 16 - 0
PRS.Avalonia/PRS.Avalonia/Modules/MyHR/MyHRLeaveRequests/MyHRLeaveRequestsEditViewModel.cs

@@ -0,0 +1,16 @@
+using CommunityToolkit.Mvvm.ComponentModel;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PRS.Avalonia.Modules.MyHR;
+
+internal partial class MyHRLeaveRequestsEditViewModel : ModuleViewModel
+{
+    public override string Title => "Leave Request";
+
+    [ObservableProperty]
+    private LeaveRequestShell? _shell;
+}

+ 95 - 0
PRS.Avalonia/PRS.Avalonia/Modules/MyHR/MyHRLeaveRequests/MyHRLeaveRequestsView.axaml

@@ -0,0 +1,95 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             xmlns:listView="clr-namespace:PRS.Avalonia.Components.ListView"
+             xmlns:local="using:PRS.Avalonia.Modules.MyHR"
+             xmlns:prs="using:PRS.Avalonia"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+             x:Class="PRS.Avalonia.Modules.MyHR.MyHRLeaveRequestsView"
+             x:DataType="local:MyHRLeaveRequestsViewModel">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="*"/>
+            <RowDefinition Height="Auto"/>
+        </Grid.RowDefinitions>
+        <listView:PrsListView Grid.Row="0"
+                              Repository="{Binding Model}"
+                              FilterShell="PrsListView_FilterShell"
+                              FiltersVisible="True">
+            <listView:PrsListView.ItemTemplate>
+                <DataTemplate DataType="prs:LeaveRequestShell">
+                    <Button Classes="Standard" Background="{Binding .,Converter={x:Static local:LeaveRequestBackgroundConverter.Instance}}"
+                            Command="{Binding $parent[local:MyHRLeaveRequestsView].((local:MyHRLeaveRequestsViewModel)DataContext).LeaveRequestClickedCommand}"
+                            CommandParameter="{Binding .}"
+                            Padding="5"
+                            HorizontalContentAlignment="Stretch">
+                        <Grid>
+                            <Grid.RowDefinitions>
+                                <RowDefinition Height="Auto"/>
+                                <RowDefinition Height="Auto"/>
+                            </Grid.RowDefinitions>
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition Width="Auto"/>
+                                <ColumnDefinition Width="*"/>
+                            </Grid.ColumnDefinitions>
+
+                            <Image Classes="Large"
+                                   Grid.Row="0" Grid.Column="0" Grid.RowSpan="2"
+                                   HorizontalAlignment="Center" VerticalAlignment="Center"
+                                   Source="{Binding .,Converter={x:Static local:LeaveRequestImageConverter.Instance}}"/>
+                            
+                            <DockPanel Grid.Row="0" Grid.Column="1">
+                                <Label DockPanel.Dock="Right"
+                                       Content="{Binding ., Converter={x:Static local:LeaveRequestStatusConverter.Instance}}"
+                                       FontSize="{StaticResource PrsFontSizeExtraSmall}"
+                                       VerticalAlignment="Stretch"
+                                       VerticalContentAlignment="Center"
+                                       Foreground="Black"/>
+                                <Label DockPanel.Dock="Left"
+                                       Content="{Binding TypeDescription}"
+                                       FontSize="{StaticResource PrsFontSizeExtraSmall}"
+                                       VerticalAlignment="Stretch"
+                                       VerticalContentAlignment="Center"
+                                       Foreground="Black"/>
+                            </DockPanel>
+                            <DockPanel Grid.Row="1" Grid.Column="1">
+                                <Label DockPanel.Dock="Left"
+                                       Content="{Binding From, StringFormat='{}{0:dd/MM/yy}'}"
+                                       FontSize="{StaticResource PrsFontSizeExtraSmall}"
+                                       VerticalAlignment="Stretch"
+                                       VerticalContentAlignment="Center"
+                                       Foreground="Black"/>
+                                <Label DockPanel.Dock="Left"
+                                       Content="{Binding FromTime, StringFormat='{}{0:hh\:mm}'}"
+                                       FontSize="{StaticResource PrsFontSizeExtraSmall}"
+                                       VerticalAlignment="Stretch"
+                                       VerticalContentAlignment="Center"
+                                       Foreground="Black"/>
+                                <Label DockPanel.Dock="Right"
+                                       Content="{Binding To, StringFormat='{}{0:dd/MM/yy}'}"
+                                       FontSize="{StaticResource PrsFontSizeExtraSmall}"
+                                       VerticalAlignment="Stretch"
+                                       VerticalContentAlignment="Center"
+                                       Foreground="Black"/>
+                                <Label DockPanel.Dock="Right"
+                                       Content="{Binding ToTime, StringFormat='{}{0:hh\:mm}'}"
+                                       FontSize="{StaticResource PrsFontSizeExtraSmall}"
+                                       VerticalAlignment="Stretch"
+                                       VerticalContentAlignment="Center"
+                                       Foreground="Black"/>
+                            </DockPanel>
+                        </Grid>
+                    </Button>
+                </DataTemplate>
+            </listView:PrsListView.ItemTemplate>
+        </listView:PrsListView>
+        <TabStrip Name="_tabList" Classes="Standard"
+                  Grid.Row="1"
+                  Margin="{StaticResource PrsControlSpacing}"
+                  SelectedIndex="{Binding SelectedTab}">
+            <TabStripItem Content="Upcoming"/>
+            <TabStripItem Content="History"/>
+        </TabStrip>
+    </Grid>
+</UserControl>

+ 79 - 0
PRS.Avalonia/PRS.Avalonia/Modules/MyHR/MyHRLeaveRequests/MyHRLeaveRequestsView.axaml.cs

@@ -0,0 +1,79 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Media;
+using Comal.Classes;
+using InABox.Avalonia;
+using InABox.Avalonia.Converters;
+using System;
+
+namespace PRS.Avalonia.Modules.MyHR;
+
+public class LeaveRequestBackgroundConverter : AbstractConverter<LeaveRequestShell, IBrush?>
+{
+    public static readonly LeaveRequestBackgroundConverter Instance = new LeaveRequestBackgroundConverter();
+
+    protected override IBrush? Convert(LeaveRequestShell? value, object? parameter = null)
+    {
+        if ((value?.OpenForms ?? 0) > 0)
+            return new SolidColorBrush(Colors.Orange);
+        else
+            return new SolidColorBrush(Colors.WhiteSmoke);
+    }
+}
+public class LeaveRequestImageConverter : AbstractConverter<LeaveRequestShell, IImage?>
+{
+    public static readonly LeaveRequestImageConverter Instance = new LeaveRequestImageConverter();
+
+    protected override IImage? Convert(LeaveRequestShell? value, object? parameter = null)
+    {
+        if ((value?.OpenForms ?? 0) > 0)
+            return Images.question;
+        return (value?.Status ?? LeaveRequestStatus.NotSubmitted) switch
+        {
+            LeaveRequestStatus.InProgress => Images.clock,
+            LeaveRequestStatus.Approved => Images.tick,
+            LeaveRequestStatus.Rejected => Images.cross,
+            _ => Images.warning
+        };
+    }
+}
+
+public class LeaveRequestStatusConverter : AbstractConverter<LeaveRequestShell, string>
+{
+    public static readonly LeaveRequestStatusConverter Instance = new();
+
+    protected override string Convert(LeaveRequestShell? value, object? parameter = null)
+    {
+        if ((value?.OpenForms ?? 0) > 0)
+            return "Not Submitted";
+        return (value?.Status ?? LeaveRequestStatus.InProgress) switch
+        {
+            LeaveRequestStatus.InProgress => "Awaiting Approval",
+            LeaveRequestStatus.Approved => "Approved",
+            LeaveRequestStatus.Rejected => "Rejected",
+            _ => "Not Submitted"
+        };
+    }
+}
+
+public partial class MyHRLeaveRequestsView : UserControl
+{
+    private MyHRLeaveRequestsViewModel? ViewModel = null;
+
+    public MyHRLeaveRequestsView()
+    {
+        InitializeComponent();
+    }
+
+    protected override void OnDataContextChanged(EventArgs e)
+    {
+        base.OnDataContextChanged(e);
+        
+        ViewModel = DataContext as MyHRLeaveRequestsViewModel;
+    }
+
+    private bool PrsListView_FilterShell(IShell shell)
+    {
+        return ViewModel?.FilterShell(shell) ?? true;
+    }
+}