Improved filtering implemented.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.Utility;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.Log
|
||||
{
|
||||
@@ -6,6 +9,59 @@ namespace MileageTraker.Web.ViewModels.Log
|
||||
{
|
||||
public int? Year { get; set; }
|
||||
public int? Month { get; set; }
|
||||
public int? MonthRange { get; set; }
|
||||
public MileageLogType? LogType { get; set; }
|
||||
public string EmployeeName { get; set; }
|
||||
public string VehicleId { get; set; }
|
||||
|
||||
public string YearMonthStart {get
|
||||
{
|
||||
return string.Format("{0}-{1:00}", Year, Month);
|
||||
}}
|
||||
|
||||
public string YearMonthEnd
|
||||
{
|
||||
get
|
||||
{
|
||||
var dateTime = new DateTime(Year.Value, Month.Value, 1);
|
||||
var time = dateTime.AddMonths(MonthRange.Value - 1);
|
||||
return string.Format("{0}-{1:00}", time.Year, time.Month);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var v = new List<string>();
|
||||
//string.Format("{0}-{1}{2}", Year, Month, LogType.HasValue ? "-" + LogType.Value.GetDisplayShortName() : "");
|
||||
|
||||
if (Year.HasValue && Month.HasValue)
|
||||
{
|
||||
var str = YearMonthStart;
|
||||
|
||||
if (MonthRange.HasValue && MonthRange > 1)
|
||||
str += "to" + YearMonthEnd;
|
||||
|
||||
v.Add(str);
|
||||
}
|
||||
|
||||
if (LogType.HasValue)
|
||||
v.Add(LogType.Value.GetDisplayShortName());
|
||||
|
||||
if (!string.IsNullOrEmpty(VehicleId))
|
||||
v.Add(VehicleId);
|
||||
|
||||
if (!string.IsNullOrEmpty(EmployeeName))
|
||||
v.Add(EmployeeName);
|
||||
|
||||
return String.Join("_", v).Replace(' ', '-');
|
||||
}
|
||||
|
||||
public bool HasParameters()
|
||||
{
|
||||
return Year.HasValue ||
|
||||
LogType.HasValue ||
|
||||
!string.IsNullOrEmpty(EmployeeName) ||
|
||||
!string.IsNullOrEmpty(VehicleId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using MiscUtil.Collections;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.Log
|
||||
{
|
||||
public class LogResultsViewModel
|
||||
{
|
||||
public IEnumerable<int> Years { get; set; }
|
||||
public IEnumerable<int> Months { get; set; }
|
||||
public IEnumerable<LogIndexViewModel> Logs { get; set; }
|
||||
public int SelectedYear { get; set; }
|
||||
public int SelectedMonth { get; set; }
|
||||
public string SelectedLogType { get; set; }
|
||||
public Dictionary<string, List<string>> AvailableYearMonths { get; set; }
|
||||
public IEnumerable<string> SelectedYearMonths{get
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Year))
|
||||
return AvailableYearMonths[Year];
|
||||
return new List<string>();
|
||||
}}
|
||||
|
||||
// filter parameters
|
||||
public string Year { get; set; }
|
||||
public string Month { get; set; }
|
||||
public string MonthRange { get; set; }
|
||||
public string LogType { get; set; }
|
||||
public string VehicleId { get; set; }
|
||||
public string EmployeeName { get; set; }
|
||||
|
||||
public LogResultsViewModel(IEnumerable<LogIndexViewModel> logs, LogQueryViewModel query, Dictionary<string, List<string>> availableYearMonths)
|
||||
{
|
||||
Logs = logs;
|
||||
AvailableYearMonths = availableYearMonths;
|
||||
Year = query.Year.HasValue ? query.Year.Value.ToString() : string.Empty;
|
||||
Month = query.Month.HasValue ? query.Month.Value.ToString() : string.Empty;
|
||||
MonthRange = query.MonthRange.HasValue ? query.MonthRange.Value.ToString() : string.Empty;
|
||||
LogType = query.LogType.ToString();
|
||||
EmployeeName = query.EmployeeName;
|
||||
VehicleId = query.VehicleId;
|
||||
}
|
||||
|
||||
public bool SecondRowSet
|
||||
{
|
||||
get
|
||||
{
|
||||
return !string.IsNullOrEmpty(LogType) ||
|
||||
!string.IsNullOrEmpty(VehicleId) ||
|
||||
!string.IsNullOrEmpty(EmployeeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user