예제 #1
0
        public GridItem CreateItem(object dataItem)
        {
            var item = new GridItem
            {
                DataItem = dataItem,
                State = GridItemStates.Default,
                Type = GridItemType.DataRow
            };

            if (dataItem is IGroup)
            {
                AsGroupRow(item);
            }
            else
            {
                var current = comparer.KeysEqualTo(dataItem);

                AsEditRow(item, current);

                AsSelected(item, current);

                AsMaster(item);
            }

            return item;
        }
예제 #2
0
 private void AsEditRow(GridItem item, bool current)
 {
     if (current && creatorData.Mode == GridItemMode.Edit)
     {
         item.Type = GridItemType.EditRow;
     }
 }
예제 #3
0
        public IGridRowBuilder CreateBuilder(GridRenderingData renderingData, GridItem item)
        {
            var creator = BuilderRegistry[item.Type];

            ExecuteRowCallback(item, renderingData.Callback);

            var gridRowBuilder = creator(renderingData, item);

            return decoratorProvider.ApplyDecorators(gridRowBuilder, item, renderingData.HasDetailTemplate);
        }
 public IGridRowBuilder ApplyDecorators(IGridRowBuilder gridRowBuilder, GridItem item, bool hasDetailView)
 {
     var builderToDecorate = gridRowBuilder;
     foreach (var decorator in decorators)
     {
         var temp = decorator();
         temp.Decorate(builderToDecorate, item, hasDetailView);
         builderToDecorate = temp;
     }
     return builderToDecorate;
 }
예제 #5
0
        public virtual IGridRowBuilder CreateFooterBuilder(GridRenderingData renderingData)
        {
            var builder = new GridRowBuilder(renderingData.Columns.Select(column => cellBuilderFactory.CreateFooterCellBuilder(column, renderingData.AggregateResults )));

            var item = new GridItem
            {
                GroupLevel = renderingData.GroupMembers.Count(),
                Type = GridItemType.FooterRow
            };

            return decoratorProvider.ApplyDecorators(builder, item, renderingData.HasDetailTemplate);
        }
예제 #6
0
 public GridItem CreateGroupFooterItem(object dataItem)
 {
     if (creatorData.ShowGroupFooter)
     {
         var groupFooter = new GridItem
         {
             GroupLevel = creatorData.GroupsCount,
             DataItem = dataItem,
             Type = GridItemType.GroupFooterRow
         };
         return groupFooter;
     }
     return null;
 }
예제 #7
0
 protected virtual IGridRowBuilder CreatePopUpInsertRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     return(new GridPopUpInsertRowBuilder(CreateInsertFormBuilder(renderingData, item), renderingData.PopUpContainer));
 }
예제 #8
0
 private void AsGroupRow(GridItem item)
 {
     item.Type = GridItemType.GroupRow;
 }
예제 #9
0
 protected virtual IGridRowBuilder CreateInsertRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     switch (renderingData.EditMode)
     {
         //TODO: Implement InForm editing
         //case GridEditMode.InForm:
         //    return CreateInFormInsertRowBuilder(renderingData, item);
         case GridEditMode.PopUp:
             return CreatePopUpInsertRowBuilder(renderingData, item);
         default:
             return CreateInLineInsertRowBuilder(renderingData, item);
     }
 }
예제 #10
0
        private IGridEditFormBuilder CreateEditFormBuilder(GridRenderingData renderingData, GridItem item, 
            Func<IGridActionCommand, IEnumerable<IGridButtonBuilder>> buttons, Func<object, string> action)
        {
            var commands = renderingData.Columns.OfType<IGridActionColumn>().SelectMany(column => column.Commands);

            var editCommand = commands.OfType<GridEditActionCommand>().FirstOrDefault() ?? new GridEditActionCommand();

            var buttonBuilders = buttons(editCommand).Select(builder =>
            {
                Func<IHtmlNode> result = () => builder.Create(item.DataItem);
                return result;
            });

            var formHtmlAttributes = CreateFormAttributes(renderingData.FormId, action(item.DataItem));
            //formHtmlAttributes.Merge(renderingData.EditFormHtmlAttributes);

            return new GridEditFormBuilder(new GridFormBuilder(formHtmlAttributes),
                () => renderingData.HtmlHelper.EditorForModel(item.DataItem,
                    renderingData.EditTemplateName,
                    renderingData.Columns.OfType<IGridForeignKeyColumn>().Select(c => c.SerializeSelectList),
                    renderingData.AdditionalViewData
                ),
                buttonBuilders);
        }
