public void MoveItem(ContainablePart item, ContainerPart targetContainer, int?position = null) { var commonPart = item.As <CommonPart>(); if (commonPart == null) { throw new ArgumentException("Cannot move content that have no CommonPart", "item"); } var previousContainer = commonPart.Container != null?commonPart.Container.As <ContainerPart>() : default(ContainerPart); commonPart.Container = targetContainer; if (previousContainer != null && previousContainer.Id != targetContainer.Id) { UpdateItemCount(previousContainer); } if (position != null) { item.Position = position.Value; } UpdateItemCount(targetContainer); UpdateItemPath(item.ContentItem); }
public ContentItem Next(int containerId, ContainablePart current) { if (current == null) { return(null); } return(GetOrderedContentItemsQuery(containerId, null, VersionOptions.Latest).Where(x => x.Position < current.Position).Slice(0, 1).Select(x => x.ContentItem).FirstOrDefault()); }
private void UpdateItemCount(ContainablePart part) { var commonPart = part.As<CommonPart>(); if (commonPart == null || commonPart.Container == null) return; var containerPart = commonPart.Container.As<ContainerPart>(); if (containerPart == null) return; _containerService.UpdateItemCount(containerPart); }
public GenericDashboardHandler(IContentManager contentManager) { OnPublished <GenericDashboardPart>((context, part) => { if (!part.CreatePortletsOnPublishing) { return; } // set default portlets for DashboardWidget if (part.ContentItem.ContentType == Consts.GenericDashboardWidgetContentType && string.IsNullOrEmpty(part.PortletList)) { part.PortletList = string.Join(",", (new string[] { Consts.SmtpPortletContentType, Consts.IMAPTPortletContentType })); } // portlet list var portlets = string.IsNullOrEmpty(part.PortletList) ? new string[] { } : part.PortletList.Split(','); // current portlets var currentPortlets = contentManager.Query().Where <CommonPartRecord>(c => c.Container.Id == part.ContentItem.Id).List(); // add new portlets int position = -1; foreach (var newPortlet in portlets.Where(c => !currentPortlets.Any(d => d.ContentType == c))) { position++; var newPortletContentItem = contentManager.Create(newPortlet, VersionOptions.Draft); ContainablePart containablePart = newPortletContentItem.As <ContainablePart>(); if (containablePart == null) { continue; } // Position containablePart.Position = position; // Container var newPortletCommon = newPortletContentItem.As <CommonPart>(); newPortletCommon.Container = part.ContentItem; contentManager.Publish(newPortletContentItem); } // delete portlets foreach (var portlet in currentPortlets.Where(c => !portlets.Any(d => d == c.ContentType))) { contentManager.Remove(portlet); } }); }
public void AddPortlet(ContentItem projectDashboard, ContentItem portletTemplate, int position) { ContentItem newPortlet = null; if (portletTemplate.ContentType == ContentTypes.ProjectDashboardProjectionPortletTemplateContentType) { newPortlet = this.services.ContentManager.Create(ContentTypes.ProjectDashboardProjectionPortletContentType); ProjectionWithDynamicSortPart destinationProjectionPart = newPortlet.As <ProjectionWithDynamicSortPart>(); ProjectionWithDynamicSortPart sourceProjectionPart = portletTemplate.As <ProjectionWithDynamicSortPart>(); CRMHelper.Copy(layoutRepository, sourceProjectionPart.Record, destinationProjectionPart.Record); } else if (portletTemplate.ContentType == ContentTypes.ProjectDashboardReportViewerPortletTemplateContentType) { newPortlet = this.services.ContentManager.Create(ContentTypes.ProjectDashboardReportViewerPortletContentType); DataReportViewerPart destinationReportViewerPart = newPortlet.As <DataReportViewerPart>(); DataReportViewerPart sourceReportViewerPart = portletTemplate.As <DataReportViewerPart>(); CRMHelper.Copy(sourceReportViewerPart.Record, destinationReportViewerPart.Record); } else if (portletTemplate.ContentType == ContentTypes.ProjectLastActivityStreamTemplateContentType) { newPortlet = this.services.ContentManager.Create(ContentTypes.ProjectLastActivityStreamContentType); var sourceActivityStreamPart = portletTemplate.As <ActivityStreamPart>(); var destinationActivityStreamPart = newPortlet.As <ActivityStreamPart>(); destinationActivityStreamPart.QueryId = sourceActivityStreamPart.QueryId; } else { throw new ArgumentOutOfRangeException("The ContentType of the portletTemplate is not supported."); } // store templateId newPortlet.As <InfosetPart>().Store <int>(FieldNames.ProjectDashboardPortletTemplateId, portletTemplate.Id); // copy Title TitlePart titlePart = newPortlet.As <TitlePart>(); TitlePart templateTitlePart = portletTemplate.As <TitlePart>(); titlePart.Title = templateTitlePart.Title; ContainablePart containablePart = newPortlet.As <ContainablePart>(); containablePart.Position = position; var projectDetailContainerPart = projectDashboard.As <ContainerPart>(); var newPortletCommon = newPortlet.As <CommonPart>(); newPortletCommon.Container = projectDashboard; this.services.ContentManager.Publish(newPortlet); }
private void UpdateItemCount(ContainablePart part) { var commonPart = part.As <CommonPart>(); if (commonPart == null || commonPart.Container == null) { return; } var containerPart = commonPart.Container.As <ContainerPart>(); if (containerPart == null) { return; } _containerService.UpdateItemCount(containerPart); }
public SidebarDashboardHandler(IContentManager contentManager, IRepository <LayoutRecord> layoutRepository) { OnPublished <SidebarDashboardPart>((context, part) => { // portlet list var portletNames = string.IsNullOrEmpty(part.SidebarPortletList) ? new string[] { } : part.SidebarPortletList.Split(','); var portlets = contentManager.HqlQuery().ForType(Consts.SidebarProjectionPortletTemplateType, Consts.SidebarStaticPortletType).Where(c => c.ContentPartRecord <TitlePartRecord>(), c => c.In("Title", portletNames)).List().Select(c => c.As <TitlePart>()); // current portlets var currentPortlets = contentManager.Query().Where <CommonPartRecord>(c => c.Container.Id == part.ContentItem.Id).List().Select(c => c.As <TitlePart>()); // add new portlets int position = -1; foreach (var newPortlet in portletNames.Where(c => !currentPortlets.Any(d => d.Title == c))) { position++; var newPortletContentItemTemplate = portlets.FirstOrDefault(c => c.Title == newPortlet); if (newPortletContentItemTemplate == null) { continue; } ContentItem newPortletContentItem = null; if (newPortletContentItemTemplate.ContentItem.ContentType == Consts.SidebarProjectionPortletTemplateType) { newPortletContentItem = contentManager.Create(Consts.SidebarProjectionPortletType); CRMHelper.Copy(layoutRepository, newPortletContentItemTemplate.As <ProjectionWithDynamicSortPart>().Record, newPortletContentItem.As <ProjectionWithDynamicSortPart>().Record); } else { newPortletContentItem = contentManager.Create(Consts.SidebarStaticPortletType); newPortletContentItem.As <BodyPart>().Text = newPortletContentItemTemplate.As <BodyPart>().Text; } // Title newPortletContentItem.As <TitlePart>().Title = newPortletContentItemTemplate.Title; // Container var newPortletCommon = newPortletContentItem.As <CommonPart>(); if (newPortletCommon.Container != null && newPortletCommon.Container.Id != part.ContentItem.Id) { continue; } newPortletCommon.Container = part.ContentItem; ContainablePart containablePart = newPortletContentItem.As <ContainablePart>(); if (containablePart == null) { continue; } // Position containablePart.Position = position; // publish new portlet contentManager.Publish(newPortletContentItem); } // delete portlets foreach (var portlet in currentPortlets.Where(c => !portletNames.Any(d => d == c.Title))) { // Container contentManager.Remove(portlet.ContentItem); } // set position foreach (var portlet in currentPortlets.Where(c => portletNames.Any(d => d == c.Title))) { // Container int index = portletNames.ToList().IndexOf(portlet.Title); ContainablePart containablePart = portlet.As <ContainablePart>(); if (containablePart == null) { continue; } // Position containablePart.Position = index; // publish new portlet contentManager.Publish(portlet.ContentItem); } }); }
public ProjectHandler( ISearchTicketService searchTicketService, IContentManager contentManager, IMenuService menuService, IRepository <ProjectPartRecord> repository, IRepository <AttachToProjectPartRecord> attachToProjectRepository, IExtendedProjectService projectService) { OnCreated <ProjectPart>((context, projectPart) => { projectService.CreateProjectDependencies(projectPart); }); OnRemoved <ProjectPart>((context, projectPart) => { // Delete menu and menu widget var menu = menuService.GetMenu(projectPart.MenuId); if (menu != null) { contentManager.Remove(menu.ContentItem); var projectMenuWidget = projectService.GetProjectMenuWidget(projectPart.Id); if (projectMenuWidget != null) { contentManager.Remove(projectMenuWidget); } } // update all tickets who are attached to the project var attachToProjects = contentManager.HqlQuery <AttachToProjectPart>().Where(c => c.ContentPartRecord <AttachToProjectPartRecord>(), c => c.Eq("Project.Id", projectPart.Record.Id)).List(); foreach (var attachToProject in attachToProjects) { contentManager.Remove(attachToProject.ContentItem); } }); OnLoaded <ProjectPart>((context, projectPart) => { if (projectPart.RelatedItemsHaveBeenInitialized == false) { projectService.CreateMilestoneAndBacklogForProject(projectPart); projectPart.RelatedItemsHaveBeenInitialized = true; } // if the project doesn't have a menu, create a new one for it. if (projectPart.MenuId == default(int)) { projectService.CreateProjectMenu(projectPart); } }); OnPublished <ProjectPart>((context, projectPart) => { ProjectDashboardEditorPart dashboardPart = projectPart.As <ProjectDashboardEditorPart>(); int[] portletIds = dashboardPart.PortletList ?? new int[] { }; ContentItem projectDetail = contentManager .Query() .ForType(ContentTypes.ProjectDetailContentType) .Where <AttachToProjectPartRecord>(c => c.Project.Id == projectPart.Id) .Slice(1) .FirstOrDefault(); if (projectDetail == null) { return; } // portlets var currentPortlets = contentManager.Query().Where <CommonPartRecord>(c => c.Container.Id == projectDetail.Id).List(); var portletTemplates = contentManager.GetMany <ContentItem>(portletIds, VersionOptions.Published, new QueryHints()); // add new portlets int position = -1; foreach (var portletId in portletIds) { position++; var currentPortlet = currentPortlets.FirstOrDefault(c => c.As <InfosetPart>().Retrieve <int>(FieldNames.ProjectDashboardPortletTemplateId) == portletId); if (currentPortlet != null) { ContainablePart containablePart = currentPortlet.As <ContainablePart>(); containablePart.Position = position; continue; } var portletTemplate = portletTemplates.FirstOrDefault(c => c.Id == portletId); if (portletTemplate == null) { continue; } projectService.AddPortlet(projectDetail, portletTemplate, position); } // delete existing portlets that are not exist in the portletIds foreach (var portlet in currentPortlets) { var templateId = portlet.As <InfosetPart>().Retrieve <int>(FieldNames.ProjectDashboardPortletTemplateId); if (!portletIds.Contains(templateId)) { contentManager.Remove(portlet); } } }); }
public GenericDashboardHandler( IContentManager contentManager, IContentDefinitionManager contentDefinitionManager, IRepository <LayoutRecord> layoutRepository) { OnPublished <GenericDashboardPart>((context, part) => { if (!part.CreatePortletsOnPublishing) { return; } // set default portlets for DashboardWidget if (part.ContentItem.ContentType == Consts.GenericCoverWidgetContentType && string.IsNullOrEmpty(part.PortletList)) { part.PortletList = string.Join(",", (new string[] { Consts.SmtpPortletContentType, Consts.IMAPTPortletContentType })); } var portletTypes = Helper.GetGenericDashboardAvailablePortletTypes(contentDefinitionManager); var portlets = contentManager.HqlQuery().ForType(portletTypes).List(); // portlet list var portletNames = string.IsNullOrEmpty(part.PortletList) ? new string[] { } : part.PortletList.Split(','); // current portlets var currentPortlets = contentManager.Query().Where <CommonPartRecord>(c => c.Container.Id == part.ContentItem.Id).List().Select(c => c.As <TitlePart>()); // add new portlets int position = -1; foreach (var newPortlet in portletNames.Where(c => !currentPortlets.Any(d => d.Title == c))) { position++; ContentTypeDefinition portletType = null; var newPortletContentItemTemplate = portlets.FirstOrDefault(c => (c.As <TitlePart>() != null && c.As <TitlePart>().Title == newPortlet)); if (newPortletContentItemTemplate != null) { portletType = newPortletContentItemTemplate.TypeDefinition; } else if (portletTypes.Any(c => c == newPortlet)) { portletType = contentDefinitionManager.GetTypeDefinition(newPortlet); } if (portletType == null) { continue; } ContentItem newPortletContentItem = null; if (portletType.Name == Consts.GenericProjectionPortletTemplateType) { newPortletContentItem = contentManager.Create(Consts.GenericProjectionPortletType); CRMHelper.Copy(layoutRepository, newPortletContentItemTemplate.As <ProjectionWithDynamicSortPart>().Record, newPortletContentItem.As <ProjectionWithDynamicSortPart>().Record); } else if (portletType.Name == Consts.GenericReportViewerPortletTemplateType) { newPortletContentItem = contentManager.Create(Consts.GenericReportViewerPortletType); CRMHelper.Copy(newPortletContentItemTemplate.As <DataReportViewerPart>().Record, newPortletContentItem.As <DataReportViewerPart>().Record); } else if (portletType.Name == Consts.GenericActivityStreamPortletTemplateType) { newPortletContentItem = contentManager.Create(Consts.GenericActivityStreamPortletType); var sourceActivityStreamPart = newPortletContentItemTemplate.As <ActivityStreamPart>(); var destinationActivityStreamPart = newPortletContentItem.As <ActivityStreamPart>(); destinationActivityStreamPart.QueryId = sourceActivityStreamPart.QueryId; } else { newPortletContentItem = contentManager.Create(portletType.Settings[Consts.TemplateInstanceType], VersionOptions.Draft); } ContainablePart containablePart = newPortletContentItem.As <ContainablePart>(); if (containablePart == null) { continue; } // Position containablePart.Position = position; // Container var newPortletCommon = newPortletContentItem.As <CommonPart>(); newPortletCommon.Container = part.ContentItem; contentManager.Publish(newPortletContentItem); } // delete portlets foreach (var portlet in currentPortlets.Where(c => !portletNames.Any(d => d == c.Title))) { // Container contentManager.Remove(portlet.ContentItem); } // set position foreach (var portlet in currentPortlets.Where(c => portletNames.Any(d => d == c.Title))) { // Container int index = portletNames.ToList().IndexOf(portlet.Title); ContainablePart containablePart = portlet.As <ContainablePart>(); if (containablePart == null) { continue; } // Position containablePart.Position = index; // publish new portlet contentManager.Publish(portlet.ContentItem); } }); }