Beispiel #1
0
        /// <summary>
        /// Returns page whose pages are enumerated. Page returned determined by rules executed in the following order:
        ///  1. If page specified in page list settings, then use this page
        ///  2. If page not specified in page list settings and current page a folder, then use current page
        ///  3. If page not specified in page list settings and current page a document, then use current page parent
        /// Case 3 ensures that we list documents even at the leaves of the page hierarchy.
        /// </summary>
        /// <param name="pageListSettings">Page list settings.</param>
        /// <param name="pageContext">Page context.</param>
        /// <returns>The page whose child pages are enumerated.</returns>
        private long GetPageWhosePagesAreListed(PageListSettings pageListSettings, IPageContext pageContext)
        {
            // If page is specified in page list settings, then always use that page
            if (pageListSettings.PageId != null)
            {
                return(pageListSettings.PageId.Value);
            }

            // If page not specified, then use current page if the current page is a folder
            if (pageContext.MasterPage.PageType == PageType.Folder)
            {
                return(pageContext.Page.PageId);
            }

            // If page not specified and current page is document, then return document's parent folder
            Page page           = pageContext.Hierarchy;
            Page documentParent = page;

            if (page.ChildPages.Count > 0)
            {
                while (page.ChildPages[0].ChildPages.Count > 0)
                {
                    page           = page.ChildPages[0];
                    documentParent = page;
                }
            }
            return(documentParent.PageId);
        }
Beispiel #2
0
        public void Update(IElementSettings settings, IUnitOfWork unitOfWork = null)
        {
            // Get page list typed settings
            PageListSettings pageListSettings = (PageListSettings)settings;

            // Set non mandatory text fields null if they only contain white space
            if (string.IsNullOrWhiteSpace(pageListSettings.DisplayName))
            {
                pageListSettings.DisplayName = null;
            }
            if (string.IsNullOrWhiteSpace(pageListSettings.MoreMessage))
            {
                pageListSettings.MoreMessage = null;
            }
            if (string.IsNullOrWhiteSpace(pageListSettings.Preamble))
            {
                pageListSettings.Preamble = null;
            }
            if (string.IsNullOrWhiteSpace(pageListSettings.NoPagesMessage))
            {
                pageListSettings.NoPagesMessage = null;
            }

            // Do the update
            _pageListRepository.Update(pageListSettings, unitOfWork);
        }