예제 #11
0
        protected virtual IGridRowBuilder CreateGroupRowBuilder(GridRenderingData renderingData, GridItem item)
        {
            var groupKey = ((IGroup) item.DataItem).Key;

            var colspan = renderingData.Colspan - item.GroupLevel;

            var member = renderingData.GroupMembers.ElementAtOrDefault(item.GroupLevel);

            var column = renderingData.Columns.OfType<IGridBoundColumn>().FirstOrDefault(c => c.Member == member);

            var format = column != null && column.Format.HasValue() ? column.Format : "{0}";

            var template = new HtmlTemplate<GridGroupAggregateResult>
            {
                InlineTemplate = (result) => "{0}: {1}".FormatWith(result.Title, format.FormatWith(ExtractForeignKeyText(column, result.Key)))
            };

            var title = member.AsTitle();

            if (column != null)
            {
                title = column.Title.HasValue() ? column.Title : column.Member.AsTitle();
                if (column.GroupHeaderTemplate.HasValue())
                {
                    template = column.GroupHeaderTemplate;
                }
            }

            var functionsGroup = item.DataItem as AggregateFunctionsGroup;
            var itemAggregateResult = functionsGroup.GetAggregateResults(renderingData.Aggregates);

            var aggregateResult = new GridGroupAggregateResult(title, groupKey, itemAggregateResult);

            return new GridGroupRowBuilder((container) => template.Apply(aggregateResult, container), colspan);
        }
예제 #12
0
 protected virtual IGridRowBuilder CreateInLineInsertRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     return CreateInLineRowBuilder(renderingData, item, renderingData.UrlBuilder.InsertUrl, cellBuilderFactory.CreateInsertCellBuilder);
 }
예제 #13
0
 public override bool ShouldDecorate(GridItem gridItem)
 {
     return HasDetailView && gridItem.Type != GridItemType.EmptyRow &&
            gridItem.Type != GridItemType.GroupRow;
 }
예제 #14
0
 protected virtual IGridRowBuilder CreateEmptyRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     return new GridEmptyRowBuilder(renderingData.Colspan, renderingData.NoRecordsTemplate);
 }
예제 #15
0
 protected virtual IGridRowBuilder CreateDetailRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     return(new GridDetailRowBuilder
     {
         Colspan = (renderingData.Colspan - 1) - item.GroupLevel,
         DataItem = item.DataItem,
         Template = renderingData.DetailTemplate,
         Expanded = item.Expanded,
         IsMasterAlternate = item is GridDetailViewItem && ((item as GridDetailViewItem).Parent.State & GridItemStates.Alternating) == GridItemStates.Alternating,
         Html = item.DetailRowHtml,
         HtmlAttributes = item.DetailRowHtmlAttributes
     });
 }
예제 #16
0
 protected virtual IGridEditFormBuilder CreateEditFormBuilder(GridRenderingData renderingData, GridItem item)
 {
     return(CreateEditFormBuilder(renderingData,
                                  item,
                                  (command) => command.CreateEditButtons(renderingData.UrlBuilder, renderingData.HtmlHelper),
                                  renderingData.UrlBuilder.UpdateUrl
                                  ));
 }
예제 #17
0
        protected virtual IGridRowBuilder CreateDataRowBuilder(GridRenderingData renderingData, GridItem item)
        {
            if (renderingData.RowTemplate != null)
            {
                return(new GridTemplateRowBuilder(td => renderingData.RowTemplate(item.DataItem, td), renderingData.Colspan));
            }

            return(new GridDataRowBuilder(item.DataItem, renderingData.Columns.Select(column => cellBuilderFactory.CreateDisplayCellBuilder(column, renderingData.HtmlHelper))));
        }
예제 #18
0
        private IGridRowBuilder CreateInLineRowBuilder(GridRenderingData renderingData, GridItem item, Func <object, string> action, Func <IGridColumn, IGridHtmlHelper, IGridDataCellBuilder> cellBuilder)
        {
            var tableBuilder = tableBuilderFactory.CreateTableBuilder(renderingData.Columns.Select(c => new GridColData {
                Width = c.Width, Hidden = c.Hidden
            }));

            var cellBuilders = renderingData.Columns.Select(column => cellBuilder(column, renderingData.HtmlHelper));

            var formHtmlAttributes = CreateFormAttributes(renderingData.FormId, action(item.DataItem));

            //formHtmlAttributes.Merge(renderingData.EditFormHtmlAttributes);

            return(new GridInLineEditRowBuilder(tableBuilder, new GridFormBuilder(formHtmlAttributes),
                                                renderingData.Colspan, item.DataItem, cellBuilders));
        }
