예제 #1
0
 public GridFiltersTests()
 {
     column = new GridColumn<GridModel, String>(new Grid<GridModel>(new GridModel[0]), model => model.Name);
     column.Grid.Query = new QueryCollection();
     column.IsMultiFilterable = true;
     filters = new GridFilters();
 }
        protected string GetSortHeaderContent(IGridColumn column)
        {
            var sortTitle = new TagBuilder("div");
            sortTitle.AddCssClass("grid-header-title");

            if (column.SortEnabled)
            {
                var columnHeaderLink = new TagBuilder("a")
                    {
                        InnerHtml = column.Title
                    };
                string url = GetSortUrl(column.Name, column.Direction);
                columnHeaderLink.Attributes.Add("href", url);
                sortTitle.InnerHtml += columnHeaderLink.ToString();
            }
            else
            {
                var columnTitle = new TagBuilder("span")
                    {
                        InnerHtml = column.Title
                    };
                sortTitle.InnerHtml += columnTitle.ToString();
            }

            if (column.IsSorted)
            {
                sortTitle.AddCssClass("sorted");
                sortTitle.AddCssClass(column.Direction == GridSortDirection.Ascending ? "sorted-asc" : "sorted-desc");

                var sortArrow = new TagBuilder("span");
                sortArrow.AddCssClass("grid-sort-arrow");
                sortTitle.InnerHtml += sortArrow.ToString();
            }
            return sortTitle.ToString();
        }
        private string writeColumn(IGridColumn<ColumnDefTarget> column)
        {
            var builder = new StringBuilder();
            column.WriteColumn(builder);

            return builder.ToString();
        }
        private string writeColumn(IGridColumn column)
        {
            var builder = new StringBuilder();
            column.WriteColumn(builder, AccessRight.All);

            return builder.ToString();
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GridColumnViewModel"/> class.
        /// </summary>
        /// <param name="parentColumnList">The parent column list.</param>
        /// <param name="systemName">Name of the system.</param>
        /// <param name="parentNotifyLayoutChanged">The parent notify layout changed.</param>
        public GridColumnViewModel(IList<IGridColumn> parentColumnList, string systemName, INotifyLayoutChanged parentNotifyLayoutChanged)
        {
            _column = new GridColumn { SystemName = systemName };
            _parentColumnList = parentColumnList;
            _parentNotifyLayoutChanged = parentNotifyLayoutChanged;

            InitializeDefaultValues();
        }
        public IHtmlString Render(IGridColumn column)
        {
            if (!column.FilterEnabled)
                return MvcHtmlString.Create(string.Empty);


            //determine current column filter settings
            var filterSettings = new List<ColumnFilterValue>();
            if (_settings.IsInitState && column.InitialFilterSettings != ColumnFilterValue.Null)
            {
                filterSettings.Add(column.InitialFilterSettings);
            }
            else
            {
                filterSettings.AddRange(_settings.FilteredColumns.GetByColumn(column));
            }

            bool isColumnFiltered = filterSettings.Any();

            //determine current url:
            var builder = new CustomQueryStringBuilder(_settings.Context.Request.QueryString);

            var exceptQueryParameters = new List<string>
                {
                    QueryStringFilterSettings.DefaultTypeQueryParameter,
                    QueryStringFilterSettings.DefaultFilterInitQueryParameter
                };
            string pagerParameterName = GetPagerQueryParameterName(column.ParentGrid.Pager);
            if (!string.IsNullOrEmpty(pagerParameterName))
                exceptQueryParameters.Add(pagerParameterName);

            string url = builder.GetQueryStringExcept(exceptQueryParameters);

            var gridFilterButton = new TagBuilder("span");
            gridFilterButton.AddCssClass(FilterButtonCss);
            if (isColumnFiltered)
                gridFilterButton.AddCssClass(FilteredButtonCssClass);
            gridFilterButton.Attributes.Add("title", Strings.FilterButtonTooltipText);

            var gridFilter = new TagBuilder("div");
            var dataKeyList = new Dictionary<string, string>
                {
                    {"data-type", column.FilterWidgetTypeName},
                    {"data-name", column.Name},
                    {"data-widgetdata", JsonHelper.JsonSerializer(column.FilterWidgetData)},
                    {"data-filterdata", JsonHelper.JsonSerializer(filterSettings)},
                    {"data-url", url}
                };
            gridFilter.InnerHtml = gridFilterButton.ToString();
            gridFilter.AddCssClass("grid-filter");
            foreach (var data in dataKeyList)
            {
                if (!string.IsNullOrWhiteSpace(data.Value))
                    gridFilter.Attributes.Add(data.Key, data.Value);
            }

            return MvcHtmlString.Create(gridFilter.ToString());
        }
 protected virtual string RenderAdditionalContent(IGridColumn column)
 {
     if (_additionalRenders.Count == 0) return string.Empty;
     var sb = new StringBuilder();
     foreach (IGridColumnHeaderRenderer gridColumnRenderer in _additionalRenders)
     {
         sb.Append(gridColumnRenderer.Render(column));
     }
     return sb.ToString();
 }
예제 #8
0
 public PagedGrid(List<Item> items)
 {
     _items = items;
     Data = items;
     Columns = new IGridColumn[]
               	{
               		new ItemNameColumn {HeaderText = "Item Name"},
               		new SalesCountColumn {HeaderText = "Sales Count"},
               		new PriceColumn {HeaderText = "Price"}
               	};
     PageSize = 4;
 }
예제 #9
0
        public GridFiltersTests()
        {
            Expression<Func<GridModel, String>> expression = (model) => model.Name;
            column = Substitute.For<IGridColumn<GridModel>>();
            column.Grid.Query = new NameValueCollection();
            column.Expression.Returns(expression);
            column.IsMultiFilterable = true;
            column.Grid.Name = "Grid";
            column.Name = "Name";

            filters = new GridFilters();
        }
예제 #10
0
        public IHtmlString Render(IGridColumn column, IGridCell cell)
        {
            string cssStyles = GetCssStylesString();
            string cssClass = GetCssClassesString();

            var builder = new TagBuilder("td");
            if (!string.IsNullOrWhiteSpace(cssClass))
                builder.AddCssClass(cssClass);
            if (!string.IsNullOrWhiteSpace(cssStyles))
                builder.MergeAttribute("style", cssStyles);
            builder.MergeAttribute("data-name", column.Name);

            builder.InnerHtml = cell.ToString();

            return MvcHtmlString.Create(builder.ToString());
        }
예제 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GridColumnViewModel"/> class.
        /// </summary>
        /// <param name="parentColumnList">The parent column list.</param>
        /// <param name="column">The column.</param>
        /// <param name="parentNotifyLayoutChanged">The parent notify layout changed.</param>
        /// <param name="index">The index.</param>
        public GridColumnViewModel(IList<IGridColumn> parentColumnList, IGridColumn column, INotifyLayoutChanged parentNotifyLayoutChanged, int index)
        {
            _parentColumnList = parentColumnList;
            _column = column;
            _parentNotifyLayoutChanged = parentNotifyLayoutChanged;
            OnGroupLevelChanged();
            Index = index;
            //_layoutChanged = layoutChanged;

            Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(x => this.PropertyChanged += x,
                x => this.PropertyChanged -= x)
                .Where(et => et.EventArgs.PropertyName == "Width")
                .Throttle(TimeSpan.FromMilliseconds(500), DispatcherScheduler.Current)
                .Subscribe(d => OnLayoutChanged());

            InitializeDefaultValues();
        }
예제 #12
0
        public IHtmlString Render(IGridColumn column)
        {
            string cssStyles = GetCssStylesString();
            string cssClass = GetCssClassesString();

            if (!string.IsNullOrWhiteSpace(column.Width))
                cssStyles = string.Concat(cssStyles, " width:", column.Width, ";").Trim();

            var builder = new TagBuilder("th");
            if (!string.IsNullOrWhiteSpace(cssClass))
                builder.AddCssClass(cssClass);
            if (!string.IsNullOrWhiteSpace(cssStyles))
                builder.MergeAttribute("style", cssStyles);
            builder.InnerHtml = RenderAdditionalContent(column);

            return MvcHtmlString.Create(builder.ToString());
        }
        public void AddActionLink_Authorized_Renders()
        {
            AllTypesView view = new AllTypesView();

            Authorization.Provider = Substitute.For <IAuthorizationProvider>();
            UrlHelper urlHelper = new UrlHelper(columns.Grid.HttpContext.Request.RequestContext);

            Authorization.Provider.IsAuthorizedFor(Arg.Any <Int32?>(), Arg.Any <String>(), Arg.Any <String>(), "Details").Returns(true);

            IGridColumn <AllTypesView> column = columns.AddActionLink("Details", "fa fa-info");

            String actual   = column.ValueFor(new GridRow <AllTypesView>(view)).ToString();
            String expected =
                $"<a class=\"details-action\" href=\"{urlHelper.Action("Details", new { view.Id })}\">" +
                "<i class=\"fa fa-info\"></i>" +
                "</a>";

            Assert.Equal(expected, actual);
        }
        private void ChangeValue(ChangeEventArgs e, IGridColumn column, string typeAttr = null)
        {
            if (string.IsNullOrWhiteSpace(e.Value.ToString()))
            {
                SetValue(null, column);
            }
            else
            {
                if (typeAttr == "week")
                {
                    var value = DateTimeUtils.FromIso8601WeekDate(e.Value.ToString());
                    SetValue(value, column);
                }
                else if (typeAttr == "month")
                {
                    var value = DateTimeUtils.FromMonthDate(e.Value.ToString());
                    SetValue(value, column);
                }
                else
                {
                    var(type, _) = ((IGridColumn <T>)column).GetTypeAndValue(Item);
                    var typeConverter = TypeDescriptor.GetConverter(type);
                    if (typeConverter != null)
                    {
                        try
                        {
                            var value = typeConverter.ConvertFrom(e.Value.ToString());
                            SetValue(value, column);

                            if (typeAttr == "file")
                            {
                                _shouldRender = true;
                                StateHasChanged();
                            }
                        }
                        catch (Exception)
                        {
                            SetValue(null, column);
                        }
                    }
                }
            }
        }
예제 #15
0
        public void RemoveFilterParameter(IGridColumn column)
        {
            var filters = _query.Get(QueryStringFilterSettings.DefaultTypeQueryParameter).ToArray();

            if (filters != null)
            {
                var newFilters = filters.Where(r => !r.ToLower().StartsWith(column.Name.ToLower()
                                                                            + QueryStringFilterSettings.FilterDataDelimeter));
                _query[QueryStringFilterSettings.DefaultTypeQueryParameter] =
                    new StringValues(newFilters.ToArray());
            }

            AddClearInitFilters(column);

            _settings = new QueryStringGridSettingsProvider(_query);
            _columnsCollection.SortSettings = _settings.SortSettings;
            _columnsCollection.UpdateColumnsSorting();
            ((GridPager)_pager).Query = _query;
        }
예제 #16
0
        public IQueryable <T> Process(IQueryable <T> items)
        {
            if (_grid.SearchingEnabled && !string.IsNullOrWhiteSpace(_settings.SearchValue))
            {
                ParameterExpression parameter        = Expression.Parameter(typeof(T), "x");
                Expression          binaryExpression = null;

                foreach (IGridColumn column in _grid.Columns)
                {
                    IGridColumn <T> gridColumn = column as IGridColumn <T>;
                    if (gridColumn == null)
                    {
                        continue;
                    }
                    if (gridColumn.Search == null)
                    {
                        continue;
                    }

                    if (binaryExpression == null)
                    {
                        binaryExpression = gridColumn.Search.GetExpression(_settings.SearchValue,
                                                                           _grid.SearchingOnlyTextColumns, parameter);
                    }
                    else
                    {
                        Expression expression = gridColumn.Search.GetExpression(_settings.SearchValue,
                                                                                _grid.SearchingOnlyTextColumns, parameter);
                        if (expression != null)
                        {
                            binaryExpression = Expression.OrElse(binaryExpression, expression);
                        }
                    }
                }

                // apply extension to items
                if (binaryExpression != null)
                {
                    return(items.Where(Expression.Lambda <Func <T, bool> >(binaryExpression, parameter)));
                }
            }
            return(items);
        }
예제 #17
0
        public void Add_GridColumn()
        {
            IGridColumn <GridModel, Object> expected = new GridColumn <GridModel, Object>(columns.Grid, model => "");
            IGridColumn <GridModel, Object> actual   = columns.Add();

            Assert.Equal("", actual.Expression.Compile().Invoke(new GridModel()));
            Assert.Equal(expected.Filter.IsEnabled, actual.Filter.IsEnabled);
            Assert.Equal(expected.Title.ToString(), actual.Title.ToString());
            Assert.Equal(expected.Sort.IsEnabled, actual.Sort.IsEnabled);
            Assert.Equal(expected.ProcessorType, actual.ProcessorType);
            Assert.Equal(expected.Filter.Type, actual.Filter.Type);
            Assert.Equal(expected.Filter.Name, actual.Filter.Name);
            Assert.Equal(expected.CssClasses, actual.CssClasses);
            Assert.Equal(expected.Sort.Order, actual.Sort.Order);
            Assert.Equal(expected.IsEncoded, actual.IsEncoded);
            Assert.Equal(expected.Format, actual.Format);
            Assert.Equal(expected.Name, actual.Name);
            Assert.Equal(expected.Grid, actual.Grid);
        }
 protected void ChangeDateTime(ChangeEventArgs e, IGridColumn column)
 {
     if (string.IsNullOrWhiteSpace(e.Value.ToString()))
     {
         ChangeValue(null, column);
     }
     else
     {
         DateTime value;
         if (DateTime.TryParse(e.Value.ToString(), out value))
         {
             ChangeValue(value, column);
         }
         else
         {
             ChangeValue(null, column);
         }
     }
 }
예제 #19
0
        public void AddAction_Authorized_Renders()
        {
            AllTypesView   view          = new AllTypesView();
            StringWriter   writer        = new StringWriter();
            LinkGenerator  link          = Substitute.For <LinkGenerator>();
            IAuthorization authorization = columns.Grid.ViewContext.HttpContext.RequestServices.GetService <IAuthorization>();

            authorization.IsGrantedFor(Arg.Any <Int32?>(), Arg.Any <String>(), Arg.Any <String>(), "Details").Returns(true);
            columns.Grid.ViewContext.HttpContext.RequestServices.GetService <LinkGenerator>().Returns(link);

            IGridColumn <AllTypesView, IHtmlContent> column = columns.AddAction("Details", "fa fa-info");

            column.ValueFor(new GridRow <AllTypesView>(view)).WriteTo(writer, HtmlEncoder.Default);

            String expected = "<a class=\"fa fa-info\" href=\"\"></a>";
            String actual   = writer.ToString();

            Assert.Equal(expected, actual);
        }
예제 #20
0
        public void AddAction_Authorized_Renders()
        {
            AllTypesView   view          = new();
            StringWriter   writer        = new();
            IUrlHelper     url           = context.HttpContext.RequestServices.GetRequiredService <IUrlHelperFactory>().GetUrlHelper(context);
            IAuthorization authorization = html.Grid.ViewContext !.HttpContext.RequestServices.GetRequiredService <IAuthorization>();

            url.Action(Arg.Any <UrlActionContext>()).Returns("/test");
            authorization.IsGrantedFor(Arg.Any <Int64?>(), "//Details").Returns(true);

            IGridColumn <AllTypesView, IHtmlContent> column = columns.AddAction("Details", "fa fa-info");

            column.ValueFor(new GridRow <AllTypesView>(view, 0)).WriteTo(writer, HtmlEncoder.Default);

            String expected = $"<a class=\"fa fa-info\" href=\"/test\" title=\"{Resource.ForAction("Details")}\"></a>";
            String actual   = writer.ToString();

            Assert.Equal(expected, actual);
        }
예제 #21
0
        void IGridControlAct.GridActEx(string actionName, int rowIndex, IGridColumn column, string[] paramValues)
        {
            var layoutView = control.DefaultView as LayoutView;

            if (layoutView == null || actionName != "SetTableFilter")
            {
                if (actionName == "SelectAll")
                {
                    ((ColumnView)control.DefaultView).SelectAll();
                }
                else
                {
                    GridActEx(actionName, rowIndex, column, paramValues);
                }
            }
            else
            {
                layoutView.ActiveFilterCriteria = CriteriaOperator.Parse(paramValues[0]);
            }
        }
        private void OnFileChange(IGridColumn column, IFileListEntry[] files)
        {
            if (!column.MultipleInput && files.Length > 1)
            {
                files = new IFileListEntry[] { files[0] }
            }
            ;

            if (Files.ContainsKey(column.FieldName))
            {
                Files[column.FieldName] = files;
            }
            else
            {
                Files.Add(column.FieldName, files);
            }

            _shouldRender = true;
            StateHasChanged();
        }
예제 #23
0
        public void AddActionLink_OnModelWihoutKeyPropertyThrows()
        {
            Func <Object, String>          deleteFunc    = null;
            IGridColumn <Object>           objectColumn  = SubstituteColumn <Object>();
            IGridColumnCollection <Object> objectColumns = SubstituteColumns <Object, String>(objectColumn);

            objectColumn
            .RenderValueAs(Arg.Any <Func <Object, String> >())
            .Returns(objectColumn)
            .AndDoes(info =>
            {
                deleteFunc = info.Arg <Func <Object, String> >();
            });

            objectColumns.AddActionLink(LinkAction.Delete);

            Exception expected = Assert.Throws <Exception>(() => deleteFunc.Invoke(new Object()));

            Assert.AreEqual(expected.Message, "Object type does not have a key property.");
        }
예제 #24
0
        public IGridColumnFilter <T> GetFilter <T>(IGridColumn <T> column)
        {
            String[] keys = column
                            .Grid
                            .Query
                            .Keys
                            .Where(key =>
                                   (key ?? "").StartsWith(column.Grid.Name + "-" + column.Name + "-") &&
                                   key != column.Grid.Name + "-" + column.Name + "-Op")
                            .ToArray();

            GridColumnFilter <T> filter = new GridColumnFilter <T>();

            filter.Second   = GetSecondFilter(column, keys);
            filter.First    = GetFirstFilter(column, keys);
            filter.Operator = GetOperator(column);
            filter.Column   = column;

            return(filter);
        }
예제 #25
0
        public void GetFilter_ReturnsFilter()
        {
            IGridColumn <GridModel> column = Substitute.For <IGridColumn <GridModel> >();
            Expression <Func <GridModel, String> > expression = (model) => "Test";

            column.Expression.Returns(expression);

            IGridFilter <GridModel> actual   = filters.GetFilter <GridModel>(column, "Equals", "Test");
            IGridFilter <GridModel> expected = new StringEqualsFilter <GridModel>();

            expected.FilteredExpression = column.Expression;
            expected.Type  = "Equals";
            expected.Value = "Test";

            Assert.AreEqual(expected.FilteredExpression, actual.FilteredExpression);
            Assert.AreEqual(expected.ProcessorType, actual.ProcessorType);
            Assert.AreEqual(expected.GetType(), actual.GetType());
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected.Type, actual.Type);
        }
