Example #1
0
        protected override string PropertyValidation(PropertyInfo pi)
        {
            if (token != null && token.ParseException == null)
            {
                if (pi.Name == nameof(Token))
                {
                    return(QueryUtils.CanFilter(token.Token));
                }

                if (pi.Name == nameof(Operation))
                {
                    FilterType?filterType = QueryUtils.TryGetFilterType(Token.Token.Type);

                    if (filterType == null)
                    {
                        return(UserQueryMessage._0IsNotFilterable.NiceToString().FormatWith(token));
                    }

                    if (!QueryUtils.GetFilterOperations(filterType.Value).Contains(Operation))
                    {
                        return(UserQueryMessage.TheFilterOperation0isNotCompatibleWith1.NiceToString().FormatWith(Operation, filterType));
                    }
                }

                if (pi.Name == nameof(ValueString))
                {
                    return(FilterValueConverter.TryParse(ValueString, Token.Token.Type, out object val, Operation.IsList()));
                }
            }

            return(null);
        }
Example #2
0
        public ContentResult AddFilter(string webQueryName, string tokenName, int index)
        {
            ChartRequest request = this.ExtractChartRequestCtx(null).Value;

            QueryDescription qd = DynamicQueryManager.Current.QueryDescription(request.QueryName);

            var          token = QueryUtils.Parse(tokenName, qd, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement | (request.GroupResults ? SubTokensOptions.CanAggregate : 0));
            FilterOption fo    = new FilterOption(tokenName, null)
            {
                Token     = token,
                Operation = QueryUtils.GetFilterOperations(QueryUtils.GetFilterType(token.Type)).FirstEx(),
            };

            return(Content(FilterBuilderHelper.NewFilter(
                               FinderController.CreateHtmlHelper(this), fo, new Context(null, this.Prefix()), index).ToHtmlString()));
        }
Example #3
0
        public override void OnSelected(DynamicQueryOmniboxResult r, Window window)
        {
            Finder.Explore(new ExploreOptions(r.QueryNameMatch.Value)
            {
                FilterOptions = r.Filters.Select(f =>
                {
                    FilterType ft = QueryUtils.GetFilterType(f.QueryToken.Type);

                    var operation = f.Operation;
                    if (operation != null && !QueryUtils.GetFilterOperations(ft).Contains(f.Operation.Value))
                    {
                        MessageBox.Show(window, "Operation {0} not compatible with {1}".FormatWith(operation, f.QueryToken.ToString()));
                        operation = FilterOperation.EqualTo;
                    }

                    object value = f.Value;
                    if (value as string == DynamicQueryOmniboxResultGenerator.UnknownValue)
                    {
                        MessageBox.Show(window, "Unknown value for {0}".FormatWith(f.QueryToken.ToString()));
                        value = null;
                    }
                    else
                    {
                        if (value is Lite <IEntity> )
                        {
                            Server.FillToStr((Lite <IEntity>)value);
                        }
                    }

                    return(new FilterOption
                    {
                        Token = f.QueryToken,
                        Operation = operation ?? FilterOperation.EqualTo,
                        Value = value,
                    });
                }).ToList(),
                SearchOnLoad = r.Filters.Any(),
            });
        }
        public ContentResult AddFilter(string webQueryName, string tokenName, int index, string prefix, string value)
        {
            object queryName = Finder.ResolveQueryName(webQueryName);

            FilterOption fo = new FilterOption(tokenName, null);

            QueryDescription qd = DynamicQueryManager.Current.QueryDescription(queryName);

            fo.Token = QueryUtils.Parse(tokenName, qd, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement);

            fo.Operation = QueryUtils.GetFilterOperations(QueryUtils.GetFilterType(fo.Token.Type)).FirstEx();

            try
            {
                fo.Value = FindOptionsModelBinder.Convert(value, fo.Token.Type);
            }
            catch (Exception)
            {
                //Cell Value must be custom and cannot be parsed automatically: Leave value to null
            }

            return(Content(FilterBuilderHelper.NewFilter(CreateHtmlHelper(this), fo, new Context(null, prefix), index).ToHtmlString()));
        }
