/// <summary>
        /// Handles the SelectedIndexChanged event of the ddlEntityType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void etpEntityType_SelectedIndexChanged(object sender, EventArgs e)
        {
            var dataViewFilter = new DataViewFilter();

            dataViewFilter.Guid           = Guid.NewGuid();
            dataViewFilter.ExpressionType = FilterExpressionType.GroupAll;
            var rockContext = new RockContext();

            BindDataTransformations(rockContext);

            var emptyFilter = new DataViewFilter();

            emptyFilter.ExpressionType = FilterExpressionType.Filter;
            emptyFilter.Guid           = Guid.NewGuid();
            dataViewFilter.ChildFilters.Add(emptyFilter);

            CreateFilterControl(etpEntityType.SelectedEntityTypeId, dataViewFilter, true, rockContext);
        }
Esempio n. 2
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);
         }
     }
 }
        private DataViewFilter GetFilterGroupControl(FilterGroup filterGroup)
        {
            DataViewFilter filter = new DataViewFilter
            {
                Guid           = filterGroup.DataViewFilterGuid,
                ExpressionType = filterGroup.FilterType
            };

            foreach (Control control in filterGroup.Controls)
            {
                DataViewFilter childFilter = GetFilterControl(control);
                if (childFilter != null)
                {
                    filter.ChildFilters.Add(childFilter);
                }
            }

            return(filter);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the filter field control.
        /// </summary>
        /// <param name="filterField">The filter field.</param>
        /// <returns></returns>
        private static DataViewFilter GetFilterFieldControl(FilterField filterField)
        {
            if (filterField.ShowCheckbox && !filterField.CheckBoxChecked.GetValueOrDefault(true))
            {
                return(null);
            }

            DataViewFilter filter = new DataViewFilter();

            filter.Guid           = filterField.DataViewFilterGuid;
            filter.ExpressionType = FilterExpressionType.Filter;
            filter.Expanded       = filterField.Expanded;
            if (filterField.FilterEntityTypeName != null)
            {
                filter.EntityTypeId = EntityTypeCache.Get(filterField.FilterEntityTypeName).Id;
                filter.Selection    = filterField.GetSelection();
            }

            return(filter);
        }
Esempio n. 5
0
        /// <summary>
        /// Sets the data filter, unless it has been set already
        /// Use this if this DataFilter wasn't known at the time the exception was raised.
        /// </summary>
        /// <param name="dataViewFilter">The data view filter.</param>
        public void SetDataFilterIfNotSet(DataViewFilter dataViewFilter)
        {
            if (_dataViewFilter != null)
            {
                return;
            }

            try
            {
                if (dataViewFilter?.DataViewId != null)
                {
                    DataView = dataViewFilter.DataView;
                }
            }
            catch
            {
                // if we weren't able to lazy-load DataView (or some other problem), just ignore
                DataView = null;
            }

            _dataViewFilter = dataViewFilter;
        }
Esempio n. 6
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DataView dataView = null;

            var             rockContext = new RockContext();
            DataViewService service     = new DataViewService(rockContext);

            int dataViewId           = int.Parse(hfDataViewId.Value);
            int?origDataViewFilterId = null;

            if (dataViewId == 0)
            {
                dataView          = new DataView();
                dataView.IsSystem = false;
            }
            else
            {
                dataView             = service.Get(dataViewId);
                origDataViewFilterId = dataView.DataViewFilterId;
            }

            dataView.Name                             = tbName.Text;
            dataView.Description                      = tbDescription.Text;
            dataView.TransformEntityTypeId            = ddlTransform.SelectedValueAsInt();
            dataView.EntityTypeId                     = etpEntityType.SelectedEntityTypeId;
            dataView.CategoryId                       = cpCategory.SelectedValueAsInt();
            dataView.PersistedScheduleIntervalMinutes = nbPersistedScheduleIntervalMinutes.Text.AsIntegerOrNull();

            var newDataViewFilter = ReportingHelper.GetFilterFromControls(phFilters);

            if (!Page.IsValid)
            {
                return;
            }

            if (!dataView.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            var adding = dataView.Id.Equals(0);

            if (adding)
            {
                service.Add(dataView);
            }

            rockContext.WrapTransaction(() =>
            {
                if (origDataViewFilterId.HasValue)
                {
                    // delete old report filter so that we can add the new filter (but with original guids), then drop the old filter
                    DataViewFilterService dataViewFilterService = new DataViewFilterService(rockContext);
                    DataViewFilter origDataViewFilter           = dataViewFilterService.Get(origDataViewFilterId.Value);

                    dataView.DataViewFilterId = null;
                    rockContext.SaveChanges();

                    DeleteDataViewFilter(origDataViewFilter, dataViewFilterService);
                }

                dataView.DataViewFilter = newDataViewFilter;
                rockContext.SaveChanges();
            });

            if (dataView.PersistedScheduleIntervalMinutes.HasValue)
            {
                dataView.PersistResult(GetAttributeValue("DatabaseTimeout").AsIntegerOrNull() ?? 180);
                dataView.PersistedLastRefreshDateTime = RockDateTime.Now;
                rockContext.SaveChanges();
            }

            if (adding)
            {
                // add EDIT and ADMINISTRATE to the person who added the dataView
                Rock.Security.Authorization.AllowPerson(dataView, Authorization.EDIT, this.CurrentPerson, rockContext);
                Rock.Security.Authorization.AllowPerson(dataView, Authorization.ADMINISTRATE, this.CurrentPerson, rockContext);
            }

            var qryParams = new Dictionary <string, string>();

            qryParams["DataViewId"]       = dataView.Id.ToString();
            qryParams["ParentCategoryId"] = null;
            NavigateToCurrentPageReference(qryParams);
        }
Esempio n. 7
0
        /// <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="setSelection">if set to <c>true</c> [set selection].</param>
        /// <param name="rockContext">The rock context.</param>
        private void CreateFilterControl(
            Control parentControl,
            DataViewFilter filter,
            EntityType reportEntityType,
            bool setSelection,
            RockContext rockContext)
        {
            try
            {
                var filteredEntityTypeName = EntityTypeCache.Get(reportEntityType).Name;
                if (filter.ExpressionType == FilterExpressionType.Filter)
                {
                    var  filterControl   = new FilterField();
                    bool filterIsVisible = _selectedDataFilterGuids.Contains(filter.Guid);

                    if (filterIsVisible)
                    {
                        // only set FilterMode to simple if the filter is visible since SimpleFilters might have a different filtering behavior
                        filterControl.FilterMode = FilterMode.SimpleFilter;
                    }
                    else
                    {
                        filterControl.FilterMode = FilterMode.AdvancedFilter;
                    }

                    bool filterIsConfigurable        = _configurableDataFilterGuids.Contains(filter.Guid);
                    bool showCheckbox                = _togglableDataFilterGuids.Contains(filter.Guid) || !filterIsConfigurable;
                    var  dataFilterPrePostHtmlConfig = _dataFiltersPrePostHtmlConfig.GetValueOrNull(filter.Guid) ?? new DataFilterPrePostHtmlConfig();

                    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 = EntityTypeCache.Get(filter.EntityTypeId.Value, rockContext);
                        if (entityTypeCache != null)
                        {
                            filterControl.FilterEntityTypeName = entityTypeCache.Name;
                        }
                    }

                    filterControl.Expanded = true;

                    filterControl.ShowCheckbox = filterIsVisible && showCheckbox;

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

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

                            if (filterControl.ShowCheckbox)
                            {
                                checkedUserPreference = this.GetUserPreference(string.Format("{0}_{1}_Checked", GetReportDataKeyPrefix(), filterControl.DataViewFilterGuid.ToString("N"))).AsBooleanOrNull() ?? true;
                            }
                        }

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

                        if (setSelection)
                        {
                            var selection = filter.Selection;
                            if (!string.IsNullOrWhiteSpace(selectionUserPreference))
                            {
                                if (component is Rock.Reporting.DataFilter.PropertyFilter)
                                {
                                    selection = (component as Rock.Reporting.DataFilter.PropertyFilter).UpdateSelectionFromUserPreferenceSelection(selection, selectionUserPreference);
                                }
                                else
                                {
                                    selection = selectionUserPreference;
                                }
                            }

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

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

                        string defaultFilterLabel;
                        if (!filterIsConfigurable)
                        {
                            // not configurable so just label it with the selection summary
                            defaultFilterLabel = component.FormatSelection(reportEntityTypeModel, filter.Selection);

                            // configuration not visible, so set the selection to what it was in the dataview when it was saved, even if setSelection=False
                            filterControl.SetSelection(filter.Selection);
                        }
                        else if (component is Rock.Reporting.DataFilter.PropertyFilter)
                        {
                            defaultFilterLabel = (component as Rock.Reporting.DataFilter.PropertyFilter).GetSelectionLabel(reportEntityTypeModel, filter.Selection);
                        }
                        else if (component is Rock.Reporting.DataFilter.EntityFieldFilter)
                        {
                            defaultFilterLabel = (component as Rock.Reporting.DataFilter.EntityFieldFilter).GetSelectedFieldName(filter.Selection);
                        }
                        else
                        {
                            defaultFilterLabel = component.GetTitle(reportEntityTypeModel);
                        }

                        var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson, new Rock.Lava.CommonMergeFieldsOptions {
                            GetLegacyGlobalMergeFields = false
                        });
                        mergeFields.Add("Filter", filter);
                        mergeFields.Add("Label", defaultFilterLabel);

                        filterControl.Label = dataFilterPrePostHtmlConfig.LabelHtml.ResolveMergeFields(mergeFields);

                        if (!string.IsNullOrEmpty(dataFilterPrePostHtmlConfig.PreHtml))
                        {
                            filterControl.PreHtml = dataFilterPrePostHtmlConfig.PreHtml.ResolveMergeFields(mergeFields);
                        }

                        if (!string.IsNullOrEmpty(dataFilterPrePostHtmlConfig.PostHtml))
                        {
                            filterControl.PostHtml = dataFilterPrePostHtmlConfig.PostHtml.ResolveMergeFields(mergeFields);
                        }

                        if (component is Rock.Reporting.DataFilter.OtherDataViewFilter)
                        {
                            // don't include the actual DataView Picker filter, just the child filters
                            parentControl.Controls.Remove(filterControl);

                            Rock.Reporting.DataFilter.OtherDataViewFilter otherDataViewFilter = component as Rock.Reporting.DataFilter.OtherDataViewFilter;
                            var otherDataView = otherDataViewFilter.GetSelectedDataView(filter.Selection);
                            if (otherDataView != null)
                            {
                                CreateFilterControl(parentControl, otherDataView.DataViewFilter, reportEntityType, setSelection, rockContext);
                            }
                        }
                    }
                }
                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, rockContext);
                    }
                }
            }
            catch (Exception ex)
            {
                this.LogException(new Exception("Exception creating FilterControl for DataViewFilter: " + filter.Guid, ex));
            }
        }
