/// <summary> /// Handles the user command to show custom settings. /// </summary> protected override void ShowSettings() { List <DashboardBlockType> blockTypes; // // Get the current configuration settings for the list of available blocks. // try { blockTypes = JsonConvert.DeserializeObject <List <DashboardBlockType> >(GetAttributeValue("AvailableBlocks")); if (blockTypes == null) { blockTypes = new List <DashboardBlockType>(); } } catch { blockTypes = new List <DashboardBlockType>(); } // // Get all the known blocks and remove any blocks that no longer exist from the // configuration data. // var blocks = GetAllBlocks(); var removeBlockTypes = blockTypes.Where(b => !blocks.Any(bb => bb.Id == b.BlockId)).ToList(); blockTypes.RemoveAll(b => removeBlockTypes.Any(rb => rb.BlockId == b.BlockId)); // // Walk each block and either initialize the block type or load it from cache. // foreach (var block in blocks) { var blockType = blockTypes.Where(b => b.BlockId == block.Id).FirstOrDefault(); if (blockType == null) { blockType = new DashboardBlockType(); blockType.BlockCache = block; blockType.BlockId = block.Id; blockTypes.Add(blockType); } else { blockType.BlockCache = BlockCache.Read(blockType.BlockId); } } rblSettingsDefaultLayout.SelectedValue = GetAttributeValue("DefaultLayout"); AvailableBlocksLive = blockTypes; gSettingsBlocks.DataSource = blockTypes; gSettingsBlocks.DataBind(); mdlSettings.Show(); }
/// <summary> /// Get the list of available blocks that the user can enable on the dashboard. /// </summary> /// <returns>An enumerable list of block types available.</returns> private List <DashboardBlockType> GetAvailableBlocks() { List <DashboardBlockType> blockTypes; // // Get the current configuration settings for the list of available blocks. // try { blockTypes = JsonConvert.DeserializeObject <List <DashboardBlockType> >(GetAttributeValue("AvailableBlocks")); if (blockTypes == null) { blockTypes = new List <DashboardBlockType>(); } } catch { blockTypes = new List <DashboardBlockType>(); } // // Get all the blocks the user can see. // var blocks = GetAllBlocks() .Where(b => b.IsAuthorized(Authorization.VIEW, CurrentPerson) || b.IsAuthorized(Authorization.EDIT, CurrentPerson) || b.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson)) .ToList(); // // Filter the block types to those the user has permissions to view. // blockTypes = blockTypes.Where(bt => blocks.Any(b => b.Id == bt.BlockId)).ToList(); // // Walk each block and either initialize the block type or load it from cache. // foreach (var block in blocks) { var blockType = blockTypes.Where(b => b.BlockId == block.Id).FirstOrDefault(); if (blockType == null) { blockType = new DashboardBlockType(); blockType.BlockCache = block; blockType.BlockId = block.Id; blockTypes.Add(blockType); } else { blockType.BlockCache = BlockCache.Read(blockType.BlockId); } } return(blockTypes); }