public override WidgetResult Show(IssueDto issue = null)
        {
            WidgetResult result = new WidgetResult();

            RepeaterModel model = GetRepeatingModel();

            result.Markup = new WidgetMarkup("views\\Repeater.cshtml", model);

            result.Success = true;

            return(result);
        }
        public RepeaterModel GetRepeatingModel()
        {
            RepeaterModel model = new RepeaterModel();

            var filter = new IssuesFilter();

            if (IsSessionFilter() || !CurrentCard.Options.ContainsKey(AppGuid))
            {
                filter = HttpSessionManager.GetFilter(CurrentCard.Id, IssuesFilter.CreateProjectFilter(CurrentUser.Entity.Id, CurrentProject.Entity.Id));
            }
            else if (CurrentCard.Options.ContainsKey(AppGuid))
            {
                filter = CurrentCard.Options[AppGuid].FromJson <IssuesFilter>();
            }
            else
            {
                filter = CurrentCard.Filter;
            }

            if (filter.Repeat.IsEmpty() || filter.Repeat == "-|3")
            {
                filter.Repeat = "-|1";
            }

            var transformedFilter = ItemFilterManager.TransformFilter(filter);

            SetCurrentProjectFromFilter(transformedFilter);

            model.Filter           = IssueFilterHelper.PopulateModel(model.Filter, filter, transformedFilter, PermissionsManager, ItemFilterManager, IssueFilterHelper.GetViewableFields(filter, ProjectManager, MetaManager), false);
            model.GeminiDateFormat = CurrentUser.GeminiDateFormat;
            model.BaseUrl          = string.Format("{0}workspace/{1}/", UserContext.Url, CurrentCard.Id);

            var allIssues = IssueManager.GetFiltered(filter);

            var allIssuesRelatedRepeating = allIssues.Count > 0 ? allIssues.FindAll(s => s.Repeated.HasValue() || s.Entity.OriginatorData.HasValue() && s.Entity.OriginatorType == IssueOriginatorType.Repeat) : new List <IssueDto>();

            var masterIssues = allIssuesRelatedRepeating.Count > 0 ? allIssuesRelatedRepeating.FindAll(i => i.Repeated.HasValue()) : new List <IssueDto>();

            List <string> repeatValues = new List <string>();

            repeatValues.Add("-|1");
            repeatValues.Add("-|2");
            repeatValues.Add("-|3");

            int totalNumberOfRepeatedItems = 0;

            if (masterIssues.Count > 0)
            {
                foreach (var masterIssue in masterIssues)
                {
                    ItemsGrid item = new ItemsGrid();

                    item.MasterItem    = masterIssue;
                    item.RepeatedItems = allIssuesRelatedRepeating.FindAll(s => s.OriginatorData.HasValue() && s.OriginatorData.Equals(masterIssue.Entity.Id.ToString()));

                    if (item.RepeatedItems.Count > 0 || filter.Repeat == "-|2" || !repeatValues.Contains(filter.Repeat))
                    {
                        item.RepeatedItems = item.RepeatedItems.OrderBy("Created").ToList();
                        IssueDto lastRepeated = IssueManager.GetLastCreatedIssueForOriginator(IssueOriginatorType.Repeat, masterIssue.Id.ToString());

                        if (lastRepeated != null)
                        {
                            item.LastRepitition = lastRepeated.Created.ToString(UserContext.User.DateFormat);
                        }
                    }


                    //Create Next repitition
                    RepeatParser repeat = new RepeatParser(masterIssue.Repeated);

                    for (DateTime date = DateTime.Today; item.NextRepitition.IsEmpty(); date = date.AddDays(1))
                    {
                        repeat.CurrentDateTime = date;

                        DateTime lastRepeatedDate = masterIssue.Created;

                        if (item.RepeatedItems.Count > 0)
                        {
                            lastRepeatedDate = item.RepeatedItems.Last().Entity.Created;
                        }

                        if (item.RepeatedItems.Count >= repeat.MaximumRepeats)
                        {
                            break;
                        }

                        if (repeat.NeedsToRepeat(lastRepeatedDate))
                        {
                            item.NextRepitition = date.ToShortDateString();
                            break;
                        }
                    }

                    totalNumberOfRepeatedItems += item.RepeatedItems.Count;

                    model.Items.Add(item);
                }
            }
            else if (allIssuesRelatedRepeating.Count > 0)
            {
                foreach (var repeatedIssue in allIssuesRelatedRepeating)
                {
                    ItemsGrid item = new ItemsGrid()
                    {
                        MasterItem = repeatedIssue, RepeatedItems = new List <IssueDto>()
                    };
                    model.Items.Add(item);
                }
            }

            model.ItemCount = masterIssues.Count + totalNumberOfRepeatedItems;
            return(model);
        }
        public ActionResult GetItemGrid()
        {
            RepeaterModel model = GetRepeatingModel();

            return(JsonSuccess(new { Html = RenderPartialViewToString(this, AppManager.Instance.GetAppUrl(AppGuid, "views/_Grid.cshtml"), model) }));
        }