Esempio n. 1
0
        /// <summary>
        /// Handles the Click event of the btnPreview 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 btnPreview_Click(object sender, EventArgs e)
        {
            DataView dv = new DataView();

            dv.TransformEntityTypeId = ddlTransform.SelectedValueAsInt();
            dv.EntityTypeId          = etpEntityType.SelectedEntityTypeId;
            dv.DataViewFilter        = ReportingHelper.GetFilterFromControls(phFilters);
            ShowPreview(dv);
        }
Esempio n. 2
0
        /// <summary>
        /// Saves any user control view-state changes that have occurred since the last page postback.
        /// </summary>
        /// <returns>
        /// Returns the user control's current view state. If there is no view state associated with the control, it returns null.
        /// </returns>
        protected override object SaveViewState()
        {
            ViewState["FieldSettings"]  = this.FieldSettings.ToJson();
            ViewState["PropertyInfo"]   = _contentChannelProperties.ToJson();
            ViewState["DataViewFilter"] = ReportingHelper.GetFilterFromControls(phFilters).ToJson();
            ViewState["ChannelId"]      = ddlContentChannel.SelectedValueAsId();

            return(base.SaveViewState());
        }
Esempio n. 3
0
        /// <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;
                }
            }
        }
Esempio n. 4
0
        /// <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;
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Saves the data view filter and removes the old one.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <returns>
        /// A reference to the new DataViewFilter.
        /// </returns>
        private DataViewFilter SaveDataViewFilter(RockContext rockContext)
        {
            var dataViewFilter = ReportingHelper.GetFilterFromControls(phFilters);

            // update Guids since we are creating a new dataFilter and children and deleting the old one
            SetNewDataFilterGuids(dataViewFilter);

            DataViewFilterService dataViewFilterService = new DataViewFilterService(rockContext);

            int?dataViewFilterId = hfDataFilterId.Value.AsIntegerOrNull();

            if (dataViewFilterId.HasValue)
            {
                var oldDataViewFilter = dataViewFilterService.Get(dataViewFilterId.Value);
                DeleteDataViewFilter(oldDataViewFilter, dataViewFilterService);
            }

            dataViewFilterService.Add(dataViewFilter);

            rockContext.SaveChanges();

            return(dataViewFilter);
        }
        /// <summary>
        /// Handles the SaveClick event of the mdContentComponentConfig 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 mdContentComponentConfig_SaveClick(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            var dataViewFilter = ReportingHelper.GetFilterFromControls(phFilters);

            if (dataViewFilter != null)
            {
                // update Guids since we are creating a new dataFilter and children and deleting the old one
                SetNewDataFilterGuids(dataViewFilter);

                if (!Page.IsValid)
                {
                    return;
                }

                if (!dataViewFilter.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                DataViewFilterService dataViewFilterService = new DataViewFilterService(rockContext);

                int?dataViewFilterId = hfDataFilterId.Value.AsIntegerOrNull();
                if (dataViewFilterId.HasValue)
                {
                    var oldDataViewFilter = dataViewFilterService.Get(dataViewFilterId.Value);
                    DeleteDataViewFilter(oldDataViewFilter, dataViewFilterService);
                }

                dataViewFilterService.Add(dataViewFilter);
            }

            rockContext.SaveChanges();

            ContentChannelService contentChannelService = new ContentChannelService(rockContext);
            Guid?          contentChannelGuid           = this.GetAttributeValue("ContentChannel").AsGuidOrNull();
            ContentChannel contentChannel = null;

            if (contentChannelGuid.HasValue)
            {
                contentChannel = contentChannelService.Get(contentChannelGuid.Value);
            }

            if (contentChannel == null)
            {
                contentChannel = new ContentChannel();
                contentChannel.ContentChannelTypeId = this.ContentChannelTypeId;
                contentChannelService.Add(contentChannel);
            }

            contentChannel.LoadAttributes(rockContext);
            avcContentChannelAttributes.GetEditValues(contentChannel);

            contentChannel.Name = tbComponentName.Text;
            rockContext.SaveChanges();
            contentChannel.SaveAttributeValues(rockContext);

            this.SetAttributeValue("ContentChannel", contentChannel.Guid.ToString());

            this.SetAttributeValue("ItemCacheDuration", nbItemCacheDuration.Text);

            int? contentComponentTemplateValueId   = dvpContentComponentTemplate.SelectedValue.AsInteger();
            Guid?contentComponentTemplateValueGuid = null;

            if (contentComponentTemplateValueId.HasValue)
            {
                var contentComponentTemplate = DefinedValueCache.Get(contentComponentTemplateValueId.Value);
                if (contentComponentTemplate != null)
                {
                    contentComponentTemplateValueGuid = contentComponentTemplate.Guid;
                }
            }

            this.SetAttributeValue("ContentComponentTemplate", contentComponentTemplateValueGuid.ToString());
            this.SetAttributeValue("AllowMultipleContentItems", cbAllowMultipleContentItems.Checked.ToString());
            this.SetAttributeValue("OutputCacheDuration", nbOutputCacheDuration.Text);
            this.SetAttributeValue("CacheTags", cblCacheTags.SelectedValues.AsDelimited(","));
            if (dataViewFilter != null)
            {
                this.SetAttributeValue("FilterId", dataViewFilter.Id.ToString());
            }
            else
            {
                this.SetAttributeValue("FilterId", null);
            }

            this.SaveAttributeValues();

            var block = new BlockService(rockContext).Get(this.BlockId);

            block.PreHtml  = cePreHtml.Text;
            block.PostHtml = cePostHtml.Text;
            rockContext.SaveChanges();

            mdContentComponentConfig.Hide();
            pnlContentComponentConfig.Visible = false;

            RemoveCacheItem(OUTPUT_CACHE_KEY);
            RemoveCacheItem(ITEM_CACHE_KEY);

            // reload the page to make sure we have a clean load
            NavigateToCurrentPageReference();
        }
 /// <summary>
 /// Saves any user control view-state changes that have occurred since the last page postback.
 /// </summary>
 /// <returns>
 /// Returns the user control's current view state. If there is no view state associated with the control, it returns null.
 /// </returns>
 protected override object SaveViewState()
 {
     ViewState["DataViewFilter"] = ReportingHelper.GetFilterFromControls(phFilters).ToJson();
     return(base.SaveViewState());
 }
