Inheritance: System.Web.UI.WebControls.CompositeControl
Example #1
0
 private DataViewFilter GetFilterGroupControl( FilterGroup filterGroup )
 {
     DataViewFilter filter = new DataViewFilter();
     filter.ExpressionType = filterGroup.FilterType;
     foreach ( Control control in filterGroup.Controls )
     {
         DataViewFilter childFilter = GetFilterControl( control );
         if ( childFilter != null )
         {
             filter.ChildFilters.Add( childFilter );
         }
     }
     return filter;
 }
        /// <summary>
        /// Creates the filter control.
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="reportEntityType">Type of the report entity.</param>
        /// <param name="filteredEntityTypeName">Name of the filtered entity type.</param>
        /// <param name="setSelection">if set to <c>true</c> [set selection].</param>
        /// <param name="selectedDataFieldGuids">The selected data field guids.</param>
        /// <param name="configurableDataFieldGuids">The configurable data field guids.</param>
        /// <param name="rockContext">The rock context.</param>
        private void CreateFilterControl(
            Control parentControl,
            DataViewFilter filter,
            EntityType reportEntityType,
            bool setSelection,
            List<Guid> selectedDataFieldGuids,
            List<Guid> configurableDataFieldGuids,
            List<Guid> togglableDataFieldGuids,
            RockContext rockContext )
        {
            try
            {
                var filteredEntityTypeName = EntityTypeCache.Read( reportEntityType ).Name;
                if ( filter.ExpressionType == FilterExpressionType.Filter )
                {
                    var filterControl = new FilterField();
                    filterControl.FilterMode = FilterMode.SimpleFilter;

                    bool filterIsVisible = selectedDataFieldGuids.Contains( filter.Guid );
                    bool filterIsConfigurable = configurableDataFieldGuids.Contains( filter.Guid );
                    bool showCheckbox = togglableDataFieldGuids.Contains( filter.Guid ) || !filterIsConfigurable;
                    filterControl.Visible = filterIsVisible;
                    parentControl.Controls.Add( filterControl );
                    filterControl.DataViewFilterGuid = filter.Guid;

                    filterControl.HideFilterCriteria = !filterIsConfigurable;
                    filterControl.ID = string.Format( "ff_{0}", filterControl.DataViewFilterGuid.ToString( "N" ) );
                    filterControl.FilteredEntityTypeName = filteredEntityTypeName;

                    if ( filter.EntityTypeId.HasValue )
                    {
                        var entityTypeCache = Rock.Web.Cache.EntityTypeCache.Read( filter.EntityTypeId.Value, rockContext );
                        if ( entityTypeCache != null )
                        {
                            filterControl.FilterEntityTypeName = entityTypeCache.Name;
                        }
                    }

                    filterControl.Expanded = true;

                    filterControl.ShowCheckbox = filterIsVisible && showCheckbox;

                    var reportEntityTypeCache = EntityTypeCache.Read( reportEntityType );
                    var reportEntityTypeModel = reportEntityTypeCache.GetEntityType();

                    var filterEntityType = EntityTypeCache.Read( filter.EntityTypeId ?? 0 );
                    var component = Rock.Reporting.DataFilterContainer.GetComponent( filterEntityType.Name );
                    if ( component != null )
                    {
                        string selectionUserPreference = null;
                        bool? checkedUserPreference = null;
                        if ( setSelection && filterIsVisible && filterIsConfigurable )
                        {
                            selectionUserPreference = this.GetUserPreference( string.Format( "{0}_{1}_Selection", GetReportDataKeyPrefix(), filterControl.DataViewFilterGuid.ToString( "N" ) ) );
                        }
                        else if ( setSelection && filterIsVisible && !filterIsConfigurable )
                        {
                            checkedUserPreference = this.GetUserPreference( string.Format( "{0}_{1}_Checked", GetReportDataKeyPrefix(), filterControl.DataViewFilterGuid.ToString( "N" ) ) ).AsBooleanOrNull();
                        }

                        if ( checkedUserPreference.HasValue )
                        {
                            filterControl.SetCheckBoxChecked( checkedUserPreference.Value );
                        }

                        if ( filterIsVisible && !filterIsConfigurable )
                        {
                            // not configurable so just label it with the selection summary
                            filterControl.Label = component.FormatSelection( reportEntityTypeModel, filter.Selection );
                        }
                        else if ( component is Rock.Reporting.DataFilter.PropertyFilter )
                        {
                            // a configurable property filter
                            var propertyFilter = component as Rock.Reporting.DataFilter.PropertyFilter;
                            if ( setSelection )
                            {
                                var selection = filter.Selection;

                                if ( !string.IsNullOrWhiteSpace( selectionUserPreference ) )
                                {
                                    selection = propertyFilter.UpdateSelectionFromUserPreferenceSelection( selection, selectionUserPreference );
                                }

                                selection = propertyFilter.UpdateSelectionFromPageParameters( selection, this );

                                try
                                {
                                    filterControl.SetSelection( selection );
                                }
                                catch ( Exception ex )
                                {
                                    this.LogException( new Exception( "Exception setting selection for DataViewFilter: " + filter.Guid, ex ) );
                                }
                            }
                        }
                        else
                        {
                            if ( setSelection )
                            {
                                var selection = filter.Selection;
                                if ( !string.IsNullOrWhiteSpace( selectionUserPreference ) )
                                {
                                    selection = selectionUserPreference;
                                }

                                if ( component is Rock.Reporting.DataFilter.IUpdateSelectionFromPageParameters )
                                {
                                    selection = ( component as Rock.Reporting.DataFilter.IUpdateSelectionFromPageParameters ).UpdateSelectionFromPageParameters( selection, this );
                                }

                                filterControl.SetSelection( selection );

                                try
                                {
                                    filterControl.SetSelection( selection );
                                }
                                catch ( Exception ex )
                                {
                                    this.LogException( new Exception( "Exception setting selection for DataViewFilter: " + filter.Guid, ex ) );
                                }
                            }

                            // a configurable data filter
                            filterControl.Label = component.GetTitle( reportEntityTypeModel );
                        }
                    }
                }
                else
                {
                    var groupControl = new FilterGroup();
                    parentControl.Controls.Add( groupControl );
                    groupControl.DataViewFilterGuid = filter.Guid;
                    groupControl.ID = string.Format( "fg_{0}", groupControl.DataViewFilterGuid.ToString( "N" ) );
                    groupControl.FilteredEntityTypeName = filteredEntityTypeName;
                    groupControl.IsDeleteEnabled = false;
                    groupControl.HidePanelHeader = true;
                    if ( setSelection )
                    {
                        groupControl.FilterType = filter.ExpressionType;
                    }

                    foreach ( var childFilter in filter.ChildFilters )
                    {
                        CreateFilterControl( groupControl, childFilter, reportEntityType, setSelection, selectedDataFieldGuids, configurableDataFieldGuids, togglableDataFieldGuids, rockContext );
                    }
                }
            }
            catch ( Exception ex )
            {
                this.LogException( new Exception( "Exception creating FilterControl for DataViewFilter: " + filter.Guid, ex ) );
            }
        }