Esempio n. 8
0
        /// <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();
                    bool filterIsVisible = selectedDataFieldGuids.Contains(filter.Guid);

                    if (filterIsVisible)
                    {
                        // only set FilterMode to simple if the filter is visible since SimpleFilters might have a different filtering behavior
                        filterControl.FilterMode = FilterMode.SimpleFilter;
                    }
                    else
                    {
                        filterControl.FilterMode = FilterMode.AdvancedFilter;
                    }

                    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)
                        {
                            if (filterIsConfigurable)
                            {
                                selectionUserPreference = this.GetUserPreference(string.Format("{0}_{1}_Selection", GetReportDataKeyPrefix(), filterControl.DataViewFilterGuid.ToString("N")));
                            }

                            if (filterControl.ShowCheckbox)
                            {
                                checkedUserPreference = this.GetUserPreference(string.Format("{0}_{1}_Checked", GetReportDataKeyPrefix(), filterControl.DataViewFilterGuid.ToString("N"))).AsBooleanOrNull();
                            }
                        }

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

                        if (setSelection)
                        {
                            var selection = filter.Selection;
                            if (!string.IsNullOrWhiteSpace(selectionUserPreference))
                            {
                                if (component is Rock.Reporting.DataFilter.PropertyFilter)
                                {
                                    selection = (component as Rock.Reporting.DataFilter.PropertyFilter).UpdateSelectionFromUserPreferenceSelection(selection, selectionUserPreference);
                                }
                                else
                                {
                                    selection = selectionUserPreference;
                                }
                            }

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

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

                        if (!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)
                        {
                            // Property Filters already render a Label based on the selected Property Field, so leave the filter control label blank
                            filterControl.Label = string.Empty;
                        }
                        else
                        {
                            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));
            }
        }
