Example #1
0
        /// <summary>
        /// Checks ReportField model for legacy lava and outputs SQL to correct it.
        /// Fields evaluated: Selection
        /// </summary>
        public void CheckReportField()
        {
            RockContext        rockContext        = new RockContext();
            ReportFieldService reportFieldService = new ReportFieldService(rockContext);

            foreach (ReportField reportField in reportFieldService.Queryable().ToList())
            {
                // don't change if modified
                if (reportField.ModifiedDateTime != null)
                {
                    continue;
                }

                bool isUpdated = false;

                reportField.Selection = ReplaceUnformatted(reportField.Selection, ref isUpdated);
                reportField.Selection = ReplaceUrl(reportField.Selection, ref isUpdated);
                reportField.Selection = ReplaceGlobal(reportField.Selection, ref isUpdated);
                reportField.Selection = ReplaceDotNotation(reportField.Selection, ref isUpdated);

                if (isUpdated)
                {
                    string sql = $"UPDATE [ReportField] SET [Selection] = '{reportField.Selection.Replace( "'", "''" )}' WHERE [Id] = {reportField.Id};";
                    _sqlUpdateScripts.Add(sql);
                }
            }
        }
Example #2
0
        /// <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 );
        }
Example #3
0
        /// <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 );
        }
Example #4
0
        /// <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 );
        }
Example #5
0
        /// <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);
        }