예제 #26
0
        protected virtual IHtmlContent RenderAdditionalContent(IGridColumn column)
        {
            HtmlString strHtml = new HtmlString(string.Empty);

            if (_additionalRenders.Count == 0)
            {
                return(strHtml);
            }


            using (System.IO.StringWriter ms = new System.IO.StringWriter())
            {
                foreach (IGridColumnHeaderRenderer gridColumnRenderer in _additionalRenders)
                {
                    gridColumnRenderer.Render(column).WriteTo(ms, System.Text.Encodings.Web.HtmlEncoder.Default);
                }

                return(new HtmlString(ms.ToString()));
            }
        }
예제 #27
0
        public void GetFilter_GetsFilterForNullableType()
        {
            IGridColumn <GridModel> column = Substitute.For <IGridColumn <GridModel> >();
            Expression <Func <GridModel, Int32?> > expression = (model) => 0;

            column.Expression.Returns(expression);

            IGridFilter <GridModel> actual   = filters.GetFilter <GridModel>(column, "Equals", "1");
            IGridFilter <GridModel> expected = new Int32Filter <GridModel>();

            expected.FilteredExpression = column.Expression;
            expected.Type  = "Equals";
            expected.Value = "1";

            Assert.AreEqual(expected.FilteredExpression, actual.FilteredExpression);
            Assert.AreEqual(expected.ProcessorType, actual.ProcessorType);
            Assert.AreEqual(expected.GetType(), actual.GetType());
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected.Type, actual.Type);
        }
