示例#1
0
        protected internal virtual ActionResult SimpleFilterBuilderResult(ControllerBase controller, List <FilterOption> filterOptions)
        {
            object queryName = Finder.ResolveQueryName(controller.ParseValue <string>("webQueryName"));

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

            FilterOption.SetFilterTokens(filterOptions, qd, canAggregate: false);

            if (controller.ParseValue <bool>("returnHtml"))
            {
                controller.ViewData.Model = new Context(null, controller.Prefix());
                controller.ViewData[ViewDataKeys.FilterOptions] = filterOptions;

                return(new PartialViewResult
                {
                    ViewName = FilterRowsView,
                    ViewData = controller.ViewData,
                });
            }
            else
            {
                return(new ContentResult
                {
                    Content = filterOptions.ToString(";")
                });
            }
        }
示例#2
0
        protected internal virtual int QueryCount(CountOptions options)
        {
            var queryDescription = DynamicQueryManager.Current.QueryDescription(options.QueryName);

            FilterOption.SetFilterTokens(options.FilterOptions, queryDescription, canAggregate: false);

            var request = new QueryCountRequest
            {
                QueryName = options.QueryName,
                Filters   = options.FilterOptions.Select(f => f.ToFilter()).ToList()
            };

            return(DynamicQueryManager.Current.ExecuteQueryCount(request));
        }
示例#3
0
        protected internal virtual Lite <Entity> FindUnique(UniqueOptions options)
        {
            var queryDescription = DynamicQueryManager.Current.QueryDescription(options.QueryName);

            FilterOption.SetFilterTokens(options.FilterOptions, queryDescription, canAggregate: false);
            OrderOption.SetOrderTokens(options.OrderOptions, queryDescription, canAggregate: false);

            var request = new UniqueEntityRequest
            {
                QueryName  = options.QueryName,
                Filters    = options.FilterOptions.Select(f => f.ToFilter()).ToList(),
                Orders     = options.OrderOptions.Select(o => o.ToOrder()).ToList(),
                UniqueType = options.UniqueType,
            };

            return(DynamicQueryManager.Current.ExecuteUniqueEntity(request));
        }
示例#4
0
        public override string ToString()
        {
            if (FilterOptions.Any())
            {
                QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(QueryName);

                FilterOption.SetFilterTokens(FilterOptions, queryDescription, canAggregate: false);
            }

            var elements = Pagination != null?Pagination.GetElementsPerPage() : null;

            string options = new Sequence <string>
            {
                Pagination != null ? "pagination=" + pagination.GetMode().ToString() : null,
                elements != null ? "elems=" + elements : null,
                SearchOnLoad ? "searchOnLoad=true" : null,
                !Create ? "create=false": null,
                !Navigate ? "navigate=false": null,
                !AllowSelection ? "allowSelection=false" : null,
                !AllowChangeColumns ? "allowChangeColumns=false" : null,
                !AllowOrder ? "allowOrder=false" : null,
                !showHeader ? "showHeader=false" : null,
                !showFilters ? "showFilters=false" : null,
                !showFilterButton ? "showFilterButton=false" : null,
                !showFooter ? "showFooter=false" : null,
                !showContextMenu ? "showContextMenu=false" : null,
                (FilterOptions != null && FilterOptions.Count > 0) ? ("filters=" + FilterOptions.ToString(";")) : null,
                (OrderOptions != null && OrderOptions.Count > 0) ? ("orders=" + OrderOptions.ToString(";")) : null,
                (ColumnOptions != null && ColumnOptions.Count > 0) ? ("columns=" + ColumnOptions.ToString(";")) : null,
                (ColumnOptionsMode != ColumnOptionsMode.Add ? ("columnMode=" + ColumnOptionsMode.ToString()) : null),
                !SelectedItemsContextMenu ? "selectedItemsContextMenu=false" : null
            }.NotNull().ToString("&");

            if (options.HasText())
            {
                return(Finder.FindRoute(QueryName) + "?" + options);
            }
            else
            {
                return(Finder.FindRoute(QueryName));
            }
        }