Esempio n. 8
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)
        {
            DataView dataView = null;

            var             rockContext = new RockContext();
            DataViewService service     = new DataViewService(rockContext);

            int dataViewId           = int.Parse(hfDataViewId.Value);
            int?origDataViewFilterId = null;

            if (dataViewId == 0)
            {
                dataView          = new DataView();
                dataView.IsSystem = false;
            }
            else
            {
                dataView             = service.Get(dataViewId);
                origDataViewFilterId = dataView.DataViewFilterId;
            }

            dataView.Name                             = tbName.Text;
            dataView.Description                      = tbDescription.Text;
            dataView.TransformEntityTypeId            = ddlTransform.SelectedValueAsInt();
            dataView.EntityTypeId                     = etpEntityType.SelectedEntityTypeId;
            dataView.CategoryId                       = cpCategory.SelectedValueAsInt();
            dataView.PersistedScheduleIntervalMinutes = nbPersistedScheduleIntervalMinutes.Text.AsIntegerOrNull();

            var newDataViewFilter = ReportingHelper.GetFilterFromControls(phFilters);

            if (!Page.IsValid)
            {
                return;
            }

            if (!dataView.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            var adding = dataView.Id.Equals(0);

            if (adding)
            {
                service.Add(dataView);
            }

            rockContext.WrapTransaction(() =>
            {
                if (origDataViewFilterId.HasValue)
                {
                    // delete old report filter so that we can add the new filter (but with original guids), then drop the old filter
                    DataViewFilterService dataViewFilterService = new DataViewFilterService(rockContext);
                    DataViewFilter origDataViewFilter           = dataViewFilterService.Get(origDataViewFilterId.Value);

                    dataView.DataViewFilterId = null;
                    rockContext.SaveChanges();

                    DeleteDataViewFilter(origDataViewFilter, dataViewFilterService);
                }

                dataView.DataViewFilter = newDataViewFilter;
                rockContext.SaveChanges();
            });

            if (dataView.PersistedScheduleIntervalMinutes.HasValue)
            {
                dataView.PersistResult(GetAttributeValue("DatabaseTimeout").AsIntegerOrNull() ?? 180);
                dataView.PersistedLastRefreshDateTime = RockDateTime.Now;
                rockContext.SaveChanges();
            }

            if (adding)
            {
                // add EDIT and ADMINISTRATE to the person who added the dataView
                Rock.Security.Authorization.AllowPerson(dataView, Authorization.EDIT, this.CurrentPerson, rockContext);
                Rock.Security.Authorization.AllowPerson(dataView, Authorization.ADMINISTRATE, this.CurrentPerson, rockContext);
            }

            var qryParams = new Dictionary <string, string>();

            qryParams["DataViewId"]       = dataView.Id.ToString();
            qryParams["ParentCategoryId"] = null;
            NavigateToCurrentPageReference(qryParams);
        }
Esempio n. 9
0
 /// <summary>
 /// Saves any user control view-state changes that have occurred since the last page postback.
 /// </summary>
 /// <returns>
 /// Returns the user control's current view state. If there is no view state associated with the control, it returns null.
 /// </returns>
 protected override object SaveViewState()
 {
     ViewState["DataViewFilter"] = ReportingHelper.GetFilterFromControls(phFilters).ToJson();
     ViewState["EntityTypeId"]   = etpEntityType.SelectedEntityTypeId;
     return(base.SaveViewState());
 }