/// <summary>
        /// Loads the schedules
        /// </summary>
        private void LoadDropdowns()
        {
            var currentRange    = RockPage.GetUserPreference(ContextPreferenceName);
            var dateRangeString = Request.QueryString["SlidingDateRange"];

            if (!string.IsNullOrEmpty(dateRangeString) && currentRange != dateRangeString)
            {
                // set context to query string
                SetDateRangeContext(dateRangeString, false);
                currentRange = dateRangeString;
            }

            // if current range is selected, show a tooltip, otherwise show the default
            var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(currentRange);

            if (dateRange != null && dateRange.Start != null && dateRange.End != null)
            {
                lCurrentSelection.Text = dateRange.ToStringAutomatic();
                drpSlidingDateRange.DelimitedValues = currentRange;
            }
            else
            {
                lCurrentSelection.Text = GetAttributeValue("NoDateRangeText");
                drpSlidingDateRange.DelimitedValues = GetAttributeValue("DefaultDateRange");
            }
        }
Пример #2
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.Get(typeof(Campus)));

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

            if (GetAttributeValue(preKey + "RespectGroupContext").AsBoolean())
            {
                var groupTypeContext = RockPage.GetCurrentContext(EntityTypeCache.Get(typeof(GroupType)));
                var groupContext     = RockPage.GetCurrentContext(EntityTypeCache.Get(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.Get(typeof(Schedule)));

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

            return(metricValues.ToList());
        }
Пример #3
0
 /// <summary>
 /// Returns the user preference value for the current user for a given key
 /// </summary>
 /// <param name="key">A <see cref="System.String" /> representing the key to the user preference.</param>
 /// <returns>A <see cref="System.String" /> representing the user preference value. If a match for the key is not found,
 /// an empty string will be returned.</returns>
 public string GetUserPreference(string key)
 {
     return(RockPage.GetUserPreference(key));
 }