/// <summary> /// Заполняет модель данными /// </summary> private void FillTasks(FormCollection collection, int id, string cookiePage, bool isArchive) { // Получаем данные либо из запроса либо из кук, в зависимости от типа действия TaskFilter filter = _FilterUtility.GetCurrentFilter(id, !isArchive, collection); if (isArchive && filter.SortType == TasksSortType.ByStatus) { filter.SortType = TasksSortType.ByName; } #region Подготавливаем данные int page; if (collection["Page"] == null) { page = Cookies.GetFromCookies(cookiePage).TryToInt(1); // Сюда попадаем при фильтрации, при пейджинге не попадаем // Запоминаем фильтры пользователя _FilterUtility.SaveFilterToCookies(id, collection); } else { page = collection["Page"].TryToInt(1); Cookies.AddToCookie(cookiePage, page.ToString()); } // Данные для отображения List <ITask> tasks = isArchive ? Utility.Tasks.GetFromArchive(filter) : Utility.Tasks.Get(filter); var pagedTasks = new PagedTasks(page, tasks); ViewData.Model = pagedTasks.Tasks; ViewData.Add("Page", page); ViewData.Add("TotalItems", pagedTasks.TotalCount); ViewData.Add("isArchive", isArchive); #endregion }
public PartialViewResult Kanban(int id, FormCollection collection) { #region Получаем данные либо из запроса либо из кук, в зависимости от типа действия TaskFilter filter = _FilterUtility.GetCurrentFilter(id, false, collection); IEnumerable <int> userIds = filter.ExecutorIds.ToArray(); if (collection.Count > 0) { // Сюда попадаем при фильтрации // Запоминаем фильтры пользователя collection["Statuses"] = string.Empty; _FilterUtility.SaveFilterToCookies(id, collection); } string rawCollapsedStatuses = Cookies.GetFromCookies("CollapsedStatuses"); // Если просматриваем конкретного пользователя, то и при создании задач используем его. // Этот пользователь текущий if (userIds.Count() == 1) { Cookies.AddToCookie("SelectedUser", userIds.First().ToString(CultureInfo.InvariantCulture), false); } #endregion #region Парсим сырые данные // Исключенные статусы // исключаем архив, так как в канбане его не показываем List <int> excludedStatuses = new List <int>(); if (!rawCollapsedStatuses.IsNullOrEmpty()) { excludedStatuses.AddRange(rawCollapsedStatuses .UrlDecode() .Split(new[] { "||" }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.ToInt()) .ToList()); } // Данные для отображения var statuses = Utility.Statuses.GetByBoard(id); IEnumerable <int> needTaskStatuses = statuses .Select(x => x.Id) .Except(excludedStatuses) .ToArray(); filter.Statuses = needTaskStatuses; var tasks = Utility.Tasks.Get(filter); #endregion #region Подготавливаем данные foreach (int status in needTaskStatuses) { string key = "status-page-" + status.ToString(CultureInfo.InvariantCulture); int page = Cookies.GetFromCookies(key).TryToInt() ?? 1; ViewData.Add(key, page); } ViewData.Model = statuses; ViewData.Add("Tasks", tasks); ViewData.Add("CollapsedStatuses", excludedStatuses); // Определяем ширину статуса // если алгоритм поменяется, поменять в Kanban.js float sw = Cookies.GetFromCookies("document.width").To(1280 - 17); float hidenCount = excludedStatuses.Count(); float count = statuses.Count() - hidenCount; // количество развернутых статусов sw -= hidenCount * 31; float width = sw / count - 1; ViewData.Add("StatusWidth", width); #endregion return(PartialView("Kanban")); }
public ActionResult TaskPopup(int id, int?taskId, FormCollection collection) { taskId = collection["task-id"].ToNullable <int>(); int statusId = collection["task-statusid"].ToInt(); return(TaskAction(taskId, statusId, delegate { int userId = collection["task-userid"].ToInt(); string name = collection["task-name"]; string desc = collection["task-description"]; int projectId = collection["task-projectsid"].ToInt(); int colorId = collection["task-colorid"].ToInt(); int planingHours = collection["task-planning-hours"].TryToInt(0) * 60; int planingMinutes = collection["task-planning-minutes"].TryToInt(0); int?planingTime = planingHours + planingMinutes; if (planingTime <= 0) { planingTime = null; } // Статус не запоминаем куках, так как он определяется нажатием на + в интерфейсе Cookies.AddToCookie("SelectedProject", projectId.ToString()); Cookies.AddToCookie("SelectedUser", userId.ToString()); Cookies.AddToCookie("SelectedColor", colorId.ToString()); // Какие лимиты нужно проверять Limits limits = LimitsToCheck(collection); #region Создание/Редактирование ITask task; if (taskId.HasValue) { limits |= Limits.PopupUpdating; // Обновляем задачу task = Utility.Tasks.Update( id, taskId.Value, name, desc, userId, projectId, colorId, planingTime, limits); Utility.Tasks.UpdateStatus(task.Id, statusId, limits); } else { // Создаем задачу task = Utility.Tasks.Create(name, desc, userId, projectId, colorId, statusId, id, planingTime, limits); } ViewData.Model = task; return PartialView("Task"); #endregion })); }
public PartialViewResult Items(int id, FormCollection collection) { #region Получаем данные фильтра либо из запроса либо из кук, в зависимости от того действия List <int> userIds; List <int> projectIds; List <int> dummy; TasksSortType sortType; _FilterUtility.GetCurrentFilter(id, out userIds, out projectIds, out dummy, out sortType, out dummy, collection); EventType eventTypes = GetEventTypes(collection); if (collection != null && collection.Count > 0 && collection["Page"] == null) { // Сюда попадаем при фильтрации // затираем значение, что бы оно не менялось в куках collection["Statuses"] = string.Empty; collection["Colors"] = string.Empty; // Запоминаем фильтры пользователя _FilterUtility.SaveFilterToCookies(id, collection); #region Сохранение типа int valueForCoocke = (int)EventType.All; if (collection["EventTypes"] != null && !string.IsNullOrEmpty(collection["EventTypes"])) { // собираем все выбранные флаги в одно число и сохраняем исключенные var checkedIds = GetIds(collection["EventTypes"]); valueForCoocke = ~checkedIds.Aggregate((current, i) => current | i); } Cookies.AddToCookie("EventTypes", valueForCoocke.ToString()); #endregion } #endregion #region int page; if (collection == null || collection["Page"] == null) { page = Cookies.GetFromCookies("LogTablePage").TryToInt(1); } else { page = collection["Page"].TryToInt(1); Cookies.AddToCookie("LogTablePage", page.ToString()); } EventDataFilter filter = new EventDataFilter { BoardId = id, UserIds = userIds, ProjectIds = projectIds, EventTypes = eventTypes, Page = page, ItemsOnPage = Pager.DefaultItemsOnPage }; int total; var data = Utility.Events.Get(filter, out total); #endregion ViewData.Model = data; ViewData.Add("Page", page); ViewData.Add("TotalItems", total); return(PartialView("Items")); }