Ejemplo n.º 1
0
        public ActionResult History(string issueId)
        {
            var issueMemoizer = new LocalMemoizer <string, Issue>(id => _getIssueQuery.Invoke(new GetIssueRequest
            {
                CurrentUser = Core.AppContext.CurrentUser, IssueId = id
            }).Issue);

            var history = Core.Session.Raven.Query <HistoryDocument, Core.Indexing.History>()
                          .Where(h => h.IssueId == Issue.GetId(issueId))
                          .As <IssueHistory>()
                          .ToList();

            var users = Core.GetUsers();

            var results = history.OrderByDescending(h => h.DateAddedUtc).Select(h =>
            {
                var user = users.Items.FirstOrDefault(u => u.Id == h.UserId);
                return(RenderPartial("Issue/HistoryItem", new IssueHistoryItemViewModel
                {
                    Message = h.GetMessage(users.Items, issueMemoizer, GetIssueLink),
                    VerbalTime = h.DateAddedUtc.ToVerbalTimeSinceUtc(Core.AppContext.CurrentUser.ActiveOrganisation.TimezoneId),
                    UserEmail = user != null ? user.Email : string.Empty,
                    Username = user != null ? user.FullName : string.Empty,
                    SystemMessage = h.SystemMessage,
                }));
            });

            return(new JsonSuccessResult(results, allowGet: true));
        }
Ejemplo n.º 2
0
        public ActivityViewModelBase GetActivityViewModel(int pageNumber)
        {
            var curentApplication = CurrentApplication;
            var applicationId     = curentApplication == null ? null : curentApplication.Id;
            var issueMemoizer     = new LocalMemoizer <string, Issue>(id => _getIssueQuery.Invoke(new GetIssueRequest {
                CurrentUser = Core.AppContext.CurrentUser, IssueId = id
            }).Issue);
            var users        = Core.GetUsers();
            var applications = Core.GetApplications();
            var activity     = _getActivityLogQuery.Invoke(new GetActivityLogRequest
            {
                Paging        = new PageRequestWithSort(pageNumber, 20),
                ApplicationId = applicationId
            }).Log;

            var selectedApplication = applicationId.IsNotNullOrEmpty()
                    ? applications.Items.FirstOrDefault(a => a.FriendlyId == applicationId.GetFriendlyId())
                    : null;

            var items = activity.Items.Select(h =>
            {
                var user = users.Items.FirstOrDefault(u => u.Id == h.UserId);

                return(new IssueHistoryItemViewModel
                {
                    Message = h.GetMessage(users.Items, issueMemoizer, GetIssueLink),
                    VerbalTime = h.DateAddedUtc.ToVerbalTimeSinceUtc(Core.AppContext.CurrentUser.ActiveOrganisation.TimezoneId, true),
                    UserEmail = user != null ? user.Email : string.Empty,
                    Username = user != null ? user.FullName : string.Empty,
                    SystemMessage = h.SystemMessage,
                    IssueLink = issueMemoizer.Get(h.IssueId).IfPoss(i => "<a href=\"{0}\">{1}</a>".FormatWith(Url.Issue(i.Id), i.Name), "DELETED"),
                    IssueId = IdHelper.GetFriendlyId(h.IssueId),
                });
            });

            var model = new ActivityViewModelBase
            {
                Paging                  = activity.PagingStatus,
                Items                   = items,
                Applications            = applications.Items,
                SelectedApplicationId   = selectedApplication == null ? null : selectedApplication.FriendlyId,
                SelectedApplicationName = selectedApplication == null ? null : selectedApplication.Name,
                UrlGetter               = GetFeedUrl
            };

            return(model);
        }
Ejemplo n.º 3
0
        public string GetMessage(IEnumerable <User> users, LocalMemoizer <string, Issue> issueMemoizer, Func <string, string> issueUrlGetter)
        {
            var user = UserId.IfPoss(id => users.FirstOrDefault(u => u.Id == id));

            switch (Type)
            {
            case HistoryItemType.CreatedByRuleAdjustment:
                return("Issue was created by adjustment of rules of {0} by {1}.".FormatWith(issueUrlGetter(SpawningIssueId), GetUserString(user)));

            case HistoryItemType.ManuallyCreated:
                return("Issue was created manually by <span class=\"bold\">{0}</span> with status <span class=\"bold\">{1}</span>, assigned to <span class=\"bold\">{2}</span>".FormatWith(GetUserString(user), PreviousStatus, AssignedToUserId));

            case HistoryItemType.AssignedUserChanged:
                return("Status was updated from {0} to {1} by {2}.".FormatWith(PreviousStatus, NewStatus, GetUserString(user)));

            case HistoryItemType.MergedTo:
                return("Issue was created by adjustment of rules of issue {0} by <span class=\"bold\">{1}</span>.".FormatWith(issueUrlGetter(SpawningIssueId), GetUserString(user)));

            case HistoryItemType.ErrorsPurged:
                return("All errors attached to this issue were deleted by <span class=\"bold\">{0}</span>.".FormatWith(GetUserString(user)));

            case HistoryItemType.ErrorsReprocessed:
                return("All errors associated with this issue were re-processed by <span class=\"bold\">{0}</span>.<br />{1}".FormatWith(
                           GetUserString(user),
                           new ReprocessIssueErrorsResponse {
                    AttachedIssueIds = ReprocessingResult, Status = ReprocessIssueErrorsStatus.Ok
                }.GetMessage(IssueId)));

            case HistoryItemType.Comment:
                return(Comment);

            case HistoryItemType.RulesAdjustedCreatedNewIssue:
                return("Issue rules were adjusted by <span class=\"bold\">{0}</span>. Errors that no longer match this issue got attached to issue {1}.".FormatWith(GetUserString(user), issueUrlGetter(SpawnedIssueId)));

            case HistoryItemType.RulesAdjustedNoNewIssue:
                return("Issue rules were adjusted by <span class=\"bold\">{0}</span>. All errors stayed attached to this issue.".FormatWith(GetUserString(user)));

            case HistoryItemType.AutoCreated:
                return("Issue created by new error of type <span class=\"bold\">{0}</span> in method <span class=\"bold\">{1}</span> on machine <span class=\"bold\">{2}</span>".FormatWith(HttpUtility.HtmlEncode(ExceptionType), HttpUtility.HtmlEncode(ExceptionMethod), HttpUtility.HtmlEncode(ExceptionMachine)));

            case HistoryItemType.StatusUpdated:
                return("Status was updated from <span class=\"bold\">{0}</span> to <span class=\"bold\">{1}</span> by <span class=\"bold\">{2}</span>.".FormatWith(PreviousStatus, NewStatus, GetUserString(user)));

            default:
                return("No message");
            }
        }