예제 #28
0
        private void AddClearInitFilters(IGridColumn column)
        {
            if (ComponentOptions.AllowMultipleFilters)
            {
                if (column.InitialFilterSettings != ColumnFilterValue.Null)
                {
                    if (_query.ContainsKey(QueryStringFilterSettings.DefaultClearInitFilterQueryParameter))
                    {
                        StringValues clearInitFilters = _query[QueryStringFilterSettings.DefaultClearInitFilterQueryParameter];
                        if (!clearInitFilters.Contains(column.Name))
                        {
                            clearInitFilters = StringValues.Concat(clearInitFilters, column.Name);
                            _query[QueryStringFilterSettings.DefaultClearInitFilterQueryParameter] = clearInitFilters;
                        }
                    }
                    else
                    {
                        _query.Add(QueryStringFilterSettings.DefaultClearInitFilterQueryParameter, column.Name);
                    }
                }
            }
            else
            {
                StringValues clearInitFilters = new StringValues();

                var columnsToAdd = Columns.Where(r => r.InitialFilterSettings != ColumnFilterValue.Null);
                foreach (var columnToAdd in columnsToAdd)
                {
                    clearInitFilters = StringValues.Concat(clearInitFilters, columnToAdd.Name);
                }

                if (_query.ContainsKey(QueryStringFilterSettings.DefaultClearInitFilterQueryParameter))
                {
                    _query[QueryStringFilterSettings.DefaultClearInitFilterQueryParameter] = clearInitFilters;
                }
                else
                {
                    _query.Add(QueryStringFilterSettings.DefaultClearInitFilterQueryParameter, clearInitFilters);
                }
            }
        }