示例#5
0
        public static MvcHtmlString SearchControl(this HtmlHelper helper, FindOptions findOptions, Context context, Action <SearchControl> settingsModifier)
        {
            var options = new SearchControl {
                Prefix = context.Prefix
            };

            if (settingsModifier != null)
            {
                settingsModifier(options);
            }

            QueryDescription description = DynamicQueryManager.Current.QueryDescription(findOptions.QueryName);

            FilterOption.SetFilterTokens(findOptions.FilterOptions, description, false);
            OrderOption.SetOrderTokens(findOptions.OrderOptions, description, false);
            ColumnOption.SetColumnTokens(findOptions.ColumnOptions, description, false);
            Finder.Manager.SetSearchViewableAndCreable(findOptions, description);
            FinderManager.SetDefaultOrder(findOptions, description);

            var viewData = new ViewDataDictionary(context);

            viewData[ViewDataKeys.FindOptions]      = findOptions;
            viewData[ViewDataKeys.QueryDescription] = DynamicQueryManager.Current.QueryDescription(findOptions.QueryName);

            viewData[ViewDataKeys.Title] = helper.ViewData.ContainsKey(ViewDataKeys.Title) ?
                                           helper.ViewData[ViewDataKeys.Title] : QueryUtils.GetNiceName(findOptions.QueryName);

            if (!options.ToolBarButton.IsNullOrEmpty())
            {
                viewData[ViewDataKeys.ManualToolbarButtons] = options.ToolBarButton;
            }

            if (options.AvoidFullScreenButton)
            {
                viewData[ViewDataKeys.AvoidFullScreenButton] = true;
            }

            return(helper.Partial(Finder.Manager.SearchControlView, viewData));
        }
示例#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());
        }
