public ActionResult Add(int id)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new FilterAddViewModel {
                Id = id, Filters = _projectionManager.DescribeFilters()
            };

            return(View(viewModel));
        }
        public IHqlQuery ApplyFilter(QueryPartRecord queryRecord, IHqlQuery contentQuery, string category, string type, dynamic state)
        {
            var availableFilters = projectionManager.DescribeFilters().ToList();

            // look for the specific filter component
            var descriptor = availableFilters
                             .SelectMany(x => x.Descriptors)
                             .FirstOrDefault(x => x.Category == category && x.Type == type);

            // ignore unfound descriptors
            if (descriptor == null)
            {
                return(contentQuery);
            }

            var filterContext = new FilterContext
            {
                Query           = contentQuery,
                State           = state,
                QueryPartRecord = queryRecord
            };

            // apply alteration
            descriptor.Filter(filterContext);

            return(filterContext.Query);
        }
        public ActionResult Add(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.UserQuery, T("Not authorized to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }
            var content = Services.ContentManager.Get(_groupRepository.Get(id).QueryPartRecord.Id, VersionOptions.Latest);
            QueryUserFilterExtensionPartSettingVM setting = ((ContentPart)(((dynamic)content).QueryUserFilterExtensionPart)).Settings.GetModel <QueryUserFilterExtensionPartSettingVM>();
            var selection = setting.QueryUserFilter.Split(',');
            var viewModel = new FilterAddViewModel {
                Id      = id,
                Filters = _projectionManager.DescribeFilters().Where(x => selection.Contains(x.Category))
            };

            return(View(viewModel));
        }
        public override IEnumerable <TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition)
        {
            if (definition.PartDefinition.Name != "QueryUserFilterExtensionPart")
            {
                yield break;
            }
            var model = definition.Settings.GetModel <QueryUserFilterExtensionPartSettingVM>();

            if (model.QueryUserFilter == null)
            {
                model.QueryUserFilter = "";
            }
            model.SelezionatiElenco = (model.QueryUserFilter).Split(',');
            List <string>         filtriselezionati = new List <string>(model.SelezionatiElenco);
            var                   elencofiltri      = _projectionManager.DescribeFilters().OrderByDescending(x => x.Category);
            List <SelectListItem> sl = new List <SelectListItem>();

            foreach (var filtro in elencofiltri)
            {
                sl.Insert(0, new SelectListItem {
                    Value = filtro.Category, Text = filtro.Name.ToString(), Selected = filtriselezionati.Contains(filtro.Category)
                });
            }

            model.Elenco = new SelectList((IEnumerable <SelectListItem>)sl, "Value", "Text", model.QueryUserFilter);

            yield return(DefinitionTemplate(model));
        }
Пример #5
0
        public ActionResult GetFieldFilters(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(null);
            }
            var pluralService = PluralizationService.CreateService(new CultureInfo("en-US"));

            id = pluralService.Singularize(id);

            string category = id + "ContentFields";
            var    filters  = _projectionManager.DescribeFilters()
                              .Where(x => x.Category == category)
                              .SelectMany(x => x.Descriptors);

            var fieldFilters = filters.Select(filter =>
                                              new FieldFilterViewModel {
                DisplayName = filter.Name.Text,
                FormName    = filter.Form,
                Type        = filter.Type
            }).ToList();

            return(Json(fieldFilters, JsonRequestBehavior.AllowGet));
        }
