コード例 #1
0
ファイル: PageRoutes.ascx.cs プロジェクト: jh2mhs8/Rock-ChMS
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click( object sender, EventArgs e )
        {
            PageRoute pageRoute;
            PageRouteService pageRouteService = new PageRouteService();

            int pageRouteId = int.Parse( hfPageRouteId.Value );

            if ( pageRouteId == 0 )
            {
                pageRoute = new PageRoute();
                pageRouteService.Add( pageRoute, CurrentPersonId );
            }
            else
            {
                pageRoute = pageRouteService.Get( pageRouteId );
            }

            pageRoute.Route = tbRoute.Text.Trim();
            int selectedPageId = int.Parse( ddlPageName.SelectedValue );
            pageRoute.PageId = selectedPageId;

            // check for duplicates
            if ( pageRouteService.Queryable().Count( a => a.Route.Equals( pageRoute.Route, StringComparison.OrdinalIgnoreCase ) && !a.Id.Equals( pageRoute.Id ) ) > 0 )
            {
                nbMessage.Text = WarningMessage.DuplicateFoundMessage( "route", Rock.Model.Page.FriendlyTypeName );
                nbMessage.Visible = true;
                return;
            }

            if ( !pageRoute.IsValid )
            {
                // Controls will render the error messages
                return;
            }

            pageRouteService.Save( pageRoute, CurrentPersonId );

            RemovePageRoute( pageRoute );

            // new or updated route
            RouteTable.Routes.AddPageRoute( pageRoute );

            BindGrid();
            pnlDetails.Visible = false;
            pnlList.Visible = true;
        }
コード例 #2
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click( object sender, EventArgs e )
        {
            PageRoute pageRoute;
            var rockContext = new RockContext();
            PageRouteService pageRouteService = new PageRouteService( rockContext );

            int pageRouteId = int.Parse( hfPageRouteId.Value );

            if ( pageRouteId == 0 )
            {
                pageRoute = new PageRoute();
                pageRouteService.Add( pageRoute );
            }
            else
            {
                pageRoute = pageRouteService.Get( pageRouteId );
            }

            pageRoute.Route = tbRoute.Text.Trim();
            int selectedPageId = int.Parse( ppPage.SelectedValue );
            pageRoute.PageId = selectedPageId;

            if ( !pageRoute.IsValid )
            {
                // Controls will render the error messages
                return;
            }

            if ( pageRouteService.Queryable().Any( r => r.Route == pageRoute.Route && r.Id != pageRoute.Id ) )
            {
                // Duplicate
                nbErrorMessage.Title = "Duplicate Route";
                nbErrorMessage.Text = "<p>There is already an existing route with this name and route names must be unique. Please choose a different route name.</p>";
                nbErrorMessage.Visible = true;
            }
            else
            {
                rockContext.SaveChanges();

                // new or updated route
                var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == pageRoute.Id );
                if ( existingRoute != null )
                {
                    RouteTable.Routes.Remove( existingRoute );
                }

                RouteTable.Routes.AddPageRoute( pageRoute );

                NavigateToParentPage();
            }
        }
