Exemplo n.º 1
1
        private static void OnUserQueryChanged(DependencyObject s, UserQueryEntity uc)
        {
            UserQueryPermission.ViewUserQuery.Authorize();

            var currentEntity = UserAssetsClient.GetCurrentEntity(s);

            var csc = s as CountSearchControl;
            if (csc != null)
            {
                csc.QueryName = QueryClient.GetQueryName(uc.Query.Key);
                using (currentEntity == null ? null : CurrentEntityConverter.SetCurrentEntity(currentEntity))
                    UserQueryClient.ToCountSearchControl(uc, csc);
                csc.Search();
                return;
            }

            var sc = s as SearchControl;
            if (sc != null && sc.ShowHeader == false)
            {
                sc.QueryName = QueryClient.GetQueryName(uc.Query.Key);
                using (currentEntity == null ? null : CurrentEntityConverter.SetCurrentEntity(currentEntity))
                UserQueryClient.ToSearchControl(uc, sc);
                sc.Search();
                return;
            }

            return;
        }
Exemplo n.º 2
0
        public static MvcHtmlString SearchControl(this HtmlHelper helper, UserQueryEntity userQuery, FindOptions findOptions, Context context, Action<SearchControl> searchControl = null)
        {
            if (findOptions == null)
                throw new ArgumentNullException("findOptions");

            findOptions.ApplyUserQuery(userQuery);

            return helper.SearchControl(findOptions, context, searchControl);
        }
Exemplo n.º 3
0
 public static void SetUserQuery(DependencyObject obj, UserQueryEntity value)
 {
     obj.SetValue(UserQueryProperty, value);
 }
Exemplo n.º 4
0
        internal static void Explore(UserQueryEntity userQuery, Entity currentEntity)
        {
            var query = QueryClient.GetQueryName(userQuery.Query.Key);

            Finder.Explore(new ExploreOptions(query)
            {
                InitializeSearchControl = sc =>
                {
                    using (userQuery.EntityType == null ? null : CurrentEntityConverter.SetCurrentEntity(currentEntity))
                        UserQueryClient.SetUserQuery(sc, userQuery);
                }
            });
        }
Exemplo n.º 5
0
        internal static void ToCountSearchControl(UserQueryEntity uq, CountSearchControl countSearchControl)
        {
            var filters = uq.WithoutFilters ? countSearchControl.FilterOptions.ToList() :
                countSearchControl.FilterOptions.Where(f => f.Frozen).Concat(uq.Filters.Select(qf => new FilterOption
                {
                    ColumnName = qf.Token.Token.FullKey(),
                    Operation = qf.Operation,
                    Value = Signum.Entities.UserAssets.FilterValueConverter.Parse(qf.ValueString, qf.Token.Token.Type, qf.Operation.IsList())
                })).ToList();

            var columns = uq.Columns.Select(qc => new ColumnOption
            {

                ColumnName = qc.Token.Token.FullKey(),
                DisplayName = qc.DisplayName.DefaultText(null)
            }).ToList();

            var orders = uq.Orders.Select(of => new OrderOption
            {
                ColumnName = of.Token.Token.FullKey(),
                OrderType = of.OrderType,
            }).ToList();

            countSearchControl.Reinitialize(filters, columns, uq.ColumnsMode, orders);
            countSearchControl.Text = uq.DisplayName + ": {0}";
            countSearchControl.LinkClick += (object sender, EventArgs e) =>
            {
                Finder.Explore(new ExploreOptions(countSearchControl.QueryName)
                {
                    InitializeSearchControl = sc => UserQueryClient.SetUserQuery(sc, uq)
                });
            };
        }
