Example #1
0
        protected override DriverResult Display(MenuWidgetPart part, string displayType, dynamic shapeHelper)
        {
            var request  = _workContextAccessor.GetContext().HttpContext.Request;
            var cacheKey = "MenuWidget";

            if (request != null)
            {
                cacheKey = string.Format("{0}.{1}.{2}", cacheKey, request.Path, request.ApplicationPath);
            }

            return(_driverResultFactory.BuildResult(part, "Parts_MenuWidget", () => base.Display(part, displayType, (object)shapeHelper), cacheKey));
        }
Example #2
0
        public ContentItem CreateProjectMenu(ProjectPart project)
        {
            var editUrl = this.urlHelper.Action("Edit", "Project", new { id = project.Id, area = "Orchard.CRM.Project" });

            // if editUrl is null, it means the routes are not existed yet, so all menu items will br crap, then the creation of the menu must be postponed to the first load of the project
            if (string.IsNullOrEmpty(editUrl))
            {
                return(null);
            }

            // create menu
            var menu = this.menuService.Create(string.Format("Project-{0} --'{1}'", project.Id.ToString(CultureInfo.InvariantCulture), project.Record.Title));

            project.MenuId = menu.Id;

            var         contentManger   = this.services.ContentManager;
            ContentItem menuContentItem = contentManger.Create(ContentTypes.ProjectMenuContentType);

            // update AttachToProjectPart
            AttachToProjectPart attachToProjectPart = menuContentItem.As <AttachToProjectPart>();

            attachToProjectPart.Record.Project = project.Record;

            // update MenuWidgetPart
            MenuWidgetPart menuWidgetPart = menuContentItem.As <MenuWidgetPart>();

            menuWidgetPart.AddHomePage       = false;
            menuWidgetPart.Breadcrumb        = false;
            menuWidgetPart.MenuContentItemId = menu.Id;

            // create menu items
            Action <string, LocalizedString> createMenu = (url, localizedText) =>
            {
                var menuItemPart = contentManger.Create <MenuItemPart>("MenuItem");
                menuItemPart.Url = url;

                var menuPart = menuItemPart.As <MenuPart>();
                menuPart.MenuPosition = Position.GetNext(this.navigationManager.BuildMenu(menu));
                menuPart.MenuText     = localizedText.Text;
                menuPart.Menu         = menu;

                contentManger.Publish(menuItemPart.ContentItem);
            };

            Action <ContentItem, string> createProjectSubPartListUrl = (contentItem, title) =>
            {
                var url = this.urlHelper.Action("Display", "Item", new { id = contentItem.Id, area = "Orchard.CRM.Core" });
                createMenu(url, T(title));
            };

            var targetContentItems = contentManger.HqlQuery().ForType(new[]
            {
                ContentTypes.ProjectWikiContentType,
                ContentTypes.ProjectTicketsContentType,
                ContentTypes.ProjectDiscussionsContentType,
                ContentTypes.ProjectActivityStreamType,
                ContentTypes.ProjectProjectionContentType
            }).Where(c => c.ContentPartRecord <AttachToProjectPartRecord>(), d => d.Eq("Project.Id", project.Id)).List();

            foreach (var contentItem in targetContentItems)
            {
                string title = string.Empty;
                if (contentItem.ContentType == ContentTypes.ProjectWikiContentType)
                {
                    title = "Wiki";
                }
                else
                {
                    TitlePart titlePart = contentItem.As <TitlePart>();
                    title = titlePart.Title;

                    if (string.IsNullOrEmpty(title))
                    {
                        switch (contentItem.ContentType)
                        {
                        case ContentTypes.ProjectTicketsContentType:
                            title = T("Tickets").Text;
                            break;

                        case ContentTypes.ProjectDiscussionsContentType:
                            title = T("Discussion").Text;
                            // version 2.1 creates two discussion for each project. Because of it, we have to apply this hack to prevent creation of two menus.
                            ProjectionWithDynamicSortPart projectionWithDynamicSortPart = contentItem.As <ProjectionWithDynamicSortPart>();
                            if (projectionWithDynamicSortPart.Record.QueryPartRecord == null)
                            {
                                continue;
                            }
                            break;

                        case ContentTypes.ProjectActivityStreamType:
                            title = T("Activity Stream").Text;
                            break;
                        }
                    }
                }

                createProjectSubPartListUrl(contentItem, title);
            }

            // Create link to backlog
            var backLogItem = contentManger
                              .HqlQuery()
                              .ForType(ContentTypes.MilestoneContentType)
                              .Where(c => c.ContentPartRecord <AttachToProjectPartRecord>(), d => d.Eq("Project.Id", project.Id))
                              .List()
                              .FirstOrDefault(c => c.As <MilestonePart>().IsBacklog);

            if (backLogItem != null)
            {
                createProjectSubPartListUrl(backLogItem, T("Backlog").Text);
            }


            // edit project
            editUrl = this.urlHelper.Action("Edit", "Project", new { id = project.Id, area = "Orchard.CRM.Project" });
            createMenu(editUrl, T("Edit"));

            // Project People
            var peopleUrl = this.urlHelper.Action("Edit", "ProjectItemsOwnership", new { ids = project.Id, area = "Orchard.CRM.Project" });

            createMenu(peopleUrl, T("People"));

            this.services.ContentManager.Publish(menuContentItem);

            return(menuContentItem);
        }