コード例 #3
0
ファイル: Global.asax.cs プロジェクト: pkdevbox/Rock
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes( RouteCollection routes )
        {
            PageRouteService pageRouteService = new PageRouteService();

            // find each page that has defined a custom routes.
            foreach ( PageRoute pageRoute in pageRouteService.Queryable() )
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute( pageRoute );
            }

            // Add API route for dataviews
            routes.MapHttpRoute(
                name: "DataViewApi",
                routeTemplate: "api/{controller}/DataView/{id}",
                defaults: new
                {
                    action = "DataView"
                }
            );

            // Add any custom api routes
            foreach ( var type in Rock.Reflection.FindTypes(
                typeof( Rock.Rest.IHasCustomRoutes ) ) )
            {
                var controller = (Rock.Rest.IHasCustomRoutes)Activator.CreateInstance( type.Value );
                if ( controller != null )
                    controller.AddRoutes( routes );
            }

            // Add Default API Service routes
            // Instead of being able to use one default route that gets action from http method, have to 
            // have a default route for each method so that other actions do not match the default (i.e. DataViews)
            routes.MapHttpRoute(
                name: "DefaultApiGet",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
                {
                    action = "GET",
                    id = System.Web.Http.RouteParameter.Optional
                },
                constraints: new
                {
                    httpMethod = new HttpMethodConstraint( new string[] { "GET" } )
                }
            );

            routes.MapHttpRoute(
               name: "DefaultApiPut",
               routeTemplate: "api/{controller}/{id}",
               defaults: new
               {
                   action = "PUT",
                   id = System.Web.Http.RouteParameter.Optional
               },
               constraints: new
               {
                   httpMethod = new HttpMethodConstraint( new string[] { "PUT" } )
               }
           );

            routes.MapHttpRoute(
                name: "DefaultApiPost",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
                {
                    action = "POST",
                    id = System.Web.Http.RouteParameter.Optional
                },
                constraints: new
                {
                    httpMethod = new HttpMethodConstraint( new string[] { "POST" } )
                }
            );

            routes.MapHttpRoute(
                name: "DefaultApiDelete",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
                {
                    action = "DELETE",
                    id = System.Web.Http.RouteParameter.Optional
                },
                constraints: new
                {
                    httpMethod = new HttpMethodConstraint( new string[] { "DELETE" } )
                }
            );

            // Add a default page route
            routes.Add( new Route( "page/{PageId}", new Rock.Web.RockRouteHandler() ) );

            // Add a default route for when no parameters are passed
            routes.Add( new Route( "", new Rock.Web.RockRouteHandler() ) );
        }
