Rock.Web.UI.Controls.FlotChart.RegisterJavaScriptForMetric C# (CSharp) Method

RegisterJavaScriptForMetric() private method

Registers the java script for metric.
private RegisterJavaScriptForMetric ( Metric metric ) : void
metric Metric The metric.
return void
        private void RegisterJavaScriptForMetric( Metric metric )
        {
            if ( string.IsNullOrWhiteSpace( this.XAxisLabel ) )
            {
                // if XAxisLabel hasn't been set, and this is a metric, automatically set it to the metric.XAxisLabel
                this.XAxisLabel = metric.XAxisLabel;
            }

            if ( string.IsNullOrWhiteSpace( this.YAxisLabel ) )
            {
                // if YAxisLabel hasn't been set, and this is a metric, automatically set it to the metric.YAxisLabel
                this.YAxisLabel = metric.YAxisLabel;
            }

            _hfRestUrlParams.Value = string.Format( "{0}", this.MetricId );

            List<string> filterParams = new List<string>();
            List<string> qryParams = new List<string>();
            if ( this.StartDate.HasValue )
            {
                filterParams.Add( string.Format( "MetricValueDateTime ge DateTime'{0}'", this.StartDate.Value.ToString( "o" ) ) );
            }

            if ( this.EndDate.HasValue )
            {
                filterParams.Add( string.Format( "MetricValueDateTime lt DateTime'{0}'", this.EndDate.Value.ToString( "o" ) ) );
            }

            if ( this.MetricValueType.HasValue )
            {
                // MetricValueType is an enum, which isn't quite supported for $filters as of Web Api 2.1, so pass it as a regular rest param instead of as part of the odata $filter
                qryParams.Add( string.Format( "metricValueType={0}", this.MetricValueType ) );
            }

            var entityTypeEntityIds = (MetricValuePartitionEntityIds ?? string.Empty).Split( ',' ).Select( a => a.Split( '|' ) ).Where( a => a.Length == 2 ).Select( a => new
            {
                EntityTypeId = a[0].AsIntegerOrNull(),
                EntityId = a[1].AsIntegerOrNull()
            } ).ToList();

            if ( entityTypeEntityIds.Any() )
            {
                var position = 0;
                foreach ( var metricPartition in metric.MetricPartitions.OrderBy(a => a.Order ))
                {
                    if ( entityTypeEntityIds.Count() > position )
                    {
                        var entry = entityTypeEntityIds[position];
                        if ( entry.EntityTypeId == metricPartition.EntityTypeId && entry.EntityId.HasValue )
                        {
                            filterParams.Add( string.Format( "MetricValuePartitions/any(metricValuePartition: metricValuePartition/EntityId eq {0} and metricValuePartition/MetricPartitionId eq {1})", entry.EntityId.Value, metricPartition.Id ) );
                        }
                    }

                    position++;
                }
            }
            else if ( this.legacyEntityId.HasValue )
            {

                int partitionId = metric.MetricPartitions.OrderBy( a => a.Order ).First().Id;
                filterParams.Add( string.Format( "MetricValuePartitions/any(metricValuePartition: metricValuePartition/EntityId eq {0} and metricValuePartition/MetricPartitionId eq {1})", this.legacyEntityId, partitionId ) );
            }

            if ( filterParams.Count > 0 )
            {
                qryParams.Add( "$filter=" + filterParams.AsDelimited( " and " ) );
            }

            _hfRestUrlParams.Value += "?" + qryParams.AsDelimited( "&" );
        }