Example #1
0
        /// <summary>
        /// Creates the control(s) neccessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl( Dictionary<string, ConfigurationValue> configurationValues, string id )
        {
            var editControl = new RockDropDownList { ID = id };

            var roles = new GroupService( new RockContext() ).Queryable().Where(g => g.IsSecurityRole).OrderBy( t => t.Name );
            if ( roles.Any() )
            {
                foreach ( var role in roles )
                {
                    editControl.Items.Add( new ListItem( role.Name, role.Guid.ToString() ) );
                }

                return editControl;
            }

            return null;
        }
        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            Controls.Clear();

            _hfExpanded = new HiddenField();
            Controls.Add( _hfExpanded );
            _hfExpanded.ID = this.ID + "_hfExpanded";
            _hfExpanded.Value = "False";

            _hfActivityGuid = new HiddenField();
            Controls.Add( _hfActivityGuid );
            _hfActivityGuid.ID = this.ID + "_hfActivityTypeGuid";

            _lblActivityTypeName = new Label();
            Controls.Add( _lblActivityTypeName );
            _lblActivityTypeName.ClientIDMode = ClientIDMode.Static;
            _lblActivityTypeName.ID = this.ID + "_lblActivityTypeName";
            
            _lblActivityTypeDescription = new Label();
            Controls.Add( _lblActivityTypeDescription );
            _lblActivityTypeDescription.ClientIDMode = ClientIDMode.Static;
            _lblActivityTypeDescription.ID = this.ID + "_lblActivityTypeDescription";

            _lblStatus = new Label();
            Controls.Add( _lblStatus );
            _lblStatus.ClientIDMode = ClientIDMode.Static;
            _lblStatus.ID = this.ID + "_lblInactive";
            _lblStatus.CssClass = "label label-important pull-right";

            _lbDeleteActivityType = new LinkButton();
            Controls.Add( _lbDeleteActivityType );
            _lbDeleteActivityType.CausesValidation = false;
            _lbDeleteActivityType.ID = this.ID + "_lbDeleteActivityType";
            _lbDeleteActivityType.CssClass = "btn btn-xs btn-danger js-activity-delete";
            _lbDeleteActivityType.Click += lbDeleteActivityType_Click;
            _lbDeleteActivityType.Controls.Add( new LiteralControl { Text = "<i class='fa fa-times'></i>" } );

            _cbActivityIsComplete = new RockCheckBox { Text = "Complete" };
            Controls.Add( _cbActivityIsComplete );
            _cbActivityIsComplete.ID = this.ID + "_cbActivityTypeIsActive";

            _ppAssignedToPerson = new PersonPicker();
            _ppAssignedToPerson.ID = this.ID + "_ppAssignedToPerson";
            Controls.Add( _ppAssignedToPerson );
            _ppAssignedToPerson.Label = "Assign to Person";

            _gpAssignedToGroup = new GroupPicker();
            _gpAssignedToGroup.ID = this.ID + "_gpAssignedToGroup";
            Controls.Add( _gpAssignedToGroup );
            _gpAssignedToGroup.Label = "Assign to Group";

            _ddlAssignedToRole = new RockDropDownList();
            Controls.Add( _ddlAssignedToRole );
            _ddlAssignedToRole.ID = this.ID + "_ddlAssignedToRole";
            _ddlAssignedToRole.Label = "Assign to Security Role";
            _lState = new Literal();
            Controls.Add( _lState );
            _lState.ID = this.ID + "_lState";

            _ddlAssignedToRole.Items.Add( new ListItem( string.Empty, "0" ) );
            var roles = new GroupService( new RockContext() ).Queryable().Where( g => g.IsSecurityRole ).OrderBy( t => t.Name );
            if ( roles.Any() )
            {
                foreach ( var role in roles )
                {
                    _ddlAssignedToRole.Items.Add( new ListItem( role.Name, role.Id.ToString() ) );
                }
            }

            _phAttributes = new PlaceHolder();
            Controls.Add( _phAttributes );
            _phAttributes.ID = this.ID + "_phAttributes";
        }