Exemplo n.º 6
0
        internal static void ToSearchControl(UserQueryEntity uq, SearchControl searchControl)
        {
            var filters = uq.WithoutFilters ? searchControl.FilterOptions.ToList() :
                 searchControl.FilterOptions.Where(f => f.Frozen).Concat(uq.Filters.Select(qf => new FilterOption
             {
                 ColumnName = qf.Token.Token.FullKey(),
                 Operation = qf.Operation,
                 Value = Signum.Entities.UserAssets.FilterValueConverter.Parse(qf.ValueString, qf.Token.Token.Type, qf.Operation.IsList())
             })).ToList();

            var columns = uq.Columns.Select(qc => new ColumnOption
            {
                ColumnName = qc.Token.Token.FullKey(),
                DisplayName = qc.DisplayName.DefaultText(null)
            }).ToList();

            var orders = uq.Orders.Select(of => new OrderOption
            {
                ColumnName = of.Token.Token.FullKey(),
                OrderType = of.OrderType,
            }).ToList();

            var pagination = uq.GetPagination() ?? Finder.GetQuerySettings(searchControl.QueryName).Pagination ?? FindOptions.DefaultPagination;

            searchControl.Reinitialize(filters, columns, uq.ColumnsMode, orders, pagination);
        }
Exemplo n.º 7
0
        public static MvcHtmlString SearchControl(this HtmlHelper helper, UserQueryEntity userQuery, Context context, Action<SearchControl> searchControl = null)
        {
            FindOptions findOptions = userQuery.ToFindOptions();

            return helper.SearchControl(userQuery, findOptions, context, searchControl);
        }
Exemplo n.º 8
0
        static List<Column> MergeColumns(UserQueryEntity uq)
        {
            QueryDescription qd = DynamicQueryManager.Current.QueryDescription(uq.Query.ToQueryName());

            switch (uq.ColumnsMode)
            {
                case ColumnOptionsMode.Add:
                    return qd.Columns.Where(cd => !cd.IsEntity).Select(cd => new Column(cd, qd.QueryName)).Concat(uq.Columns.Select(co => ToColumn(co))).ToList();
                case ColumnOptionsMode.Remove:
                    return qd.Columns.Where(cd => !cd.IsEntity && !uq.Columns.Any(co => co.Token.TokenString == cd.Name)).Select(cd => new Column(cd, qd.QueryName)).ToList();
                case ColumnOptionsMode.Replace:
                    return uq.Columns.Select(co => ToColumn(co)).ToList();
                default:
                    throw new InvalidOperationException("{0} is not a valid ColumnOptionMode".FormatWith(uq.ColumnsMode));
            }
        }
