|
@@ -10,95 +10,118 @@ using System.Threading.Tasks;
|
|
|
using comal.timesheets.CustomControls;
|
|
|
using comal.timesheets.iOS.Assignments;
|
|
|
using InABox.Configuration;
|
|
|
+using Syncfusion.Office;
|
|
|
using Syncfusion.SfSchedule.XForms;
|
|
|
using Xamarin.Forms.Xaml;
|
|
|
+using XF.Material.Forms;
|
|
|
using XF.Material.Forms.UI.Dialogs;
|
|
|
+using XF.Material.Forms.UI.Dialogs.Configurations;
|
|
|
|
|
|
namespace comal.timesheets
|
|
|
{
|
|
|
+
|
|
|
+ public enum AssignmentView
|
|
|
+ {
|
|
|
+ Day,
|
|
|
+ TimeLine
|
|
|
+ }
|
|
|
+
|
|
|
public partial class AssignmentList : ContentPage
|
|
|
{
|
|
|
|
|
|
private AssignmentEdit _editor = null;
|
|
|
|
|
|
- private Guid[] _employeeids = new Guid[] { App.Data.Employee.ID };
|
|
|
+ private Guid[] _employeeids = new Guid[] { };
|
|
|
+
|
|
|
+ private AssignmentModuleSettings _settings = null;
|
|
|
|
|
|
- private List<AssignmentColumn> _columns = new List<AssignmentColumn>();
|
|
|
+ private AssignmentView _view = AssignmentView.Day;
|
|
|
|
|
|
- private AssignmentModuleSettings _settings = null;
|
|
|
-
|
|
|
public AssignmentList()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
_settings = new LocalConfiguration<AssignmentModuleSettings>().Load();
|
|
|
-
|
|
|
+
|
|
|
DatePicker.Date = _settings.Date.IsEmpty() ? DateTime.Today : _settings.Date;
|
|
|
|
|
|
- if (_settings.Employees != null)
|
|
|
- _employeeids = _settings.Employees;
|
|
|
+ _view = _settings.View;
|
|
|
+
|
|
|
+ _employeeids = (_settings.Employees != null)
|
|
|
+ ? _settings.Employees
|
|
|
+ : new Guid[] { App.Data.Employee.ID };
|
|
|
|
|
|
- ReloadColumns();
|
|
|
}
|
|
|
-
|
|
|
- private void ReloadColumns()
|
|
|
+
|
|
|
+
|
|
|
+ protected override void OnAppearing()
|
|
|
+ {
|
|
|
+ base.OnAppearing();
|
|
|
+ Reload();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Reload()
|
|
|
{
|
|
|
- _columns.Clear();
|
|
|
- Grid.Children.Clear();
|
|
|
- Grid.ColumnDefinitions.Clear();
|
|
|
- foreach (var empid in _employeeids)
|
|
|
+
|
|
|
+ DayView.DataSource = null;
|
|
|
+ TimeLineView.DataSource = null;
|
|
|
+
|
|
|
+ if (_view == AssignmentView.Day)
|
|
|
{
|
|
|
- AssignmentColumn column = new AssignmentColumn();
|
|
|
- column.OnChanged += (o,e) => Refresh();
|
|
|
- column.EmployeeID = empid;
|
|
|
- var empname = GlobalVariables.EmployeeShells.FirstOrDefault(x => x.ID == empid)?.Name;
|
|
|
- var comps = (empname ?? empid.ToString()).Split(' ');
|
|
|
- column.EmployeeName = _employeeids.Length == 1
|
|
|
- ? empname
|
|
|
- : string.Format("{0}{1}", comps.First().Substring(0, 1), comps.Length > 1 ? comps.Skip(1).First().Substring(0, 1) : "");
|
|
|
-
|
|
|
- if (_columns.Count == 0)
|
|
|
+ DayViewColumn.Width = new GridLength(1, GridUnitType.Star);
|
|
|
+ TimeLineViewColumn.Width = new GridLength(0, GridUnitType.Absolute);
|
|
|
+ DayView.DayViewSettings.DayLabelSettings.TimeFormat = "HH:mm";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DayViewColumn.Width = new GridLength(0, GridUnitType.Absolute);
|
|
|
+ TimeLineViewColumn.Width = new GridLength(1, GridUnitType.Star);
|
|
|
+
|
|
|
+ TimeLineView.ResourceViewSettings.VisibleResourceCount = Math.Max(1,Math.Min(8, _employeeids.Length));
|
|
|
+ TimeLineView.TimelineViewSettings.AppointmentHeight =
|
|
|
+ (this.Height / TimeLineView.ResourceViewSettings.VisibleResourceCount) + 100;
|
|
|
+
|
|
|
+ var resources = new ObservableCollection<object>();
|
|
|
+ foreach (var empid in _employeeids)
|
|
|
{
|
|
|
- Grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(50,GridUnitType.Absolute)});
|
|
|
- column.SetValue(Grid.ColumnProperty,0);
|
|
|
- column.SetValue(Grid.ColumnSpanProperty,2);
|
|
|
+ var empname = GlobalVariables.EmployeeShells.FirstOrDefault(x => x.ID == empid)?.Name ?? empid.ToString();
|
|
|
+ resources.Add(
|
|
|
+ new ScheduleResource()
|
|
|
+ {
|
|
|
+ Name = empname, //String.Join("", empname.Split(' ').Select(x=>x.Substring(0,1))),
|
|
|
+ Id = empid,
|
|
|
+ Color = Color.Red,
|
|
|
+ Image = ""
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
- else
|
|
|
- column.SetValue(Grid.ColumnProperty, _columns.Count + 1);
|
|
|
+ TimeLineView.ScheduleResources = resources;
|
|
|
+ TimeLineView.ShowResourceView = true;
|
|
|
|
|
|
- column.ShowTime = _columns.Count == 0;
|
|
|
- Grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star)});
|
|
|
- Grid.Children.Add(column);
|
|
|
- _columns.Add(column);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Refresh();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void Refresh()
|
|
|
{
|
|
|
Title.Text = $"{DatePicker.Date:dd MMMM yyyy}";
|
|
|
-
|
|
|
DataModel.Load(
|
|
|
new Filter<Assignment>(x => x.Date).IsEqualTo(DatePicker.Date).And(x => x.EmployeeLink.ID).InList(_employeeids),
|
|
|
() =>
|
|
|
{
|
|
|
Dispatcher.BeginInvokeOnMainThread(() =>{
|
|
|
- foreach (var column in _columns)
|
|
|
- {
|
|
|
- column.Date = DatePicker.Date;
|
|
|
- column.Load(DataModel.Items.Where(x => x.EmployeeId == column.EmployeeID).ToArray());
|
|
|
- }
|
|
|
+ if (_view == AssignmentView.Day)
|
|
|
+ DayView.DataSource = new ObservableCollection<AssignmentListDataModelItem>(DataModel.Items);
|
|
|
+ else
|
|
|
+ TimeLineView.DataSource = new ObservableCollection<AssignmentListDataModelItem>(DataModel.Items);
|
|
|
});
|
|
|
|
|
|
}
|
|
|
);
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- protected override void OnAppearing()
|
|
|
- {
|
|
|
- base.OnAppearing();
|
|
|
- Refresh();
|
|
|
- }
|
|
|
|
|
|
private void BackButton_OnClicked(object sender, EventArgs e)
|
|
|
{
|
|
@@ -112,9 +135,17 @@ namespace comal.timesheets
|
|
|
|
|
|
private void DatePicker_OnDateSelected(object sender, DateChangedEventArgs e)
|
|
|
{
|
|
|
- _settings.Date = DatePicker.Date;
|
|
|
- new LocalConfiguration<AssignmentModuleSettings>().Save(_settings);
|
|
|
- Refresh();
|
|
|
+ if (_employeeids.Any())
|
|
|
+ {
|
|
|
+ _settings.Date = DatePicker.Date;
|
|
|
+ new LocalConfiguration<AssignmentModuleSettings>().Save(_settings);
|
|
|
+ }
|
|
|
+ DayView.MoveToDate = DatePicker.Date;
|
|
|
+ TimeLineView.MoveToDate = DatePicker.Date;
|
|
|
+ Dispatcher.BeginInvokeOnMainThread(()=>
|
|
|
+ {
|
|
|
+ Refresh();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private async void SelectEmployees_Tapped(object sender, EventArgs e)
|
|
@@ -125,22 +156,83 @@ namespace comal.timesheets
|
|
|
|
|
|
var result = await MaterialDialog.Instance.SelectActionAsync(title: "Select a Team",
|
|
|
actions: actions);
|
|
|
-
|
|
|
+
|
|
|
if (result == 0)
|
|
|
+ {
|
|
|
+ _view = AssignmentView.Day;
|
|
|
_employeeids = new Guid[] { App.Data.Employee.ID };
|
|
|
+ }
|
|
|
else if (result > 0)
|
|
|
+ {
|
|
|
+ _view = AssignmentView.TimeLine;
|
|
|
_employeeids = GlobalVariables.TeamEmployeeShells.Where(x => String.Equals(x.TeamName, actions[result]))
|
|
|
.Select(x => x.ID).Distinct().ToArray();
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
_settings.Employees = _employeeids;
|
|
|
+ _settings.View = _view;
|
|
|
new LocalConfiguration<AssignmentModuleSettings>().Save(_settings);
|
|
|
|
|
|
Dispatcher.BeginInvokeOnMainThread(()=>
|
|
|
{
|
|
|
- ReloadColumns();
|
|
|
- Refresh();
|
|
|
+ Reload();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private async void Schedule_OnCellTapped(object sender, CellTappedEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.Appointment is AssignmentListDataModelItem item)
|
|
|
+ {
|
|
|
+ var editor = new AssignmentEdit(item);
|
|
|
+ Navigation.PushAsync(editor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void Schedule_OnCellLongPressed(object sender, CellTappedEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.Appointment == null)
|
|
|
+ {
|
|
|
+ if (InABox.Core.Security.CanEdit<Assignment>())
|
|
|
+ {
|
|
|
+ var assignment = new Assignment()
|
|
|
+ {
|
|
|
+ Date = e.Datetime.Date,
|
|
|
+ Start = new TimeSpan(e.Datetime.TimeOfDay.Hours,0,0),
|
|
|
+ Finish = e.Datetime.TimeOfDay.Add(new TimeSpan(1, 0, 0)),
|
|
|
+ Duration = new TimeSpan(1, 0, 0),
|
|
|
+ Title = "New Assignment"
|
|
|
+ };
|
|
|
+ assignment.EmployeeLink.ID = (e.Resource is ScheduleResource sr)
|
|
|
+ ? (Guid)sr.Id
|
|
|
+ : App.Data.Employee.ID;
|
|
|
+
|
|
|
+ var editor = new AssignmentEdit(assignment);
|
|
|
+ Navigation.PushAsync(editor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (InABox.Core.Security.CanDelete<Assignment>())
|
|
|
+ {
|
|
|
+ var confirm = await MaterialDialog.Instance.ConfirmAsync(
|
|
|
+ "Are you sure you wish to delete this assignment?",
|
|
|
+ "Confirm Deletion",
|
|
|
+ "Yes, Delete",
|
|
|
+ "Cancel",
|
|
|
+ new MaterialAlertDialogConfiguration()
|
|
|
+ {
|
|
|
+ ButtonFontFamily = Material.FontFamily.Body2
|
|
|
+ }
|
|
|
+ );
|
|
|
+ if (confirm == true)
|
|
|
+ {
|
|
|
+ using(await MaterialDialog.Instance.LoadingDialogAsync(message: "Deleting Assignment"))
|
|
|
+ {
|
|
|
+ var assignment = new Assignment() { ID = (e.Appointment as AssignmentListDataModelItem).Id };
|
|
|
+ new Client<Assignment>().Delete(assignment, "Deleted on Mobile Device");
|
|
|
+ }
|
|
|
+ Refresh();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|