Exemple #1
0
        private static void OnUserQueryChanged(DependencyObject s, UserQueryEntity uc)
        {
            UserQueryPermission.ViewUserQuery.Authorize();

            var currentEntity = UserAssetsClient.GetCurrentEntity(s);

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

            if (s is SearchControl sc && 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;
        }
Exemple #2
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)
                });
            };
        }
Exemple #3
0
        public override void OnSelected(UserQueryOmniboxResult result, Window window)
        {
            UserQueryEntity uq = result.UserQuery.RetrieveAndForget();

            var query = QueryClient.GetQueryName(uq.Query.Key);

            Finder.Explore(new ExploreOptions(query)
            {
                InitializeSearchControl = sc => UserQueryClient.SetUserQuery(sc, uq)
            });
        }
Exemple #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);
                }
            });
        }
Exemple #5
0
        public static MenuItem Construct(SearchControl sc)
        {
            List <Lite <UserQueryEntity> > userQueries = null;
            UserQueryEntity current = null;

            MenuItem miResult = new MenuItem
            {
                Icon = ExtensionsImageLoader.GetImageSortName("favorite.png").ToSmallImage()
            };

            MenuItem edit   = null;
            MenuItem remove = null;

            Action updatecurrent = () =>
            {
                miResult.Header = new TextBlock
                {
                    Inlines =
                    {
                        new Run(
                            current == null ? UserQueryMessage.MyQueries.NiceToString() : current.DisplayName),
                        userQueries.IsNullOrEmpty() ? (Inline) new Run():  new Bold(new Run(" (" + userQueries.Count + ")"))
                    }
                };

                foreach (var item in miResult.Items.OfType <MenuItem>().Where(mi => mi.IsCheckable))
                {
                    item.IsChecked = ((Lite <UserQueryEntity>)item.Tag).RefersTo(current);
                }

                bool isEnabled = current != null && !Navigator.IsReadOnly(current);

                if (edit != null)
                {
                    edit.IsEnabled = isEnabled;
                }

                if (remove != null)
                {
                    remove.IsEnabled = isEnabled;
                }
            };

            Action initialize = null;

            RoutedEventHandler new_Clicked = (object sender, RoutedEventArgs e) =>
            {
                e.Handled = true;

                sc.FocusSearch(); //Commit RealValue bindings

                UserQueryEntity userQuery = UserQueryClient.FromSearchControl(sc);

                var disp = Dispatcher.CurrentDispatcher;
                Navigator.Navigate(userQuery, new NavigateOptions
                {
                    View = () => new UserQuery {
                        QueryDescription = sc.Description
                    },
                    Closed = (s, args) =>
                    {
                        disp.Invoke(() =>
                        {
                            initialize();

                            if (userQuery.IdOrNull != null)
                            {
                                current = userQuery;
                            }

                            updatecurrent();
                        });
                    }
                });
            };

            RoutedEventHandler edit_Clicked = (object sender, RoutedEventArgs e) =>
            {
                e.Handled = true;

                var d = Dispatcher.CurrentDispatcher;
                Navigator.Navigate(current.ToLite().Retrieve(), new NavigateOptions
                {
                    View = () => new UserQuery {
                        QueryDescription = sc.Description
                    },
                    Closed = (s, args) =>
                    {
                        d.Invoke(() =>
                        {
                            initialize();
                            updatecurrent();
                        });
                    }
                });
            };

            RoutedEventHandler remove_Clicked = (object sender, RoutedEventArgs e) =>
            {
                e.Handled = true;

                if (MessageBox.Show(UserQueryMessage.AreYouSureToRemove0.NiceToString().FormatWith(current), UserQueryMessage.RemoveUserQuery.NiceToString(),
                                    MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No) == MessageBoxResult.Yes)
                {
                    current.ToLite().DeleteLite(UserQueryOperation.Delete);

                    initialize();

                    updatecurrent();
                }
            };

            RoutedEventHandler menuItem_Clicked = (object sender, RoutedEventArgs e) =>
            {
                e.Handled = true;

                if (e.OriginalSource is MenuItem b)
                {
                    Lite <UserQueryEntity> userQuery = (Lite <UserQueryEntity>)b.Tag;

                    var uq = Server.Return((IUserQueryServer s) => s.RetrieveUserQuery(userQuery));

                    UserQueryClient.ToSearchControl(uq, sc);

                    current = uq;

                    updatecurrent();

                    sc.Search();
                }
            };

            initialize = () =>
            {
                miResult.Items.Clear();

                userQueries = Server.Return((IUserQueryServer s) => s.GetUserQueries(sc.QueryName));

                if (current != null && !userQueries.Contains(current.ToLite()))
                {
                    current = null;
                }

                if (userQueries.Count > 0)
                {
                    foreach (Lite <UserQueryEntity> report in userQueries.OrderBy(a => a.ToString()))
                    {
                        MenuItem mi = new MenuItem()
                        {
                            IsCheckable = true,
                            Header      = report.ToString(),
                            Tag         = report,
                        };
                        mi.Click += menuItem_Clicked;
                        miResult.Items.Add(mi);
                    }
                }

                if (Navigator.IsNavigable(typeof(UserQueryEntity), isSearch: true))
                {
                    miResult.Items.Add(new Separator());

                    if (Navigator.IsCreable(typeof(UserQueryEntity), true))
                    {
                        miResult.Items.Add(new MenuItem()
                        {
                            Header = EntityControlMessage.Create.NiceToString(),
                            Icon   = ExtensionsImageLoader.GetImageSortName("add.png").ToSmallImage()
                        }.Handle(MenuItem.ClickEvent, new_Clicked));
                    }

                    miResult.Items.Add(edit = new MenuItem()
                    {
                        Header = UserQueryMessage.Edit.NiceToString(),
                        Icon   = ExtensionsImageLoader.GetImageSortName("edit.png").ToSmallImage()
                    }.Handle(MenuItem.ClickEvent, edit_Clicked));

                    miResult.Items.Add(remove = new MenuItem()
                    {
                        Header = EntityControlMessage.Remove.NiceToString(),
                        Icon   = ExtensionsImageLoader.GetImageSortName("remove.png").ToSmallImage()
                    }.Handle(MenuItem.ClickEvent, remove_Clicked));
                }
            };

            initialize();

            var autoSet = UserQueryClient.GetUserQuery(sc);

            if (autoSet != null)
            {
                UserQueryClient.ToSearchControl(autoSet, sc);
                current = autoSet;

                updatecurrent();

                sc.Search();
            }
            else
            {
                updatecurrent();
            }

            return(miResult);
        }
Exemple #6
0
 public override void Execute()
 {
     UserQueryClient.Explore(userQuery.Retrieve(), entity.Retrieve());
 }