Exemplo n.º 9
0
        static SqlPreCommand ProcessUserQuery(Replacements replacements, Table table, UserQueryEntity uq)
        {
            try
            {
                Console.Clear();

                SafeConsole.WriteLineColor(ConsoleColor.White, "UserQuery: " + uq.DisplayName);
                Console.WriteLine(" Query: " + uq.Query.Key);

                if (uq.Filters.Any(a => a.Token.ParseException != null) ||
                   uq.Columns.Any(a => a.Token != null && a.Token.ParseException != null) ||
                   uq.Orders.Any(a => a.Token.ParseException != null))
                {

                    QueryDescription qd = DynamicQueryManager.Current.QueryDescription(uq.Query.ToQueryName());

                    if (uq.Filters.Any())
                    {
                        Console.WriteLine(" Filters:");
                        foreach (var item in uq.Filters.ToList())
                        {
                            QueryTokenEntity token = item.Token;
                            switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement, "{0} {1}".FormatWith(item.Operation, item.ValueString), allowRemoveToken: true, allowReCreate: false))
                            {
                                case FixTokenResult.Nothing: break;
                                case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uq);
                                case FixTokenResult.RemoveToken: uq.Filters.Remove(item); break;
                                case FixTokenResult.SkipEntity: return null;
                                case FixTokenResult.Fix: item.Token = token; break;
                                default: break;
                            }
                        }
                    }

                    if (uq.Columns.Any())
                    {
                        Console.WriteLine(" Columns:");
                        foreach (var item in uq.Columns.ToList())
                        {
                            QueryTokenEntity token = item.Token;
                            switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, item.DisplayName.HasText() ? "'{0}'".FormatWith(item.DisplayName) : null, allowRemoveToken: true, allowReCreate: false))
                            {
                                case FixTokenResult.Nothing: break;
                                case FixTokenResult.DeleteEntity: ; return table.DeleteSqlSync(uq);
                                case FixTokenResult.RemoveToken: uq.Columns.Remove(item); break;
                                case FixTokenResult.SkipEntity: return null;
                                case FixTokenResult.Fix: item.Token = token; break;
                                default: break;
                            }
                        }
                    }

                    if (uq.Orders.Any())
                    {
                        Console.WriteLine(" Orders:");
                        foreach (var item in uq.Orders.ToList())
                        {
                            QueryTokenEntity token = item.Token;
                            switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, item.OrderType.ToString(), allowRemoveToken: true, allowReCreate: false))
                            {
                                case FixTokenResult.Nothing: break;
                                case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uq);
                                case FixTokenResult.RemoveToken: uq.Orders.Remove(item); break;
                                case FixTokenResult.SkipEntity: return null;
                                case FixTokenResult.Fix: item.Token = token; break;
                                default: break;
                            }
                        }
                    }
                }

                foreach (var item in uq.Filters.ToList())
                {
                retry:
                    string val = item.ValueString;
                    switch (QueryTokenSynchronizer.FixValue(replacements, item.Token.Token.Type, ref val, allowRemoveToken: true, isList: item.Operation.IsList()))
                    {
                        case FixTokenResult.Nothing: break;
                        case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uq);
                        case FixTokenResult.RemoveToken: uq.Filters.Remove(item); break;
                        case FixTokenResult.SkipEntity: return null;
                        case FixTokenResult.Fix: item.ValueString = val; goto retry;
                    }
                }

                if (uq.WithoutFilters)
                    uq.Filters.Clear();

                if (!uq.ShouldHaveElements && uq.ElementsPerPage.HasValue)
                    uq.ElementsPerPage = null;

                if (uq.ShouldHaveElements && !uq.ElementsPerPage.HasValue)
                    uq.ElementsPerPage = 20;

                Console.Clear();

                using (replacements.WithReplacedDatabaseName())
                    return table.UpdateSqlSync(uq, includeCollections: true);
            }
            catch (Exception e)
            {
                return new SqlPreCommandSimple("-- Exception in {0}: {1}".FormatWith(uq.BaseToString(), e.Message));
            }
        }
Exemplo n.º 10
0
        static void UserQueryLogic_Retrieved(UserQueryEntity userQuery)
        {
            object queryName = QueryLogic.ToQueryName(userQuery.Query.Key);
            QueryDescription description = DynamicQueryManager.Current.QueryDescription(queryName);

            userQuery.ParseData(description);
        }
Exemplo n.º 11
0
        public static void ApplyUserQuery(this FindOptions findOptions, UserQueryEntity userQuery)
        {
            if (!userQuery.WithoutFilters)
            {
                findOptions.FilterOptions.RemoveAll(fo => !fo.Frozen);

                findOptions.FilterOptions.AddRange(userQuery.Filters.Select(qf => new FilterOption
                {
                    Token = qf.Token.Token,
                    ColumnName = qf.Token.TokenString,
                    Operation = qf.Operation,
                    Value = FilterValueConverter.Parse(qf.ValueString, qf.Token.Token.Type, qf.Operation.IsList()),
                }));
            }

            findOptions.ColumnOptionsMode = userQuery.ColumnsMode;

            findOptions.ColumnOptions.Clear();
            findOptions.ColumnOptions.AddRange(userQuery.Columns.Select(qc => new ColumnOption
            {
                Token = qc.Token.Token,
                ColumnName = qc.Token.TokenString,                
                DisplayName = qc.DisplayName.DefaultText(null),
            }));

            findOptions.OrderOptions.Clear();
            findOptions.OrderOptions.AddRange(userQuery.Orders.Select(qo => new OrderOption
            {
                Token = qo.Token.Token,
                ColumnName = qo.Token.TokenString,
                OrderType = qo.OrderType
            }));

            findOptions.Pagination = userQuery.GetPagination();
        }