예제 #19
0
        private IGridEditFormBuilder CreateEditFormBuilder(GridRenderingData renderingData, GridItem item,
                                                           Func <IGridActionCommand, IEnumerable <IGridButtonBuilder> > buttons, Func <object, string> action)
        {
            var commands = renderingData.Columns.OfType <IGridActionColumn>().SelectMany(column => column.Commands);

            var editCommand = commands.OfType <GridEditActionCommand>().FirstOrDefault() ?? new GridEditActionCommand();

            var buttonBuilders = buttons(editCommand).Select(builder =>
            {
                Func <IHtmlNode> result = () => builder.Create(item.DataItem);
                return(result);
            });

            var formHtmlAttributes = CreateFormAttributes(renderingData.FormId, action(item.DataItem));

            //formHtmlAttributes.Merge(renderingData.EditFormHtmlAttributes);

            return(new GridEditFormBuilder(new GridFormBuilder(formHtmlAttributes),
                                           () => renderingData.HtmlHelper.EditorForModel(item.DataItem,
                                                                                         renderingData.EditTemplateName,
                                                                                         renderingData.Columns.OfType <IGridForeignKeyColumn>().Select(c => c.SerializeSelectList),
                                                                                         renderingData.AdditionalViewData
                                                                                         ),
                                           buttonBuilders));
        }
예제 #20
0
 private void AsMaster(GridItem item)
 {
     if (creatorData.HasDetailTemplate)
     {
         item.State |= GridItemStates.Master;
     }
 }
예제 #21
0
 protected virtual IGridRowBuilder CreateInLineInsertRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     return(CreateInLineRowBuilder(renderingData, item, renderingData.UrlBuilder.InsertUrl, cellBuilderFactory.CreateInsertCellBuilder));
 }
예제 #22
0
 protected virtual IGridRowBuilder CreateDetailRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     return new GridDetailRowBuilder
     {
         Colspan = (renderingData.Colspan - 1) - item.GroupLevel,
         DataItem = item.DataItem,
         Template = renderingData.DetailTemplate,
         Expanded = item.Expanded,
         IsMasterAlternate = item is GridDetailViewItem && ((item as GridDetailViewItem).Parent.State & GridItemStates.Alternating) == GridItemStates.Alternating,
         Html = item.DetailRowHtml,
         HtmlAttributes = item.DetailRowHtmlAttributes
     };
 }
예제 #23
0
 public override bool ShouldDecorate(GridItem gridItem)
 {
     return(HasDetailView && gridItem.Type != GridItemType.EmptyRow &&
            gridItem.Type != GridItemType.GroupRow);
 }
예제 #24
0
 protected virtual IGridRowBuilder CreateGroupFooterRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     var functionsGroup = item.DataItem as AggregateFunctionsGroup;
     var itemAggregateResult = functionsGroup.GetAggregateResults(renderingData.Aggregates);
     return new GridGroupFooterRowBuilder(renderingData.Columns.Select(column => cellBuilderFactory.CreateGroupFooterCellBuilder(column, itemAggregateResult)));
 }
예제 #25
0
 private void AsSelected(GridItem item, bool current)
 {
     if (current && creatorData.Mode == GridItemMode.Select)
     {
         item.State |= GridItemStates.Selected;
     }
 }
예제 #26
0
 protected virtual IGridRowBuilder CreateInFormInsertRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     return new GridInFormEditRowBuilder(CreateInsertFormBuilder(renderingData, item), renderingData.Colspan);
 }
예제 #27
0
 private void ExecuteRowCallback(GridItem item, Action<GridItem> callback)
 {
     if (item.Type != GridItemType.DetailRow
         && item.Type != GridItemType.GroupRow
         && item.Type != GridItemType.GroupFooterRow
         && item.Type != GridItemType.EmptyRow)
     {
         callback(item);
     }
 }
예제 #28
0
 protected virtual IGridEditFormBuilder CreateInsertFormBuilder(GridRenderingData renderingData, GridItem item)
 {
     return CreateEditFormBuilder(renderingData,
         item,
         (command) => command.CreateInsertButtons(renderingData.UrlBuilder,
             renderingData.HtmlHelper),
         renderingData.UrlBuilder.InsertUrl
     );
 }
예제 #29
0
 protected virtual IGridRowBuilder CreateInFormInsertRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     return(new GridInFormEditRowBuilder(CreateInsertFormBuilder(renderingData, item), renderingData.Colspan));
 }
예제 #30
0
 protected virtual IGridRowBuilder CreatePopUpInsertRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     return new GridPopUpInsertRowBuilder(CreateInsertFormBuilder(renderingData, item), renderingData.PopUpContainer);
 }