コード例 #4
0
        /// <summary>
        /// Handles the OnSave event of the masterPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void masterPage_OnSave( object sender, EventArgs e )
        {
            Page.Validate( BlockValidationGroup );
            if ( Page.IsValid && _pageId.HasValue )
            {
                var rockContext = new RockContext();
                var pageService = new PageService( rockContext );
                var routeService = new PageRouteService( rockContext );
                var contextService = new PageContextService( rockContext );

                var page = pageService.Get( _pageId.Value );

                // validate/check for removed routes
                var editorRoutes = tbPageRoute.Text.SplitDelimitedValues().Distinct();
                var databasePageRoutes = page.PageRoutes.ToList();
                var deletedRouteIds = new List<int>();
                var addedRoutes = new List<string>();

                if ( editorRoutes.Any() )
                {
                    // validate for any duplicate routes
                    var duplicateRoutes = routeService.Queryable()
                        .Where( r => editorRoutes.Contains( r.Route ) && r.PageId != _pageId )
                        .Select( r => r.Route )
                        .Distinct()
                        .ToList();

                    if ( duplicateRoutes.Any() )
                    {
                        // Duplicate routes
                        nbPageRouteWarning.Title = "Duplicate Route(s)";
                        nbPageRouteWarning.Text = string.Format( "<p>The page route <strong>{0}</strong>, already exists for another page. Please choose a different route name.</p>", duplicateRoutes.AsDelimited( "</strong> and <strong>" ) );
                        nbPageRouteWarning.Dismissable = true;
                        nbPageRouteWarning.Visible = true;
                        CurrentTab = "Advanced Settings";

                        rptProperties.DataSource = _tabs;
                        rptProperties.DataBind();
                        ShowSelectedPane();
                        return;
                    }
                }

                // validate if removed routes can be deleted
                foreach ( var pageRoute in databasePageRoutes )
                {
                    if ( !editorRoutes.Contains( pageRoute.Route ) )
                    {
                        // make sure the route can be deleted
                        string errorMessage;
                        if ( !routeService.CanDelete( pageRoute, out errorMessage ) )
                        {
                            nbPageRouteWarning.Text = string.Format( "The page route <strong>{0}</strong>, cannot be removed. {1}", pageRoute.Route, errorMessage );
                            nbPageRouteWarning.NotificationBoxType = NotificationBoxType.Warning;
                            nbPageRouteWarning.Dismissable = true;
                            nbPageRouteWarning.Visible = true;
                            CurrentTab = "Advanced Settings";

                            rptProperties.DataSource = _tabs;
                            rptProperties.DataBind();
                            ShowSelectedPane();
                            return;
                        }
                    }
                }

                // take care of deleted routes
                foreach ( var pageRoute in databasePageRoutes )
                {
                    if ( !editorRoutes.Contains( pageRoute.Route ) )
                    {
                        // if they removed the Route, remove it from the database
                        page.PageRoutes.Remove( pageRoute );

                        routeService.Delete( pageRoute );
                        deletedRouteIds.Add( pageRoute.Id );
                    }
                }

                // take care of added routes
                foreach ( string route in editorRoutes )
                {
                    // if they added the Route, add it to the database
                    if ( !databasePageRoutes.Any( a => a.Route == route ) )
                    {
                        var pageRoute = new PageRoute();
                        pageRoute.Route = route.TrimStart( new char[] { '/' } );
                        pageRoute.Guid = Guid.NewGuid();
                        page.PageRoutes.Add( pageRoute );
                        addedRoutes.Add( route );
                    }
                }

                int parentPageId = ppParentPage.SelectedValueAsInt() ?? 0;
                if ( page.ParentPageId != parentPageId )
                {
                    if ( page.ParentPageId.HasValue )
                    {
                        PageCache.Flush( page.ParentPageId.Value );
                    }

                    if ( parentPageId != 0 )
                    {
                        PageCache.Flush( parentPageId );
                    }
                }

                page.InternalName = tbPageName.Text;
                page.PageTitle = tbPageTitle.Text;
                page.BrowserTitle = tbBrowserTitle.Text;
                if ( parentPageId != 0 )
                {
                    page.ParentPageId = parentPageId;
                }
                else
                {
                    page.ParentPageId = null;
                }

                page.LayoutId = ddlLayout.SelectedValueAsInt().Value;

                int? orphanedIconFileId = null;

                page.IconCssClass = tbIconCssClass.Text;

                page.PageDisplayTitle = cbPageTitle.Checked;
                page.PageDisplayBreadCrumb = cbPageBreadCrumb.Checked;
                page.PageDisplayIcon = cbPageIcon.Checked;
                page.PageDisplayDescription = cbPageDescription.Checked;

                page.DisplayInNavWhen = ddlMenuWhen.SelectedValue.ConvertToEnumOrNull<DisplayInNavWhen>() ?? DisplayInNavWhen.WhenAllowed;
                page.MenuDisplayDescription = cbMenuDescription.Checked;
                page.MenuDisplayIcon = cbMenuIcon.Checked;
                page.MenuDisplayChildPages = cbMenuChildPages.Checked;

                page.BreadCrumbDisplayName = cbBreadCrumbName.Checked;
                page.BreadCrumbDisplayIcon = cbBreadCrumbIcon.Checked;

                page.RequiresEncryption = cbRequiresEncryption.Checked;
                page.EnableViewState = cbEnableViewState.Checked;
                page.IncludeAdminFooter = cbIncludeAdminFooter.Checked;
                page.OutputCacheDuration = tbCacheDuration.Text.AsIntegerOrNull() ?? 0;
                page.Description = tbDescription.Text;
                page.HeaderContent = ceHeaderContent.Text;

                // update PageContexts
                foreach ( var pageContext in page.PageContexts.ToList() )
                {
                    contextService.Delete( pageContext );
                }

                page.PageContexts.Clear();
                foreach ( var control in phContext.Controls )
                {
                    if ( control is RockTextBox )
                    {
                        var tbContext = control as RockTextBox;
                        if ( !string.IsNullOrWhiteSpace( tbContext.Text ) )
                        {
                            var pageContext = new PageContext();
                            pageContext.Entity = tbContext.ID.Substring( 8 ).Replace( '_', '.' );
                            pageContext.IdParameter = tbContext.Text;
                            page.PageContexts.Add( pageContext );
                        }
                    }
                }

                // save page and it's routes
                if ( page.IsValid )
                {
                    rockContext.SaveChanges();

                    // remove any routes that were deleted
                    foreach (var deletedRouteId in deletedRouteIds )
                    {
                        var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == deletedRouteId );
                        if ( existingRoute != null )
                        {
                            RouteTable.Routes.Remove( existingRoute );
                        }
                    }

                    // ensure that there aren't any other extra routes for this page in the RouteTable
                    foreach (var routeTableRoute in RouteTable.Routes.OfType<Route>().Where(a => a.PageId() == page.Id))
                    {
                        if ( !editorRoutes.Any( a => a == routeTableRoute.Url ) )
                        {
                            RouteTable.Routes.Remove( routeTableRoute );
                        }
                    }

                    // Add any routes that were added
                    foreach ( var pageRoute in new PageRouteService( rockContext ).GetByPageId( page.Id ) )
                    {
                        if ( addedRoutes.Contains( pageRoute.Route ) )
                        {
                            RouteTable.Routes.AddPageRoute( pageRoute );
                        }
                    }

                    if ( orphanedIconFileId.HasValue )
                    {
                        BinaryFileService binaryFileService = new BinaryFileService( rockContext );
                        var binaryFile = binaryFileService.Get( orphanedIconFileId.Value );
                        if ( binaryFile != null )
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = true;
                            rockContext.SaveChanges();
                        }
                    }

                    Rock.Web.Cache.PageCache.Flush( page.Id );

                    string script = "if (typeof window.parent.Rock.controls.modal.close === 'function') window.parent.Rock.controls.modal.close('PAGE_UPDATED');";
                    ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "close-modal", script, true );
                }
            }
        }