Beispiel #3
0
        public void Read(PageListSettings settings, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                dbm.SetSQL(_sqlManager.GetSql("Sql.ReadPageList.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.ExecuteReader();
                dbm.Read();
                settings.PageTenantId        = dbm.DataReaderValue("PageTenantId") == DBNull.Value ? null : (long?)dbm.DataReaderValue("PageTenantId");
                settings.PageId              = dbm.DataReaderValue("PageId") == DBNull.Value ? null : (long?)dbm.DataReaderValue("PageId");
                settings.DisplayName         = dbm.DataReaderValue("DisplayName") == DBNull.Value ? null : (string)dbm.DataReaderValue("DisplayName");
                settings.SortBy              = (PageSortBy)(int)dbm.DataReaderValue("SortBy");
                settings.SortAsc             = (bool)dbm.DataReaderValue("SortAsc");
                settings.ShowRelated         = (bool)dbm.DataReaderValue("ShowRelated");
                settings.ShowDescription     = (bool)dbm.DataReaderValue("ShowDescription");
                settings.ShowImage           = (bool)dbm.DataReaderValue("ShowImage");
                settings.ShowBackgroundImage = (bool)dbm.DataReaderValue("ShowBackgroundImage");
                settings.ShowCreated         = (bool)dbm.DataReaderValue("ShowCreated");
                settings.ShowUpdated         = (bool)dbm.DataReaderValue("ShowUpdated");
                settings.ShowOccurred        = (bool)dbm.DataReaderValue("ShowOccurred");
                settings.ShowComments        = (bool)dbm.DataReaderValue("ShowComments");
                settings.ShowTags            = (bool)dbm.DataReaderValue("ShowTags");
                settings.ShowPager           = (bool)dbm.DataReaderValue("ShowPager");
                settings.MoreMessage         = dbm.DataReaderValue("MoreMessage") == DBNull.Value ? null : (string)dbm.DataReaderValue("MoreMessage");
                settings.Recursive           = (bool)dbm.DataReaderValue("Recursive");
                settings.PageType            = (PageType)(int)dbm.DataReaderValue("PageType");
                settings.PageSize            = (int)dbm.DataReaderValue("PageSize");
                settings.NoPagesMessage      = dbm.DataReaderValue("NoPagesMessage") == DBNull.Value ? null : (string)dbm.DataReaderValue("NoPagesMessage");
                settings.Preamble            = dbm.DataReaderValue("Preamble") == DBNull.Value ? null : (string)dbm.DataReaderValue("Preamble");
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Beispiel #4
0
        public void Create(PageListSettings settings, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                dbm.SetSQL(_sqlManager.GetSql("Sql.CreatePageList.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.AddParameter("@PageTenantId", FieldType.BigInt, settings.PageTenantId ?? (object)DBNull.Value);
                dbm.AddParameter("@PageId", FieldType.BigInt, settings.PageId ?? (object)DBNull.Value);
                dbm.AddParameter("@DisplayName", FieldType.NVarChar, 256, settings.DisplayName ?? (object)DBNull.Value);
                dbm.AddParameter("@SortBy", FieldType.Int, (int)settings.SortBy);
                dbm.AddParameter("@SortAsc", FieldType.Bit, settings.SortAsc);
                dbm.AddParameter("@ShowRelated", FieldType.Bit, settings.ShowRelated);
                dbm.AddParameter("@ShowDescription", FieldType.Bit, settings.ShowDescription);
                dbm.AddParameter("@ShowImage", FieldType.Bit, settings.ShowImage);
                dbm.AddParameter("@ShowBackgroundImage", FieldType.Bit, settings.ShowBackgroundImage);
                dbm.AddParameter("@ShowCreated", FieldType.Bit, settings.ShowCreated);
                dbm.AddParameter("@ShowUpdated", FieldType.Bit, settings.ShowUpdated);
                dbm.AddParameter("@ShowOccurred", FieldType.Bit, settings.ShowOccurred);
                dbm.AddParameter("@ShowComments", FieldType.Bit, settings.ShowComments);
                dbm.AddParameter("@ShowTags", FieldType.Bit, settings.ShowTags);
                dbm.AddParameter("@ShowPager", FieldType.Bit, settings.ShowPager);
                dbm.AddParameter("@MoreMessage", FieldType.NVarChar, 256, settings.MoreMessage ?? (object)DBNull.Value);
                dbm.AddParameter("@Recursive", FieldType.Bit, settings.Recursive);
                dbm.AddParameter("@PageType", FieldType.Int, (int)settings.PageType);
                dbm.AddParameter("@PageSize", FieldType.Int, settings.PageSize);
                dbm.AddParameter("@NoPagesMessage", FieldType.NVarChar, -1, settings.NoPagesMessage ?? (object)DBNull.Value);
                dbm.AddParameter("@Preamble", FieldType.NVarChar, -1, settings.Preamble ?? (object)DBNull.Value);
                dbm.ExecuteNonQuery();
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Beispiel #5
0
        public IElementContent GetContent(IElementSettings settings, IPageContext pageContext, IUnitOfWork unitOfWork = null)
        {
            // Get 1-based page index
            int pageIndex = 1;

            if (pageContext.Parameters.ContainsKey("page"))
            {
                Int32.TryParse(pageContext.Parameters["page"], out pageIndex);
            }
            pageIndex = Math.Max(pageIndex, 1);

            // Retrieve list of pages
            PageListSettings  pageListSettings = (PageListSettings)settings;
            ISearchParameters parameters       = new SearchParameters {
                PageIndex = pageIndex - 1, PageSize = pageListSettings.PageSize
            };
            long tenantId = pageListSettings.PageTenantId ?? pageContext.Page.TenantId;
            long pageId   = GetPageWhosePagesAreListed(pageListSettings, pageContext);
            ISearchResult <Page> result = null;

            if (pageContext.Tags.Count == 0)
            {
                result = _pageService.List(tenantId, parameters, pageId, pageListSettings.SortBy, pageListSettings.SortAsc, pageListSettings.Recursive, pageListSettings.PageType, pageListSettings.ShowTags, unitOfWork);
            }
            else
            {
                result = _pageService.ListTagged(tenantId, parameters, pageContext.Tags, pageId, pageListSettings.SortBy, pageListSettings.SortAsc, pageListSettings.Recursive, pageListSettings.PageType, pageListSettings.ShowTags, unitOfWork);
            }

            // If required, get parent page details whose child pages are displayed
            Page page = null;

            if (pageListSettings.MoreMessage != null)
            {
                if ((pageListSettings.PageId == null) || (pageListSettings.PageId.Value == pageContext.Page.PageId))
                {
                    page = pageContext.Page;
                }
                else
                {
                    page = _pageService.Read(pageListSettings.PageTenantId.Value, pageListSettings.PageId.Value, unitOfWork);
                }
            }

            // Get comment counts?
            IDictionary <long, int> commentCounts = null;

            if (pageListSettings.ShowComments)
            {
                commentCounts = _forumRepository.ListPageForumCounts(tenantId, result.Items, unitOfWork);
            }
            else
            {
                commentCounts = new Dictionary <long, int>();
            }

            // Setup pager
            UrlParameters urlParameters = new UrlParameters {
                RouteName = "ReadPage", RouteValues = new { pageid = pageContext.Page.PageId }
            };
            Pager pager = new Pager {
                PageSize = pageListSettings.PageSize, Total = result.Total, PageIndex = pageIndex, UrlParameters = urlParameters
            };

            // Get display name
            string displayName = pageListSettings.DisplayName;

            if (displayName != null && pageContext.Tags.Count > 0)
            {
                displayName += " " + string.Join(" ", pageContext.Tags.Select(t => "#" + t.Name));
            }

            // Return page list content
            return(new PageListContent {
                Pages = result.Items.ToList(), Total = result.Total, PartialViewName = "PageList", Pager = pager, Page = page, DisplayName = displayName, CurrentPage = pageContext.Page, CommentCounts = commentCounts
            });
        }
        public Form GetForm(string context)
        {
            // Check permissions
            _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

            // Get page and element identifiers
            string[] parts     = context.Split('|');
            long     pageId    = Convert.ToInt64(parts[0]);
            long     elementId = Convert.ToInt64(parts[1]);

            // Get current page list settings
            Guid elementTypeId = FormId;
            IAdvancedElementService elementService   = (IAdvancedElementService)_elementFactory.GetElementService(elementTypeId);
            PageListSettings        pageListSettings = (PageListSettings)elementService.New(_authenticationService.TenantId);

            pageListSettings.ElementId = elementId;
            elementService.Read(pageListSettings);

            // Get possible parent pages for page list
            long tenantId = _authenticationService.TenantId;
            ISearchParameters searchParameters = new SearchParameters {
                PageIndex = 0, PageSize = 1000
            };                                                                                            // TODO: Need way to return all pages, not have some max bound upper limit
            ISearchResult <Page> result = _pageService.List(tenantId, searchParameters, null, PageSortBy.Name, true, true, PageType.Folder, false);

            // Construct form
            Form form = new Form {
                Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context
            };

            form.Fields.Add("displayName", new TextField
            {
                Name                  = "displayName",
                Label                 = ElementResource.PageListDisplayNameLabel,
                MaxLength             = PageListLengths.DisplayNameMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.PageListDisplayNameMaxLengthMessage, "displayName", PageListLengths.DisplayNameMaxLength),
                Value                 = pageListSettings.DisplayName
            });
            form.Fields.Add("preamble", new MultiLineTextField
            {
                Name  = "preamble",
                Label = ElementResource.PageListPreambleLabel,
                Value = pageListSettings.Preamble,
                Rows  = 4
            });
            form.Fields.Add("page", new SelectListField <string>
            {
                Name  = "page",
                Label = ElementResource.PageListPageLabel,
                Value = pageListSettings.PageId == null ? string.Empty : pageListSettings.PageId.Value.ToString(),
                Items = new List <ListFieldItem <string> > {
                    new ListFieldItem <string> {
                        Name = ElementResource.FolderDefaultOption, Value = string.Empty
                    }
                }
            });
            foreach (Page page in result.Items)
            {
                ((SelectListField <string>)form.Fields["page"]).Items.Add(new ListFieldItem <string> {
                    Name = page.Name, Value = page.PageId.ToString()
                });
            }
            form.Fields.Add("sortBy", new SelectListField <string>
            {
                Name  = "sortBy",
                Label = ElementResource.PageListSortByLabel,
                Value = pageListSettings.SortBy.ToString(),
                Items = new List <ListFieldItem <string> > {
                    new ListFieldItem <string> {
                        Name = _dataAnnotationsService.GetEnumDisplayName <PageSortBy>(PageSortBy.Created), Value = PageSortBy.Created.ToString()
                    },
                    new ListFieldItem <string> {
                        Name = _dataAnnotationsService.GetEnumDisplayName <PageSortBy>(PageSortBy.Updated), Value = PageSortBy.Updated.ToString()
                    },
                    new ListFieldItem <string> {
                        Name = _dataAnnotationsService.GetEnumDisplayName <PageSortBy>(PageSortBy.Occurred), Value = PageSortBy.Occurred.ToString()
                    },
                    new ListFieldItem <string> {
                        Name = _dataAnnotationsService.GetEnumDisplayName <PageSortBy>(PageSortBy.Name), Value = PageSortBy.Name.ToString()
                    },
                },
                Required             = true,
                RequiredErrorMessage = ElementResource.PageListSortByRequiredMessage
            });
            form.Fields.Add("sortAsc", new SelectListField <string>
            {
                Name  = "sortAsc",
                Label = ElementResource.PageListSortAscLabel,
                Value = pageListSettings.SortAsc.ToString(),
                Items = new List <ListFieldItem <string> > {
                    new ListFieldItem <string> {
                        Name = ElementResource.PageListSortAscendingOption, Value = true.ToString()
                    },
                    new ListFieldItem <string> {
                        Name = ElementResource.PageListSortDescendingOption, Value = false.ToString()
                    }
                },
                Required             = true,
                RequiredErrorMessage = ElementResource.PageListSortAscRequiredMessage
            });
            form.Fields.Add("showRelated", new BooleanField
            {
                Name  = "showRelated",
                Label = ElementResource.PageListShowRelatedLabel,
                Value = pageListSettings.ShowRelated
            });
            form.Fields.Add("showDescription", new BooleanField
            {
                Name  = "showDescription",
                Label = ElementResource.PageListShowDescriptionLabel,
                Value = pageListSettings.ShowDescription
            });
            form.Fields.Add("showImage", new BooleanField
            {
                Name  = "showImage",
                Label = ElementResource.PageListShowImageLabel,
                Value = pageListSettings.ShowImage
            });
            form.Fields.Add("showBackgroundImage", new BooleanField
            {
                Name  = "showBackgroundImage",
                Label = ElementResource.PageListShowBackgroundImageLabel,
                Value = pageListSettings.ShowBackgroundImage
            });
            form.Fields.Add("showCreated", new BooleanField
            {
                Name  = "showCreated",
                Label = ElementResource.PageListShowCreatedLabel,
                Value = pageListSettings.ShowCreated
            });
            form.Fields.Add("showUpdated", new BooleanField
            {
                Name  = "showUpdated",
                Label = ElementResource.PageListShowUpdatedLabel,
                Value = pageListSettings.ShowUpdated
            });
            form.Fields.Add("showOccurred", new BooleanField
            {
                Name  = "showOccurred",
                Label = ElementResource.PageListShowOccurredLabel,
                Value = pageListSettings.ShowOccurred
            });
            form.Fields.Add("showComments", new BooleanField
            {
                Name  = "showComments",
                Label = ElementResource.PageListShowCommentsLabel,
                Value = pageListSettings.ShowComments
            });
            form.Fields.Add("showTags", new BooleanField
            {
                Name  = "showTags",
                Label = ElementResource.PageListShowTagsLabel,
                Value = pageListSettings.ShowTags
            });
            form.Fields.Add("pageSize", new IntegerField
            {
                Name                 = "pageSize",
                Label                = ElementResource.PageListPageSizeLabel,
                Min                  = PageListLengths.PageSizeMinValue,
                Max                  = PageListLengths.PageSizeMaxValue,
                Value                = pageListSettings.PageSize,
                Required             = true,
                RequiredErrorMessage = ElementResource.PageListPageSizeRequiredMessage,
                MinErrorMessage      = string.Format(ElementResource.PageListPageSizeRangeMessage, "pageSize", PageListLengths.PageSizeMinValue, PageListLengths.PageSizeMaxValue),
                MaxErrorMessage      = string.Format(ElementResource.PageListPageSizeRangeMessage, "pageSize", PageListLengths.PageSizeMinValue, PageListLengths.PageSizeMaxValue)
            });
            form.Fields.Add("showPager", new BooleanField
            {
                Name  = "showPager",
                Label = ElementResource.PageListShowPagerLabel,
                Value = pageListSettings.ShowPager
            });
            form.Fields.Add("moreMessage", new TextField
            {
                Name                  = "moreMessage",
                Label                 = ElementResource.PageListMoreMessageLabel,
                MaxLength             = PageListLengths.MoreMessageMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.PageListMoreMessageMaxLengthMessage, "moreMessage", PageListLengths.MoreMessageMaxLength),
                Value                 = pageListSettings.MoreMessage
            });
            form.Fields.Add("recursive", new BooleanField
            {
                Name  = "recursive",
                Label = ElementResource.PageListRecursiveLabel,
                Value = pageListSettings.Recursive
            });
            form.Fields.Add("pageType", new SelectListField <string>
            {
                Name  = "pageType",
                Label = ElementResource.PageListPageTypeLabel,
                Value = pageListSettings.PageType.ToString(),
                Items = new List <ListFieldItem <string> > {
                    new ListFieldItem <string> {
                        Name = _dataAnnotationsService.GetEnumDisplayName <PageType>(PageType.Document), Value = PageType.Document.ToString()
                    },
                    new ListFieldItem <string> {
                        Name = _dataAnnotationsService.GetEnumDisplayName <PageType>(PageType.Folder), Value = PageType.Folder.ToString()
                    }
                },
                Required             = true,
                RequiredErrorMessage = ElementResource.PageListPageTypeRequiredMessage
            });
            form.Fields.Add("noPagesMessage", new TextField
            {
                Name  = "noPagesMessage",
                Label = ElementResource.PageListNoPagesMessageLabel,
                Value = pageListSettings.NoPagesMessage
            });
            form.SubmitLabel = ElementResource.PageListButtonLabel;

            // Return result
            return(form);
        }
        public FormResult PostForm(Form form)
        {
            try
            {
                // Check permissions
                _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

                // Get page and element identifiers
                string[] parts     = form.Context.Split('|');
                long     pageId    = Convert.ToInt64(parts[0]);
                long     elementId = Convert.ToInt64(parts[1]);

                // Get website identifier
                long tenantId = _authenticationService.TenantId;

                // Get sort by enumeration value
                PageSortBy sortBy;
                Enum.TryParse <PageSortBy>(((SelectListField <string>)form.Fields["sortBy"]).Value, out sortBy);

                // Get page type enumeration value
                PageType pageType;
                Enum.TryParse <PageType>(((SelectListField <string>)form.Fields["pageType"]).Value, out pageType);

                // Get Booleans
                bool sortAsc;
                Boolean.TryParse(((SelectListField <string>)form.Fields["sortAsc"]).Value, out sortAsc);

                // Get page list page
                string pageValue        = ((SelectListField <string>)form.Fields["page"]).Value;
                long?  pageListPageId   = pageValue == string.Empty ? null : (long?)Convert.ToInt64(((SelectListField <string>)form.Fields["page"]).Value);
                long?  pageListTenantId = pageListPageId.HasValue ? (long?)tenantId : null;

                // Get the page list element service
                IAdvancedElementService elementService = (IAdvancedElementService)_elementFactory.GetElementService(FormId);

                // Get updated page list settings
                PageListSettings pageListSettings = (PageListSettings)elementService.New(_authenticationService.TenantId);
                pageListSettings.ElementId           = elementId;
                pageListSettings.DisplayName         = string.IsNullOrWhiteSpace(((TextField)form.Fields["displayName"]).Value) ? null : ((TextField)form.Fields["displayName"]).Value;
                pageListSettings.PageId              = pageListPageId;
                pageListSettings.PageTenantId        = pageListTenantId;
                pageListSettings.SortBy              = sortBy;
                pageListSettings.SortAsc             = sortAsc;
                pageListSettings.ShowRelated         = ((BooleanField)form.Fields["showRelated"]).Value;
                pageListSettings.ShowDescription     = ((BooleanField)form.Fields["showDescription"]).Value;
                pageListSettings.ShowImage           = ((BooleanField)form.Fields["showImage"]).Value;
                pageListSettings.ShowBackgroundImage = ((BooleanField)form.Fields["showBackgroundImage"]).Value;
                pageListSettings.ShowCreated         = ((BooleanField)form.Fields["showCreated"]).Value;
                pageListSettings.ShowUpdated         = ((BooleanField)form.Fields["showUpdated"]).Value;
                pageListSettings.ShowOccurred        = ((BooleanField)form.Fields["showOccurred"]).Value;
                pageListSettings.ShowComments        = ((BooleanField)form.Fields["showComments"]).Value;
                pageListSettings.ShowTags            = ((BooleanField)form.Fields["showTags"]).Value;
                pageListSettings.PageSize            = ((IntegerField)form.Fields["pageSize"]).Value.Value;
                pageListSettings.ShowPager           = ((BooleanField)form.Fields["showPager"]).Value;
                pageListSettings.MoreMessage         = ((TextField)form.Fields["moreMessage"]).Value;
                pageListSettings.Recursive           = ((BooleanField)form.Fields["recursive"]).Value;
                pageListSettings.PageType            = pageType;
                pageListSettings.NoPagesMessage      = string.IsNullOrWhiteSpace(((TextField)form.Fields["noPagesMessage"]).Value) ? null : ((TextField)form.Fields["noPagesMessage"]).Value;
                pageListSettings.Preamble            = string.IsNullOrWhiteSpace(((MultiLineTextField)form.Fields["preamble"]).Value) ? null : ((MultiLineTextField)form.Fields["preamble"]).Value;

                // Perform the update
                elementService.Update(pageListSettings);

                // Return form result with no errors
                return(_formHelperService.GetFormResult());
            }
            catch (ValidationErrorException ex)
            {
                // Return form result containing errors
                return(_formHelperService.GetFormResultWithValidationErrors(ex.Errors));
            }
            catch (Exception)
            {
                // Return form result containing unexpected error message
                return(_formHelperService.GetFormResultWithErrorMessage(ApplicationResource.UnexpectedErrorMessage));
            }
        }