Example #3
0
 private void CreateFilterControl( Control parentControl, DataViewFilter filter, string filteredEntityTypeName, bool setSelection )
 {
     if ( filter.ExpressionType == FilterExpressionType.Filter )
     {
         var filterControl = new FilterField();
         parentControl.Controls.Add( filterControl );
         filterControl.ID = string.Format( "{0}_ff_{1}", parentControl.ID, parentControl.Controls.Count );
         filterControl.FilteredEntityTypeName = filteredEntityTypeName;
         if ( filter.EntityTypeId.HasValue )
         {
             var entityTypeCache = Rock.Web.Cache.EntityTypeCache.Read( filter.EntityTypeId.Value );
             if ( entityTypeCache != null )
             {
                 filterControl.FilterEntityTypeName = entityTypeCache.Name;
             }
         }
         filterControl.Expanded = filter.Expanded;
         if ( setSelection )
         {
             filterControl.Selection = filter.Selection;
         }
         filterControl.DeleteClick += filterControl_DeleteClick;
     }
     else
     {
         var groupControl = new FilterGroup();
         parentControl.Controls.Add( groupControl );
         groupControl.ID = string.Format( "{0}_fg_{1}", parentControl.ID, parentControl.Controls.Count );
         groupControl.FilteredEntityTypeName = filteredEntityTypeName;
         groupControl.IsDeleteEnabled = parentControl is FilterGroup;
         if ( setSelection )
         {
             groupControl.FilterType = filter.ExpressionType;
         }
         groupControl.AddFilterClick += groupControl_AddFilterClick;
         groupControl.AddGroupClick += groupControl_AddGroupClick;
         groupControl.DeleteGroupClick += groupControl_DeleteGroupClick;
         foreach ( var childFilter in filter.ChildFilters )
         {
             CreateFilterControl( groupControl, childFilter, filteredEntityTypeName, setSelection );
         }
     }
 }
