public static IQueryable<Issue> Filter(this IQueryable<Issue> issues, UserOptions userOptions)
        {
            if (userOptions.StatusFilter.HasValue() && !userOptions.StatusFilter.Is("-"))
                issues = issues.Where(x => x.Status.ToLower() == userOptions.StatusFilter.ToLower());

            if (userOptions.TextFilter.HasValue() && !userOptions.TextFilter.Is("-"))
                issues =
                    issues.Where(
                        x =>
                            SqlMethods.Like(x.Text, "%" + userOptions.TextFilter + "%") || SqlMethods.Like(x.StackTrace, "%" + userOptions.TextFilter + "%") ||
                            SqlMethods.Like(x.ServerVariables, "%" + userOptions.TextFilter + "%"));

            if (userOptions.UserFilter.HasValue() && userOptions.UserFilter.Is("--"))
                issues = issues.Where(x => x.AssignedTo == null);
            else if (userOptions.UserFilter.HasValue() && !userOptions.UserFilter.Is("-"))
                issues = issues.Where(x => x.AssignedTo.ToLower() == userOptions.UserFilter.ToLower());

            var now = DateTime.Now.ToUniversalTime();
            if (userOptions.DateFilter.HasValue)
                issues =
                    issues.Where(
                        x =>
                            DbFunctions.DiffDays(x.DateOfCreation, now) <= userOptions.DateFilter ||
                            x.Comments.Any(y => DbFunctions.DiffDays(y.DateOfCreation, now) <= userOptions.DateFilter));

            return issues;
        }
Exemplo n.º 2
0
        public ActionResult Index(int? page, string tags)
        {
            var viewModel = new IndexViewModel(_db, ViewData);

            page = page.HasValue ? page.Value - 1 : 0;
            var issues = from x in _db.Issues
                         where !x.ParentIssueId.HasValue
                         select x;
            viewModel.CountTotal = issues.Count();

            SaveUserOptions(null, null, null, null, null, tags);
            var userOptions = new UserOptions(Request.Cookies, Response.Cookies);
            issues = issues.Filter(userOptions);
            viewModel.CountFiltered = issues.Count();
            issues = issues.FilterByTags(userOptions);
            viewModel.CountFilteredIncludingTags = issues.Count();

            viewModel.Issues = issues.Sort(userOptions).Skip(page.Value * IssueTrackerSettings.IssuesPerPage)
                    .Take(IssueTrackerSettings.IssuesPerPage)
                    .Include(y => y.Comments).Include(y => y.Tags)
                    .ToList()
                    .Select(x => new IndexIssuePartialViewModel(this.GetCurrentUser(_db), x))
                    .ToList();
            viewModel.Start = page.Value * IssueTrackerSettings.IssuesPerPage;
            viewModel.End = viewModel.Start + viewModel.Issues.Count();
            viewModel.Page = page.Value + 1;

            // ReSharper disable once PossibleLossOfFraction
            viewModel.MaxPage = (int)Math.Ceiling((double)(viewModel.CountFilteredIncludingTags / IssueTrackerSettings.IssuesPerPage)) + 1;

            return View("Index", viewModel);
        }
        public static IQueryable<Issue> Sort(this IQueryable<Issue> issues, UserOptions userOptions)
        {
            var sortedIssues = issues.OrderByDescending(x => x.Comments.Count <= 0 ? x.DateOfCreation : x.Comments.Max(y => y.DateOfCreation));
            if (userOptions.Sorting.Is("status"))
                sortedIssues = issues.OrderBy(x => x.Status);
            else if (userOptions.Sorting.Is("comments"))
                sortedIssues = issues.OrderByDescending(x => x.Comments.Count);

            return sortedIssues.AsQueryable();
        }
        public static IQueryable<Issue> FilterByTags(this IQueryable<Issue> issues, UserOptions userOptions)
        {
            if (userOptions.TagsFilter.Any())
            {
                var includesUntagged = userOptions.TagsFilter.Any(x => x.Is("untagged"));
                var lowercaseTags = userOptions.TagsFilter.Select(x => x.ToLower()).Where(x => !x.Is("untagged")).ToArray();
                issues = issues.Where(x => (includesUntagged || x.Tags.Any()) && x.Tags.All(y => lowercaseTags.Contains(y.Tag.ToLower())));
            }

            return issues;
        }