コード例 #5
0
ファイル: Global.asax.cs プロジェクト: jh2mhs8/Rock-ChMS
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes( RouteCollection routes )
        {
            PageRouteService pageRouteService = new PageRouteService();

            // find each page that has defined a custom routes.
            foreach ( PageRoute pageRoute in pageRouteService.Queryable() )
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute( pageRoute );
            }

            // Add any custom api routes
            foreach ( var type in Rock.Reflection.FindTypes(
                typeof( Rock.Rest.IHasCustomRoutes ),
                new DirectoryInfo[] { new DirectoryInfo( Server.MapPath( "~/bin" ) ), new DirectoryInfo( Server.MapPath( "~/Plugins" ) ) } ) )
            {
                var controller = (Rock.Rest.IHasCustomRoutes)Activator.CreateInstance( type.Value );
                if ( controller != null )
                    controller.AddRoutes( routes );
            }

            // Add API Service routes
            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = System.Web.Http.RouteParameter.Optional }
            );

            // Add a default page route
            routes.Add( new Route( "page/{PageId}", new Rock.Web.RockRouteHandler() ) );

            // Add a default route for when no parameters are passed
            routes.Add( new Route( "", new Rock.Web.RockRouteHandler() ) );
        }
コード例 #6
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            PageRouteService pageRouteService = new PageRouteService( new RockContext() );
            SortProperty sortProperty = gPageRoutes.SortProperty;
            gPageRoutes.EntityTypeId = EntityTypeCache.Read<PageRoute>().Id;

            var qry = pageRouteService.Queryable().Select( a =>
                new
                {
                    a.Id,
                    a.Route,
                    PageName = a.Page.InternalName,
                    PageId = a.Page.Id,
                    a.IsSystem
                } );

            if ( sortProperty != null )
            {
                gPageRoutes.DataSource = qry.Sort( sortProperty ).ToList();
            }
            else
            {
                gPageRoutes.DataSource = qry.OrderBy( p => p.Route ).ToList();
            }

            gPageRoutes.DataBind();
        }
コード例 #7
0
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes( RockContext rockContext, RouteCollection routes )
        {
            routes.Clear();

            PageRouteService pageRouteService = new PageRouteService( rockContext );

            // find each page that has defined a custom routes.
            foreach ( PageRoute pageRoute in pageRouteService.Queryable() )
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute( pageRoute );
            }

            // Add a default page route
            routes.Add( new Route( "page/{PageId}", new Rock.Web.RockRouteHandler() ) );

            // Add a default route for when no parameters are passed
            routes.Add( new Route( "", new Rock.Web.RockRouteHandler() ) );
        }
コード例 #8
0
ファイル: PageRoutes.ascx.cs プロジェクト: jh2mhs8/Rock-ChMS
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            PageRouteService pageRouteService = new PageRouteService();
            SortProperty sortProperty = gPageRoutes.SortProperty;

            if ( sortProperty != null )
            {
                gPageRoutes.DataSource = pageRouteService.Queryable().Sort( sortProperty ).ToList();
            }
            else
            {
                gPageRoutes.DataSource = pageRouteService.Queryable().OrderBy( p => p.Route ).ToList();
            }

            gPageRoutes.DataBind();
        }
