public static void BootstrapNavbarRender(AppJson appJson) { int buttonId = 0; // BootstrapNavbarButton.Id foreach (BootstrapNavbar bootstrapNavbar in appJson.ComponentListAll().OfType <BootstrapNavbar>()) { bootstrapNavbar.ButtonList = new List <BootstrapNavbarButton>(); // Clear foreach (var item in bootstrapNavbar.GridList) { if (item.Grid?.TypeRow != null) { var propertyInfoList = UtilDalType.TypeRowToPropertyInfoList(item.Grid.TypeRow); PropertyInfo propertyInfoId = propertyInfoList.Where(item => item.Name == "Id" && item.PropertyType == typeof(int)).SingleOrDefault(); PropertyInfo propertyInfoParentId = propertyInfoList.Where(item => item.Name == "ParentId" && item.PropertyType == typeof(int?)).SingleOrDefault(); PropertyInfo propertyInfoTextHtml = propertyInfoList.Where(item => item.Name == "TextHtml" && item.PropertyType == typeof(string)).SingleOrDefault(); if (propertyInfoParentId != null) { UtilFramework.Assert(propertyInfoId != null, "Row needs a column 'Id'!"); } UtilFramework.Assert(propertyInfoTextHtml != null, string.Format("Row needs a column 'TextHtml' ({0})!", UtilDalType.TypeRowToTableNameCSharp(item.Grid.TypeRow))); // Add for example language switch if (item.IsSelectMode) { if (item.Grid.RowSelect != null) { string textHtml = (string)propertyInfoTextHtml.GetValue(item.Grid.RowSelect); var args = new BootstrapNavbarButtonArgs { BootstrapNavbar = bootstrapNavbar, Grid = item.Grid, Row = item.Grid.RowSelect }; var result = new BootstrapNavbarButtonResult { TextHtml = textHtml }; bootstrapNavbar.ButtonTextHtml(args, result); buttonId += 1; var button = new BootstrapNavbarButton { Id = buttonId, Grid = item.Grid, RowStateId = item.Grid.RowSelectRowStateId.Value, TextHtml = result.TextHtml }; bootstrapNavbar.ButtonList.Add(button); BootstrapNavbarRender(bootstrapNavbar, item, button, ref button.ButtonList, findParentId: null, propertyInfoId, propertyInfoParentId, propertyInfoTextHtml, ref buttonId); } } else { BootstrapNavbarRender(bootstrapNavbar, item, null, ref bootstrapNavbar.ButtonList, findParentId: null, propertyInfoId, propertyInfoParentId, propertyInfoTextHtml, ref buttonId); } } } } }
/// <summary> /// Add BootstrapNavbarButton. /// </summary> /// <param name="buttonList">List to add buttons.</param> /// <param name="gridSession">Grid on which to search (child) buttons.</param> /// <param name="findParentId">Add buttons with this parentId.</param> private static void BootstrapNavbarRender(BootstrapNavbar bootstrapNavbar, BootstrapNavbarGrid bootstrapNavbarGrid, BootstrapNavbarButton buttonParent, ref List <BootstrapNavbarButton> buttonList, int?findParentId, PropertyInfo propertyInfoId, PropertyInfo propertyInfoParentId, PropertyInfo propertyInfoTextHtml, ref int buttonId) { var grid = bootstrapNavbarGrid.Grid; foreach (var rowState in grid.RowStateList) { if (rowState.RowEnum == GridRowEnum.Index) { Row row = grid.RowListInternal[rowState.RowId.Value - 1]; string itemTextHtml = (string)propertyInfoTextHtml.GetValue(row); int? itemParentId = (int?)propertyInfoParentId?.GetValue(row); // Null if row does not have field "ParentId". bool isActive = rowState.IsSelect; if (itemParentId == findParentId) { if (buttonParent != null) { buttonParent.IsDropDown = true; // Has children. } var args = new BootstrapNavbarButtonArgs { BootstrapNavbar = bootstrapNavbar, Grid = grid, Row = row }; var result = new BootstrapNavbarButtonResult { TextHtml = itemTextHtml }; bootstrapNavbar.ButtonTextHtml(args, result); if (!(bootstrapNavbarGrid.IsSelectMode && row == grid.RowSelect)) // For example for language: do not show selected language again under drop down button. { buttonId += 1; BootstrapNavbarButton button = new BootstrapNavbarButton { Id = buttonId, Grid = grid, RowStateId = rowState.Id, TextHtml = result.TextHtml, IsActive = isActive }; if (buttonList == null) { buttonList = new List <BootstrapNavbarButton>(); } buttonList.Add(button); if (propertyInfoParentId != null) // Hierarchical navigation { int itemId = (int)propertyInfoId.GetValue(grid.RowListInternal[rowState.RowId.Value - 1]); BootstrapNavbarRender(bootstrapNavbar, bootstrapNavbarGrid, button, ref button.ButtonList, itemId, propertyInfoId, propertyInfoParentId, propertyInfoTextHtml, ref buttonId); } } } } } }