private void checkPlanification(Action action, DateTime dateFrom, int startTimePeriod, int endTimePeriod) { DateTime start = dateFrom.AddMinutes(startTimePeriod * Settings.POMOCYCLE); DateTime end = dateFrom.AddMinutes(endTimePeriod * Settings.POMOCYCLE); if (start.AddMinutes(Settings.POMOCYCLE) > end) { throw new CalendarException(CalendarWarning.NonPositiveInterval, "Planification must have a minimum of one pomodoro"); } if (start < DateTime.UtcNow.ToUserLocalTime(action.Owner.TimeZoneId)) { throw new CalendarException(CalendarWarning.PastTime, "Planification datetime must be in the future"); } if (action == null || action.Status != Status.Active) { throw new CalendarException(CalendarWarning.InvalidAction, "Invalid or inactive action (ID: " + action.ID + ")"); } List <Pomodoro> conflictingPomodoros = db.GetMyPomodoros(User).Where(p => p.Start.HasValue).AsEnumerable().Where(p => ((p.StartLocal.Value <= start && DbFunctions.AddMinutes(p.StartLocal.Value, Settings.POMOCYCLE) > start) || (p.StartLocal.Value < end && DbFunctions.AddMinutes(p.StartLocal.Value, Settings.POMOCYCLE) >= end))).ToList(); if (conflictingPomodoros.Count > 0) { throw new ConflictCalendarException(CalendarWarning.Conflict, conflictingPomodoros); } }
public PartialViewResult Working() { WorkingPanelViewModel viewModel = new WorkingPanelViewModel(); //(first) pomodoro with status = working(if exists) viewModel.pomodoro = db.GetMyPomodoros(User) .Where(p => p.Start.HasValue) .OrderByDescending(p => p.Start) .FirstOrDefault(p => p.Status == PomodoroStatus.Working); if (viewModel.pomodoro != null) { //target time reached -> pomodoro is completed if (viewModel.TargetTime <= DateTime.UtcNow) { viewModel.pomodoro.Status = PomodoroStatus.Unconfirmed; db.Entry(viewModel.pomodoro).State = EntityState.Modified; db.SaveChanges(); } } //not exists if (viewModel.pomodoro == null) { //(first) pomodoro with status = unconfirmed(if exists) viewModel.pomodoro = db.GetMyPomodoros(User) .Where(p => p.Start.HasValue) .OrderByDescending(p => p.Start) .FirstOrDefault(p => p.Status == PomodoroStatus.Unconfirmed); } if (viewModel.pomodoro != null) { viewModel.action = viewModel.pomodoro.Action; } else { var currentUser = manager.FindById(User.Identity.GetUserId()); if (currentUser.ActionID.HasValue && currentUser.ActionID.Value > 0) { viewModel.action = db.GetActionById(User, currentUser.ActionID.Value); } } if (viewModel.action != null) { ViewBag.ActionID = new SelectList(db.GetMyActions(User), "ID", "Name", viewModel.action); } else { ViewBag.ActionID = new SelectList(db.GetMyActions(User), "ID", "Name"); } return(PartialView("Panels/_WorkingPanel", viewModel)); }
public ViewResult WorkHistory(string start, string end, int?statusFilter) { DateTime dtStart = DateTime.Today.AddDays(-29); if (!string.IsNullOrWhiteSpace(start)) { DateTime.TryParseExact(start, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dtStart); } ViewBag.start = dtStart.ToString("dd/MM/yyyy"); DateTime dtEnd = DateTime.Today; if (!string.IsNullOrWhiteSpace(start)) { DateTime.TryParseExact(end, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dtEnd); } ViewBag.end = dtEnd.ToString("dd/MM/yyyy"); var pomodoros = db.GetMyPomodoros(User).ToList().Where( p => p.Start.HasValue && p.StartLocal.Value.Date >= dtStart && p.StartLocal.Value.Date <= dtEnd); if (statusFilter.HasValue) { pomodoros = pomodoros.Where(p => p.Status == (PomodoroStatus)statusFilter.Value); } ViewBag.reportType = new SelectList(new string[] { "Working history" }); WorkHistoryViewModel model = new WorkHistoryViewModel(); model.WorkHistory = pomodoros.ToList(); model.ReportType = ReportType.WorkHistory; model.Start = dtStart; model.End = dtEnd; return(View(model)); }
public ViewResult Index(string sortOrder, string currentFilter, string searchString, int?statusFilter, int?page) { ViewBag.CurrentSort = sortOrder; ViewBag.ProjectSortParm = (sortOrder == "proj") ? "proj_desc" : "proj"; ViewBag.TaskSortParm = (sortOrder == "task") ? "task_desc" : "task"; ViewBag.ActionSortParm = (sortOrder == "acti") ? "acti_desc" : "acti"; ViewBag.DateSortParm = String.IsNullOrEmpty(sortOrder) ? "date" : ""; var pomodoros = db.GetMyPomodoros(User); if (statusFilter.HasValue) { pomodoros = pomodoros.Where(p => p.Status == (PomodoroStatus)statusFilter.Value); } if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; switch (sortOrder) { case "proj": pomodoros = pomodoros.OrderBy(p => p.Action.Task.Project.Code); break; case "proj_desc": pomodoros = pomodoros.OrderByDescending(p => p.Action.Task.Project.Code); break; case "task": pomodoros = pomodoros.OrderBy(p => p.Action.Task.Code); break; case "task_desc": pomodoros = pomodoros.OrderByDescending(p => p.Action.Task.Code); break; case "acti": pomodoros = pomodoros.OrderBy(p => p.Action.Name); break; case "acti_desc": pomodoros = pomodoros.OrderByDescending(p => p.Action.Name); break; case "date": pomodoros = pomodoros.OrderBy(p => p.Start); break; default: // Date descending pomodoros = pomodoros.OrderByDescending(p => p.Start); break; } int pageSize = 25; int pageNumber = (page ?? 1); return(View(pomodoros.ToPagedList(pageNumber, pageSize))); }
// GET: /Dashboard public ViewResult Dashboard() { DashboardViewModel dashboard = new DashboardViewModel(); //active projects dashboard.ActiveProjects = db.GetMyProjects(User).ToList().Where(p => p.IsActive); //active tasks dashboard.ActiveTasks = db.GetMyTasks(User).ToList().Where(t => t.IsActive); //active actions dashboard.ActiveActions = db.GetMyActions(User).ToList().Where(a => a.IsActive); //completed pomodoros dashboard.CompletedPomodoros = db.GetMyPomodoros(User).ToList().Where(p => p.Status == PomodoroStatus.Completed); //last active actions dashboard.LastActiveActions = new PomodoroContainerDateViewModel { HeaderTitle = "Last Active Actions", TableId = "last-active-actions", IconCssClass = "fa-play", ReportTypeDate = ReportTypeDate.LastPomodoro, RowsPerPage = 5, Type = PomodoroContainerType.Action, Items = db.GetMyPomodoros(User) .Where(pm => pm.Status == PomodoroStatus.Completed && pm.Start.HasValue) .Select(pm => pm.Action) .Distinct().ToList() .OrderByDescending(a => a.LastPomodoro.Start.Value) .Take(20) }; //last active tasks dashboard.LastActiveTasks = new PomodoroContainerDateViewModel { HeaderTitle = "Last Active Tasks", TableId = "last-active-tasks", IconCssClass = "fa-play-circle", ReportTypeDate = ReportTypeDate.LastPomodoro, RowsPerPage = 5, Type = PomodoroContainerType.Task, Items = db.GetMyPomodoros(User) .Where(pm => pm.Status == PomodoroStatus.Completed && pm.Start.HasValue) .Select(pm => pm.Action.Task) .Distinct().ToList() .OrderByDescending(t => t.LastPomodoro.Start.Value) .Take(20) }; //upcoming deadlines (actions) dashboard.UpcomingDeadlines = new PomodoroContainerDateViewModel { HeaderTitle = "Upcoming Deadlines", TableId = "upcoming-deadlines", IconCssClass = "fa-clock-o", ReportTypeDate = ReportTypeDate.NextDeadline, RowsPerPage = 5, Type = PomodoroContainerType.Action, Items = db.GetMyActions(User) .Where(a => a.Status == Status.Active && a.Deadline.HasValue) .ToList() .OrderBy(a => a.NextDeadline.Value) .Take(20) }; ////upcoming planified work (actions) //dashboard.UpcomingPlanifiedActions = new PomodoroContainerDateViewModel //{ // HeaderTitle = "Upcoming Planified Actions", // TableId = "upcoming-planified-actions", // IconCssClass = "fa-calendar", // ReportTypeDate = ReportTypeDate.NextPlanifiedPomodoro, // RowsPerPage = 5, // Items = db.GetMyPomodoros(User).ToList() // .Where(pm => pm.CalculatedStatus == PomodoroCalculatedStatus.Planified && pm.Start.HasValue) // .Select(pm => pm.Action) // .Distinct().ToList() // .OrderBy(a => a.NextPlanifiedPomodoro.Start.Value) // .Take(20) //}; //last active actions dashboard.LastCreatedActions = new PomodoroContainerDateViewModel { HeaderTitle = "Last Created Actions", TableId = "last-created-actions", IconCssClass = "fa-plus-circle", ReportTypeDate = ReportTypeDate.LastCreationDate, RowsPerPage = 5, Type = PomodoroContainerType.Action, Items = db.GetMyActions(User) .Where(a => a.CreationDate.HasValue) .ToList() .OrderByDescending(a => a.CreationDateLocal.Value) .Take(20) }; //work amount (line-chart) dashboard.WorkAmountChartViewModel = new MorrisLineChartViewModel { HeaderTitle = "Work Amount", Dates = db.GetMyPomodoros(User).ToList() .Where(p => p.Start.HasValue && p.CalculatedStatus == LoggableItemCalculatedStatus.Completed) .Select(p => p.StartLocal.Value).AsEnumerable(), Interval = DateInterval.Monthly, Label = "Work units", HtmlElementId = "work-amount" }; dashboard.WorkDivisionViewModel = new MorrisDonutChartViewModel { HeaderTitle = "Work Division", Items = db.GetMyProjects(User) .AsEnumerable() .OrderByDescending(p => p.CompletedPomodorosCount), HtmlElementId = "work-division" }; dashboard.MyWorkspace = db.GetMyWorkspace(User); //dashboard.WorkDivisionViewModels = new List<MorrisDonutChartViewModel> { // //work project division (donut chart) // new MorrisDonutChartViewModel // { // HeaderTitle = "Projects", // Items = db.GetMyProjects(User), // HtmlElementId = "project-chart" // }, // //work task division (donut chart) // new MorrisDonutChartViewModel // { // HeaderTitle = "Tasks", // Items = db.GetMyTasks(User), // HtmlElementId = "task-chart", // UseFullPathItemName = true // } //}; return(View(dashboard)); }