コード例 #9
0
ファイル: Global.asax.cs プロジェクト: NewSpring/Rock
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes( RockContext rockContext, RouteCollection routes )
        {
            routes.Clear();

            PageRouteService pageRouteService = new PageRouteService( rockContext );

            // Add ingore rule for asp.net ScriptManager files.
            routes.Ignore("{resource}.axd/{*pathInfo}");

            // Add page routes
            foreach ( var route in pageRouteService
                .Queryable().AsNoTracking()
                .GroupBy( r => r.Route )
                .Select( s => new {
                    Name = s.Key,
                    Pages = s.Select( pr => new Rock.Web.PageAndRouteId { PageId = pr.PageId, RouteId = pr.Id } ).ToList()
                } )
                .ToList() )
            {
                routes.AddPageRoute( route.Name, route.Pages );
            }

            // Add a default page route
            routes.Add( new Route( "page/{PageId}", new Rock.Web.RockRouteHandler() ) );

            // Add a default route for when no parameters are passed
            routes.Add( new Route( "", new Rock.Web.RockRouteHandler() ) );
        }
コード例 #10
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click( object sender, EventArgs e )
        {
            PageRoute pageRoute;
            var rockContext = new RockContext();
            PageRouteService pageRouteService = new PageRouteService( rockContext );

            int pageRouteId = int.Parse( hfPageRouteId.Value );

            if ( pageRouteId == 0 )
            {
                pageRoute = new PageRoute();
                pageRouteService.Add( pageRoute );
            }
            else
            {
                pageRoute = pageRouteService.Get( pageRouteId );
            }

            pageRoute.Route = tbRoute.Text.Trim();
            int selectedPageId = int.Parse( ppPage.SelectedValue );
            pageRoute.PageId = selectedPageId;

            if ( !pageRoute.IsValid )
            {
                // Controls will render the error messages
                return;
            }

            int? siteId = null;
            var pageCache = PageCache.Read( selectedPageId );
            if ( pageCache != null && pageCache.Layout != null )
            {
                siteId = pageCache.Layout.SiteId;
            }

            var duplicateRoutes = pageRouteService
                .Queryable().AsNoTracking()
                .Where( r =>
                    r.Route == pageRoute.Route &&
                    r.Id != pageRoute.Id );
            if ( siteId.HasValue )
            {
                duplicateRoutes = duplicateRoutes
                    .Where( r =>
                        r.Page != null &&
                        r.Page.Layout != null &&
                        r.Page.Layout.SiteId == siteId.Value );
            }

            if ( duplicateRoutes.Any() )
            {
                // Duplicate
                nbErrorMessage.Title = "Duplicate Route";
                nbErrorMessage.Text = "<p>There is already an existing route with this name for the selected page's site. Route names must be unique per site. Please choose a different route name.</p>";
                nbErrorMessage.Visible = true;
            }
            else
            {
                rockContext.SaveChanges();

                // Remove previous route
                var oldRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteIds().Contains( pageRoute.Id ) );
                if ( oldRoute != null )
                {
                    var pageAndRouteIds = oldRoute.DataTokens["PageRoutes"] as List<Rock.Web.PageAndRouteId>;
                    pageAndRouteIds = pageAndRouteIds.Where( p => p.RouteId != pageRoute.Id ).ToList();
                    if ( pageAndRouteIds.Any() )
                    {
                        oldRoute.DataTokens["PageRoutes"] = pageAndRouteIds;
                    }
                    else
                    {
                        RouteTable.Routes.Remove( oldRoute );
                    }
                }

                // Add new route
                var pageAndRouteId = new Rock.Web.PageAndRouteId { PageId = pageRoute.PageId, RouteId = pageRoute.Id };
                var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( r => r.Url == pageRoute.Route );
                if ( existingRoute != null )
                {
                    var pageAndRouteIds = existingRoute.DataTokens["PageRoutes"] as List<Rock.Web.PageAndRouteId>;
                    pageAndRouteIds.Add( pageAndRouteId );
                    existingRoute.DataTokens["PageRoutes"] = pageAndRouteIds;
                }
                else
                {
                    var pageAndRouteIds = new List<Rock.Web.PageAndRouteId>();
                    pageAndRouteIds.Add( pageAndRouteId );
                    RouteTable.Routes.AddPageRoute( pageRoute.Route, pageAndRouteIds );
                }

                NavigateToParentPage();
            }
        }