Esempio n. 9
0
 public FilterInfo(DataViewFilter dataViewFilter)
 {
     DataViewFilter = dataViewFilter;
 }
Esempio n. 10
0
        /// <summary>
        /// Handles the SelectedIndexChanged event of the ddlEntityType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void ddlEntityType_SelectedIndexChanged( object sender, EventArgs e )
        {
            var dataViewFilter = new DataViewFilter();
            dataViewFilter.ExpressionType = FilterExpressionType.GroupAll;

            BindDataTransformations();

            var emptyFilter = new DataViewFilter();
            emptyFilter.ExpressionType = FilterExpressionType.Filter;
            dataViewFilter.ChildFilters.Add( emptyFilter );

            CreateFilterControl( ddlEntityType.SelectedValueAsInt(), dataViewFilter, true );
        }
Esempio n. 11
0
        /// <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 ) );
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Creates the filter control.
        /// </summary>
        /// <param name="channel">The channel.</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( ContentChannel channel, DataViewFilter filter, bool setSelection, RockContext rockContext )
        {
            HackEntityFields( channel, rockContext );

            phFilters.Controls.Clear();
            if ( filter != null )
            {
                CreateFilterControl( phFilters, filter, setSelection, rockContext );
            }
        }
Esempio n. 13
0
        public void AddStepDataViews()
        {
            var dataContext = new RockContext();

            // Add Data View Category "Steps".
            const string categoryDataViewStepsName = "Steps";

            Debug.Print($"Adding Data View Category \"{ categoryDataViewStepsName }\"...");

            var entityTypeId = EntityTypeCache.Get(typeof(Rock.Model.DataView)).Id;

            var stepsCategory = CreateCategory(categoryDataViewStepsName, Constants.CategoryStepsGuid, entityTypeId);

            AddOrUpdateCategory(dataContext, stepsCategory);

            dataContext.SaveChanges();

            // Create Data View: Steps Completed
            const string dataViewStepsCompleted2001Name = "Steps Completed in 2001";

            Debug.Print($"Adding Data View \"{ dataViewStepsCompleted2001Name }\"...");

            DataView dataView = new DataView();

            dataView.IsSystem = false;

            var service = new DataViewService(dataContext);

            int categoryId = CategoryCache.GetId(Constants.CategoryStepsGuid) ?? 0;

            dataView.Name         = dataViewStepsCompleted2001Name;
            dataView.Description  = "Steps that have a completion in the year 2001.";
            dataView.EntityTypeId = EntityTypeCache.GetId(typeof(Rock.Model.Step));
            dataView.CategoryId   = categoryId;
            dataView.Guid         = Constants.DataViewStepsCompleted2001Guid;
            dataView.ForeignKey   = _SampleDataForeignKey;

            var rootFilter = new DataViewFilter();

            rootFilter.ExpressionType = FilterExpressionType.GroupAll;

            dataView.DataViewFilter = rootFilter;

            // Add filter for Step Type
            var dateCompletedFilter = new DataViewFilter();

            dateCompletedFilter.ExpressionType = FilterExpressionType.Filter;
            dateCompletedFilter.EntityTypeId   = EntityTypeCache.GetId(typeof(Rock.Reporting.DataFilter.PropertyFilter));

            var dateFilterSettings = new List <string> {
                "Property_CompletedDateTime", "4096", "\tDateRange|||1/01/2001 12:00:00 AM|31/12/2001 12:00:00 AM"
            };

            dateCompletedFilter.Selection = dateFilterSettings.ToJson();

            rootFilter.ChildFilters.Add(dateCompletedFilter);

            service.Add(dataView);

            dataContext.SaveChanges();
        }
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RockDataViewFilterExpressionException" /> class.
 /// </summary>
 /// <param name="dataViewFilter">The data view filter.</param>
 /// <param name="message">The message.</param>
 public RockDataViewFilterExpressionException(DataViewFilter dataViewFilter, string message)
     : this(dataViewFilter, message, null)
 {
 }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RockDataViewFilterExpressionException"/> class.
 /// </summary>
 /// <param name="dataViewFilter">The data view filter.</param>
 /// <param name="message">The message.</param>
 /// <param name="innerException">The inner exception.</param>
 public RockDataViewFilterExpressionException(DataViewFilter dataViewFilter, string message, Exception innerException)
     : base(message, innerException)
 {
     SetDataFilterIfNotSet(dataViewFilter);
     _message = message;
 }
Esempio n. 16
0
 private void CreateFilterControl( int? filteredEntityTypeId, DataViewFilter filter, bool setSelection )
 {
     phFilters.Controls.Clear();
     if ( filter != null && filteredEntityTypeId.HasValue )
     {
         var filteredEntityType = EntityTypeCache.Read( filteredEntityTypeId.Value );
         CreateFilterControl( phFilters, filter, filteredEntityType.Name, setSelection );
     }
 }
Esempio n. 17
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;
 }