Example #5
0
        protected override string?PropertyValidation(PropertyInfo pi)
        {
            if (IsGroup)
            {
                if (pi.Name == nameof(GroupOperation) && GroupOperation == null)
                {
                    return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName()));
                }


                if (token != null && token.ParseException == null)
                {
                    if (pi.Name == nameof(Token))
                    {
                        return(QueryUtils.CanFilter(token.Token));
                    }
                }
            }
            else
            {
                if (pi.Name == nameof(Operation) && Operation == null)
                {
                    return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName()));
                }

                if (pi.Name == nameof(Token) && Token == null)
                {
                    return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName()));
                }

                if (token != null && token.ParseException == null)
                {
                    if (pi.Name == nameof(Token))
                    {
                        return(QueryUtils.CanFilter(token.Token));
                    }

                    if (pi.Name == nameof(Operation) && Operation != null)
                    {
                        FilterType?filterType = QueryUtils.TryGetFilterType(Token !.Token.Type);

                        if (filterType == null)
                        {
                            return(UserQueryMessage._0IsNotFilterable.NiceToString().FormatWith(token));
                        }

                        if (!QueryUtils.GetFilterOperations(filterType.Value).Contains(Operation.Value))
                        {
                            return(UserQueryMessage.TheFilterOperation0isNotCompatibleWith1.NiceToString().FormatWith(Operation, filterType));
                        }
                    }

                    if (pi.Name == nameof(ValueString))
                    {
                        var result = FilterValueConverter.TryParse(ValueString, Token !.Token.Type, Operation !.Value.IsList());
                        return(result is Result <object> .Error e ? e.ErrorText : null);
                    }
                }
            }

            return(null);
        }
Example #6
0
        public static MvcHtmlString NewFilter(this HtmlHelper helper, FilterOption filterOptions, Context context, int index)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            FilterType             filterType         = QueryUtils.GetFilterType(filterOptions.Token.Type);
            List <FilterOperation> possibleOperations = QueryUtils.GetFilterOperations(filterType);

            var id = context.Compose("trFilter", index.ToString());

            using (sb.SurroundLine(new HtmlTag("tr").Id(id)))
            {
                using (sb.SurroundLine("td"))
                {
                    if (!filterOptions.Frozen)
                    {
                        sb.AddLine(new HtmlTag("a", context.Compose("btnDelete", index.ToString()))
                                   .Attr("title", SearchMessage.DeleteFilter.NiceToString())
                                   .Attr("onclick", JsModule.Finder["deleteFilter"](id).ToString())
                                   .Class("sf-line-button sf-remove")
                                   .InnerHtml(new HtmlTag("span").Class("glyphicon glyphicon-remove")));
                    }
                }

                using (sb.SurroundLine(new HtmlTag("td")))
                {
                    sb.AddLine(new HtmlTag("input")
                               .Attr("type", "hidden")
                               .Attr("value", filterOptions.Token.FullKey())
                               .ToHtmlSelf());

                    foreach (var t in filterOptions.Token.Follow(tok => tok.Parent).Reverse())
                    {
                        sb.AddLine(new HtmlTag("span")
                                   .Class("sf-filter-token")
                                   .Attr("title", t.NiceTypeName)
                                   .Attr("style", "color:" + t.TypeColor)
                                   .SetInnerText(t.ToString()).ToHtml());
                    }
                }

                using (sb.SurroundLine("td"))
                {
                    var dic = new Dictionary <string, object> {
                        { "class", "form-control" }
                    };
                    if (filterOptions.Frozen)
                    {
                        dic.Add("disabled", "disabled");
                    }

                    sb.AddLine(
                        helper.SafeDropDownList(
                            context.Compose("ddlSelector", index.ToString()),
                            possibleOperations.Select(fo =>
                                                      new SelectListItem
                    {
                        Text     = fo.NiceToString(),
                        Value    = fo.ToString(),
                        Selected = fo == filterOptions.Operation
                    }),
                            dic));
                }

                using (sb.SurroundLine("td"))
                {
                    Context valueContext = new Context(context, "value_" + index.ToString());

                    if (filterOptions.Frozen && !filterOptions.Token.Type.IsLite())
                    {
                        string txtValue = (filterOptions.Value != null) ? filterOptions.Value.ToString() : "";
                        sb.AddLine(helper.TextBox(valueContext.Prefix, txtValue, new { @readonly = "readonly" }));
                    }
                    else
                    {
                        sb.AddLine(PrintValueField(helper, valueContext, filterOptions));
                    }
                }
            }

            return(sb.ToHtml());
        }