예제 #29
0
        public void Add_Expression_GridColumn()
        {
            Expression <Func <GridModel, String?> > expression = (model) => model.Name;

            IGridColumn <GridModel, String?> expected = new GridColumn <GridModel, String?>(columns.Grid, expression);
            IGridColumn <GridModel, String?> actual   = columns.Add(expression);

            Assert.Equal(expected.Filter.IsEnabled, actual.Filter.IsEnabled);
            Assert.Equal(expected.Title.ToString(), actual.Title.ToString());
            Assert.Equal(expected.Sort.IsEnabled, actual.Sort.IsEnabled);
            Assert.Equal(expected.ProcessorType, actual.ProcessorType);
            Assert.Equal(expected.Filter.Type, actual.Filter.Type);
            Assert.Equal(expected.Filter.Name, actual.Filter.Name);
            Assert.Equal(expected.Expression, actual.Expression);
            Assert.Equal(expected.CssClasses, actual.CssClasses);
            Assert.Equal(expected.Sort.Order, actual.Sort.Order);
            Assert.Equal(expected.IsEncoded, actual.IsEncoded);
            Assert.Equal(expected.Format, actual.Format);
            Assert.Equal(expected.Name, actual.Name);
            Assert.Equal(expected.Grid, actual.Grid);
        }