Example #3
0
        /// <summary>
        /// Gets the metric values.
        /// </summary>
        /// <param name="isPrimary">if set to <c>true</c> [is primary].</param>
        /// <returns></returns>
        protected List<MetricValue> GetMetricValues( bool isPrimary )
        {
            var rockContext = new RockContext();
            var metricService = new MetricService( rockContext );
            List<Guid> sourceGuids = null;
            var preKey = isPrimary ? string.Empty : "Comparison";
            IQueryable<MetricValue> metricValues = null;

            var attributeValue = GetAttributeValue( preKey + "MetricSource" );

            if ( string.IsNullOrWhiteSpace( attributeValue ) )
            {
                attributeValue = string.Empty;
            }

            var pairs = MetricCategoriesFieldAttribute.GetValueAsGuidPairs( attributeValue );
            sourceGuids = pairs.Select( p => p.MetricGuid ).ToList();

            if ( sourceGuids.Any() )
            {
                metricValues = metricService.GetByGuids( sourceGuids ).SelectMany( m => m.MetricValues );
            }
            else
            {
                nbMetricWarning.Visible = true;
                pnlMetricDisplay.Visible = false;
                return null;
            }

            if ( GetAttributeValue( preKey + "RespectCampusContext" ).AsBoolean() )
            {
                var campusContext = RockPage.GetCurrentContext( EntityTypeCache.Read( typeof( Campus ) ) );

                if ( campusContext != null )
                {
                    metricValues = FilterMetricValuesByPartition( metricValues, "Campus", campusContext.Id );
                }
            }

            if ( GetAttributeValue( preKey + "RespectGroupContext" ).AsBoolean() )
            {
                var groupTypeContext = RockPage.GetCurrentContext( EntityTypeCache.Read( typeof( GroupType ) ) );
                var groupContext = RockPage.GetCurrentContext( EntityTypeCache.Read( typeof( Group ) ) );

                if ( groupContext != null )
                {
                    metricValues = FilterMetricValuesByPartition( metricValues, "Group", groupContext.Id );
                }
                else if ( groupTypeContext != null )
                {
                    var groupTypeIds = new GroupTypeService( rockContext ).GetAllAssociatedDescendents( groupTypeContext.Id ).Select( gt => gt.Id );
                    var groupIds = new GroupService( rockContext ).Queryable().Where( g => groupTypeIds.Contains( g.GroupTypeId ) ).Select( g => g.Id );
                    metricValues = metricValues.Where( a => a.MetricValuePartitions.Any( mvp => mvp.MetricPartition.Label == "Group" && groupIds.Any( i => i == mvp.EntityId ) ) );
                }
            }

            if ( GetAttributeValue( preKey + "RespectDateContext" ).AsBoolean() )
            {
                var dateRangeString = RockPage.GetUserPreference( ContextPreferenceName );

                if ( !string.IsNullOrWhiteSpace( dateRangeString ) )
                {
                    var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues( dateRangeString );
                    metricValues = metricValues.Where( v => v.MetricValueDateTime >= dateRange.Start && v.MetricValueDateTime <= dateRange.End );
                }
            }

            if ( GetAttributeValue( preKey + "RespectScheduleContext" ).AsBoolean() )
            {
                var scheduleContext = RockPage.GetCurrentContext( EntityTypeCache.Read( typeof( Schedule ) ) );

                if ( scheduleContext != null )
                {
                    metricValues = FilterMetricValuesByPartition( metricValues, "Schedule", scheduleContext.Id );
                }
            }

            return metricValues.ToList();
        }
Example #4
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
        {
            Guid groupGuid = selection.AsGuid();

            var geoQry = new GroupService( (RockContext)serviceInstance.Context )
                .GetGeofencedFamilies( groupGuid )
                .SelectMany( g => g.Members );

            var qry = new PersonService( (RockContext)serviceInstance.Context ).Queryable()
                .Where( p => geoQry.Any( xx => xx.PersonId == p.Id ) );

            Expression extractedFilterExpression = FilterExpressionExtractor.Extract<Rock.Model.Person>( qry, parameterExpression, "p" );

            return extractedFilterExpression;
        }
Example #5
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
        {
            var values = selection.Split( '|' );

            ComparisonType comparisonType = values[0].ConvertToEnum<ComparisonType>( ComparisonType.EqualTo );
            string postalCode = values[1];

            var familyGroupTypeGuid = Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid();

            var groupLocationQry = new GroupLocationService( ( RockContext ) serviceInstance.Context ).Queryable();

            switch ( comparisonType )
            {
                case ComparisonType.EqualTo:
                    groupLocationQry = groupLocationQry.Where( gl => gl.Location.PostalCode == postalCode );
                    break;
                case ComparisonType.NotEqualTo:
                    groupLocationQry = groupLocationQry.Where( gl => gl.Location.PostalCode != postalCode );
                    break;
                case ComparisonType.StartsWith:
                    groupLocationQry = groupLocationQry.Where( gl => gl.Location.PostalCode.StartsWith( postalCode ) );
                    break;
                case ComparisonType.Contains:
                    groupLocationQry = groupLocationQry.Where( gl => gl.Location.PostalCode.Contains( postalCode ) );
                    break;
                case ComparisonType.DoesNotContain:
                    groupLocationQry = groupLocationQry.Where( gl => !gl.Location.PostalCode.Contains( postalCode ) );
                    break;
                case ComparisonType.IsBlank:
                    groupLocationQry = groupLocationQry
                        .Where( gl => gl.Location.PostalCode == null || gl.Location.PostalCode == string.Empty );
                    break;
                case ComparisonType.IsNotBlank:
                    groupLocationQry = groupLocationQry
                        .Where( gl => gl.Location.PostalCode != null && gl.Location.PostalCode != string.Empty );
                    break;
                case ComparisonType.EndsWith:
                    groupLocationQry = groupLocationQry.Where( gl => gl.Location.PostalCode.EndsWith( postalCode ) );
                    break;
                default:
                    break;
            }

            IQueryable<Rock.Model.Person> qry;

            var groupMemberQry = groupLocationQry.Select( gl => gl.Group )
                .Where( g => g.GroupType.Guid == familyGroupTypeGuid )
                .SelectMany( g => g.Members );

            // Families which do not have locations need to be added separately
            if ( comparisonType == ComparisonType.IsBlank || comparisonType == ComparisonType.DoesNotContain || comparisonType == ComparisonType.NotEqualTo )
            {
                var noLocationGroupMembersQry = new GroupService( ( RockContext ) serviceInstance.Context ).Queryable()
                .Where( g => g.GroupType.Guid == familyGroupTypeGuid && !g.GroupLocations.Any() )
                .SelectMany( g => g.Members );

                qry = new PersonService( ( RockContext ) serviceInstance.Context ).Queryable()
                    .Where( p => groupMemberQry.Any( xx => xx.PersonId == p.Id ) || noLocationGroupMembersQry.Any( xx => xx.PersonId == p.Id ) );
            }
            else
            {
                qry = new PersonService( ( RockContext ) serviceInstance.Context ).Queryable()
                    .Where( p => groupMemberQry.Any( xx => xx.PersonId == p.Id ) );
            }

            Expression extractedFilterExpression = FilterExpressionExtractor.Extract<Rock.Model.Person>( qry, parameterExpression, "p" );

            return extractedFilterExpression;
        }