Exemple #1
0
        public void DbItemCounts()
        {
            // Arrange

            int dbProjectCount = db.GetMyProjects(user).Count();
            int dbTaskCount    = db.GetMyTasks(user).Count();
            int dbActionCount  = db.GetMyActions(user).Count();

            //////////////////////////////////////////

            // Act

            //create project
            project = CreateProject();

            //create task
            task = CreateTask(project.ID);

            //create action
            action = CreateAction(task.ID);

            //////////////////////////////////////////

            // Assert

            Assert.AreEqual <int>(db.GetMyProjects(user).Count(), dbProjectCount + 1);
            Assert.AreEqual <int>(db.GetMyTasks(user).Count(), dbTaskCount + 1);
            Assert.AreEqual <int>(db.GetMyActions(user).Count(), dbActionCount + 1);
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        public ActionResult Create([Bind(Include = "ID,Start,ActionID,Status")] Pomodoro pomodoro)
        {
            if (ModelState.IsValid)
            {
                //set creation date
                pomodoro.CreationDate = DateTime.UtcNow;

                db.Pomodoros.Add(pomodoro);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = pomodoro.ID }));
            }

            ViewBag.ActionID = new SelectList(db.GetMyActions(User), "ID", "Name", pomodoro.ActionID);
            return(View(pomodoro));
        }
Exemple #4
0
        private SearchResults SearchActions(string term = "", SearchResults currentResults = null, Status?status = null)
        {
            if (currentResults == null)
            {
                currentResults = new SearchResults();
            }
            currentResults.SearchTerm = term;

            currentResults.ActionResults = db.GetMyActions(User)
                                           .Where(a =>
                                                  a.Name.ToLower().Contains(currentResults.SearchTerm) ||
                                                  a.Description.ToLower().Contains(currentResults.SearchTerm))
                                           .Where(a =>
                                                  !status.HasValue || a.Status == status.Value)
                                           .ToList();

            return(currentResults);
        }
Exemple #5
0
        // 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));
        }
