public ActionResult GetRoadmap(int versionId, int projectId, bool includeSubVersions) { UserContext.Project = ProjectManager.Get(projectId); IssuesFilter filter = null; if (Request.Form.Keys.Count > 0) { filter = new IssuesFilter(); string[] sort = Request.Form[0].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); StringBuilder sortField = new StringBuilder(); StringBuilder sortDirection = new StringBuilder(); for (int i = 0; i < sort.Length; i += 2) { sortField.Append(sort[i]); sortField.Append('|'); sortDirection.Append(sort[i + 1] == "0" ? (int)SortDirection.Ascending : (int)SortDirection.Descending); sortDirection.Append('|'); } filter.SortField = sortField.ToString(); filter.SortOrder = sortDirection.ToString(); filter.ShowSequenced = false; } if (filter == null) { filter = HttpSessionManager.GetFilter(CurrentCard.Id, new IssuesFilter()); filter.ShowSequenced = false; } IEnumerable <Countersoft.Gemini.Commons.Entity.Version> versions = Cache.Versions.GetAll().Where(v => v.ProjectId == projectId && v.Released == false && v.Archived == false).OrderBy(o => o.Sequence); // get all versions that are released or not according to settings passed (BUT - NEVER show archived projects) if (!versions.Any(s => s.Id == versionId)) { VersionDto newVersion = VersionManager.GetFirstRoadmapVersion(UserContext.Project.Entity.Id); if (newVersion != null) { versionId = newVersion.Entity.Id; } else { versionId = versions.Count() > 0 ? versions.First().Id : 0; } } var version = VersionManager.Get(versionId); List <IssueDto> issues = new List <IssueDto>(); if (version != null && !version.Entity.Released) { issues = IssueManager.GetRoadmap(UserContext.Project.Entity.Id, filter, versionId); if (includeSubVersions) { var child = versions.Where(v => v.ParentId == version.Entity.Id).ToList(); AddChildVersions(versions.ToList(), UserContext.Project.Entity.Id, filter, child, ref issues); } } RoadmapAppModel model = BuildModelData(versionId, versions, issues, filter); model.IncludeSubVersions = includeSubVersions; model.Issues = issues; return(JsonSuccess(new { success = true, grid = RenderPartialViewToString(this, "~/Views/Shared/DisplayTemplates/IssueDto.cshtml", model), statusBar = RenderPartialViewToString(this, AppManager.Instance.GetAppUrl("1F21A63F-94FF-46D0-8773-9E482EF0CA90", "views/StatusBar.cshtml"), model), versions = RenderPartialViewToString(this, AppManager.Instance.GetAppUrl("1F21A63F-94FF-46D0-8773-9E482EF0CA90", "views/VersionProgress.cshtml"), model) })); }
public override WidgetResult Show(IssueDto issue = null) { var filter = IsSessionFilter() || CurrentCard.CardType != ProjectTemplatePageType.Custom && "app/roadmap/view".Equals(CurrentCard.Url, StringComparison.InvariantCultureIgnoreCase) ? HttpSessionManager.GetFilter(CurrentCard.Id, IssuesFilter.CreateProjectFilter(CurrentUser.Entity.Id, CurrentProject.Entity.Id)) : CurrentCard.Filter; HttpSessionManager.SetFilter(CurrentCard.Id, filter); int? currentProjectId = 0; bool includeSubversions = false; int versionId = 0; HttpSessionManager.Set <List <UserIssuesView> >(null, Constants.RoadmapSessionView); // Safety check required because of http://gemini.countersoft.com/project/DEV/21/item/5088 PageSettings pageSettings = null; try { if (CurrentCard.Options.ContainsKey(AppGuid)) { pageSettings = CurrentCard.Options[AppGuid].FromJson <PageSettings>(); if (pageSettings.PageData != null) { currentProjectId = pageSettings.PageData.projectId; versionId = pageSettings.PageData.versionId; includeSubversions = pageSettings.PageData.includeSubversions; } } } catch { } //If no project is selected, select the first workspace project. if ((!currentProjectId.HasValue || currentProjectId.Value == 0) && filter.Projects.HasValue()) { try { var workspaceProjects = filter.Projects.Split('|'); if (workspaceProjects.Count() > 0) { currentProjectId = Convert.ToInt32(workspaceProjects[0]); } } catch { } } var viewableProjects = ProjectManager.GetAppViewableProjects(this).ToList(); if (!viewableProjects.Any(s => s.Entity.Id == currentProjectId.Value)) { currentProjectId = viewableProjects.Count > 0 ? viewableProjects.First().Entity.Id : 0; } UserContext.Project = ProjectManager.Get(currentProjectId); IEnumerable <Countersoft.Gemini.Commons.Entity.Version> versions = null; // get all versions that are released or not according to settings passed (BUT - NEVER show archived projects) versions = Cache.Versions.GetAll().Where(v => v.ProjectId == currentProjectId && v.Released == false && v.Archived == false).OrderBy(o => o.Sequence); if (versionId == 0) { VersionDto version = VersionManager.GetFirstRoadmapVersion(UserContext.Project.Entity.Id); if (version != null) { versionId = version.Entity.Id; } else { versionId = versions.Count() > 0 ? versions.First().Id : 0; } } List <IssueDto> issues; issues = IssueManager.GetRoadmap(UserContext.Project.Entity.Id, filter, versionId); if (includeSubversions) { var child = versions.Where(v => v.ParentId == versionId).ToList(); AddChildVersions(versions.ToList(), UserContext.Project.Entity.Id, filter, child, ref issues); } RoadmapAppModel model = BuildModelData(versionId, versions, issues); model.ProjectList = new SelectList(viewableProjects, "Entity.Id", "Entity.Name", currentProjectId.GetValueOrDefault()); model.IncludeSubVersions = includeSubversions; if (pageSettings == null) { pageSettings = new PageSettings(); } pageSettings.PageData.versionId = versionId; pageSettings.PageData.projectId = currentProjectId.GetValueOrDefault(); CurrentCard.Options[AppGuid] = pageSettings.ToJson(); //var view = RenderPartialViewToString(this, "~/views/Roadmap.cshtml", model); return(new WidgetResult() { Success = true, Markup = new WidgetMarkup("views/Roadmap.cshtml", model) }); }
private RoadmapAppModel BuildModelData(int versionId, IEnumerable <Countersoft.Gemini.Commons.Entity.Version> iVersions, List <IssueDto> issues, IssuesFilter OriginalFilter = null) { StringBuilder builder = new StringBuilder(); RoadmapAppModel model = new RoadmapAppModel();//GetModel<RoadmapAppModel>(); List <VersionDto> versions = VersionManager.Convert(new List <Countersoft.Gemini.Commons.Entity.Version>(iVersions)); if (versions.Count != iVersions.Count()) { // Need to get the version again as parents is missing, probably released foreach (var ver in iVersions) { if (versions.Find(v => v.Entity.Id == ver.Id) == null) { int index = versions.FindIndex(v => v.Entity.Sequence > ver.Sequence); if (index == -1) { versions.Add(VersionManager.Convert(ver)); } else { versions.Insert(index, VersionManager.Convert(ver)); } } } } IssuesFilter filter = new IssuesFilter(); // Build up the progress data on all the cards as we go foreach (var version in versions) { RoadmapAppModel tmp = new RoadmapAppModel(); builder.Append(BuildAllProjectVersions(version.Entity, version.Entity.Id == versionId, version.HierarchyLevel)); if (version.Entity.Id == versionId) { var visibility = GetRoadmapFields(UserContext.Project.Entity.Id); var properties = GridManager.GetDisplayProperties(MetaManager.TypeGetAll(new List <ProjectDto>() { CurrentProject }), visibility, new List <int>() { version.Project.Entity.Id }); List <ColumnInfoModel> gridColumns = GridManager.DescribeGridColumns(properties); GridOptionsModel gridOptions = GridManager.DescribeGridOptions(); // get the version specific data tmp.Issues = issues; tmp.Columns = gridColumns; tmp.Options = gridOptions; tmp.Closed = tmp.Issues.Count(i => i.IsClosed); tmp.Open = tmp.Issues.Count(i => !i.IsClosed); tmp.Statuses = (from i in tmp.Issues group i by new { Id = i.Entity.StatusId, Name = i.Status } into g select new Triple <string, int, string>(g.Key.Name, g.Count(), string.Format("{0}{1}?versions={2}&statuses={3}", UserContext.Url, NavigationHelper.GetProjectPageUrl(UserContext.Project, ProjectTemplatePageType.Items), versionId, g.Key.Id))).OrderByDescending(g => g.Second).Take(3); tmp.Types = (from i in tmp.Issues group i by new { Id = i.Entity.TypeId, Name = i.Type } into g select new Triple <string, int, string>(g.Key.Name, g.Count(), string.Format("{0}{1}?versions={2}&types={3}&includeclosed=yes", UserContext.Url, NavigationHelper.GetProjectPageUrl(UserContext.Project, ProjectTemplatePageType.Items), versionId, g.Key.Id))).OrderByDescending(g => g.Second).Take(3); // store the version Id model.VersionId = version.Entity.Id; model.VersionLabel = version.Entity.Name; model.Closed = tmp.Closed; model.Columns = tmp.Columns; model.Issues = tmp.Issues; model.DisplayData = GridManager.GetDisplayData(tmp.Issues, tmp.Columns); model.Open = tmp.Open; model.Options = tmp.Options; model.Statuses = tmp.Statuses; model.Types = tmp.Types; model.Estimated = issues.Sum(i => i.Entity.EstimatedHours * 60 + i.EstimatedMinutes); model.Logged = issues.Sum(i => i.Entity.LoggedHours * 60 + i.Entity.LoggedMinutes); model.Remain = model.Estimated > model.Logged ? model.Estimated - model.Logged : 0; model.TimeLoggedOver = model.Logged > model.Estimated ? model.Logged - model.Estimated : 0; model.ReleaseStartDate = version.Entity.StartDate; model.ReleaseEndDate = version.Entity.ReleaseDate; // Now get with the extra data that we need var projectId = UserContext.Project.Entity.Id; IssuesGridFilter defaultFilter = new IssuesGridFilter(IssuesFilter.CreateProjectFilter(CurrentUser.Entity.Id, CurrentProject.Entity.Id)); filter = IssuesFilter.CreateVersionFilter(CurrentUser.Entity.Id, CurrentProject.Entity.Id, version.Entity.Id); if (OriginalFilter != null) { filter.SortField = OriginalFilter.SortField; filter.SortOrder = OriginalFilter.SortOrder; } ItemFilterManager.SetSortedColumns(gridColumns, filter); model.Filter = IssueFilterHelper.PopulateModel(model.Filter, filter, filter, PermissionsManager, ItemFilterManager, IssueFilterHelper.GetViewableFields(filter, ProjectManager, MetaManager), false); } } // attach version cards model.VersionCards = builder.ToString(); // Visibility model[ItemAttributeVisibility.Status] = CanSeeProjectItemAttribute(ItemAttributeVisibility.Status); model[ItemAttributeVisibility.EstimatedEffort] = CanSeeProjectItemAttribute(ItemAttributeVisibility.EstimatedEffort); model[ItemAttributeVisibility.CalculatedTimeLogged] = CanSeeProjectItemAttribute(ItemAttributeVisibility.CalculatedTimeLogged); model[ItemAttributeVisibility.CalculatedTimeRemaining] = model[ItemAttributeVisibility.EstimatedEffort] && model[ItemAttributeVisibility.CalculatedTimeLogged]; StringBuilder sort = new StringBuilder(); List <string> sorting = new IssuesFilter().GetSortFields(); List <int> orders = new IssuesFilter().GetSortOrders(); for (int i = 0; i < sorting.Count; i++) { sort.AppendFormat("{0}|{1}", sorting[i], orders[i] == 1 ? 0 : 1); } model.Sort = sort.ToString(); model.CurrentPageCard = CurrentCard; return(model); }