예제 #30
0
        public void AddAction_NoAuthorization_Renders()
        {
            AllTypesView      view    = new AllTypesView();
            StringWriter      writer  = new StringWriter();
            IUrlHelper        url     = Substitute.For <IUrlHelper>();
            IUrlHelperFactory factory = Substitute.For <IUrlHelperFactory>();

            html.Grid.ViewContext?.HttpContext.RequestServices.GetService(typeof(IUrlHelperFactory)).Returns(factory);
            html.Grid.ViewContext?.HttpContext.RequestServices.GetService(typeof(IAuthorization)).ReturnsNull();
            factory.GetUrlHelper(html.Grid.ViewContext).Returns(url);
            url.Action(Arg.Any <UrlActionContext>()).Returns("/test");

            IGridColumn <AllTypesView, IHtmlContent> column = columns.AddAction("Details", "fa fa-info");

            column.ValueFor(new GridRow <AllTypesView>(view, 0)).WriteTo(writer, HtmlEncoder.Default);

            String expected = $"<a class=\"fa fa-info\" href=\"/test\" title=\"{Resource.ForAction("Details")}\"></a>";
            String actual   = writer.ToString();

            Assert.Equal(expected, actual);
        }
예제 #31
0
        private bool ValidateFiltering(TestGrid grid, IGridColumn column, ColumnFilterValue value,
                                       Func <TestModel, bool> filterExpression)
        {
            grid.AddFilterParameter(column, new FilterCollection(value.FilterType.ToString("d"), value.FilterValue));
            grid.UpdateGrid().Wait();

            IEnumerable <TestModel> resultCollection = grid.GetItemsToDisplay();

            if (!resultCollection.Any())
            {
                Assert.Fail("No items to compare");
            }

            IEnumerable <TestModel> etalonCollection = _repo.GetAll().Where(filterExpression);

            if (!ValidateCollectionsTheSame(resultCollection, etalonCollection))
            {
                return(false);
            }
            return(true);
        }
