Creating Projection (Query) Filter

Projection, Query, Filter, IFilterProvider, IFormProvider

Aims: Create a selection filter for the slider projection. Lets say we only want 'feature' items appearing when we select them. We could go and fetch the ids and create a filter that way but having a check-box on the editor page for the content type is far more user friendly.

To achieve this we are going to need to do a bit of work. First we need a part and a record that can be used to define the sql query for the content items.

This part will be used to enable the item to be included in the query.

  • public class ItemSliderPart : ContentPart<ItemSliderPartRecord>
  • public bool ShowItem {
  • get { return this.Record.ShowItem; }
  • set { this.Record.ShowItem = value; }
  • }
  • }

The Record is as simple:

  • public class ItemSliderPartRecord : ContentPartRecord {
  • public virtual bool ShowItem { get; set; }
  • }

The above part is attached to the content type which is being displayed in the Query. Time to create and define the filter for the query then...

Second part is a little more fiddly with dynamic forms but should be simple enough.

The two sections that we need to implement are:

  • IFilterProvider - Defines the query options and any forms that may belong to the options
  • IFormProvider - Define a dynamic form that the provider can find and display for the filter option(s)

SliderItemFilter : IFilterProvider

  • public void Describe(DescribeFilterContext describe) {
  • var descriptor = describe.For("ItemSliderPart", T("Item Slider Part"), T("Item slider part filters"));
  •  descriptor.Element(
  • type: "ItemSlider",
  •    name: T("Item Slider Options"),
  •    description: T("Show only enabled items"),
  •    filter: ApplyFilter,
  •    display: DisplayFilter,
  •    form: "SliderItemFilter"
  •  );
  • }

The above function is used to define how the filter acts and looks:

Name and Description are how the filter are visibly shown in the group lists. Filter how Describe.For is the section where the item falls into.

filter: ApplyFilter - develop the query by saying how the value is used from the part. When the setting is needed and how to therefore query the data. The filter is creating two options:

  • Enabled: Require part value to be true.
  • Not checked: equivalent to not having a filter on the query.

display: DisplayFilter - Displays a user hint and describes how the filter is acting when once enabled.

form: "SliderItemFilter" - the dynamic form that the user uses to set the filter. The form is described through the implementation of IFormProvider. The provider creates a dynamic form, where its name matches the above string.

Still writing...

On Jun 3 2013 3:19 PMBy admin