Exemplo n.º 5
0
        public HeaderViewModel Fill(IPrincipal user, UserOptions userOptions)
        {
            CurrentUser = Utils.GetCurrentUser(_db, _viewData, user);

            var usedStati = new List<SelectListItem>
            {
                new SelectListItem
                {
                    Value = "-",
                    Text = "< All >"
                }
            };
            usedStati.AddRange(
                    from x in Utils.GetAllStati(_db, _viewData)
                    select new SelectListItem
                    {
                        Text = x.Name,
                        Value = x.Name
                    }
                );
            AvailableStati = usedStati;

            var usedUsers = new List<SelectListItem>
            {
                new SelectListItem
                {
                    Value = "-",
                    Text = "< All >"
                },
                new SelectListItem
                {
                    Value = "--",
                    Text = "< None >"
                }
            };
            usedUsers.AddRange(
                    from x in Utils.GetAllUsers(_db, _viewData)
                    select new SelectListItem
                    {
                        Text = x.Name,
                        Value = x.Name
                    }
                );
            AvailableUsers = usedUsers;

            CurrentSorting = userOptions.Sorting ?? "";
            CurrentDateFilter = userOptions.DateFilter.HasValue ? userOptions.DateFilter.Value.ToString(CultureInfo.InvariantCulture) : "";
            CurrentUserFilter = userOptions.UserFilter ?? "";
            CurrentStatusFilter = userOptions.StatusFilter ?? "";

            return this;
        }
Exemplo n.º 6
0
        public TagFilterViewModel(Db db, UserOptions userOptions)
        {
            var allTagRules = db.TagRules.OrderBy(x => x.Group).ThenBy(x => x.Tag).ToList();
            var issues = db.Issues.Filter(userOptions).Where(y => !y.ParentIssueId.HasValue);

            var issueTags = issues.SelectMany(y => y.Tags);
            var issuesCount = new List<Tuple<string, int>>();

            if (issueTags.Any())
                issuesCount = (from x in issueTags
                    group x by x.Tag
                    into g
                    select new {Tag = g.Key, Count = g.Count()}).ToList().Select(x => new Tuple<string, int>(x.Tag, x.Count)).ToList();

            var groups = new List<Group>();
            foreach (var groupName in allTagRules.Select(x => x.Group).Distinct())
            {
                var groupNameClosure = groupName;
                var group = new Group
                {
                    Name = groupName,
                    Tags = from x in allTagRules.Where(x => x.Group == groupNameClosure)
                        select new Tag
                        {
                            Name = x.Tag,
                            Count = issuesCount.Where(y => y.Item1 == x.Tag).Sum(y => y.Item2),
                            IsFiltered = userOptions.TagsFilter.Any() && !userOptions.TagsFilter.Any(y => y.Is(x.Tag))
                        }
                };
                groups.Add(group);
            }
            Groups = groups;

            CountUntagged = issues.Count(x => !x.Tags.Any());
            FilterUntagged = userOptions.TagsFilter.Any() && !userOptions.TagsFilter.Any(x => x.Is("untagged"));
        }
Exemplo n.º 7
0
 public ActionResult TagFilter()
 {
     var userOptions = new UserOptions(Request.Cookies, Response.Cookies);
     var viewModel = new TagFilterViewModel(_db, userOptions);
     return PartialView(viewModel);
 }
Exemplo n.º 8
0
        private void SaveUserOptions(string order, string date, string user, string status, string text, string tags)
        {
            var userOptions = new UserOptions(Request.Cookies, Response.Cookies);

            // make sure we only update the settings if we get a new value from the request

            if (order.HasValue())
                userOptions.Sorting = order;

            if (user.HasValue())
                userOptions.UserFilter = user;

            if (status.HasValue())
                userOptions.StatusFilter = status;

            if (text.HasValue())
                userOptions.TextFilter = text;

            if (date.HasValue())
                userOptions.DateFilter = date.GetIntOrNull();

            if (tags.HasValue())
                userOptions.TagsFilter = tags == "-" ? new string[0] : tags.Split(',').Select(x => x.Trim(' ', ',')).Where(x => x.HasValue());
        }