예제 #32
0
        string IGridBase.GetCellValue(int row, IGridColumn column)
        {
            var layoutView = control.DefaultView as LayoutView;

            if (layoutView == null)
            {
                return(base.GetCellValue(row, column));
            }
            var gridColumn  = ((DXGridColumn)column).Column;
            var displayText = layoutView.GetRowCellDisplayText(row, gridColumn);
            var value       = layoutView.GetRowCellValue(row, gridColumn);

            if (value is bool)
            {
                if (string.IsNullOrEmpty(displayText) || displayText == "Checked" || displayText == "Unchecked")
                {
                    displayText = value.ToString();
                }
            }
            return(displayText);
        }
예제 #33
0
        public void AddActionLink_OnModelWihoutKeyPropertyThrows()
        {
            Func <Object, String>          renderer      = null;
            IGridColumn <Object>           objectColumn  = SubstituteColumn <Object>();
            IGridColumnCollection <Object> objectColumns = SubstituteColumns <Object, String>(objectColumn);

            objectColumn
            .RenderValueAs(Arg.Any <Func <Object, String> >())
            .Returns(objectColumn)
            .AndDoes(info =>
            {
                renderer = info.Arg <Func <Object, String> >();
            });

            objectColumns.AddActionLink("Delete", "fa fa-times");

            String actual   = Assert.Throws <Exception>(() => renderer.Invoke(new Object())).Message;
            String expected = "Object type does not have a key property.";

            Assert.AreEqual(expected, actual);
        }
예제 #34
0
        public IHtmlString Render(IGridColumn column, IGridCell cell)
        {
            string cssStyles = GetCssStylesString();
            string cssClass  = GetCssClassesString();

            var builder = new TagBuilder("td");

            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                builder.AddCssClass(cssClass);
            }
            if (!string.IsNullOrWhiteSpace(cssStyles))
            {
                builder.MergeAttribute("style", cssStyles);
            }
            builder.MergeAttribute("data-name", column.Name);

            builder.InnerHtml = cell.ToString();

            return(MvcHtmlString.Create(builder.ToString()));
        }
예제 #35
0
        public virtual IEnumerable <SelectListItem> OptionsFor <T, TValue>(IGridColumn <T, TValue> column)
        {
            Type?type = GetElementType(typeof(TValue)) ?? typeof(TValue);
            List <SelectListItem> options = new List <SelectListItem>();

            type = Nullable.GetUnderlyingType(type) ?? type;

            if (type == typeof(Boolean))
            {
                options.Add(new SelectListItem {
                    Value = "", Text = BooleanEmptyOptionText?.Invoke()
                });
                options.Add(new SelectListItem {
                    Value = "true", Text = BooleanTrueOptionText?.Invoke()
                });
                options.Add(new SelectListItem {
                    Value = "false", Text = BooleanFalseOptionText?.Invoke()
                });
            }
            else if (type.IsEnum)
            {
                options.Add(new SelectListItem());

                IEnumerable <SelectListItem>?items = column.Grid
                                                     .ViewContext?
                                                     .HttpContext
                                                     .RequestServices
                                                     .GetRequiredService <IHtmlHelper>()
                                                     .GetEnumSelectList(type)
                                                     .OrderBy(item => item.Text);

                if (items != null)
                {
                    options.AddRange(items);
                }
            }

            return(options);
        }
