/// <summary> /// Sets the selection. /// </summary> /// <param name="controls">The controls.</param> /// <param name="selection">The selection.</param> public override void SetSelection(Control[] controls, string selection) { var ddlDataView = controls.GetByName <DataViewPicker>(_CtlDataView); var ddlRoleType = controls.GetByName <RockDropDownList>(_CtlRoleType); var ddlFormat = controls.GetByName <RockDropDownList>(_CtlFormat); var ddlGroupMemberStatus = controls.GetByName <RockDropDownList>(_CtlGroupStatus); var settings = new GroupParticipationSelectSettings(selection); if (!settings.IsValid) { return; } ddlFormat.SelectedValue = settings.ListFormat.ToString(); if (settings.DataViewGuid.HasValue) { var dsService = new DataViewService(new RockContext()); var dataView = dsService.Get(settings.DataViewGuid.Value); if (dataView != null) { ddlDataView.SelectedValue = dataView.Id.ToString(); } } ddlRoleType.SelectedValue = settings.RoleType.ToStringSafe(); ddlGroupMemberStatus.SelectedValue = settings.MemberStatus.ToStringSafe(); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { lMessage.Text = GetAttributeValue("LockdownAlert"); lAlertTitle.Text = GetAttributeValue("LockdownTitle"); if (GetAttributeValue("DataView").IsNotNullOrWhiteSpace()) { DataViewService dataViewService = new DataViewService(new RockContext()); //var dvipReviewDataView.SetValue( dataViewService.Get( GetAttributeValue( "DefaultReviewDataView" ).AsGuid() ) ); } var campus = CampusCache.Get(GetBlockUserPreference("Campus").AsInteger()); if (campus != null) { bddlCampus.Title = campus.Name; bddlCampus.SetValue(campus.Id); lCampusTitle.Text = bddlCampus.Title; pnlCampuses.Visible = false; pnlMain.Visible = true; } else { pnlCampuses.Visible = true; pnlMain.Visible = false; } } }
/// <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 dataViewService = new DataViewService(); var dataView = dataViewService.Get(int.Parse(hfDataViewId.Value)); if (dataView != null) { string errorMessage; if (!dataViewService.CanDelete(dataView, out errorMessage)) { ShowReadonlyDetails(dataView); mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); } else { categoryId = dataView.CategoryId; dataViewService.Delete(dataView, CurrentPersonId); dataViewService.Save(dataView, 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> /// Get the people's Ids inside a DataView filter. /// </summary> /// <param name="dataViewId">The data view identifier.</param> /// <param name="rockContext">The rock context.</param> /// <returns>Returns a directory of people IDs that result from applying the DataView filter</returns> public Dictionary <int, int> DataViewPeopleDirectory(int dataViewId, RockContext rockContext) { var dataViewService = new DataViewService(rockContext); var dataView = dataViewService.GetNoTracking(dataViewId); // Verify that there is not a child filter that uses this view (would result in stack-overflow error) if (dataViewService.IsViewInFilter(dataView.Id, dataView.DataViewFilter)) { throw new Exception("Data View Filter issue(s): One of the filters contains a circular reference to the Data View itself."); } // Evaluate the Data View that defines the candidate population. List <string> errorMessages; var personService = new PersonService(rockContext); var personQuery = personService.Queryable().AsNoTracking(); var paramExpression = personService.ParameterExpression; var whereExpression = dataView.GetExpression(personService, paramExpression, out errorMessages); if (errorMessages.Any()) { throw new Exception("Data View Filter issue(s): " + errorMessages.AsDelimited("; ")); } return(personQuery.Where(paramExpression, whereExpression, null).Select(p => p.Id).ToDictionary(p => p, p => p)); }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public void Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; int sqlCommandTimeout = dataMap.GetString("SQLCommandTimeout").AsIntegerOrNull() ?? 300; StringBuilder results = new StringBuilder(); int updatedDataViewCount = 0; using (var rockContext = new RockContext()) { var currentDateTime = RockDateTime.Now; // get a list of all the dataviews that need to be refreshed var expiredPersistedDataViews = new DataViewService(rockContext).Queryable() .Where(a => a.PersistedScheduleIntervalMinutes.HasValue) .Where(a => (a.PersistedLastRefreshDateTime == null) || (System.Data.Entity.SqlServer.SqlFunctions.DateAdd("mi", a.PersistedScheduleIntervalMinutes.Value, a.PersistedLastRefreshDateTime.Value) < currentDateTime) ); var expiredPersistedDataViewsList = expiredPersistedDataViews.ToList(); foreach (var dataView in expiredPersistedDataViewsList) { context.UpdateLastStatusMessage($"Updating {dataView.Name}"); dataView.PersistResult(sqlCommandTimeout); dataView.PersistedLastRefreshDateTime = RockDateTime.Now; rockContext.SaveChanges(); updatedDataViewCount++; } } results.AppendLine($"Updated {updatedDataViewCount} {"dataview".PluralizeIf( updatedDataViewCount != 1 )}"); context.UpdateLastStatusMessage(results.ToString()); }
/// <summary> /// Reads new values entered by the user for the field /// returns DataView.Guid /// </summary> /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param> /// <param name="configurationValues">The configuration values.</param> /// <returns></returns> public override string GetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues) { var picker = control as DataViewItemPicker; if (picker != null) { int?id = picker.SelectedValue.AsIntegerOrNull(); if (id.HasValue) { using (var rockContext = new RockContext()) { var dataview = new DataViewService(rockContext).GetNoTracking(id.Value); if (dataview != null) { return(dataview.Guid.ToString()); } } } return(string.Empty); } return(null); }
/// <summary> /// Renders the controls. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="filterControl">The filter control.</param> /// <param name="writer">The writer.</param> /// <param name="controls">The controls.</param> public override void RenderControls(Type entityType, FilterField filterControl, HtmlTextWriter writer, Control[] controls) { writer.AddAttribute(HtmlTextWriterAttribute.Class, "row"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "col-md-3"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.Write("<span class='data-view-filter-label'>Data View</span>"); writer.RenderEndTag(); writer.AddAttribute("class", "col-md-4"); writer.RenderBeginTag(HtmlTextWriterTag.Div); DataViewItemPicker dataViewItemPicker = controls[0] as DataViewItemPicker; dataViewItemPicker.RenderControl(writer); writer.RenderEndTag(); writer.AddAttribute("class", "col-md-5"); writer.RenderBeginTag(HtmlTextWriterTag.Div); RockCheckBox cbUsePersisted = controls[1] as RockCheckBox; cbUsePersisted.Visible = false; int?dataViewId = dataViewItemPicker.SelectedValueAsId(); if (dataViewId.HasValue) { int?persistedScheduleIntervalMinutes = new DataViewService(new RockContext()).GetSelect(dataViewId.Value, s => s.PersistedScheduleIntervalMinutes); cbUsePersisted.Visible = persistedScheduleIntervalMinutes.HasValue; } cbUsePersisted.RenderControl(writer); writer.RenderEndTag(); writer.RenderEndTag(); }
public override void SetSelection(System.Web.UI.Control[] controls, string selection) { var settings = new ParticipationRateSelectSettings(selection); if (!settings.IsValid()) { return; } var ddlDataView = (DataViewPicker)controls[0]; var ddlFormat = (DropDownList)controls[1]; if (settings.DataViewGuid.HasValue) { var dsService = new DataViewService(new RockContext()); var dataView = dsService.Get(settings.DataViewGuid.Value); if (dataView != null) { ddlDataView.SelectedValue = dataView.Id.ToString(); } } ddlFormat.SelectedValue = settings.MeasureType.ToString(); }
/// <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 (hfDataViewId.Value.Equals("0")) { int?parentCategoryId = PageParameter("ParentCategoryId").AsInteger(false); 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 DataViewService service = new DataViewService(new RockContext()); DataView item = service.Get(int.Parse(hfDataViewId.Value)); ShowReadonlyDetails(item); } }
/// <summary> /// Creates the test step program. /// There are 2 step statuses: 1 complete and 1 in-progress /// There are 4 step types: /// 1) Allow multiple with an auto-complete dataview /// 2) Allow multiple without an autocomplete dataview /// 3) No multiple with an auto-complete dataview /// 4) No multiple with no auto-complete dataview /// </summary> private static void CreateTestStepProgram() { var rockContext = new RockContext(); var stepProgramService = new StepProgramService(rockContext); var dataViewService = new DataViewService(rockContext); var dataView = dataViewService.Queryable().FirstOrDefault(dv => dv.ForeignKey == ForeignKey); var stepProgram = new StepProgram { Name = "Test", ForeignKey = ForeignKey, StepStatuses = new List <StepStatus> { new StepStatus { ForeignKey = ForeignKey, Name = "Complete", IsCompleteStatus = true }, new StepStatus { ForeignKey = ForeignKey, Name = "In-progress", IsCompleteStatus = false } }, StepTypes = new List <StepType> { new StepType { Name = "Test: AllowMultiple with DataView", ForeignKey = ForeignKey, AllowMultiple = true, AutoCompleteDataView = dataView }, new StepType { Name = "Test: AllowMultiple without DataView", ForeignKey = ForeignKey, AllowMultiple = true }, new StepType { Name = "Test: No multiple with DataView", ForeignKey = ForeignKey, AllowMultiple = false, AutoCompleteDataView = dataView }, new StepType { Name = "Test: No multiple and no dataview", ForeignKey = ForeignKey, AllowMultiple = false } } }; stepProgramService.Add(stepProgram); rockContext.SaveChanges(); }