示例#1
0
        protected internal virtual PartialViewResult Search(ControllerBase controller, QueryRequest request, bool allowSelection, bool navigate, bool showFooter, Context context)
        {
            if (!Finder.IsFindable(request.QueryName))
            {
                throw new UnauthorizedAccessException(NormalControlMessage.ViewForType0IsNotAllowed.NiceToString().FormatWith(request.QueryName));
            }

            QuerySettings    settings = QuerySettings[request.QueryName];
            QueryDescription qd       = DynamicQueryManager.Current.QueryDescription(request.QueryName);

            if (settings.HiddenColumns != null)
            {
                if (settings.HiddenColumns.Any(a => a.Token == null))
                {
                    using (ExecutionMode.Global())
                        ColumnOption.SetColumnTokens(settings.HiddenColumns, qd, canAggregate: false);
                }

                request.Columns.AddRange(settings.HiddenColumns.Select(c => c.ToColumn(qd, isVisible: false)));
            }

            ResultTable queryResult = DynamicQueryManager.Current.ExecuteQuery(request);

            controller.ViewData.Model = context;

            controller.ViewData[ViewDataKeys.AllowSelection] = allowSelection;
            controller.ViewData[ViewDataKeys.Navigate]       = navigate;
            controller.ViewData[ViewDataKeys.ShowFooter]     = showFooter;


            controller.ViewData[ViewDataKeys.QueryDescription] = qd;

            Type   entitiesType = Lite.Extract(qd.Columns.SingleEx(a => a.IsEntity).Type);
            string message      = CollectionElementToken.MultipliedMessage(request.Multiplications, entitiesType);

            if (message.HasText())
            {
                controller.ViewData[ViewDataKeys.MultipliedMessage] = message;
            }

            controller.ViewData[ViewDataKeys.Results]      = queryResult;
            controller.ViewData[ViewDataKeys.QueryRequest] = request;

            controller.ViewData[ViewDataKeys.Formatters]      = queryResult.Columns.Select((c, i) => new { c, i }).ToDictionary(c => c.i, c => settings.GetFormatter(c.c.Column));
            controller.ViewData[ViewDataKeys.EntityFormatter] = settings.EntityFormatter;
            controller.ViewData[ViewDataKeys.RowAttributes]   = settings.RowAttributes;

            return(new PartialViewResult
            {
                ViewName = SearchResultsView,
                ViewData = controller.ViewData,
                TempData = controller.TempData
            });
        }
示例#2
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));
        }