示例#7
0
        private static MvcHtmlString PrintValueField(HtmlHelper helper, Context parent, FilterOption filterOption)
        {
            var implementations = filterOption.Token.GetImplementations();

            if (filterOption.Token.Type.IsLite())
            {
                Lite <IEntity> lite = (Lite <IEntity>)Common.Convert(filterOption.Value, filterOption.Token.Type);
                if (lite != null && string.IsNullOrEmpty(lite.ToString()))
                {
                    Database.FillToString(lite);
                }

                Type cleanType = Lite.Extract(filterOption.Token.Type);
                if (EntityKindCache.IsLowPopulation(cleanType) && !cleanType.IsInterface && !implementations.Value.IsByAll)
                {
                    EntityCombo ec = new EntityCombo(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                    {
                        Implementations = implementations.Value,
                    };
                    EntityBaseHelper.ConfigureEntityButtons(ec, filterOption.Token.Type.CleanType());
                    ec.FormGroupStyle = FormGroupStyle.None;
                    ec.Create         = false;
                    ec.ReadOnly       = filterOption.Frozen;
                    return(EntityComboHelper.InternalEntityCombo(helper, ec));
                }
                else
                {
                    EntityLine el = new EntityLine(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                    {
                        Implementations = implementations.Value,
                    };

                    if (el.Implementations.Value.IsByAll)
                    {
                        el.Autocomplete = false;
                    }

                    EntityBaseHelper.ConfigureEntityButtons(el, filterOption.Token.Type.CleanType());
                    el.FormGroupStyle = FormGroupStyle.None;
                    el.Create         = false;
                    el.ReadOnly       = filterOption.Frozen;

                    return(EntityLineHelper.InternalEntityLine(helper, el));
                }
            }
            else if (filterOption.Token.Type.IsEmbeddedEntity())
            {
                EmbeddedEntity lite = (EmbeddedEntity)Common.Convert(filterOption.Value, filterOption.Token.Type);
                EntityLine     el   = new EntityLine(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                {
                    Implementations = null,
                    Autocomplete    = false,
                };
                EntityBaseHelper.ConfigureEntityButtons(el, filterOption.Token.Type.CleanType());
                el.FormGroupStyle = FormGroupStyle.None;
                el.Create         = false;
                el.ReadOnly       = filterOption.Frozen;

                return(EntityLineHelper.InternalEntityLine(helper, el));
            }
            else
            {
                var vl = new ValueLine(filterOption.Token.Type, filterOption.Value, parent, "", filterOption.Token.GetPropertyRoute())
                {
                    FormGroupStyle = FormGroupStyle.None,
                    ReadOnly       = filterOption.Frozen,
                    Format         = filterOption.Token.Format,
                    UnitText       = filterOption.Token.Unit,
                };

                if (filterOption.Token.Type.UnNullify().IsEnum)
                {
                    vl.EnumComboItems = ValueLine.CreateComboItems(EnumEntity.GetValues(vl.Type.UnNullify()), vl.UntypedValue == null || vl.Type.IsNullable());
                }

                return(ValueLineHelper.ValueLine(helper, vl));
            }

            throw new InvalidOperationException("Invalid filter for type {0}".FormatWith(filterOption.Token.Type.Name));
        }
示例#8
0
        public JObject ToJS(string prefix)
        {
            JObject op = new JObject()
            {
                { "prefix", prefix }
            };

            if (FilterOptions.Any())
            {
                QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(QueryName);

                FilterOption.SetFilterTokens(this.FilterOptions, queryDescription, false);
            }

            if (QueryName != null)
            {
                op.Add("webQueryName", Finder.ResolveWebQueryName(QueryName));
            }
            if (SearchOnLoad == true)
            {
                op.Add("searchOnLoad", true);
            }
            if (!Navigate)
            {
                op.Add("navigate", false);
            }
            if (!Create)
            {
                op.Add("create", false);
            }
            if (!AllowSelection)
            {
                op.Add("allowSelection", false);
            }
            if (!SelectedItemsContextMenu)
            {
                op.Add("selectedItemsContextMenu", false);
            }
            if (!AllowChangeColumns)
            {
                op.Add("allowChangeColumns", false);
            }
            if (!AllowOrder)
            {
                op.Add("allowOrder", false);
            }
            if (!showHeader)
            {
                op.Add("showHeader", false);
            }
            if (!showFilters)
            {
                op.Add("showFilters", false);
            }
            if (!showFilterButton)
            {
                op.Add("showFilterButton", false);
            }
            if (!showFooter)
            {
                op.Add("showFooter", false);
            }
            if (!showContextMenu)
            {
                op.Add("showContextMenu", false);
            }
            if (FilterOptions.Any())
            {
                op.Add("filters", new JArray(filterOptions.Select(f => f.ToJS())));
            }
            if (OrderOptions.Any())
            {
                op.Add("orders", new JArray(OrderOptions.Select(oo => oo.ToJS())));
            }
            if (ColumnOptions.Any())
            {
                op.Add("columns", new JArray(ColumnOptions.Select(co => co.ToJS())));
            }
            if (ColumnOptionsMode != Entities.DynamicQuery.ColumnOptionsMode.Add)
            {
                op.Add("columnMode", ColumnOptionsMode.ToString());
            }

            if (Pagination != null)
            {
                op.Add("pagination", Pagination.GetMode().ToString());
                int?elems = Pagination.GetElementsPerPage();
                if (elems != null)
                {
                    op.Add("elems", elems.Value.ToString());
                }
            }

            return(op);
        }
示例#9
0
        private static MvcHtmlString PrintValueField(HtmlHelper helper, Context parent, FilterOption filterOption)
        {
            var implementations = filterOption.Token.GetImplementations();

            if (filterOption.Token.Type.IsLite())
            {
                Lite<IEntity> lite = (Lite<IEntity>)Common.Convert(filterOption.Value, filterOption.Token.Type);
                if (lite != null && string.IsNullOrEmpty(lite.ToString()))
                    Database.FillToString(lite);

                Type cleanType = Lite.Extract(filterOption.Token.Type);
                if (EntityKindCache.IsLowPopulation(cleanType) && !cleanType.IsInterface && !implementations.Value.IsByAll)
                {
                    EntityCombo ec = new EntityCombo(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                    {
                        Implementations = implementations.Value,
                    };
                    EntityBaseHelper.ConfigureEntityButtons(ec, filterOption.Token.Type.CleanType());
                    ec.FormGroupStyle = FormGroupStyle.None;
                    ec.Create = false;
                    ec.ReadOnly = filterOption.Frozen;
                    return EntityComboHelper.InternalEntityCombo(helper, ec);
                }
                else
                {
                    EntityLine el = new EntityLine(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                    {
                        Implementations = implementations.Value,
                    };

                    if (el.Implementations.Value.IsByAll)
                        el.Autocomplete = false;

                    EntityBaseHelper.ConfigureEntityButtons(el, filterOption.Token.Type.CleanType());
                    el.FormGroupStyle = FormGroupStyle.None;
                    el.Create = false;
                    el.ReadOnly = filterOption.Frozen;

                    return EntityLineHelper.InternalEntityLine(helper, el);
                }
            }
            else if (filterOption.Token.Type.IsEmbeddedEntity())
            {
                EmbeddedEntity lite = (EmbeddedEntity)Common.Convert(filterOption.Value, filterOption.Token.Type);
                EntityLine el = new EntityLine(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                {
                    Implementations = null,
                    Autocomplete = false,
                };
                EntityBaseHelper.ConfigureEntityButtons(el, filterOption.Token.Type.CleanType());
                el.FormGroupStyle = FormGroupStyle.None;
                el.Create = false;
                el.ReadOnly = filterOption.Frozen;

                return EntityLineHelper.InternalEntityLine(helper, el);
            }
            else
            {
                var vl = new ValueLine(filterOption.Token.Type, filterOption.Value, parent, "", filterOption.Token.GetPropertyRoute())
                {
                    FormGroupStyle = FormGroupStyle.None,
                    ReadOnly = filterOption.Frozen,
                    Format = filterOption.Token.Format,
                    UnitText = filterOption.Token.Unit,
                }; 

                if (filterOption.Token.Type.UnNullify().IsEnum)
                {
                    vl.EnumComboItems = ValueLine.CreateComboItems(EnumEntity.GetValues(vl.Type.UnNullify()), vl.UntypedValue == null || vl.Type.IsNullable());
                }

                return ValueLineHelper.ValueLine(helper, vl);
            }
            
            throw new InvalidOperationException("Invalid filter for type {0}".FormatWith(filterOption.Token.Type.Name));
        }
示例#10
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();
        }