public ActionResult Edit(int id, string category, string type, int filterId = -1) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries"))) { return(new HttpUnauthorizedResult()); } var filter = _projectionManager.DescribeFilters().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault(); if (filter == null) { return(HttpNotFound()); } // if there is no form to edit, save the filter and go back to the query if (filter.Form == null) { var group = _groupRepository.Get(id); if (filterId == -1) { group.Filters.Add( new FilterRecord { Category = category, Type = type, Position = group.Filters.Count }); } return(RedirectToAction("Edit", "Admin", new { id = group.QueryPartRecord.Id })); } // build the form, and let external components alter it var form = _formManager.Build(filter.Form); string description = ""; // bind form with existing values). if (filterId != -1) { var group = _groupRepository.Get(id); var filterRecord = group.Filters.Where(f => f.Id == filterId).FirstOrDefault(); if (filterRecord != null) { description = filterRecord.Description; var parameters = FormParametersHelper.FromString(filterRecord.State); _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture)); } } var viewModel = new FilterEditViewModel { Id = id, Description = description, Filter = filter, Form = form }; return(View(viewModel)); }
public ActionResult Edit(int id, string category, string type, int sortCriterionId = -1) { if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to manage queries"))) { return(new HttpUnauthorizedResult()); } var sortCriterion = _projectionManager.DescribeSortCriteria().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type); if (sortCriterion == null) { return(HttpNotFound()); } // if there is no form to edit, save the sort criteria and go back to the query if (sortCriterion.Form == null) { if (sortCriterionId == -1) { var query = _queryService.GetQuery(id); query.SortCriteria.Add(new SortCriterionRecord { Category = category, Type = type, Position = query.SortCriteria.Count }); } return(RedirectToAction("Edit", "Admin", new { id })); } // build the form, and let external components alter it var form = _formManager.Build(sortCriterion.Form); var description = String.Empty; // bind form with existing values). if (sortCriterionId != -1) { var query = _queryService.GetQuery(id); var sortCriterionRecord = query.SortCriteria.FirstOrDefault(f => f.Id == sortCriterionId); if (sortCriterionRecord != null) { description = sortCriterionRecord.Description; var parameters = FormParametersHelper.FromString(sortCriterionRecord.State); _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture)); } } var viewModel = new SortCriterionEditViewModel { Id = id, Description = description, SortCriterion = sortCriterion, Form = form }; return(View(viewModel)); }
public ActionResult Edit(int id, string category, string type, int eventId = -1) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage rules"))) { return(new HttpUnauthorizedResult()); } var ev = _rulesManager.DescribeEvents().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault(); if (ev == null) { return(HttpNotFound()); } // if there is no form to edit, save the action and go back to the rule if (ev.Form == null) { if (eventId == -1) { var rule = _rulesServices.GetRule(id); rule.Events.Add(new EventRecord { Category = category, Type = type }); } return(RedirectToAction("Edit", "Admin", new { id })); } // build the form, and let external components alter it var form = _formManager.Build(ev.Form); // generate an anti forgery token AddSubmitButton(form); // bind form with existing values). if (eventId != -1) { var rule = _rulesServices.GetRule(id); var eventRecord = rule.Events.Where(a => a.Id == eventId).FirstOrDefault(); if (eventRecord != null) { var parameters = FormParametersHelper.FromString(eventRecord.Parameters); _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture)); } } var viewModel = new EditEventViewModel { Id = id, Event = ev, Form = form }; return(View(viewModel)); }
public ActionResult Edit(int id, string category, string type, int filterId = -1) { if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to manage queries"))) { return(new HttpUnauthorizedResult()); } var filter = _projectionManager.DescribeFilters().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type); if (filter == null) { return(HttpNotFound()); } // build the form, and let external components alter it var form = filter.Form == null ? null : _formManager.Build(filter.Form); string description = ""; // bind form with existing values). if (filterId != -1) { var group = _groupRepository.Get(id); var filterRecord = group.Filters.FirstOrDefault(f => f.Id == filterId); if (filterRecord != null) { description = filterRecord.Description; var parameters = FormParametersHelper.FromString(filterRecord.State); _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture)); } } var viewModel = new FilterEditViewModel { Id = id, Description = description, Filter = filter, Form = form }; return(View(viewModel)); }
public ActionResult Edit(int id) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit rules"))) { return(new HttpUnauthorizedResult()); } var rule = _rulesServices.GetRule(id); var viewModel = new EditRuleViewModel { Id = rule.Id, Enabled = rule.Enabled, Name = rule.Name }; #region Load events var eventEntries = new List <EventEntry>(); var allEvents = _rulesManager.DescribeEvents().SelectMany(x => x.Descriptors); foreach (var eventRecord in rule.Events) { var category = eventRecord.Category; var type = eventRecord.Type; var ev = allEvents.Where(x => category == x.Category && type == x.Type).FirstOrDefault(); if (ev != null) { var eventParameters = FormParametersHelper.FromString(eventRecord.Parameters); eventEntries.Add( new EventEntry { Category = ev.Category, Type = ev.Type, EventRecordId = eventRecord.Id, DisplayText = ev.Display(new EventContext { Properties = eventParameters }) }); } } viewModel.Events = eventEntries; #endregion #region Load actions var actionEntries = new List <ActionEntry>(); var allActions = _rulesManager.DescribeActions().SelectMany(x => x.Descriptors); foreach (var actionRecord in rule.Actions.OrderBy(x => x.Position)) { var category = actionRecord.Category; var type = actionRecord.Type; var action = allActions.Where(x => category == x.Category && type == x.Type).FirstOrDefault(); if (action != null) { var actionParameters = FormParametersHelper.FromString(actionRecord.Parameters); actionEntries.Add( new ActionEntry { Category = action.Category, Type = action.Type, ActionRecordId = actionRecord.Id, DisplayText = action.Display(new ActionContext { Properties = actionParameters }) }); } } viewModel.Actions = actionEntries; #endregion return(View(viewModel)); }
public ActionResult Edit(int id) { if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to manage queries"))) { return(new HttpUnauthorizedResult()); } var layoutRecord = _repository.Get(id); if (layoutRecord == null) { return(HttpNotFound()); } var layoutDescriptor = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == layoutRecord.Category && x.Type == layoutRecord.Type); // Build the form, and let external components alter it. var form = _formManager.Build(layoutDescriptor.Form) ?? Services.New.EmptyForm(); var viewModel = new LayoutEditViewModel { Id = id, QueryId = layoutRecord.QueryPartRecord.Id, Category = layoutDescriptor.Category, Type = layoutDescriptor.Type, Description = layoutRecord.Description, Display = layoutRecord.Display, DisplayType = String.IsNullOrWhiteSpace(layoutRecord.DisplayType) ? "Summary" : layoutRecord.DisplayType, Layout = layoutDescriptor, Form = form, GroupPropertyId = layoutRecord.GroupProperty == null ? 0 : layoutRecord.GroupProperty.Id }; // Bind form with existing values. var parameters = FormParametersHelper.FromString(layoutRecord.State); _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture)); #region Load Fields var fieldEntries = new List <PropertyEntry>(); var allFields = _projectionManager.DescribeProperties().SelectMany(x => x.Descriptors); foreach (var field in layoutRecord.Properties) { var fieldCategory = field.Category; var fieldType = field.Type; var f = allFields.FirstOrDefault(x => fieldCategory == x.Category && fieldType == x.Type); if (f != null) { fieldEntries.Add( new PropertyEntry { Category = f.Category, Type = f.Type, PropertyRecordId = field.Id, DisplayText = String.IsNullOrWhiteSpace(field.Description) ? f.Display(new PropertyContext { State = FormParametersHelper.ToDynamic(field.State) }).Text : field.Description, Position = field.Position }); } } viewModel.Properties = fieldEntries.OrderBy(f => f.Position); #endregion return(View(viewModel)); }
public ActionResult Edit(int id, string category, string type, int propertyId = -1) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries"))) { return(new HttpUnauthorizedResult()); } var property = _projectionManager.DescribeProperties().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault(); if (property == null) { return(HttpNotFound()); } var viewModel = new PropertyEditViewModel { Id = id, Description = String.Empty, Property = property }; dynamic form = null; // build the form, and let external components alter it if (property.Form != null) { form = _formManager.Build(property.Form); viewModel.Form = form; } // bind form with existing values. if (propertyId != -1) { var propertyRecord = _repository.Get(propertyId); if (propertyRecord != null) { viewModel.Description = propertyRecord.Description; if (property.Form != null) { var parameters = FormParametersHelper.FromString(propertyRecord.State); _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture)); } viewModel.CreateLabel = propertyRecord.CreateLabel; viewModel.ExcludeFromDisplay = propertyRecord.ExcludeFromDisplay; viewModel.Label = propertyRecord.Label; viewModel.LinkToContent = propertyRecord.LinkToContent; viewModel.CustomizeLabelHtml = propertyRecord.CustomizeLabelHtml; viewModel.CustomizePropertyHtml = propertyRecord.CustomizePropertyHtml; viewModel.CustomizeWrapperHtml = propertyRecord.CustomizeWrapperHtml; viewModel.CustomLabelCss = propertyRecord.CustomLabelCss; viewModel.CustomLabelTag = propertyRecord.CustomLabelTag; viewModel.CustomPropertyCss = propertyRecord.CustomPropertyCss; viewModel.CustomPropertyTag = propertyRecord.CustomPropertyTag; viewModel.CustomWrapperCss = propertyRecord.CustomWrapperCss; viewModel.CustomWrapperTag = propertyRecord.CustomWrapperTag; viewModel.NoResultText = propertyRecord.NoResultText; viewModel.ZeroIsEmpty = propertyRecord.ZeroIsEmpty; viewModel.HideEmpty = propertyRecord.HideEmpty; viewModel.RewriteOutput = propertyRecord.RewriteOutput; viewModel.RewriteText = propertyRecord.RewriteText; viewModel.StripHtmlTags = propertyRecord.StripHtmlTags; viewModel.TrimLength = propertyRecord.TrimLength; viewModel.AddEllipsis = propertyRecord.AddEllipsis; viewModel.MaxLength = propertyRecord.MaxLength; viewModel.TrimOnWordBoundary = propertyRecord.TrimOnWordBoundary; viewModel.PreserveLines = propertyRecord.PreserveLines; viewModel.TrimWhiteSpace = propertyRecord.TrimWhiteSpace; } } return(View(viewModel)); }
public ActionResult Edit(int id, string category, string type, int actionId = -1) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage rules"))) { return(new HttpUnauthorizedResult()); } var action = _rulesManager.DescribeActions().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type); if (action == null) { return(HttpNotFound()); } // if there is no form to edit, save the action and go back to the rule if (action.Form == null) { if (actionId == -1) { var rule = _rulesServices.GetRule(id); rule.Actions.Add(new ActionRecord { Category = category, Type = type, Position = rule.Actions.Count + 1 }); } return(RedirectToAction("Edit", "Admin", new { id })); } // build the form, and let external components alter it var form = _formManager.Build(action.Form); // generate an anti forgery token var viewContext = new ViewContext { HttpContext = HttpContext, Controller = this }; var token = new HtmlHelper(viewContext, new ViewDataContainer()).AntiForgeryToken(); // add a submit button to the form form ._Actions(Shape.Fieldset( _RequestAntiForgeryToken: Shape.Markup( Value: token.ToString()), _Save: Shape.Submit( Name: "op", Value: T("Save")) ) ); // bind form with existing values). if (actionId != -1) { var rule = _rulesServices.GetRule(id); var actionRecord = rule.Actions.FirstOrDefault(a => a.Id == actionId); if (actionRecord != null) { var parameters = FormParametersHelper.FromString(actionRecord.Parameters); _formManager.Bind(form, new DictionaryValueProvider <string>(parameters, CultureInfo.InvariantCulture)); } } var viewModel = new EditActionViewModel { Id = id, Action = action, Form = form }; return(View(viewModel)); }