Esempio n. 18
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        public void ShowEdit()
        {
            int? filterId = hfDataFilterId.Value.AsIntegerOrNull();

            if ( ChannelGuid.HasValue )
            {
                var rockContext = new RockContext();
                var channel = new ContentChannelService( rockContext ).Queryable( "ContentChannelType" )
                    .FirstOrDefault( c => c.Guid.Equals( ChannelGuid.Value ) );
                if ( channel != null )
                {

                    cblStatus.Visible = channel.RequiresApproval;

                    cbSetRssAutodiscover.Visible = channel.EnableRss;

                    var filterService = new DataViewFilterService( rockContext );
                    DataViewFilter filter = null;

                    if ( filterId.HasValue )
                    {
                        filter = filterService.Get( filterId.Value );
                    }

                    if ( filter == null || filter.ExpressionType == FilterExpressionType.Filter )
                    {
                        filter = new DataViewFilter();
                        filter.Guid = new Guid();
                        filter.ExpressionType = FilterExpressionType.GroupAll;
                    }

                    CreateFilterControl( channel, filter, true, rockContext );

                    kvlOrder.CustomKeys = new Dictionary<string, string>();
                    kvlOrder.CustomKeys.Add( "", "" );
                    kvlOrder.CustomKeys.Add( "Title", "Title" );
                    kvlOrder.CustomKeys.Add( "Priority", "Priority" );
                    kvlOrder.CustomKeys.Add( "Status", "Status" );
                    kvlOrder.CustomKeys.Add( "StartDateTime", "Start" );
                    kvlOrder.CustomKeys.Add( "ExpireDateTime", "Expire" );
                    kvlOrder.CustomKeys.Add( "Order", "Order" );


                    // add attributes to the meta description and meta image attribute list
                    ddlMetaDescriptionAttribute.Items.Clear();
                    ddlMetaImageAttribute.Items.Clear();
                    ddlMetaDescriptionAttribute.Items.Add( "" );
                    ddlMetaImageAttribute.Items.Add( "" );

                    string currentMetaDescriptionAttribute = GetAttributeValue( "MetaDescriptionAttribute" ) ?? string.Empty;
                    string currentMetaImageAttribute = GetAttributeValue( "MetaImageAttribute" ) ?? string.Empty;

                    // add channel attributes
                    channel.LoadAttributes();
                    foreach ( var attribute in channel.Attributes )
                    {
                        var field = attribute.Value.FieldType.Field;
                        string computedKey = "C^" + attribute.Key;

                        ddlMetaDescriptionAttribute.Items.Add( new ListItem( "Channel: " + attribute.Value.ToString(), computedKey ) );

                        if ( field is Rock.Field.Types.ImageFieldType )
                        {
                            ddlMetaImageAttribute.Items.Add( new ListItem( "Channel: " + attribute.Value.ToString(), computedKey ) );
                        }
                    }

                    // add item attributes
                    AttributeService attributeService = new AttributeService( rockContext );
                    var itemAttributes = attributeService.GetByEntityTypeId( new ContentChannelItem().TypeId ).AsQueryable()
                                            .Where( a => (
                                                    a.EntityTypeQualifierColumn.Equals( "ContentChannelTypeId", StringComparison.OrdinalIgnoreCase ) &&
                                                    a.EntityTypeQualifierValue.Equals( channel.ContentChannelTypeId.ToString() ) 
                                                ) || (
                                                    a.EntityTypeQualifierColumn.Equals( "ContentChannelId", StringComparison.OrdinalIgnoreCase ) &&
                                                    a.EntityTypeQualifierValue.Equals( channel.Id.ToString() ) 
                                                ) )
                                            .ToList();

                    foreach ( var attribute in itemAttributes )
                    {
                        kvlOrder.CustomKeys.Add( "Attribute:" + attribute.Key, attribute.Name );

                        string computedKey = "I^" + attribute.Key;
                        ddlMetaDescriptionAttribute.Items.Add( new ListItem( "Item: " + attribute.Name, computedKey ) );

                        var field = attribute.FieldType.Name;

                        if ( field == "Image" )
                        {
                            ddlMetaImageAttribute.Items.Add( new ListItem( "Item: " + attribute.Name, computedKey ) );
                        }
                    }

                    // select attributes
                    SetListValue( ddlMetaDescriptionAttribute, currentMetaDescriptionAttribute );
                    SetListValue( ddlMetaImageAttribute, currentMetaImageAttribute );

                }
            }
        }
Esempio n. 19
0
        /// <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 ) );
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Determines whether the specified Data View forms part of a filter.
        /// </summary>
        /// <param name="dataViewId">The unique identifier of a Data View.</param>
        /// <param name="filter">The filter.</param>
        /// <returns>
        ///   <c>true</c> if the specified Data View forms part of the conditions for the specified filter.
        /// </returns>
        public bool IsViewInFilter( int dataViewId, DataViewFilter filter )
        {
            var dataViewFilterEntityId = new EntityTypeService( (RockContext)this.Context ).Get( typeof( OtherDataViewFilter ), false, null ).Id;

            return IsViewInFilter( dataViewId, filter, dataViewFilterEntityId );
        }
Esempio n. 21
0
        /// <summary>
        /// Gets the filter recursive.
        /// </summary>
        /// <param name="filterList">The filter list.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="reportEntityType">Type of the report entity.</param>
        private static void GetFilterListRecursive(List <FilterInfo> filterList, DataViewFilter filter, EntityType reportEntityType)
        {
            var result = new Dictionary <Guid, string>();

            var entityType            = EntityTypeCache.Read(filter.EntityTypeId ?? 0);
            var reportEntityTypeCache = EntityTypeCache.Read(reportEntityType);
            var reportEntityTypeModel = reportEntityTypeCache.GetEntityType();

            var filterInfo = new FilterInfo(filter);

            filterInfo.FilterList = filterList;

            if (entityType != null)
            {
                var component = Rock.Reporting.DataFilterContainer.GetComponent(entityType.Name);
                filterInfo.Component             = component;
                filterInfo.ReportEntityTypeModel = reportEntityTypeModel;

                if (component != null)
                {
                    if (component is Rock.Reporting.DataFilter.EntityFieldFilter)
                    {
                        var entityFieldFilter = component as Rock.Reporting.DataFilter.EntityFieldFilter;
                        var fieldName         = entityFieldFilter.GetSelectedFieldName(filter.Selection);
                        if (!string.IsNullOrWhiteSpace(fieldName))
                        {
                            var entityFields = EntityHelper.GetEntityFields(reportEntityTypeModel);
                            var entityField  = entityFields.Where(a => a.Name == fieldName).FirstOrDefault();
                            if (entityField != null)
                            {
                                filterInfo.Title = entityField.Title;
                            }
                            else
                            {
                                filterInfo.Title = fieldName;
                            }
                        }
                    }
                    else
                    {
                        filterInfo.Title = component.GetTitle(reportEntityType.GetType());
                    }
                }
            }

            filterList.Add(filterInfo);

            if (filterInfo.Component is Rock.Reporting.DataFilter.OtherDataViewFilter)
            {
                Rock.Reporting.DataFilter.OtherDataViewFilter otherDataViewFilter = filterInfo.Component as Rock.Reporting.DataFilter.OtherDataViewFilter;
                var otherDataView = otherDataViewFilter.GetSelectedDataView(filterInfo.Selection);
                if (otherDataView != null)
                {
                    var otherDataViewFilterList = new List <FilterInfo>();
                    GetFilterListRecursive(otherDataViewFilterList, otherDataView.DataViewFilter, reportEntityType);
                    foreach (var otherFilter in otherDataViewFilterList)
                    {
                        if (otherFilter.FromOtherDataView == null)
                        {
                            otherFilter.FromOtherDataView = otherDataView.Name;
                        }
                    }

                    filterList.AddRange(otherDataViewFilterList);
                }
            }

            foreach (var childFilter in filter.ChildFilters)
            {
                GetFilterListRecursive(filterList, childFilter, reportEntityType);
            }
        }