Пример #6
0
        private IList <FilterRecord> CreateFilters(string entityName, ListQueryModel model, out string filterDescription)
        {
            IList <FilterRecord> filterRecords;

            filterDescription = string.Empty;
            if (model.FilterGroupId == 0)
            {
                var filterDescriptors = _projectionManager.DescribeFilters()
                                        .Where(x => x.Category == entityName + "ContentFields")
                                        .SelectMany(x => x.Descriptors).ToList();
                filterRecords = new List <FilterRecord>();
                if (model.IsRelationList)
                {
                    if (model.RelationType == "OneToMany")
                    {
                        var settings = new Dictionary <string, string> {
                            { "Operator", "MatchesAny" },
                            { "Value", model.CurrentItem.ToString("D") }
                        };
                        var relationFilter = new FilterRecord {
                            Category    = entityName + "ContentFields",
                            Type        = entityName + "." + model.RelationId + ".",
                            State       = FormParametersHelper.ToString(settings),
                            Description = "Only show entries related to current item."
                        };
                        filterRecords.Add(relationFilter);
                        var descriptor = filterDescriptors.First(x => x.Type == relationFilter.Type);
                        filterDescription += descriptor.Display(new FilterContext {
                            State = FormParametersHelper.ToDynamic(relationFilter.State)
                        }).Text;
                    }
                }

                foreach (var filter in model.Filters)
                {
                    if (filter.FormData.Length == 0)
                    {
                        continue;
                    }
                    var record = new FilterRecord {
                        Category = entityName + "ContentFields",
                        Type     = filter.Type,
                    };
                    var dictionary = new Dictionary <string, string>();
                    foreach (var data in filter.FormData)
                    {
                        if (dictionary.ContainsKey(data.Name))
                        {
                            dictionary[data.Name] += "&" + data.Value;
                        }
                        else
                        {
                            dictionary.Add(data.Name, data.Value);
                        }
                    }
                    record.State = FormParametersHelper.ToString(dictionary);
                    filterRecords.Add(record);
                    var descriptor = filterDescriptors.First(x => x.Type == filter.Type);
                    filterDescription += descriptor.Display(new FilterContext {
                        State = FormParametersHelper.ToDynamic(record.State)
                    }).Text;
                }
            }
            else
            {
                filterRecords = _filterGroupRepository.Get(model.FilterGroupId).Filters;
            }
            return(filterRecords);
        }
Пример #7
0
        public ActionResult Edit(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to edit queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var query     = _queryService.GetQuery(id);
            var viewModel = new AdminEditViewModel {
                Id   = query.Id,
                Name = query.Name
            };

            #region Load Filters
            var filterGroupEntries = new List <FilterGroupEntry>();
            var allFilters         = _projectionManager.DescribeFilters().SelectMany(x => x.Descriptors).ToList();

            foreach (var group in query.FilterGroups)
            {
                var filterEntries = new List <FilterEntry>();

                foreach (var filter in group.Filters)
                {
                    var category = filter.Category;
                    var type     = filter.Type;

                    var f = allFilters.FirstOrDefault(x => category == x.Category && type == x.Type);
                    if (f != null)
                    {
                        filterEntries.Add(
                            new FilterEntry {
                            Category       = f.Category,
                            Type           = f.Type,
                            FilterRecordId = filter.Id,
                            DisplayText    = String.IsNullOrWhiteSpace(filter.Description) ? f.Display(new FilterContext {
                                State = FormParametersHelper.ToDynamic(filter.State)
                            }).Text : filter.Description
                        });
                    }
                }

                filterGroupEntries.Add(new FilterGroupEntry {
                    Id = group.Id, Filters = filterEntries
                });
            }

            viewModel.FilterGroups = filterGroupEntries;

            #endregion

            #region Load Sort criterias
            var sortCriterionEntries = new List <SortCriterionEntry>();
            var allSortCriteria      = _projectionManager.DescribeSortCriteria().SelectMany(x => x.Descriptors).ToList();

            foreach (var sortCriterion in query.SortCriteria.OrderBy(s => s.Position))
            {
                var category = sortCriterion.Category;
                var type     = sortCriterion.Type;

                var f = allSortCriteria.FirstOrDefault(x => category == x.Category && type == x.Type);
                if (f != null)
                {
                    sortCriterionEntries.Add(
                        new SortCriterionEntry {
                        Category = f.Category,
                        Type     = f.Type,
                        SortCriterionRecordId = sortCriterion.Id,
                        DisplayText           = String.IsNullOrWhiteSpace(sortCriterion.Description) ? f.Display(new SortCriterionContext {
                            State = FormParametersHelper.ToDynamic(sortCriterion.State)
                        }).Text : sortCriterion.Description
                    });
                }
            }

            viewModel.SortCriteria = sortCriterionEntries;

            #endregion

            #region Load Layouts
            var layoutEntries = new List <LayoutEntry>();
            var allLayouts    = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).ToList();

            foreach (var layout in query.Layouts)
            {
                var category = layout.Category;
                var type     = layout.Type;

                var f = allLayouts.FirstOrDefault(x => category == x.Category && type == x.Type);
                if (f != null)
                {
                    layoutEntries.Add(
                        new LayoutEntry {
                        Category       = f.Category,
                        Type           = f.Type,
                        LayoutRecordId = layout.Id,
                        DisplayText    = String.IsNullOrWhiteSpace(layout.Description) ? f.Display(new LayoutContext {
                            State = FormParametersHelper.ToDynamic(layout.State)
                        }).Text : layout.Description
                    });
                }
            }

            viewModel.Layouts = layoutEntries;

            #endregion

            return(View(viewModel));
        }