예제 #31
0
        protected virtual IGridRowBuilder CreateGroupFooterRowBuilder(GridRenderingData renderingData, GridItem item)
        {
            var functionsGroup      = item.DataItem as AggregateFunctionsGroup;
            var itemAggregateResult = functionsGroup.GetAggregateResults(renderingData.Aggregates);

            return(new GridGroupFooterRowBuilder(renderingData.Columns.Select(column => cellBuilderFactory.CreateGroupFooterCellBuilder(column, itemAggregateResult))));
        }
예제 #32
0
        private IGridRowBuilder CreateInLineRowBuilder(GridRenderingData renderingData, GridItem item, Func<object, string> action, Func<IGridColumn, IGridHtmlHelper, IGridDataCellBuilder> cellBuilder)
        {
            var tableBuilder = tableBuilderFactory.CreateTableBuilder(renderingData.Columns.Select(c => new GridColData { Width = c.Width, Hidden = c.Hidden }));

            var cellBuilders = renderingData.Columns.Select(column => cellBuilder(column, renderingData.HtmlHelper));

            var formHtmlAttributes = CreateFormAttributes(renderingData.FormId, action(item.DataItem));
            //formHtmlAttributes.Merge(renderingData.EditFormHtmlAttributes);

            return new GridInLineEditRowBuilder(tableBuilder, new GridFormBuilder(formHtmlAttributes),
                                                renderingData.Colspan, item.DataItem, cellBuilders);
        }
예제 #33
0
        protected virtual IGridRowBuilder CreateInsertRowBuilder(GridRenderingData renderingData, GridItem item)
        {
            switch (renderingData.EditMode)
            {
            //TODO: Implement InForm editing
            //case GridEditMode.InForm:
            //    return CreateInFormInsertRowBuilder(renderingData, item);
            case GridEditMode.PopUp:
                return(CreatePopUpInsertRowBuilder(renderingData, item));

            default:
                return(CreateInLineInsertRowBuilder(renderingData, item));
            }
        }
예제 #34
0
 private void AsGroupRow(GridItem item)
 {
     item.Type = GridItemType.GroupRow;
 }
예제 #35
0
 protected virtual IGridRowBuilder CreateEmptyRowBuilder(GridRenderingData renderingData, GridItem item)
 {
     return(new GridEmptyRowBuilder(renderingData.Colspan, renderingData.NoRecordsTemplate));
 }
예제 #36
0
        protected virtual IGridRowBuilder CreateDataRowBuilder(GridRenderingData renderingData, GridItem item)
        {
            if (renderingData.RowTemplate != null)
            {
                return new GridTemplateRowBuilder(td => renderingData.RowTemplate(item.DataItem, td), renderingData.Colspan);
            }

            return new GridDataRowBuilder(item.DataItem, renderingData.Columns.Select(column => cellBuilderFactory.CreateDisplayCellBuilder(column, renderingData.HtmlHelper)));
        }
예제 #37
0
        protected virtual IGridRowBuilder CreateGroupRowBuilder(GridRenderingData renderingData, GridItem item)
        {
            var groupKey = ((IGroup)item.DataItem).Key;

            var colspan = renderingData.Colspan - item.GroupLevel;

            var member = renderingData.GroupMembers.ElementAtOrDefault(item.GroupLevel);

            var column = renderingData.Columns.OfType <IGridBoundColumn>().FirstOrDefault(c => c.Member == member);

            var format = column != null && column.Format.HasValue() ? column.Format : "{0}";


            var template = new HtmlTemplate <GridGroupAggregateResult>
            {
                InlineTemplate = (result) => "{0}: {1}".FormatWith(result.Title, format.FormatWith(ExtractForeignKeyText(column, result.Key)))
            };

            var title = member.AsTitle();

            if (column != null)
            {
                title = column.Title.HasValue() ? column.Title : column.Member.AsTitle();
                if (column.GroupHeaderTemplate.HasValue())
                {
                    template = column.GroupHeaderTemplate;
                }
            }

            var functionsGroup      = item.DataItem as AggregateFunctionsGroup;
            var itemAggregateResult = functionsGroup.GetAggregateResults(renderingData.Aggregates);

            var aggregateResult = new GridGroupAggregateResult(title, groupKey, itemAggregateResult);

            return(new GridGroupRowBuilder((container) => template.Apply(aggregateResult, container), colspan));
        }
예제 #38
0
 public override bool ShouldDecorate(GridItem gridItem)
 {
     return gridItem.Type != GridItemType.EmptyRow;
 }
예제 #39
0
 public override bool ShouldDecorate(GridItem gridItem)
 {
     return(gridItem.Type != GridItemType.EmptyRow);
 }