Esempio n. 22
0
        private bool IsViewInFilter( int dataViewId, DataViewFilter filter, int dataViewFilterEntityId )
        {
            if ( filter.EntityTypeId == dataViewFilterEntityId )
            {
                var filterDataViewId = filter.Selection.AsIntegerOrNull();
                if ( filterDataViewId == dataViewId )
                {
                    return true;
                }
            }

            return filter.ChildFilters.Any( childFilter => IsViewInFilter( dataViewId, childFilter, dataViewFilterEntityId ) );
        }
Esempio n. 23
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DataView dataView = null;

            using (new UnitOfWorkScope())
            {
                DataViewService service = new DataViewService();

                int dataViewId       = int.Parse(hfDataViewId.Value);
                int?dataViewFilterId = null;

                if (dataViewId == 0)
                {
                    dataView          = new DataView();
                    dataView.IsSystem = false;
                }
                else
                {
                    dataView         = service.Get(dataViewId);
                    dataViewFilterId = dataView.DataViewFilterId;
                }

                dataView.Name                  = tbName.Text;
                dataView.Description           = tbDescription.Text;
                dataView.TransformEntityTypeId = ddlTransform.SelectedValueAsInt();
                dataView.EntityTypeId          = ddlEntityType.SelectedValueAsInt();
                dataView.CategoryId            = cpCategory.SelectedValueAsInt();

                dataView.DataViewFilter = GetFilterControl();

                if (!Page.IsValid)
                {
                    return;
                }

                if (!dataView.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                RockTransactionScope.WrapTransaction(() =>
                {
                    if (dataView.Id.Equals(0))
                    {
                        service.Add(dataView, CurrentPersonId);
                    }

                    service.Save(dataView, CurrentPersonId);

                    // Delete old report filter
                    if (dataViewFilterId.HasValue)
                    {
                        DataViewFilterService dataViewFilterService = new DataViewFilterService();
                        DataViewFilter dataViewFilter = dataViewFilterService.Get(dataViewFilterId.Value);
                        DeleteDataViewFilter(dataViewFilter, dataViewFilterService);
                        dataViewFilterService.Save(dataViewFilter, CurrentPersonId);
                    }
                });
            }

            var qryParams = new Dictionary <string, string>();

            qryParams["DataViewId"] = dataView.Id.ToString();
            NavigateToPage(this.CurrentPage.Guid, qryParams);
        }
Esempio n. 24
0
        /// <summary>
        /// Reset all of the identifiers on a DataViewFilter that uniquely identify it in the permanent store.
        /// </summary>
        /// <param name="filter">The data view filter.</param>
        private void ResetPermanentStoreIdentifiers( DataViewFilter filter )
        {
            if ( filter == null )
                return;

            filter.Id = 0;
            filter.Guid = Guid.NewGuid();
            filter.ForeignId = null;
            filter.ForeignGuid = null;
            filter.ForeignKey = null;

            // Recursively reset any contained filters.
            foreach ( var childFilter in filter.ChildFilters )
            {
                this.ResetPermanentStoreIdentifiers( childFilter );
            }
        }
Esempio n. 25
0
 /// <summary>
 /// Restores the view-state information from a previous user control request that was saved by the <see cref="M:System.Web.UI.UserControl.SaveViewState" /> method.
 /// </summary>
 /// <param name="savedState">An <see cref="T:System.Object" /> that represents the user control state to be restored.</param>
 protected override void LoadViewState(object savedState)
 {
     base.LoadViewState(savedState);
     CreateFilterControl(ViewState["EntityTypeId"] as int?, DataViewFilter.FromJson(ViewState["DataViewFilter"].ToString()), false);
 }
