Ejemplo n.º 1
0
        private void RowMap(BulmaNavbarRowMapArgs args, BulmaNavbarRowMapResult result, string fieldName)
        {
            var propertyInfo = args.Row.GetType().GetProperty(fieldName);

            if (propertyInfo != null)
            {
                object value = propertyInfo.GetValue(args.Row);
                result.GetType().GetField(fieldName).SetValue(result, value);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Override this method to custom map incoming data rows to navbar items.
 /// </summary>
 protected virtual void RowMap(BulmaNavbarRowMapArgs args, BulmaNavbarRowMapResult result)
 {
     // Default row mapper
     RowMap(args, result, nameof(result.Id));
     RowMap(args, result, nameof(result.ParentId));
     RowMap(args, result, nameof(result.TextHtml));
     RowMap(args, result, nameof(result.NavigatePath));
     RowMap(args, result, nameof(result.IsDivider));
     RowMap(args, result, nameof(result.IsNavbarEnd));
     RowMap(args, result, nameof(result.Sort));
 }
Ejemplo n.º 3
0
        private static void Render(BulmaNavbar navbar, BulmaNavbarGrid navbarGrid, ref int navbarItemId)
        {
            Grid grid = navbarGrid.Grid;

            // Map all data grid rows
            var rowMapList = new List <BulmaNavbarRowMapResult>();

            foreach (var rowState in grid.RowStateList)
            {
                if (rowState.RowEnum == GridRowEnum.Index)
                {
                    var rowMapArgs = new BulmaNavbarRowMapArgs {
                        Row = grid.RowList[rowState.RowId.Value - 1]
                    };
                    var rowMapResult = new BulmaNavbarRowMapResult {
                        RowStateId = rowState.Id, IsSelect = rowState.IsSelect
                    };
                    navbar.RowMap(rowMapArgs, rowMapResult);
                    if (rowMapResult.IsHide == false)
                    {
                        rowMapList.Add(rowMapResult);
                    }
                }
            }
            rowMapList = rowMapList.OrderBy(item => item.Sort).ToList();

            // IsSelectMode for example for language selection.
            if (navbarGrid.IsSelectMode && rowMapList.Count > 0)
            {
                var rowMapTop = rowMapList.FirstOrDefault(item => item.RowStateId == grid.RowSelectRowStateId);
                if (rowMapTop == null)
                {
                    rowMapTop = rowMapList.First();
                }
                foreach (var rowMap in rowMapList)
                {
                    if (rowMap != rowMapTop)
                    {
                        rowMap.ParentId = rowMapTop.Id;
                    }
                }
            }

            // Level 0
            Dictionary <int, BulmaNavbarItem> level0List = new Dictionary <int, BulmaNavbarItem>();

            foreach (var rowMap in rowMapList)
            {
                if (rowMap.ParentId == null)
                {
                    BulmaNavbarItemEnum itemEnum = BulmaNavbarItemEnum.Text;
                    // Level 0
                    var navbarItem = new BulmaNavbarItem {
                        Id = navbarItemId += 1, ItemEnum = itemEnum, Grid = grid, RowStateId = rowMap.RowStateId, TextHtml = rowMap.TextHtml, NavigatePath = rowMap.NavigatePath, IsActive = rowMap.IsSelect
                    };
                    level0List.Add(rowMap.Id, navbarItem);
                    bool isNavbarEnd = navbarGrid.IsNavbarEnd;
                    if (rowMap.IsNavbarEnd != null)
                    {
                        isNavbarEnd = rowMap.IsNavbarEnd.Value;
                    }
                    if (isNavbarEnd == false)
                    {
                        navbar.ItemStartList.Add(navbarItem);
                    }
                    else
                    {
                        navbar.ItemEndList.Add(navbarItem);
                    }
                }
            }

            // Level 1
            foreach (var rowMap in rowMapList)
            {
                if (rowMap.ParentId != null)
                {
                    if (level0List.TryGetValue(rowMap.ParentId.Value, out var navbarItemParent))
                    {
                        navbarItemParent.ItemEnum = BulmaNavbarItemEnum.Parent;

                        BulmaNavbarItemEnum itemEnum = BulmaNavbarItemEnum.Text;
                        if (rowMap.IsDivider)
                        {
                            itemEnum = BulmaNavbarItemEnum.Divider;
                        }
                        // Level 1
                        var navbarItem = new BulmaNavbarItem {
                            Id = navbarItemId += 1, ItemEnum = itemEnum, Grid = grid, RowStateId = rowMap.RowStateId, TextHtml = rowMap.TextHtml, NavigatePath = rowMap.NavigatePath, IsActive = rowMap.IsSelect
                        };
                        navbarItemParent.ItemList.Add(navbarItem);
                    }
                }
            }
        }