/// <summary> /// Gets the primary partition entity identifier from context. /// </summary> /// <returns></returns> private List <MetricPartitionEntityId> GetPrimaryMetricPartitionEntityIdFromContext() { List <MetricPartitionEntityId> results = new List <MetricPartitionEntityId>(); if (!this.MetricId.HasValue) { return(results); } using (var rockContext = new Rock.Data.RockContext()) { var metric = new Rock.Model.MetricService(rockContext).Get(this.MetricId ?? 0); if (metric == null) { return(results); } foreach (var mp in metric.MetricPartitions.OrderBy(a => a.Order)) { var result = new MetricPartitionEntityId(); result.MetricPartition = mp; var entityTypeCache = EntityTypeCache.Get(result.MetricPartition.EntityTypeId ?? 0); if (entityTypeCache != null && this.ContextEntity(entityTypeCache.Name) != null) { result.EntityId = this.ContextEntity(entityTypeCache.Name).Id; } // if Getting the EntityFromContext, and we didn't get it from ContextEntity, get it from the Page Param if (!result.EntityId.HasValue) { // figure out what the param name should be ("CampusId, GroupId, etc") depending on metric's entityType var entityParamName = "EntityId"; if (entityTypeCache != null) { entityParamName = entityTypeCache.Name + "Id"; } result.EntityId = this.PageParameter(entityParamName).AsIntegerOrNull(); } results.Add(result); } } return(results); }
/// <summary> /// Loads the chart. /// </summary> public void LoadChart() { flotChart.Visible = true; var flotChartControl = flotChart; flotChartControl.StartDate = this.DateRange.Start; flotChartControl.EndDate = this.DateRange.End; flotChartControl.MetricValueType = this.MetricValueType; flotChartControl.CombineValues = this.CombineValues; flotChartControl.ShowTooltip = true; Guid?detailPageGuid = (GetAttributeValue("DetailPage") ?? string.Empty).AsGuidOrNull(); if (detailPageGuid.HasValue) { flotChartControl.ChartClick += lcExample_ChartClick; } flotChartControl.Options.SetChartStyle(this.ChartStyleDefinedValueGuid); flotChartControl.Options.legend = flotChartControl.Options.legend ?? new Legend(); flotChartControl.Options.legend.show = this.GetAttributeValue("ShowLegend").AsBooleanOrNull(); flotChartControl.Options.legend.position = this.GetAttributeValue("LegendPosition"); flotChartControl.MetricId = this.MetricId; if (this.GetEntityFromContextEnabled) { MetricPartitionEntityId primaryMetricPartitionEntityId = GetPrimaryMetricPartitionEntityIdFromContext(); if (primaryMetricPartitionEntityId != null && primaryMetricPartitionEntityId.MetricPartition != null) { flotChartControl.MetricValuePartitionEntityIds = string.Format("{0}|{1}", primaryMetricPartitionEntityId.MetricPartition.EntityTypeId, primaryMetricPartitionEntityId.EntityId); } } else { flotChartControl.MetricValuePartitionEntityIds = GetAttributeValue("MetricEntityTypeEntityIds"); } nbMetricWarning.Visible = !this.MetricId.HasValue; pnlDashboardTitle.Visible = !string.IsNullOrEmpty(this.Title); pnlDashboardSubtitle.Visible = !string.IsNullOrEmpty(this.Subtitle); lDashboardTitle.Text = this.Title; lDashboardSubtitle.Text = this.Subtitle; }
/// <summary> /// Gets the primary partition entity identifier from context. /// </summary> /// <returns></returns> private MetricPartitionEntityId GetPrimaryMetricPartitionEntityIdFromContext() { EntityTypeCache entityTypeCache = null; MetricPartitionEntityId result = new MetricPartitionEntityId(); if (this.MetricId.HasValue) { using (var rockContext = new Rock.Data.RockContext()) { var metric = new Rock.Model.MetricService(rockContext).Get(this.MetricId ?? 0); if (metric != null) { // for backwards compatibily, get the first metric partition result.MetricPartition = metric.MetricPartitions.OrderBy(a => a.Order).First(); entityTypeCache = EntityTypeCache.Read(result.MetricPartition.EntityTypeId ?? 0); } } } if (entityTypeCache != null && this.ContextEntity(entityTypeCache.Name) != null) { result.EntityId = this.ContextEntity(entityTypeCache.Name).Id; } // if Getting the EntityFromContext, and we didn't get it from ContextEntity, get it from the Page Param if (!result.EntityId.HasValue) { // figure out what the param name should be ("CampusId, GroupId, etc") depending on metric's entityType var entityParamName = "EntityId"; if (entityTypeCache != null) { entityParamName = entityTypeCache.Name + "Id"; } result.EntityId = this.PageParameter(entityParamName).AsIntegerOrNull(); } return(result); }
/// <summary> /// Gets the primary partition entity identifier from context. /// </summary> /// <returns></returns> private MetricPartitionEntityId GetPrimaryMetricPartitionEntityIdFromContext() { EntityTypeCache entityTypeCache = null; MetricPartitionEntityId result = new MetricPartitionEntityId(); if ( this.MetricId.HasValue ) { using ( var rockContext = new Rock.Data.RockContext() ) { var metric = new Rock.Model.MetricService( rockContext ).Get( this.MetricId ?? 0 ); if ( metric != null ) { // for backwards compatibily, get the first metric partition result.MetricPartition = metric.MetricPartitions.OrderBy( a => a.Order ).First(); entityTypeCache = EntityTypeCache.Read( result.MetricPartition.EntityTypeId ?? 0 ); } } } if ( entityTypeCache != null && this.ContextEntity( entityTypeCache.Name ) != null ) { result.EntityId = this.ContextEntity( entityTypeCache.Name ).Id; } // if Getting the EntityFromContext, and we didn't get it from ContextEntity, get it from the Page Param if ( !result.EntityId.HasValue ) { // figure out what the param name should be ("CampusId, GroupId, etc") depending on metric's entityType var entityParamName = "EntityId"; if ( entityTypeCache != null ) { entityParamName = entityTypeCache.Name + "Id"; } result.EntityId = this.PageParameter( entityParamName ).AsIntegerOrNull(); } return result; }