Esempio n. 26
0
        /// <summary>
        /// Configures the channel specific settings.
        /// </summary>
        private void ConfigureChannelSpecificSettings()
        {
            int?filterId  = hfDataFilterId.Value.AsIntegerOrNull();
            int?channelId = ddlContentChannel.SelectedValueAsId();

            if (channelId.HasValue)
            {
                var rockContext = new RockContext();
                var channel     = new ContentChannelService(rockContext).Queryable("ContentChannelType")
                                  .FirstOrDefault(c => c.Id == channelId.Value);

                if (channel != null)
                {
                    //cblStatus.Visible = channel.RequiresApproval && !channel.ContentChannelType.DisableStatus;

                    var            filterService = new DataViewFilterService(rockContext);
                    DataViewFilter filter        = null;

                    if (filterId.HasValue)
                    {
                        filter = filterService.Get(filterId.Value);
                    }

                    if (filter == null || filter.ExpressionType == FilterExpressionType.Filter)
                    {
                        filter = new DataViewFilter
                        {
                            Guid           = new Guid(),
                            ExpressionType = FilterExpressionType.GroupAll
                        };
                    }

                    CreateFilterControl(channel, filter, true, rockContext);

                    //
                    // Setup the available order-by keys.
                    //
                    kvlOrder.CustomKeys = new Dictionary <string, string>
                    {
                        { "", "" },
                        { "Title", "Title" },
                        { "Priority", "Priority" },
                        { "Status", "Status" },
                        { "StartDateTime", "Start" },
                        { "ExpireDateTime", "Expire" },
                        { "Order", "Order" }
                    };

                    //
                    // Add item attributes to the ordery-by keys.
                    //
                    AttributeService attributeService = new AttributeService(rockContext);
                    var itemAttributes = attributeService.GetByEntityTypeId(new ContentChannelItem().TypeId, false).AsQueryable()
                                         .Where(a => (
                                                    a.EntityTypeQualifierColumn.Equals("ContentChannelTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                    a.EntityTypeQualifierValue.Equals(channel.ContentChannelTypeId.ToString())
                                                    ) || (
                                                    a.EntityTypeQualifierColumn.Equals("ContentChannelId", StringComparison.OrdinalIgnoreCase) &&
                                                    a.EntityTypeQualifierValue.Equals(channel.Id.ToString())
                                                    ))
                                         .OrderByDescending(a => a.EntityTypeQualifierColumn)
                                         .ThenBy(a => a.Order)
                                         .ToAttributeCacheList();

                    foreach (var attribute in itemAttributes)
                    {
                        string attrKey = "Attribute:" + attribute.Key;
                        if (!kvlOrder.CustomKeys.ContainsKey(attrKey))
                        {
                            kvlOrder.CustomKeys.Add("Attribute:" + attribute.Key, attribute.Name);
                        }
                    }
                }
            }
        }
Esempio n. 27
0
 /// <summary>
 /// Set the Guids on the datafilter and it's children to Guid.NewGuid
 /// </summary>
 /// <param name="dataViewFilter">The data view filter.</param>
 private void SetNewDataFilterGuids( DataViewFilter dataViewFilter )
 {
     if (dataViewFilter != null)
     {
         dataViewFilter.Guid = Guid.NewGuid();
         foreach ( var childFilter in dataViewFilter.ChildFilters )
         {
             SetNewDataFilterGuids( childFilter );
         }
     }
 }
        /// <summary>
        /// Shows the edit.
        /// </summary>
        public void ShowEdit()
        {
            int?filterId = hfDataFilterId.Value.AsIntegerOrNull();

            if (ChannelGuid.HasValue)
            {
                var rockContext = new RockContext();
                var channel     = new ContentChannelService(rockContext).Queryable("ContentChannelType")
                                  .FirstOrDefault(c => c.Guid.Equals(ChannelGuid.Value));
                if (channel != null)
                {
                    cblStatus.Visible = channel.RequiresApproval && !channel.ContentChannelType.DisableStatus;

                    var            filterService = new DataViewFilterService(rockContext);
                    DataViewFilter filter        = null;

                    if (filterId.HasValue)
                    {
                        filter = filterService.Get(filterId.Value);
                    }

                    if (filter == null || filter.ExpressionType == FilterExpressionType.Filter)
                    {
                        filter                = new DataViewFilter();
                        filter.Guid           = new Guid();
                        filter.ExpressionType = FilterExpressionType.GroupAll;
                    }

                    CreateFilterControl(channel, filter, true, rockContext);

                    kvlOrder.CustomKeys = new Dictionary <string, string>();
                    kvlOrder.CustomKeys.Add("", "");
                    kvlOrder.CustomKeys.Add("Title", "Title");
                    kvlOrder.CustomKeys.Add("Priority", "Priority");
                    kvlOrder.CustomKeys.Add("Status", "Status");
                    kvlOrder.CustomKeys.Add("StartDateTime", "Start");
                    kvlOrder.CustomKeys.Add("ExpireDateTime", "Expire");
                    kvlOrder.CustomKeys.Add("Order", "Order");

                    string currentMetaDescriptionAttribute = GetAttributeValue("MetaDescriptionAttribute") ?? string.Empty;
                    string currentMetaImageAttribute       = GetAttributeValue("MetaImageAttribute") ?? string.Empty;

                    // add channel attributes
                    channel.LoadAttributes();
                    foreach (var attribute in channel.Attributes)
                    {
                        var    field       = attribute.Value.FieldType.Field;
                        string computedKey = "C^" + attribute.Key;
                    }

                    // add item attributes
                    AttributeService attributeService = new AttributeService(rockContext);
                    var itemAttributes = attributeService.GetByEntityTypeId(new ContentChannelItem().TypeId).AsQueryable()
                                         .Where(a => (
                                                    a.EntityTypeQualifierColumn.Equals("ContentChannelTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                    a.EntityTypeQualifierValue.Equals(channel.ContentChannelTypeId.ToString())
                                                    ) || (
                                                    a.EntityTypeQualifierColumn.Equals("ContentChannelId", StringComparison.OrdinalIgnoreCase) &&
                                                    a.EntityTypeQualifierValue.Equals(channel.Id.ToString())
                                                    ))
                                         .OrderByDescending(a => a.EntityTypeQualifierColumn)
                                         .ThenBy(a => a.Order)
                                         .ToList();

                    foreach (var attribute in itemAttributes)
                    {
                        string attrKey = "Attribute:" + attribute.Key;
                        if (!kvlOrder.CustomKeys.ContainsKey(attrKey))
                        {
                            kvlOrder.CustomKeys.Add("Attribute:" + attribute.Key, attribute.Name);

                            string computedKey = "I^" + attribute.Key;

                            var field = attribute.FieldType.Name;
                        }
                    }
                }
            }
        }
Esempio n. 29
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();
                    filterControl.ValidationGroup = this.BlockValidationGroup;
                    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 = EntityTypeCache.Get(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));
            }
        }
Esempio n. 31
0
 private void DeleteDataViewFilter( DataViewFilter dataViewFilter, DataViewFilterService service )
 {
     if ( dataViewFilter != null )
     {
         foreach ( var childFilter in dataViewFilter.ChildFilters.ToList() )
         {
             DeleteDataViewFilter( childFilter, service );
         }
         service.Delete( dataViewFilter, CurrentPersonId );
     }
 }
Esempio n. 32
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DataView dataView = null;

            var             rockContext = new RockContext();
            DataViewService service     = new DataViewService(rockContext);

            int dataViewId       = int.Parse(hfDataViewId.Value);
            int?dataViewFilterId = null;

            if (dataViewId == 0)
            {
                dataView          = new DataView();
                dataView.IsSystem = false;
            }
            else
            {
                dataView         = service.Get(dataViewId);
                dataViewFilterId = dataView.DataViewFilterId;
            }

            dataView.Name                  = tbName.Text;
            dataView.Description           = tbDescription.Text;
            dataView.TransformEntityTypeId = ddlTransform.SelectedValueAsInt();
            dataView.EntityTypeId          = etpEntityType.SelectedEntityTypeId;
            dataView.CategoryId            = cpCategory.SelectedValueAsInt();

            dataView.DataViewFilter = GetFilterControl();

            // update Guids since we are creating a new dataFilter and children and deleting the old one
            SetNewDataFilterGuids(dataView.DataViewFilter);

            if (!Page.IsValid)
            {
                return;
            }

            if (!dataView.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            var adding = dataView.Id.Equals(0);

            if (adding)
            {
                service.Add(dataView);
            }

            // Delete old report filter
            if (dataViewFilterId.HasValue)
            {
                DataViewFilterService dataViewFilterService = new DataViewFilterService(rockContext);
                DataViewFilter        dataViewFilter        = dataViewFilterService.Get(dataViewFilterId.Value);
                DeleteDataViewFilter(dataViewFilter, dataViewFilterService);
            }

            rockContext.SaveChanges();

            if (adding)
            {
                // add EDIT and ADMINISTRATE to the person who added the dataView
                Rock.Security.Authorization.AllowPerson(dataView, Authorization.EDIT, this.CurrentPerson, rockContext);
                Rock.Security.Authorization.AllowPerson(dataView, Authorization.ADMINISTRATE, this.CurrentPerson, rockContext);
            }

            var qryParams = new Dictionary <string, string>();

            qryParams["DataViewId"] = dataView.Id.ToString();
            NavigateToPage(RockPage.Guid, qryParams);
        }
