/// <summary> /// Binds the data filters grid in the Settings dialog /// </summary> protected void BindDataFiltersGrid( bool selectAll ) { var rockContext = new RockContext(); var reportService = new ReportService( rockContext ); var reportGuid = ddlReport.SelectedValueAsGuid(); Report report = null; if ( reportGuid.HasValue ) { report = reportService.Get( reportGuid.Value ); } nbConfigurationWarning.Visible = false; if ( report != null && report.DataView != null && report.DataView.DataViewFilter != null ) { var selectedDataFieldGuids = ( this.GetAttributeValue( "SelectedDataFieldGuids" ) ?? string.Empty ).Split( '|' ).AsGuidList(); var configurableDataFieldGuids = ( this.GetAttributeValue( "ConfigurableDataFieldGuids" ) ?? string.Empty ).Split( '|' ).AsGuidList(); var togglableDataFieldGuids = ( this.GetAttributeValue( "TogglableDataFieldGuids" ) ?? string.Empty ).Split( '|' ).AsGuidList(); var filters = new List<FilterInfo>(); GetFilterListRecursive( filters, report.DataView.DataViewFilter, report.EntityType ); // remove the top level group filter filters = filters.Where( a => a.ParentFilter != null ).ToList(); // set the Title and Summary of Grouped Filters based on the GroupFilter's child filter titles foreach ( var groupedFilter in filters.Where( a => a.FilterExpressionType != FilterExpressionType.Filter ) ) { groupedFilter.Title = string.Format( "[{0}]", groupedFilter.FilterExpressionType.ConvertToString() ); groupedFilter.Summary = filters.Where( a => a.ParentFilter == groupedFilter ).Select( a => a.Summary ?? string.Empty ).ToList().AsDelimited( ", ", groupedFilter.FilterExpressionType == FilterExpressionType.GroupAny ? " or " : " and " ); } // remove any filter that are part of a child group filter filters = filters.Where( a => a.ParentFilter != null && a.ParentFilter.ParentFilter == null ).ToList(); grdDataFilters.Visible = true; mdConfigure.ServerSaveLink.Disabled = false; grdDataFilters.DataSource = filters.Select( a => new { a.Guid, a.Title, a.TitlePath, a.Summary, a.FilterExpressionType, a.ParentFilter, ShowAsFilter = selectAll || selectedDataFieldGuids.Contains( a.Guid ), IsConfigurable = selectAll || configurableDataFieldGuids.Contains( a.Guid ), IsTogglable = selectAll || togglableDataFieldGuids.Contains( a.Guid ) } ); grdDataFilters.DataBind(); } else { grdDataFilters.Visible = false; } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { Report report = null; var rockContext = new RockContext(); ReportService service = new ReportService( rockContext ); ReportFieldService reportFieldService = new ReportFieldService( rockContext ); int reportId = int.Parse( hfReportId.Value ); if ( reportId == 0 ) { report = new Report(); report.IsSystem = false; } else { report = service.Get( reportId ); } report.Name = tbName.Text; report.Description = tbDescription.Text; report.CategoryId = cpCategory.SelectedValueAsInt(); report.EntityTypeId = etpEntityType.SelectedEntityTypeId; report.DataViewId = ddlDataView.SelectedValueAsInt(); report.FetchTop = nbFetchTop.Text.AsIntegerOrNull(); if ( !Page.IsValid ) { return; } if ( !report.IsValid ) { // Controls will render the error messages return; } // delete all the reportFields so we can cleanly add them foreach ( var reportField in report.ReportFields.ToList() ) { var field = reportFieldService.Get( reportField.Guid ); reportFieldService.Delete( field ); } report.ReportFields.Clear(); var allPanelWidgets = phReportFields.ControlsOfTypeRecursive<PanelWidget>(); int displayOrder = 0; foreach ( var panelWidget in allPanelWidgets ) { string ddlFieldsId = panelWidget.ID + "_ddlFields"; RockDropDownList ddlFields = phReportFields.ControlsOfTypeRecursive<RockDropDownList>().First( a => a.ID == ddlFieldsId ); ReportFieldType reportFieldType = ReportFieldType.Property; string fieldSelection = string.Empty; string fieldSelectionValue = ddlFields.SelectedItem.Value; string[] fieldSelectionValueParts = fieldSelectionValue.Split( '|' ); if ( fieldSelectionValueParts.Count() == 2 ) { reportFieldType = fieldSelectionValueParts[0].ConvertToEnum<ReportFieldType>(); fieldSelection = fieldSelectionValueParts[1]; } else { // skip over fields that have nothing selected in ddlFields continue; } ReportField reportField = new ReportField(); reportField.ReportFieldType = reportFieldType; string showInGridCheckBoxId = string.Format( "{0}_showInGridCheckBox", panelWidget.ID ); RockCheckBox showInGridCheckBox = phReportFields.ControlsOfTypeRecursive<RockCheckBox>().First( a => a.ID == showInGridCheckBoxId ); reportField.ShowInGrid = showInGridCheckBox.Checked; string columnHeaderTextTextBoxId = string.Format( "{0}_columnHeaderTextTextBox", panelWidget.ID ); RockTextBox columnHeaderTextTextBox = phReportFields.ControlsOfTypeRecursive<RockTextBox>().First( a => a.ID == columnHeaderTextTextBoxId ); reportField.ColumnHeaderText = columnHeaderTextTextBox.Text; reportField.Order = displayOrder++; if ( reportFieldType == ReportFieldType.DataSelectComponent ) { reportField.DataSelectComponentEntityTypeId = fieldSelection.AsIntegerOrNull(); string dataSelectComponentTypeName = EntityTypeCache.Read( reportField.DataSelectComponentEntityTypeId ?? 0 ).GetEntityType().FullName; DataSelectComponent dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName ); string placeHolderId = string.Format( "{0}_phDataSelectControls", panelWidget.ID ); var placeHolder = phReportFields.ControlsOfTypeRecursive<PlaceHolder>().Where( a => a.ID == placeHolderId ).FirstOrDefault(); reportField.Selection = dataSelectComponent.GetSelection( placeHolder.Controls.OfType<Control>().ToArray() ); } else { reportField.Selection = fieldSelection; } report.ReportFields.Add( reportField ); } if ( report.Id.Equals( 0 ) ) { service.Add( report ); } rockContext.SaveChanges(); var qryParams = new Dictionary<string, string>(); qryParams["ReportId"] = report.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Handles the Click event of the btnEdit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnEdit_Click( object sender, EventArgs e ) { var item = new ReportService( new RockContext() ).Get( int.Parse( hfReportId.Value ) ); ShowEditDetails( item ); }
/// <summary> /// Handles the Click event of the btnDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnDelete_Click( object sender, EventArgs e ) { int? categoryId = null; var rockContext = new RockContext(); var reportService = new ReportService( rockContext ); var report = reportService.Get( hfReportId.Value.AsInteger() ); if ( report != null ) { string errorMessage; if ( !reportService.CanDelete( report, out errorMessage ) ) { ShowReadonlyDetails( report ); mdDeleteWarning.Show( errorMessage, ModalAlertType.Information ); return; } else { categoryId = report.CategoryId; reportService.Delete( report ); rockContext.SaveChanges(); // reload page, selecting the deleted data view's parent var qryParams = new Dictionary<string, string>(); if ( categoryId != null ) { qryParams["CategoryId"] = categoryId.ToString(); } NavigateToPage( RockPage.Guid, qryParams ); } } }
/// <summary> /// Handles the Click event of the btnCancel control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnCancel_Click( object sender, EventArgs e ) { if ( hfReportId.Value.Equals( "0" ) ) { int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsIntegerOrNull(); if ( parentCategoryId.HasValue ) { // Cancelling on Add, and we know the parentCategoryId, so we are probably in treeview mode, so navigate to the current page var qryParams = new Dictionary<string, string>(); qryParams["CategoryId"] = parentCategoryId.ToString(); NavigateToPage( RockPage.Guid, qryParams ); } else { // Cancelling on Add. Return to Grid NavigateToParentPage(); } } else { // Cancelling on Edit. Return to Details ReportService service = new ReportService( new RockContext() ); Report item = service.Get( int.Parse( hfReportId.Value ) ); ShowReadonlyDetails( item ); } }
/// <summary> /// Shows the readonly details. /// </summary> /// <param name="dataView">The data view.</param> private void ShowReadonlyDetails( DataView dataView ) { SetEditMode( false ); hfDataViewId.SetValue( dataView.Id ); lReadOnlyTitle.Text = dataView.Name.FormatAsHtmlTitle(); hlblDataViewId.Text = "Id: " + dataView.Id.ToString(); lDescription.Text = dataView.Description; DescriptionList descriptionListMain = new DescriptionList(); if ( dataView.EntityType != null ) { descriptionListMain.Add( "Applies To", dataView.EntityType.FriendlyName ); } if ( dataView.Category != null ) { descriptionListMain.Add( "Category", dataView.Category.Name ); } if ( dataView.TransformEntityType != null ) { descriptionListMain.Add( "Post-filter Transformation", dataView.TransformEntityType.FriendlyName ); } lblMainDetails.Text = descriptionListMain.Html; DescriptionList descriptionListFilters = new DescriptionList(); if ( dataView.DataViewFilter != null && dataView.EntityTypeId.HasValue ) { var entityTypeCache = EntityTypeCache.Read( dataView.EntityTypeId.Value ); if ( entityTypeCache != null ) { var entityTypeType = entityTypeCache.GetEntityType(); if ( entityTypeType != null ) { descriptionListFilters.Add( "Filter", dataView.DataViewFilter.ToString( entityTypeType ) ); } } } lFilters.Text = descriptionListFilters.Html; DescriptionList descriptionListDataviews = new DescriptionList(); var dataViewFilterEntityId = EntityTypeCache.Read( typeof( Rock.Reporting.DataFilter.OtherDataViewFilter ) ).Id; var rockContext = new RockContext(); DataViewService dataViewService = new DataViewService( rockContext ); var dataViews = dataViewService.Queryable() .Where( d => d.DataViewFilter.ChildFilters .Any( f => f.Selection == dataView.Id.ToString() && f.EntityTypeId == dataViewFilterEntityId ) ); StringBuilder sbDataViews = new StringBuilder(); var dataViewDetailPage = GetAttributeValue( "DataViewDetailPage" ); foreach ( var dataview in dataViews ) { if ( !string.IsNullOrWhiteSpace( dataViewDetailPage ) ) { sbDataViews.Append( "<a href=\"" + LinkedPageUrl( "DataViewDetailPage", new Dictionary<string, string>() { { "DataViewId", dataview.Id.ToString() } } ) + "\">" + dataview.Name + "</a><br/>" ); } else { sbDataViews.Append( dataview.Name + "<br/>" ); } } descriptionListDataviews.Add( "Data Views", sbDataViews ); lDataViews.Text = descriptionListDataviews.Html; DescriptionList descriptionListReports = new DescriptionList(); StringBuilder sbReports = new StringBuilder(); ReportService reportService = new ReportService( rockContext ); var reports = reportService.Queryable().Where( r => r.DataViewId == dataView.Id ); var reportDetailPage = GetAttributeValue( "ReportDetailPage" ); foreach ( var report in reports ) { if ( !string.IsNullOrWhiteSpace( reportDetailPage ) ) { sbReports.Append( "<a href=\"" + LinkedPageUrl( "ReportDetailPage", new Dictionary<string, string>() { { "ReportId", report.Id.ToString() } } ) + "\">" + report.Name + "</a><br/>" ); } else { sbReports.Append( report.Name + "<br/>" ); } } descriptionListReports.Add( "Reports", sbReports ); lReports.Text = descriptionListReports.Html; ShowReport( dataView ); }
/// <summary> /// Creates and shows the Filter controls /// </summary> /// <param name="setSelection">if set to <c>true</c> [set selection].</param> protected void ShowFilters( bool setSelection ) { nbFiltersError.Visible = false; try { var rockContext = new RockContext(); var reportService = new ReportService( rockContext ); var reportGuid = this.GetAttributeValue( "Report" ).AsGuidOrNull(); var selectedDataFieldGuids = ( this.GetAttributeValue( "SelectedDataFieldGuids" ) ?? string.Empty ).Split( '|' ).AsGuidList(); var configurableDataFieldGuids = ( this.GetAttributeValue( "ConfigurableDataFieldGuids" ) ?? string.Empty ).Split( '|' ).AsGuidList(); var togglableDataFieldGuids = ( this.GetAttributeValue( "TogglableDataFieldGuids" ) ?? string.Empty ).Split( '|' ).AsGuidList(); Report report = null; if ( reportGuid.HasValue ) { report = reportService.Get( reportGuid.Value ); } if ( report == null ) { nbConfigurationWarning.Visible = true; nbConfigurationWarning.Text = "A report needs to be configured in block settings"; pnlView.Visible = false; } else { nbConfigurationWarning.Visible = false; if ( report.DataView != null && report.DataView.DataViewFilter != null ) { phFilters.Controls.Clear(); if ( report.DataView.DataViewFilter != null && report.EntityTypeId.HasValue ) { CreateFilterControl( phFilters, report.DataView.DataViewFilter, report.EntityType, setSelection, selectedDataFieldGuids, configurableDataFieldGuids, togglableDataFieldGuids, rockContext ); } } // only show the filter and button if there visible filters pnlFilter.Visible = phFilters.ControlsOfTypeRecursive<FilterField>().Any( a => a.Visible ); } } catch ( Exception ex ) { this.LogException( ex ); nbFiltersError.Text = "An error occurred trying to load the filters. Click on 'Set Default' to try again with the default filter."; nbFiltersError.Details = "see the exception log for additional details"; nbFiltersError.Visible = true; } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { Report report = null; using ( new UnitOfWorkScope() ) { ReportService service = new ReportService(); ReportFieldService reportFieldService = new ReportFieldService(); int reportId = int.Parse( hfReportId.Value ); if ( reportId == 0 ) { report = new Report(); report.IsSystem = false; } else { report = service.Get( reportId ); } report.Name = tbName.Text; report.Description = tbDescription.Text; report.CategoryId = cpCategory.SelectedValueAsInt(); report.EntityTypeId = ddlEntityType.SelectedValueAsInt(); report.DataViewId = ddlDataView.SelectedValueAsInt(); if ( !Page.IsValid ) { return; } if ( !report.IsValid ) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction( () => { // delete all the reportFields so we can cleanly add them foreach ( var reportField in report.ReportFields.ToList() ) { var field = reportFieldService.Get( reportField.Guid ); reportFieldService.Delete( field, this.CurrentPersonId ); reportFieldService.Save( field, this.CurrentPersonId ); } report.ReportFields.Clear(); var allPanelWidgets = phReportFields.ControlsOfTypeRecursive<PanelWidget>(); int displayOrder = 0; foreach ( var panelWidget in allPanelWidgets ) { string hfReportFieldTypeID = panelWidget.ID + "_hfReportFieldType"; HiddenField hfReportFieldType = phReportFields.ControlsOfTypeRecursive<HiddenField>().First( a => a.ID == hfReportFieldTypeID ); string hfFieldSelectionID = panelWidget.ID + "_hfFieldSelection"; HiddenField hfFieldSelection = phReportFields.ControlsOfTypeRecursive<HiddenField>().First( a => a.ID == hfFieldSelectionID ); ReportFieldType reportFieldType = hfReportFieldType.Value.ConvertToEnum<ReportFieldType>(); string fieldSelection = hfFieldSelection.Value; ReportField reportField = new ReportField(); reportField.ReportFieldType = reportFieldType; string showInGridCheckBoxId = string.Format( "{0}_showInGridCheckBox", panelWidget.ID ); RockCheckBox showInGridCheckBox = phReportFields.ControlsOfTypeRecursive<RockCheckBox>().First( a => a.ID == showInGridCheckBoxId ); reportField.ShowInGrid = showInGridCheckBox.Checked; string columnHeaderTextTextBoxId = string.Format( "{0}_columnHeaderTextTextBox", panelWidget.ID ); RockTextBox columnHeaderTextTextBox = phReportFields.ControlsOfTypeRecursive<RockTextBox>().First( a => a.ID == columnHeaderTextTextBoxId ); reportField.ColumnHeaderText = columnHeaderTextTextBox.Text; reportField.Order = displayOrder++; if ( reportFieldType == ReportFieldType.DataSelectComponent ) { reportField.DataSelectComponentEntityTypeId = fieldSelection.AsInteger(); string dataSelectComponentTypeName = EntityTypeCache.Read( reportField.DataSelectComponentEntityTypeId ?? 0 ).GetEntityType().FullName; DataSelectComponent dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName ); string placeHolderId = string.Format( "{0}_phDataSelectControls", panelWidget.ID ); var placeHolder = phReportFields.ControlsOfTypeRecursive<PlaceHolder>().Where( a => a.ID == placeHolderId ).FirstOrDefault(); reportField.Selection = dataSelectComponent.GetSelection( placeHolder.Controls.OfType<Control>().ToArray() ); } else { reportField.Selection = fieldSelection; } report.ReportFields.Add( reportField ); } if ( report.Id.Equals( 0 ) ) { service.Add( report, CurrentPersonId ); } service.Save( report, CurrentPersonId ); } ); } var qryParams = new Dictionary<string, string>(); qryParams["ReportId"] = report.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Handles the Click event of the btnCancel control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnCancel_Click( object sender, EventArgs e ) { if ( hfReportId.Value.Equals( "0" ) ) { // Cancelling on Add. Return to tree view with parent category selected var qryParams = new Dictionary<string, string>(); string parentCategoryId = PageParameter( "parentCategoryId" ); if ( !string.IsNullOrWhiteSpace( parentCategoryId ) ) { qryParams["CategoryId"] = parentCategoryId; } NavigateToPage( RockPage.Guid, qryParams ); } else { // Cancelling on Edit. Return to Details ReportService service = new ReportService(); Report item = service.Get( int.Parse( hfReportId.Value ) ); ShowReadonlyDetails( item ); } }
/// <summary> /// Handles the GridRebind event of the gReport control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void gReport_GridRebind( object sender, EventArgs e ) { var report = new ReportService( new RockContext() ).Get( hfReportId.ValueAsInt() ); BindGrid( report ); }
/// <summary> /// Handles the Click event of the btnDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnDelete_Click( object sender, EventArgs e ) { int? categoryId = null; var reportService = new ReportService(); var report = reportService.Get( int.Parse( hfReportId.Value ) ); if ( report != null ) { string errorMessage; if ( !reportService.CanDelete( report, out errorMessage ) ) { ShowReadonlyDetails( report ); mdDeleteWarning.Show( errorMessage, ModalAlertType.Information ); return; } else { categoryId = report.CategoryId; RockTransactionScope.WrapTransaction( () => { reportService.Delete( report, CurrentPersonId ); reportService.Save( report, CurrentPersonId ); } ); // reload page, selecting the deleted data view's parent var qryParams = new Dictionary<string, string>(); if ( categoryId != null ) { qryParams["categoryId"] = categoryId.ToString(); } NavigateToPage( RockPage.Guid, qryParams ); } } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { Report report = null; var rockContext = new RockContext(); ReportService service = new ReportService( rockContext ); ReportFieldService reportFieldService = new ReportFieldService( rockContext ); int reportId = int.Parse( hfReportId.Value ); if ( reportId == 0 ) { report = new Report(); report.IsSystem = false; } else { report = service.Get( reportId ); } report.Name = tbName.Text; report.Description = tbDescription.Text; report.CategoryId = cpCategory.SelectedValueAsInt(); report.EntityTypeId = etpEntityType.SelectedEntityTypeId; report.DataViewId = ddlDataView.SelectedValueAsInt(); report.FetchTop = nbFetchTop.Text.AsIntegerOrNull(); if ( !Page.IsValid ) { return; } if ( !report.IsValid ) { // Controls will render the error messages return; } // delete all the reportFields so we can cleanly add them foreach ( var reportField in report.ReportFields.ToList() ) { var field = reportFieldService.Get( reportField.Guid ); reportFieldService.Delete( field ); } report.ReportFields.Clear(); var allPanelWidgets = phReportFields.ControlsOfTypeRecursive<PanelWidget>(); int columnOrder = 0; foreach ( var panelWidget in allPanelWidgets ) { string ddlFieldsId = panelWidget.ID + "_ddlFields"; RockDropDownList ddlFields = phReportFields.ControlsOfTypeRecursive<RockDropDownList>().First( a => a.ID == ddlFieldsId ); ReportFieldType reportFieldType = ReportFieldType.Property; string fieldSelection = string.Empty; string fieldSelectionValue = ddlFields.SelectedItem.Value; string[] fieldSelectionValueParts = fieldSelectionValue.Split( '|' ); if ( fieldSelectionValueParts.Count() == 2 ) { reportFieldType = fieldSelectionValueParts[0].ConvertToEnum<ReportFieldType>(); fieldSelection = fieldSelectionValueParts[1]; } else { // skip over fields that have nothing selected in ddlFields continue; } ReportField reportField = new ReportField(); reportField.ReportFieldType = reportFieldType; string showInGridCheckBoxId = string.Format( "{0}_showInGridCheckBox", panelWidget.ID ); RockCheckBox showInGridCheckBox = phReportFields.ControlsOfTypeRecursive<RockCheckBox>().First( a => a.ID == showInGridCheckBoxId ); reportField.ShowInGrid = showInGridCheckBox.Checked; string columnHeaderTextTextBoxId = string.Format( "{0}_columnHeaderTextTextBox", panelWidget.ID ); RockTextBox columnHeaderTextTextBox = phReportFields.ControlsOfTypeRecursive<RockTextBox>().First( a => a.ID == columnHeaderTextTextBoxId ); reportField.ColumnHeaderText = columnHeaderTextTextBox.Text; reportField.ColumnOrder = columnOrder++; if ( reportFieldType == ReportFieldType.DataSelectComponent ) { reportField.DataSelectComponentEntityTypeId = fieldSelection.AsIntegerOrNull(); string placeHolderId = string.Format( "{0}_phDataSelectControls", panelWidget.ID ); var placeHolder = phReportFields.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == placeHolderId ); var dataSelectComponent = this.GetDataSelectComponent( rockContext, reportField.DataSelectComponentEntityTypeId ?? 0 ); if ( dataSelectComponent != null ) { reportField.Selection = dataSelectComponent.GetSelection( placeHolder.Controls.OfType<Control>().ToArray() ); } } else { reportField.Selection = fieldSelection; } reportField.Guid = panelWidget.ID.Replace( "reportFieldWidget_", string.Empty ).AsGuid(); report.ReportFields.Add( reportField ); } int sortOrder = 0; foreach ( var itemPair in kvSortFields.Value.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries ).Select( a => a.Split( '^' ) ) ) { var reportFieldGuid = itemPair[0].AsGuidOrNull(); var sortDirection = itemPair[1].ConvertToEnum<SortDirection>( SortDirection.Ascending ); var reportField = report.ReportFields.FirstOrDefault( a => a.Guid == reportFieldGuid ); if ( reportField != null ) { reportField.SortOrder = sortOrder++; reportField.SortDirection = sortDirection; } } var adding = report.Id.Equals( 0 ); if ( adding ) { service.Add( report ); } rockContext.SaveChanges(); if ( adding ) { // add EDIT and ADMINISTRATE to the person who added the report Rock.Security.Authorization.AllowPerson( report, Authorization.EDIT, this.CurrentPerson, rockContext ); Rock.Security.Authorization.AllowPerson( report, Authorization.ADMINISTRATE, this.CurrentPerson, rockContext ); } var qryParams = new Dictionary<string, string>(); qryParams["ReportId"] = report.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
protected void lbDataView_Click( object sender, EventArgs e ) { var rockContext = new RockContext(); var reportService = new ReportService( rockContext ); var report = reportService.Get( hfReportId.Value.AsInteger() ); if ( report != null && report.DataViewId.HasValue ) { NavigateToLinkedPage( "DataViewPage", "DataViewId", report.DataViewId.Value ); } }
/// <summary> /// Handles the Click event of the Copy button control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnCopy_Click( object sender, EventArgs e ) { // Create a new Report using the current item as a template. var id = int.Parse( hfReportId.Value ); var reportService = new ReportService( new RockContext() ); var newItem = reportService.GetNewFromTemplate( id ); if (newItem == null) { return; } newItem.Name += " (Copy)"; // Reset the stored identifier for the active Report. hfReportId.Value = "0"; ShowEditDetails( newItem ); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="reportId">The report identifier.</param> /// <param name="parentCategoryId">The parent category id.</param> public void ShowDetail( int reportId, int? parentCategoryId ) { pnlDetails.Visible = false; var reportService = new ReportService( new RockContext() ); Report report = null; if ( !reportId.Equals( 0 ) ) { report = reportService.Get( reportId ); } if ( report == null ) { report = new Report { Id = 0, IsSystem = false, CategoryId = parentCategoryId }; } pnlDetails.Visible = true; hfReportId.Value = report.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; string authorizationMessage; if ( !this.IsAuthorizedForAllReportComponents( Authorization.EDIT, report, out authorizationMessage ) ) { nbEditModeMessage.Text = authorizationMessage; readOnly = true; } if ( report.IsSystem ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( Report.FriendlyTypeName ); } btnSecurity.Visible = report.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson ); btnSecurity.Title = report.Name; btnSecurity.EntityId = report.Id; if ( readOnly ) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails( report ); } else { btnEdit.Visible = true; string errorMessage = string.Empty; btnDelete.Visible = reportService.CanDelete( report, out errorMessage ); if ( report.Id > 0 ) { ShowReadonlyDetails( report ); } else { ShowEditDetails( report ); } } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> /// <param name="parentCategoryId">The parent category id.</param> public void ShowDetail( string itemKey, int itemKeyValue, int? parentCategoryId ) { pnlDetails.Visible = false; if ( !itemKey.Equals( "reportId" ) ) { return; } var reportService = new ReportService(); Report report = null; if ( !itemKeyValue.Equals( 0 ) ) { report = reportService.Get( itemKeyValue ); } else { report = new Report { Id = 0, IsSystem = false, CategoryId = parentCategoryId }; } if ( report == null ) { return; } pnlDetails.Visible = true; hfReportId.Value = report.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if ( !report.IsAuthorized( "Edit", CurrentPerson ) ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Report.FriendlyTypeName ); } if ( report.IsSystem ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( Report.FriendlyTypeName ); } btnSecurity.Visible = report.IsAuthorized( "Administrate", CurrentPerson ); btnSecurity.Title = report.Name; btnSecurity.EntityId = report.Id; if ( readOnly ) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails( report ); } else { btnEdit.Visible = true; string errorMessage = string.Empty; btnDelete.Visible = reportService.CanDelete( report, out errorMessage ); if ( report.Id > 0 ) { ShowReadonlyDetails( report ); } else { ShowEditDetails( report ); } } }
/// <summary> /// Loads the drop downs. /// </summary> protected void LoadDropDowns() { var rockContext = new RockContext(); var reportService = new ReportService( rockContext ); var reportQry = reportService.Queryable().OrderBy( a => a.Name ); ddlReport.Items.Clear(); ddlReport.Items.Add( new ListItem() ); foreach ( var report in reportQry.ToList() ) { ddlReport.Items.Add( new ListItem( report.Name, report.Guid.ToString() ) ); } }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { RockContext rockContext = new RockContext(); ReportService reportService = new ReportService( rockContext ); Guid reportCategory = new Guid(GetAttributeValue( "ReportCategory" )); // sample query to display a few people var qry = reportService.Queryable() .Where( r => r.Category.Guid == reportCategory ); gList.DataSource = qry.ToList(); gList.DataBind(); }
/// <summary> /// Binds the report grid. /// </summary> private void BindReportGrid() { var rockContext = new RockContext(); var reportService = new ReportService( rockContext ); var reportGuid = this.GetAttributeValue( "Report" ).AsGuidOrNull(); var personIdField = this.GetAttributeValue( "PersonIdField" ); Report report = null; if ( reportGuid.HasValue ) { report = reportService.Get( reportGuid.Value ); } if ( report == null ) { nbConfigurationWarning.Visible = true; nbConfigurationWarning.Text = "A report needs to be configured in block settings"; pnlView.Visible = false; } else if ( report.DataView == null ) { nbConfigurationWarning.Visible = true; nbConfigurationWarning.Text = string.Format( "The {0} report does not have a dataview", report ); pnlView.Visible = false; } else { nbConfigurationWarning.Visible = false; report.DataView.DataViewFilter = ReportingHelper.GetFilterFromControls( phFilters ); string errorMessage; ReportingHelper.BindGrid( report, gReport, this.CurrentPerson, null, out errorMessage ); if ( report.EntityTypeId != EntityTypeCache.GetId<Rock.Model.Person>() ) { var personColumn = gReport.ColumnsOfType<BoundField>().Where( a => a.HeaderText == personIdField ).FirstOrDefault(); if ( personColumn != null ) { gReport.PersonIdField = personColumn.SortExpression; } } if ( !string.IsNullOrWhiteSpace( errorMessage ) ) { nbReportErrors.NotificationBoxType = NotificationBoxType.Warning; nbReportErrors.Text = errorMessage; nbReportErrors.Visible = true; } else { nbReportErrors.Visible = false; } } }
/// <summary> /// Binds the report grid. /// </summary> private void BindReportGrid() { var rockContext = new RockContext(); var reportService = new ReportService( rockContext ); var reportGuid = this.GetAttributeValue( "Report" ).AsGuidOrNull(); Report report = null; if ( reportGuid.HasValue ) { report = reportService.Get( reportGuid.Value ); } if ( report == null ) { nbConfigurationWarning.Visible = true; nbConfigurationWarning.Text = "A report needs to be configured in block settings"; pnlView.Visible = false; } else if ( report.DataView == null ) { nbConfigurationWarning.Visible = true; nbConfigurationWarning.Text = string.Format( "The {0} report does not have a dataview", report ); pnlView.Visible = false; } else { nbConfigurationWarning.Visible = false; report.DataView.DataViewFilter = ReportingHelper.GetFilterFromControls( phFilters ); string errorMessage; ReportingHelper.BindGrid( report, gReport, this.CurrentPerson, null, out errorMessage ); if ( !string.IsNullOrWhiteSpace( errorMessage ) ) { nbReportErrors.NotificationBoxType = NotificationBoxType.Warning; nbReportErrors.Text = errorMessage; nbReportErrors.Visible = true; } else { nbReportErrors.Visible = false; } } }