Exemple #6
0
        // GET: /Action/
        public ViewResult Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            ViewBag.ProjectSortParm      = (sortOrder == "proj") ? "proj_desc" : "proj";
            ViewBag.TaskSortParm         = (sortOrder == "task") ? "task_desc" : "task";
            ViewBag.ActionSortParm       = (sortOrder == "acti") ? "acti_desc" : "acti";
            ViewBag.DateSortParm         = (sortOrder == "date") ? "date_desc" : "date";
            ViewBag.EstimateSortParm     = (sortOrder == "esti") ? "esti_desc" : "esti";
            ViewBag.IsPersistentSortParm = (sortOrder == "pers") ? "pers_desc" : "pers";
            ViewBag.StatusSortParm       = (sortOrder == "stat") ? "stat_desc" : "stat";
            ViewBag.PrioritySortParm     = (sortOrder == "prio") ? "prio_desc" : "prio";
            ViewBag.LastPomodoroSortParm = (sortOrder == "last") ? "last_desc" : "last";
            ViewBag.PomodorosSortParm    = (sortOrder == "pomo") ? "pomo_desc" : "pomo";
            ViewBag.EffortSortParm       = (sortOrder == "effo") ? "effo_desc" : "effo";

            var actions = db.GetMyActions(User);

            //stores the current filter info for the pagination control
            RouteValueDictionary dict = new RouteValueDictionary();

            //initilised with the current sort order
            dict["CurrentSort"] = sortOrder;

            //status filter
            const string STATUS_PREFIX = "status-";

            string[] statusFilter = GetArrayParamsFromRequest(Request.QueryString, STATUS_PREFIX);
            if (statusFilter.Length > 0)
            {
                actions = actions.ToList().AsQueryable()
                          .Where(a => statusFilter
                                 .Any(sf => sf.ToLower() == a.CalculatedStatus.ToString().ToLower())
                                 );
                dict.AddFilterArrayToRouteValueDictionary(statusFilter, STATUS_PREFIX);
            }

            //tag filter
            const string TAG_PREFIX = "tag-";

            string[] tagFilter = GetArrayParamsFromRequest(Request.QueryString, TAG_PREFIX);
            if (tagFilter.Length > 0)
            {
                actions = actions.ToList().AsQueryable()
                          .Where(a => tagFilter
                                 .All(tf => a.OwnAndInheritedTags //all tags in the filter
                                      .Select(tc => tc.Code)      //(only tag code list)
                                      .Contains(tf))              //contained in the item tags
                                 );
                //AND Tag Filter
                //actions = actions.ToList().AsQueryable()
                //    .Where(a => tagFilter
                //        .All(tf => a.OwnAndInheritedTags    //all tags in the filter
                //            .Select(tc => tc.Code)          //(only tag code list)
                //                .Contains(tf))              //contained in the item tags
                //);
                dict.AddFilterArrayToRouteValueDictionary(tagFilter, TAG_PREFIX);
            }

            //priority filter
            const string PRIORITY_PREFIX = "priority-";

            string[] priorityFilter = GetArrayParamsFromRequest(Request.QueryString, PRIORITY_PREFIX);
            if (priorityFilter.Length > 0)
            {
                actions = actions.ToList().AsQueryable()
                          .Where(a => priorityFilter
                                 .Any(pf => pf.ToLower() == a.Priority.ToString().ToLower())
                                 );
                dict.AddFilterArrayToRouteValueDictionary(priorityFilter, PRIORITY_PREFIX);
            }

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.IsFiltered = string.IsNullOrEmpty(Request.QueryString["filtering"]) == false ||
                                 (statusFilter.Length > 0) || (priorityFilter.Length > 0) || (tagFilter.Length > 0);
            ViewBag.RouteFiltersForPagination = dict;

            ViewBag.StatusFilter   = statusFilter;
            ViewBag.PriorityFilter = priorityFilter;
            ViewBag.TagFilter      = tagFilter;
            //ViewBag.CurrentFilter = searchString;

            ViewBag.AllTags = db.GetMyTags(User).ToArray();

            switch (sortOrder)
            {
            case "proj":
                actions = actions.OrderBy(a => a.Task.Project.Code).ThenBy(a => a.Task.Code).ThenBy(a => a.Name);
                break;

            case "proj_desc":
                actions = actions.OrderByDescending(a => a.Task.Project.Code).ThenByDescending(a => a.Task.Code).ThenByDescending(a => a.Name);
                break;

            case "task":
                actions = actions.OrderBy(a => a.Task.Code).ThenBy(a => a.Name);
                break;

            case "task_desc":
                actions = actions.OrderByDescending(a => a.Task.Code).ThenByDescending(a => a.Name);
                break;

            case "acti":
                actions = actions.OrderBy(a => a.Name);
                break;

            case "acti_desc":
                actions = actions.OrderByDescending(a => a.Name);
                break;

            case "esti":
                actions = actions.OrderBy(a => a.Estimate);
                break;

            case "esti_desc":
                actions = actions.OrderByDescending(a => a.Estimate);
                break;

            case "pers":
                actions = actions.ToList().AsQueryable().OrderBy(a => a.IsPersistent);
                break;

            case "pers_desc":
                actions = actions.ToList().AsQueryable().OrderByDescending(a => a.IsPersistent);
                break;

            case "last":
                actions = actions.ToList().AsQueryable().OrderBy(t => t.LastPomodoro.ToDateTicksOrZero());
                break;

            case "last_desc":
                actions = actions.ToList().AsQueryable().OrderByDescending(t => t.LastPomodoro.ToDateTicksOrZero());
                break;

            case "pomo":
                actions = actions.ToList().AsQueryable().OrderBy(a => a.CompletedPomodorosCount);
                break;

            case "pomo_desc":
                actions = actions.ToList().AsQueryable().OrderByDescending(a => a.CompletedPomodorosCount);
                break;

            case "date":
                actions = actions.ToList().AsQueryable().OrderBy(a => a.DeadlineOrEndDate.ToTicksOrZero());
                break;

            case "date_desc":
                actions = actions.ToList().AsQueryable().OrderByDescending(a => a.DeadlineOrEndDate.ToTicksOrZero());
                break;

            case "stat":
                actions = actions.ToList().AsQueryable().OrderBy(a => a.CalculatedStatus);
                break;

            case "stat_desc":
                actions = actions.ToList().AsQueryable().OrderByDescending(a => a.CalculatedStatus);
                break;

            case "prio":
                actions = actions.OrderBy(a => a.Priority);
                break;

            case "prio_desc":
                actions = actions.OrderByDescending(a => a.Priority);
                break;

            case "effo":
                actions = actions.ToList().AsQueryable().OrderBy(t => t.Effort.ToDecimalOrZero()).ThenBy(t => t.CompletedPomodorosCount);
                break;

            case "effo_desc":
                actions = actions.ToList().AsQueryable().OrderByDescending(t => t.Effort.ToDecimalOrZero()).ThenByDescending(t => t.CompletedPomodorosCount);
                break;

            default:
                actions = actions.ToList().AsQueryable().OrderBy(a => a.Status).ThenByDescending(a => a.LastPomodoro.ToDateTicksOrZero());
                break;
            }
            int pageSize   = 20;
            int pageNumber = (page ?? 1);

            return(View(actions.ToPagedList(pageNumber, pageSize)));
        }