Esempio n. 33
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 );
         }
     }
 }
Esempio n. 34
0
        public void GroupsModule_AddDataViews()
        {
            var dataContext = new RockContext();

            // Add Data View Category "Groups".
            const string categoryDataViewName = "Groups";

            Debug.Print($"Adding Data View Category \"{ categoryDataViewName }\"...");

            var entityTypeId = EntityTypeCache.Get(typeof(global::Rock.Model.DataView)).Id;

            var coreHelper = new CoreModuleTestHelper(_SampleDataForeignKey);

            var locationsCategory = coreHelper.CreateCategory(categoryDataViewName, Constants.CategoryLocationsGuid, entityTypeId);

            coreHelper.AddOrUpdateCategory(dataContext, locationsCategory);

            dataContext.SaveChanges();

            // Get Data View service.
            var service = new DataViewService(dataContext);

            int categoryId = CategoryCache.GetId(Constants.CategoryLocationsGuid) ?? 0;

            DataViewFilter rootFilter;

            // Create Data View: Locations Inside Arizona
            const string dataViewLocationsInsideArizona = "Locations in the state of Arizona";

            Debug.Print($"Adding Data View \"{ dataViewLocationsInsideArizona }\"...");

            var dataViewInside = new DataView();

            dataViewInside.IsSystem = false;

            dataViewInside.Name         = dataViewLocationsInsideArizona;
            dataViewInside.Description  = "Locations that are within the state of Arizona.";
            dataViewInside.EntityTypeId = EntityTypeCache.GetId(typeof(global::Rock.Model.Location));
            dataViewInside.CategoryId   = categoryId;
            dataViewInside.Guid         = Constants.DataViewLocationsInsideArizonaGuid;
            dataViewInside.ForeignKey   = _SampleDataForeignKey;

            rootFilter = new DataViewFilter();

            rootFilter.ExpressionType = FilterExpressionType.GroupAll;

            dataViewInside.DataViewFilter = rootFilter;

            var inStateFilter = new TextPropertyFilterSettings {
                PropertyName = "State", Comparison = ComparisonType.EqualTo, Value = "AZ"
            };

            rootFilter.ChildFilters.Add(inStateFilter.GetFilter());

            service.Add(dataViewInside);

            dataContext.SaveChanges();

            // Create Data View: Locations Outside Arizona
            const string dataViewLocationsOutsideArizona = "Locations outside Arizona";

            Debug.Print($"Adding Data View \"{ dataViewLocationsOutsideArizona }\"...");

            var dataViewOutside = new DataView();

            dataViewOutside.IsSystem = false;

            dataViewOutside.Name         = dataViewLocationsOutsideArizona;
            dataViewOutside.Description  = "Locations that are not within the state of Arizona.";
            dataViewOutside.EntityTypeId = EntityTypeCache.GetId(typeof(global::Rock.Model.Location));
            dataViewOutside.CategoryId   = categoryId;
            dataViewOutside.Guid         = Constants.DataViewLocationsOutsideArizonaGuid;
            dataViewOutside.ForeignKey   = _SampleDataForeignKey;

            rootFilter = new DataViewFilter();

            rootFilter.ExpressionType = FilterExpressionType.GroupAll;

            dataViewOutside.DataViewFilter = rootFilter;

            var notInStateFilter = new TextPropertyFilterSettings {
                PropertyName = "State", Comparison = ComparisonType.NotEqualTo, Value = "AZ"
            };

            rootFilter.ChildFilters.Add(notInStateFilter.GetFilter());

            service.Add(dataViewOutside);

            dataContext.SaveChanges();
        }
Esempio n. 35
0
        private DataViewFilter GetFilterFieldControl( FilterField filterField )
        {
            DataViewFilter filter = new DataViewFilter();
            filter.ExpressionType = FilterExpressionType.Filter;
            filter.Expanded = filterField.Expanded;
            if ( filterField.FilterEntityTypeName != null )
            {
                filter.EntityTypeId = Rock.Web.Cache.EntityTypeCache.Read( filterField.FilterEntityTypeName ).Id;
                filter.Selection = filterField.Selection;
            }

            return filter;
        }