예제 #36
0
        public IGridColumnFilter <T> GetFilter <T>(IGridColumn <T> column)
        {
            String prefix = String.IsNullOrEmpty(column.Grid.Name) ? "" : column.Grid.Name + "-";

            String[] keys = column
                            .Grid
                            .Query
                            .AllKeys
                            .Where(key =>
                                   (key ?? "").StartsWith(prefix + column.Name + "-") &&
                                   key != prefix + column.Name + "-Op")
                            .ToArray();

            GridColumnFilter <T> filter = new GridColumnFilter <T>();

            filter.Second   = GetSecondFilter(prefix, column, keys);
            filter.First    = GetFirstFilter(prefix, column, keys);
            filter.Operator = GetOperator(prefix, column);
            filter.Column   = column;

            return(filter);
        }
        public void AddActionLink_NullAuthorization_Renders()
        {
            AllTypesView view   = new AllTypesView();
            StringWriter writer = new StringWriter();
            IRouter      router = Substitute.For <IRouter>();

            columns.Grid.ViewContext.HttpContext.RequestServices.GetService <IAuthorizationProvider>().Returns(null as IAuthorizationProvider);
            router.GetVirtualPath(Arg.Any <VirtualPathContext>()).Returns(new VirtualPathData(router, "/test"));
            columns.Grid.ViewContext.RouteData.Routers.Add(router);

            IGridColumn <AllTypesView> column = columns.AddActionLink("Details", "fa fa-info");

            column.ValueFor(new GridRow <AllTypesView>(view)).WriteTo(writer, HtmlEncoder.Default);

            String actual   = writer.ToString();
            String expected =
                $"<a class=\"details-action\" href=\"/test\">" +
                "<i class=\"fa fa-info\"></i>" +
                "</a>";

            Assert.Equal(expected, actual);
        }
예제 #38
0
        protected IHtmlContent GetSortHeaderContent(IGridColumn column)
        {
            var sortTitle = new TagBuilder("div");

            sortTitle.AddCssClass("grid-header-title");

            if (column.SortEnabled)
            {
                var columnHeaderLink = new TagBuilder("a");
                //changed by LM
                columnHeaderLink.InnerHtml.SetHtmlContent(column.Title);

                string url = GetSortUrl(column.Name, column.Direction);
                columnHeaderLink.Attributes.Add("href", url);
                sortTitle.InnerHtml.AppendHtml(columnHeaderLink);
            }
            else
            {
                var columnTitle = new TagBuilder("span");

                //changed by LM
                columnTitle.InnerHtml.SetHtmlContent(column.Title);
                sortTitle.InnerHtml.AppendHtml(columnTitle);
            }

            if (column.IsSorted)
            {
                sortTitle.AddCssClass("sorted");
                sortTitle.AddCssClass(column.Direction == GridSortDirection.Ascending ? "sorted-asc" : "sorted-desc");

                var sortArrow = new TagBuilder("span");
                sortArrow.AddCssClass("grid-sort-arrow");
                sortTitle.InnerHtml.AppendHtml(sortArrow);
            }


            return(sortTitle);
        }
예제 #39
0
        private IGridFilter GetFilter <T>(IGridColumn <T> column, String type, String value)
        {
            Type valueType = Nullable.GetUnderlyingType(column.Expression.ReturnType) ?? column.Expression.ReturnType;

            if (!Table.ContainsKey(valueType))
            {
                return(null);
            }

            IDictionary <String, Type> typedFilters = Table[valueType];

            if (!typedFilters.ContainsKey(type))
            {
                return(null);
            }

            IGridFilter filter = (IGridFilter)Activator.CreateInstance(typedFilters[type]);

            filter.Value = value;
            filter.Type  = type;

            return(filter);
        }
예제 #40
0
        private String GetName(IGridColumn <T, TValue> column)
        {
            Type type = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue);

            if (type.GetTypeInfo().IsEnum)
            {
                return("enum");
            }

            switch (Type.GetTypeCode(type))
            {
            case TypeCode.SByte:
            case TypeCode.Byte:
            case TypeCode.Int16:
            case TypeCode.UInt16:
            case TypeCode.Int32:
            case TypeCode.UInt32:
            case TypeCode.Int64:
            case TypeCode.UInt64:
            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.Decimal:
                return("number");

            case TypeCode.String:
                return("text");

            case TypeCode.DateTime:
                return("date");

            case TypeCode.Boolean:
                return("boolean");

            default:
                return(type == typeof(Guid) ? "guid" : null);
            }
        }
예제 #41
0
        public static int ColumnLevel(this IEnumerable<IGridColumn> columns, IGridColumn column)
        {
            columns = columns.Where(c => c.Visible);

            if (!columns.Any())
            {
                return 0;
            }

            var counter = 1;

            if (columns.Any(c => c == column))
            {
                return counter;
            }

            var children = columns.SelectMany(GetChildColumnsForLevel);
            if (children.Any())
            {
                return counter += children.ColumnLevel(column);
            }

            return counter;
        }
