Example #1
0
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls)
        {
            var pGroupPicker           = controls[0] as GroupPicker;
            var cbChildGroups          = controls[1] as RockCheckBox;
            var ddlIntegerCompare      = controls[2] as DropDownList;
            var tbAttendedCount        = controls[3] as RockTextBox;
            var slidingDateRangePicker = controls[4] as SlidingDateRangePicker;
            var schedulePicker         = controls[5] as SchedulePicker;

            // convert the date range from pipe-delimited to comma since we use pipe delimited for the selection values
            var dateRangeCommaDelimitedValues = slidingDateRangePicker.DelimitedValues.Replace('|', ',');
            var groupGuids = new GroupService(new RockContext()).GetByIds(pGroupPicker.ItemIds.AsIntegerList()).Select(a => a.Guid).ToList();

            var groupAttendanceFilterSelection = new GroupAttendanceFilterSelection
            {
                GroupGuids         = groupGuids,
                IntegerCompare     = ddlIntegerCompare.SelectedValue,
                AttendedCount      = tbAttendedCount.Text.AsInteger(),
                SlidingDateRange   = slidingDateRangePicker.DelimitedValues,
                IncludeChildGroups = cbChildGroups.Checked,
                // We have to eliminate zero, because the schedulePicker control adds a zero if no values are selected.
                Schedules = schedulePicker.SelectedValues.AsIntegerList().Where(x => x != 0).ToList(),
            };

            return(groupAttendanceFilterSelection.ToJson());
        }
Example #2
0
        private GroupAttendanceFilterSelection GetGroupAttendanceFilterSelection(string selection)
        {
            var groupAttendanceFilterSelection = selection.FromJsonOrNull <GroupAttendanceFilterSelection>();

            if (groupAttendanceFilterSelection != null)
            {
                return(groupAttendanceFilterSelection);
            }

            groupAttendanceFilterSelection = new GroupAttendanceFilterSelection();

            string[] options = selection.Split('|');
            if (options.Length >= 4)
            {
                groupAttendanceFilterSelection.GroupGuids     = options[0].Split(',').AsGuidList();
                groupAttendanceFilterSelection.IntegerCompare = options[1];
                groupAttendanceFilterSelection.AttendedCount  = options[2].AsInteger();

                // convert from comma-delimited to pipe since we store it as comma delimited so that we can use pipe delimited for the selection values
                var    dateRangeCommaDelimitedValues = options[3];
                string slidingDelimitedValues        = dateRangeCommaDelimitedValues.Replace(',', '|');
                groupAttendanceFilterSelection.SlidingDateRange = slidingDelimitedValues;

                if (options.Length >= 5)
                {
                    groupAttendanceFilterSelection.IncludeChildGroups = options[4].AsBooleanOrNull() ?? false;
                }
            }

            return(groupAttendanceFilterSelection);
        }
Example #3
0
        /// <summary>
        /// Creates the child controls.
        /// </summary>
        /// <returns></returns>
        public override Control[] CreateChildControls(Type entityType, FilterField filterControl)
        {
            var pGroupPicker = new GroupPicker();

            pGroupPicker.AllowMultiSelect = true;
            pGroupPicker.ID = $"{filterControl.ID}_{nameof( pGroupPicker )}";
            pGroupPicker.AddCssClass("js-group-picker");
            filterControl.Controls.Add(pGroupPicker);

            var cbChildGroups = new RockCheckBox();

            cbChildGroups.ID = $"{filterControl.ID}_{nameof( cbChildGroups )}";
            cbChildGroups.AddCssClass("js-child-groups");
            cbChildGroups.Text = "Include Child Groups";
            filterControl.Controls.Add(cbChildGroups);

            var ddlIntegerCompare = ComparisonHelper.ComparisonControl(ComparisonHelper.NumericFilterComparisonTypes);

            ddlIntegerCompare.Label = "Attendance Count";
            ddlIntegerCompare.ID    = $"{filterControl.ID}_{nameof( ddlIntegerCompare )}";
            ddlIntegerCompare.AddCssClass("js-filter-compare");
            filterControl.Controls.Add(ddlIntegerCompare);

            var tbAttendedCount = new RockTextBox();

            tbAttendedCount.ID    = $"{filterControl.ID}_{nameof( tbAttendedCount )}";
            tbAttendedCount.Label = "&nbsp;"; // give it whitespace label so it lines up nicely
            tbAttendedCount.AddCssClass("js-attended-count");
            filterControl.Controls.Add(tbAttendedCount);

            var slidingDateRangePicker = new SlidingDateRangePicker();

            slidingDateRangePicker.Label = "Date Range";
            slidingDateRangePicker.ID    = $"{filterControl.ID}_{nameof( slidingDateRangePicker )}";
            slidingDateRangePicker.AddCssClass("js-sliding-date-range");
            filterControl.Controls.Add(slidingDateRangePicker);

            var schedulePicker = new SchedulePicker();

            schedulePicker.Label = "Schedules";
            schedulePicker.ID    = $"{filterControl.ID}_{nameof( schedulePicker )}";
            schedulePicker.AddCssClass("js-schedule-picker");
            schedulePicker.AllowMultiSelect = true;
            filterControl.Controls.Add(schedulePicker);

            var controls = new Control[6] {
                pGroupPicker, cbChildGroups, ddlIntegerCompare, tbAttendedCount, slidingDateRangePicker, schedulePicker
            };

            var defaultGroupAttendanceFilterSelection = new GroupAttendanceFilterSelection
            {
                IntegerCompare     = ComparisonType.GreaterThanOrEqualTo.ConvertToInt().ToString(),
                AttendedCount      = 4,
                SlidingDateRange   = slidingDateRangePicker.DelimitedValues,
                IncludeChildGroups = false,
            };

            // set the default values in case this is a newly added filter
            SetSelection(
                entityType,
                controls,
                defaultGroupAttendanceFilterSelection.ToJson());

            return(controls);
        }