Exemplo n.º 1
0
        internal static void Render(AppJson appJson)
        {
            int navbarItemId = 0;

            foreach (BulmaNavbar navbar in appJson.ComponentListAll().OfType <BulmaNavbar>())
            {
                // ItemList clear
                navbar.ItemStartList.Clear();
                navbar.ItemEndList.Clear();

                // Add level 0 and level 1 to navbar
                foreach (var navbarGrid in navbar.GridList)
                {
                    Render(navbar, navbarGrid, ref navbarItemId);
                }

                // Add data grid filter (input text) to navbar
                if (navbar.Filter != null)
                {
                    var filter = navbar.Filter;
                    var grid   = filter.Grid;

                    // Get filter text from value store.
                    new GridFilter(grid).FilterValueList().TryGetValue(filter.FieldNameCSharp, out var gridFilterValue);
                    string filterText = gridFilterValue?.Text;
                    int    rowSateId  = grid.RowStateList.Single(item => item.RowEnum == GridRowEnum.Filter).Id;

                    // Filter input text box
                    var navbarItem = new BulmaNavbarItem {
                        Id = navbarItemId += 1, ItemEnum = BulmaNavbarItemEnum.Filter, Grid = grid, FilterFieldNameCSharp = filter.FieldNameCSharp, RowStateId = rowSateId, FilterText = filterText, FilterPlaceholder = "Search"
                    };
                    if (filter.IsNavbarEnd == false)
                    {
                        navbar.ItemStartList.Add(navbarItem);
                    }
                    else
                    {
                        navbar.ItemEndList.Add(navbarItem);
                    }
                }
            }
        }
Exemplo n.º 2
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);
                    }
                }
            }
        }