Esempio n. 36
0
        /// <summary>
        /// Handles the SelectedIndexChanged event of the ddlEntityType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void etpEntityType_SelectedIndexChanged( object sender, EventArgs e )
        {
            var dataViewFilter = new DataViewFilter();
            dataViewFilter.Guid = Guid.NewGuid();
            dataViewFilter.ExpressionType = FilterExpressionType.GroupAll;
            var rockContext = new RockContext();

            BindDataTransformations( rockContext );

            var emptyFilter = new DataViewFilter();
            emptyFilter.ExpressionType = FilterExpressionType.Filter;
            emptyFilter.Guid = Guid.NewGuid();
            dataViewFilter.ChildFilters.Add( emptyFilter );

            CreateFilterControl( etpEntityType.SelectedEntityTypeId, dataViewFilter, true, rockContext );
        }
        /// <summary>
        /// Handles the Click event of the lbConfigure control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void lbConfigure_Click(object sender, EventArgs e)
        {
            pnlContentComponentConfig.Visible = true;
            mdContentComponentConfig.Show();

            Guid?          contentChannelGuid = this.GetAttributeValue("ContentChannel").AsGuidOrNull();
            ContentChannel contentChannel     = null;

            if (contentChannelGuid.HasValue)
            {
                contentChannel = new ContentChannelService(new RockContext()).Get(contentChannelGuid.Value);
            }

            if (contentChannel == null)
            {
                contentChannel = new ContentChannel {
                    ContentChannelTypeId = this.ContentChannelTypeId
                };
            }

            tbComponentName.Text = contentChannel.Name;
            contentChannel.LoadAttributes();
            avcContentChannelAttributes.NumberOfColumns = 2;
            avcContentChannelAttributes.ValidationGroup = mdContentComponentConfig.ValidationGroup;
            avcContentChannelAttributes.AddEditControls(contentChannel);

            nbItemCacheDuration.Text = this.GetAttributeValue("ItemCacheDuration");

            DefinedTypeCache contentComponentTemplateType = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.CONTENT_COMPONENT_TEMPLATE.AsGuid());

            if (contentComponentTemplateType != null)
            {
                dvpContentComponentTemplate.DefinedTypeId = contentComponentTemplateType.Id;
            }

            DefinedValueCache contentComponentTemplate = null;
            var contentComponentTemplateValueGuid      = this.GetAttributeValue("ContentComponentTemplate").AsGuidOrNull();

            if (contentComponentTemplateValueGuid.HasValue)
            {
                contentComponentTemplate = DefinedValueCache.Get(contentComponentTemplateValueGuid.Value);
            }

            dvpContentComponentTemplate.SetValue(contentComponentTemplate);

            cbAllowMultipleContentItems.Checked = this.GetAttributeValue("AllowMultipleContentItems").AsBoolean();

            nbOutputCacheDuration.Text = this.GetAttributeValue("OutputCacheDuration");

            // Cache Tags
            cblCacheTags.DataSource = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.CACHE_TAGS.AsGuid()).DefinedValues.Select(v => v.Value).ToList();
            cblCacheTags.DataBind();
            cblCacheTags.Visible = cblCacheTags.Items.Count > 0;
            string[] selectedCacheTags = this.GetAttributeValue("CacheTags").SplitDelimitedValues();
            foreach (ListItem cacheTag in cblCacheTags.Items)
            {
                cacheTag.Selected = selectedCacheTags.Contains(cacheTag.Value);
            }

            cePreHtml.Text  = this.BlockCache.PreHtml;
            cePostHtml.Text = this.BlockCache.PostHtml;

            hfDataFilterId.Value = GetAttributeValue("FilterId");

            int?filterId    = hfDataFilterId.Value.AsIntegerOrNull();
            var rockContext = new RockContext();

            var            filterService = new DataViewFilterService(rockContext);
            DataViewFilter filter        = null;

            if (filterId.HasValue)
            {
                filter = filterService.Get(filterId.Value);
            }

            if (filter == null || filter.ExpressionType == FilterExpressionType.Filter)
            {
                filter                = new DataViewFilter();
                filter.Guid           = new Guid();
                filter.ExpressionType = FilterExpressionType.GroupAll;
            }

            CreateFilterControl(this.ContentChannelTypeId, filter, true, rockContext);
        }
Esempio n. 38
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 ) );
            }
        }
Esempio n. 39
0
        /// <summary>
        /// Gets the filter recursive.
        /// </summary>
        /// <param name="filterList">The filter list.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="reportEntityType">Type of the report entity.</param>
        private void GetFilterListRecursive( List<FilterInfo> filterList, DataViewFilter filter, EntityType reportEntityType )
        {
            var result = new Dictionary<Guid, string>();

            var entityType = EntityTypeCache.Read( filter.EntityTypeId ?? 0 );
            var reportEntityTypeCache = EntityTypeCache.Read( reportEntityType );
            var reportEntityTypeModel = reportEntityTypeCache.GetEntityType();

            var filterInfo = new FilterInfo();
            filterInfo.Guid = filter.Guid;
            filterInfo.FilterExpressionType = filter.ExpressionType;
            filterInfo.ParentFilter = filter.ParentId.HasValue ? filterList.FirstOrDefault( a => a.Guid == filter.Parent.Guid ) : null;
            if ( entityType != null )
            {
                var component = Rock.Reporting.DataFilterContainer.GetComponent( entityType.Name );
                if ( component != null )
                {
                    if ( component is Rock.Reporting.DataFilter.EntityFieldFilter )
                    {
                        var entityFieldFilter = component as Rock.Reporting.DataFilter.EntityFieldFilter;
                        var fieldName = entityFieldFilter.GetSelectedFieldName( filter.Selection );
                        if ( !string.IsNullOrWhiteSpace( fieldName ) )
                        {
                            var entityFields = EntityHelper.GetEntityFields( reportEntityTypeModel );
                            var entityField = entityFields.Where( a => a.Name == fieldName ).FirstOrDefault();
                            if ( entityField != null )
                            {
                                filterInfo.Title = entityField.Title;
                            }
                            else
                            {
                                filterInfo.Title = fieldName;
                            }
                        }
                    }
                    else
                    {
                        filterInfo.Title = component.GetTitle( reportEntityType.GetType() );
                    }

                    filterInfo.Summary = component.FormatSelection( reportEntityTypeModel, filter.Selection );

                }
            }

            filterList.Add( filterInfo );

            foreach ( var childFilter in filter.ChildFilters )
            {
                GetFilterListRecursive( filterList, childFilter, reportEntityType );
            }
        }
Esempio n. 40
0
        /// <summary>
        /// Gets the filter field control.
        /// </summary>
        /// <param name="filterField">The filter field.</param>
        /// <returns></returns>
        private static DataViewFilter GetFilterFieldControl( FilterField filterField )
        {
            if (filterField.ShowCheckbox && !filterField.CheckBoxChecked.GetValueOrDefault(true) )
            {
                return null;
            }

            DataViewFilter filter = new DataViewFilter();
            filter.Guid = filterField.DataViewFilterGuid;
            filter.ExpressionType = FilterExpressionType.Filter;
            filter.Expanded = filterField.Expanded;
            if ( filterField.FilterEntityTypeName != null )
            {
                filter.EntityTypeId = Rock.Web.Cache.EntityTypeCache.Read( filterField.FilterEntityTypeName ).Id;
                filter.Selection = filterField.GetSelection();
            }

            return filter;
        }