Example #4
0
 void groupControl_AddGroupClick( object sender, EventArgs e )
 {
     FilterGroup groupControl = sender as FilterGroup;
     FilterGroup childGroupControl = new FilterGroup();
     groupControl.Controls.Add( childGroupControl );
     childGroupControl.ID = string.Format( "{0}_fg_{1}", groupControl.ID, groupControl.Controls.Count );
     childGroupControl.FilteredEntityTypeName = groupControl.FilteredEntityTypeName;
     childGroupControl.FilterType = FilterExpressionType.GroupAll;
 }
Example #5
0
 /// <summary>
 /// Handles the AddGroupClick event of the groupControl control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected void groupControl_AddGroupClick( object sender, EventArgs e )
 {
     FilterGroup groupControl = sender as FilterGroup;
     FilterGroup childGroupControl = new FilterGroup();
     childGroupControl.DataViewFilterGuid = Guid.NewGuid();
     groupControl.Controls.Add( childGroupControl );
     childGroupControl.ID = string.Format( "fg_{0}", childGroupControl.DataViewFilterGuid.ToString( "N" ) );
     childGroupControl.FilteredEntityTypeName = groupControl.FilteredEntityTypeName;
     childGroupControl.FilterType = FilterExpressionType.GroupAll;
 }
