Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RockBlockWrapper"/> class.
 /// </summary>
 /// <param name="rockBlock">The rock block.</param>
 /// <param name="blockCache">The BlockCache information that defines this block.</param>
 /// <param name="config">The dashboard configuration for this block.</param>
 public DashboardBlockWrapper(RockBlock rockBlock, BlockCache blockCache, DashboardBlockConfig config)
 {
     _rockBlock  = rockBlock;
     _blockCache = blockCache;
     ShowDelete  = true;
     Config      = config;
 }
Beispiel #2
0
        /// <summary>
        /// Handles the Click event of the 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 mdlOptions_SaveClick(object sender, EventArgs e)
        {
            var config = GetConfig();

            config.Layout = rblOptionsLayout.SelectedValue;

            //
            // Update the selection of visible blocks based on the user's selection.
            //
            foreach (ListItem item in cblOptionsBlocks.Items)
            {
                var block = config.Blocks.Where(b => b.BlockId == item.Value.AsInteger()).FirstOrDefault();

                if (block != null)
                {
                    if (block.Visible != item.Selected)
                    {
                        block.Visible = item.Selected;

                        //
                        // Set column and order high to cause auto-layout of this "new" block.
                        //
                        if (block.Visible)
                        {
                            block.Expanded = true;
                            block.Column   = 999;
                            block.Order    = 999;
                        }
                    }
                }
                else
                {
                    block = new DashboardBlockConfig(item.Value.AsInteger());

                    block.Visible = item.Selected;

                    config.Blocks.Add(block);
                }
            }

            SaveConfig(config);
            mdlOptions.Hide();

            NavigateToPage(CurrentPageReference);
        }
Beispiel #3
0
        /// <summary>
        /// Build and layout all the blocks onto the web page.
        /// </summary>
        /// <param name="config">User configuration data that specifies how things should be laid out.</param>
        private void BuildBlocks(DashboardConfig config)
        {
            var sourcePageGuid = GetAttributeValue("SourcePage").AsGuidOrNull();

            if (sourcePageGuid.HasValue)
            {
                var sourcePage = PageCache.Read(sourcePageGuid.Value);

                if (sourcePage != null)
                {
                    var   blocks = GetAvailableBlocks();
                    Panel pnlRow = new Panel {
                        CssClass = "row"
                    };
                    List <DashboardBlockWrapper> dashboardBlocks = new List <DashboardBlockWrapper>();
                    bool needSave = false;

                    phControls.Controls.Add(pnlRow);
                    var columns = BuildColumns(config, pnlRow);

                    foreach (var block in blocks)
                    {
                        DashboardBlockConfig blockConfig = null;

                        blockConfig = config.Blocks.Where(b => b.BlockId == block.BlockId).FirstOrDefault();
                        if (blockConfig == null)
                        {
                            blockConfig         = new DashboardBlockConfig(block.BlockId);
                            blockConfig.Visible = block.DefaultVisible;
                            config.Blocks.Add(blockConfig);
                            needSave = true;
                        }

                        if (block.Required)
                        {
                            blockConfig.Visible = true;
                        }

                        if (blockConfig.Visible)
                        {
                            var control = TemplateControl.LoadControl(block.BlockCache.BlockType.Path);
                            control.ClientIDMode = ClientIDMode.AutoID;

                            var  blockControl    = control as RockBlock;
                            bool canEdit         = block.BlockCache.IsAuthorized(Authorization.EDIT, CurrentPerson);
                            bool canAdministrate = block.BlockCache.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson);

                            blockControl.SetBlock(PageCache, block.BlockCache, canEdit, canAdministrate);
                            block.BlockCache.BlockType.SetSecurityActions(blockControl);

                            var blockWrapper = new DashboardBlockWrapper(blockControl, block.BlockCache, blockConfig);
                            blockWrapper.ShowDelete = !block.Required;

                            dashboardBlocks.Add(blockWrapper);
                        }
                    }

                    //
                    // Add all the blocks that are properly layed out already.
                    //
                    var existingBlocks = dashboardBlocks.Where(b => b.Config.Column < columns.Count);
                    foreach (var blockGroup in existingBlocks.GroupBy(b => b.Config.Column))
                    {
                        var sortedBlocks = blockGroup.OrderBy(b => b.Config.Order);

                        foreach (var block in sortedBlocks)
                        {
                            columns[block.Config.Column].Placeholder.Controls.Add(block);
                        }
                    }

                    //
                    // Add in blocks that are new or don't currently fit.
                    //
                    var newBlocks = dashboardBlocks.Where(b => b.Config.Column >= columns.Count);
                    foreach (var blockGroup in newBlocks.GroupBy(b => b.Config.Column))
                    {
                        var sortedBlocks = blockGroup.OrderBy(b => b.Config.Order);

                        foreach (var block in sortedBlocks)
                        {
                            bool isRequired = blocks.Where(b => b.BlockId == block.Config.BlockId).First().Required;
                            AutoConfigBlockPlacement(config, block, columns, isRequired);
                            needSave = true;
                        }
                    }

                    //
                    // Cleanup the config for any blocks that don't exist anymore.
                    //
                    var missingKeys = config.Blocks
                                      .Where(b => !blocks.Where(db => b.BlockId == db.BlockId).Any())
                                      .Select(b => b.BlockId)
                                      .ToList();
                    foreach (var missingKey in missingKeys)
                    {
                        config.Blocks.RemoveAll(b => b.BlockId == missingKey);
                        needSave = true;
                    }

                    if (needSave)
                    {
                        SaveConfig(config);
                    }
                }
            }
        }