예제 #42
0
        public static IEnumerable<IGridColumn> ColumnParentsAndSelf(this IEnumerable<IGridColumn> columns, IGridColumn column)
        {
            var parents = new List<IGridColumn>();

            if (columns.Any(c => c == column))
            {
                parents.Add(column);

                return parents;
            }

            foreach (var c in columns.OfType<IGridColumnGroup>())
            {
                var result = c.Columns.ColumnParentsAndSelf(column);
                if (result.Any())
                {
                    parents.Add(c);
                    parents = parents.Concat(result).ToList();
                    break;
                }
            }

            return parents;
        }
        protected string GetSortHeaderContent(IGridColumn column)
        {
            var sortTitle = new TagBuilder("div");

            sortTitle.AddCssClass("grid-header-title");

            if (column.SortEnabled)
            {
                var columnHeaderLink = new TagBuilder("a")
                {
                    InnerHtml = column.Title
                };
                string url = GetSortUrl(column.Name, column.Direction);
                columnHeaderLink.Attributes.Add("href", url);
                sortTitle.InnerHtml += columnHeaderLink.ToString();
            }
            else
            {
                var columnTitle = new TagBuilder("span")
                {
                    InnerHtml = column.Title
                };
                sortTitle.InnerHtml += columnTitle.ToString();
            }

            if (column.IsSorted)
            {
                sortTitle.AddCssClass("sorted");
                sortTitle.AddCssClass(column.Direction == GridSortDirection.Ascending ? "sorted-asc" : "sorted-desc");

                var sortArrow = new TagBuilder("span");
                sortArrow.AddCssClass("grid-sort-arrow");
                sortTitle.InnerHtml += sortArrow.ToString();
            }
            return(sortTitle.ToString());
        }
        private void ApplyColumnAnnotationSettings(IGridColumn <T> column, GridColumnAttribute options)
        {
            column.Encoded(options.EncodeEnabled)
            .Sanitized(options.SanitizeEnabled)
            .Filterable(options.FilterEnabled)
            .Sortable(options.SortEnabled);

            GridSortDirection?initialDirection = options.GetInitialSortDirection();

            if (initialDirection.HasValue)
            {
                column.SortInitialDirection(initialDirection.Value);
            }

            if (!string.IsNullOrEmpty(options.FilterWidgetType))
            {
                column.SetFilterWidgetType(options.FilterWidgetType);
            }

            if (!string.IsNullOrEmpty(options.Format))
            {
                column.Format(options.Format);
            }
            if (!string.IsNullOrEmpty(options.Title))
            {
                column.Titled(options.Title);
            }
            if (!string.IsNullOrEmpty(options.Width))
            {
                column.Width = options.Width;
            }
            if (!string.IsNullOrEmpty(options.ToolTip))
            {
                column.ToolTip = options.ToolTip;
            }
        }
 public ABPageTestHitsReport_ShowTimes_GridItemColumn(IGridColumn gridColumn, object dataItem, object propertyValue)
     : base(gridColumn, dataItem, propertyValue)
 {
 }
 public GridColHtmlBuilder(IGridColumn column)
 {
     Guard.IsNotNull(column, "column");
     this.column = column;
 }
예제 #47
0
 public EditGridActionItemColumn(IGridColumn gridColumn, object dataItem, object propertyValue)
     : base(gridColumn, dataItem, propertyValue)
 {
 }
예제 #48
0
 public GridItemColumn(IGridColumn gridColumn, object dataItem, object propertyValue)
 {
     this.GridColumn = gridColumn;
     this.DataItem = dataItem;
     this.PropertyValue = propertyValue;
 }
 public IGridCellBuilder CreateGroupFooterCellBuilder(IGridColumn column, IEnumerable<AggregateResult> aggregatesResults)
 {
     return column.CreateGroupFooterBuilder(aggregatesResults);
 }
예제 #50
0
 public Page_Publish_GridItemColumn(IGridColumn gridColumn, object dataItem, object propertyValue)
     : base(gridColumn, dataItem, propertyValue)
 {
 }
 public IGridDataCellBuilder CreateDisplayCellBuilder(IGridColumn column, IGridHtmlHelper htmlHelper)
 {
     return column.CreateDisplayBuilder(htmlHelper);
 }
예제 #52
0
 public TextFolder_Name_GridItemColumn(IGridColumn gridColumn, object dataItem, object propertyValue)
     : base(gridColumn, dataItem, propertyValue)
 {
 }
 public PendingWorflowItem_Edit_GridItemColumn(IGridColumn gridColumn, object dataItem, object propertyValue)
     : base(gridColumn, dataItem, propertyValue)
 {
 }
예제 #54
0
 public Script_FileName_GridItemColumn(IGridColumn gridColumn, object dataItem, object propertyValue)
     : base(gridColumn, dataItem, propertyValue)
 {
 }
예제 #55
0
 public Label_Value_GridItemColumn(IGridColumn gridColumn, object dataItem, object propertyValue)
     : base(gridColumn, dataItem, propertyValue)
 {
 }
 public IGridDataCellBuilder CreateInsertCellBuilder(IGridColumn column, IGridHtmlHelper htmlHelper)
 {
     return column.CreateInsertBuilder(htmlHelper);
 }
예제 #57
0
 public ArrayGridItemColumn(IGridColumn gridColumn, object dataItem, object propertyValue)
     : base(gridColumn, dataItem, propertyValue)
 {
 }
 public IHtmlString Render(IGridColumn column)
 {
     return MvcHtmlString.Create(GetSortHeaderContent(column));
 }
예제 #59
0
 public Inheritable_Status_GridItemColumn(IGridColumn gridColumn, object dataItem, object propertyValue)
     : base(gridColumn, dataItem, propertyValue)
 {
 }
 public IGridCellBuilder CreateHeaderCellBuilder(IGridColumn column)
 {
     return column.CreateHeaderBuilder();
 }