Example #6
0
        /// <summary>
        /// Creates the filter control.
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="filteredEntityTypeName">Name of the filtered entity type.</param>
        /// <param name="setSelection">if set to <c>true</c> [set selection].</param>
        /// <param name="rockContext">The rock context.</param>
        private void CreateFilterControl( Control parentControl, DataViewFilter filter, string filteredEntityTypeName, bool setSelection, RockContext rockContext )
        {
            try
            {
                if ( filter.ExpressionType == FilterExpressionType.Filter )
                {
                    var filterControl = new FilterField();
                    parentControl.Controls.Add( filterControl );
                    filterControl.DataViewFilterGuid = filter.Guid;
                    filterControl.ID = string.Format( "ff_{0}", filterControl.DataViewFilterGuid.ToString( "N" ) );
                    filterControl.FilteredEntityTypeName = filteredEntityTypeName;
                    if ( filter.EntityTypeId.HasValue )
                    {
                        var entityTypeCache = Rock.Web.Cache.EntityTypeCache.Read( filter.EntityTypeId.Value, rockContext );
                        if ( entityTypeCache != null )
                        {
                            filterControl.FilterEntityTypeName = entityTypeCache.Name;
                        }
                    }

                    filterControl.Expanded = filter.Expanded;
                    if ( setSelection )
                    {
                        try
                        {
                            filterControl.SetSelection( filter.Selection );
                        }
                        catch ( Exception ex )
                        {
                            this.LogException( new Exception("Exception setting selection for DataViewFilter: " + filter.Guid, ex));
                        }
                    }

                    filterControl.DeleteClick += filterControl_DeleteClick;
                }
                else
                {
                    var groupControl = new FilterGroup();
                    parentControl.Controls.Add( groupControl );
                    groupControl.DataViewFilterGuid = filter.Guid;
                    groupControl.ID = string.Format( "fg_{0}", groupControl.DataViewFilterGuid.ToString( "N" ) );
                    groupControl.FilteredEntityTypeName = filteredEntityTypeName;
                    groupControl.IsDeleteEnabled = parentControl is FilterGroup;
                    if ( setSelection )
                    {
                        groupControl.FilterType = filter.ExpressionType;
                    }

                    groupControl.AddFilterClick += groupControl_AddFilterClick;
                    groupControl.AddGroupClick += groupControl_AddGroupClick;
                    groupControl.DeleteGroupClick += groupControl_DeleteGroupClick;
                    foreach ( var childFilter in filter.ChildFilters )
                    {
                        CreateFilterControl( groupControl, childFilter, filteredEntityTypeName, setSelection, rockContext );
                    }
                }
            }
            catch ( Exception ex )
            {
                this.LogException( new Exception( "Exception creating FilterControl for DataViewFilter: " + filter.Guid, ex ) );
            }
        }
        /// <summary>
        /// Creates the filter control.
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="setSelection">if set to <c>true</c> [set selection].</param>
        /// <param name="rockContext">The rock context.</param>
        private void CreateFilterControl( Control parentControl, DataViewFilter filter, bool setSelection, RockContext rockContext )
        {
            try
            {
                if ( filter.ExpressionType == FilterExpressionType.Filter )
                {
                    var filterControl = new FilterField();
                
                    parentControl.Controls.Add( filterControl );
                    filterControl.DataViewFilterGuid = filter.Guid;
                    filterControl.ID = string.Format( "ff_{0}", filterControl.DataViewFilterGuid.ToString( "N" ) );
                
                    // Remove the 'Other Data View' Filter as it doesn't really make sense to have it available in this scenario
                    filterControl.ExcludedFilterTypes = new string[] { typeof( Rock.Reporting.DataFilter.OtherDataViewFilter ).FullName };
                    filterControl.FilteredEntityTypeName = ITEM_TYPE_NAME;

                    if ( filter.EntityTypeId.HasValue )
                    {
                        var entityTypeCache = Rock.Web.Cache.EntityTypeCache.Read( filter.EntityTypeId.Value, rockContext );
                        if ( entityTypeCache != null )
                        {
                            filterControl.FilterEntityTypeName = entityTypeCache.Name;
                        }
                    }

                    filterControl.Expanded = filter.Expanded;
                    if ( setSelection )
                    {
                        try
                        {
                            filterControl.SetSelection( filter.Selection );
                        }
                        catch ( Exception ex )
                        {
                            this.LogException( new Exception( "Exception setting selection for DataViewFilter: " + filter.Guid, ex ) );
                        }
                    }

                    filterControl.DeleteClick += filterControl_DeleteClick;
                }
                else
                {
                    var groupControl = new FilterGroup();
                    parentControl.Controls.Add( groupControl );
                    groupControl.DataViewFilterGuid = filter.Guid;
                    groupControl.ID = string.Format( "fg_{0}", groupControl.DataViewFilterGuid.ToString( "N" ) );
                    groupControl.FilteredEntityTypeName = ITEM_TYPE_NAME;
                    groupControl.IsDeleteEnabled = parentControl is FilterGroup;
                    if ( setSelection )
                    {
                        groupControl.FilterType = filter.ExpressionType;
                    }

                    groupControl.AddFilterClick += groupControl_AddFilterClick;
                    groupControl.AddGroupClick += groupControl_AddGroupClick;
                    groupControl.DeleteGroupClick += groupControl_DeleteGroupClick;
                    foreach ( var childFilter in filter.ChildFilters )
                    {
                        CreateFilterControl( groupControl, childFilter, setSelection, rockContext );
                    }
                }
            }
            catch ( Exception ex )
            {
                this.LogException( new Exception( "Exception creating FilterControl for DataViewFilter: " + filter.Guid, ex ) );
            }
        }