public bool GenerateSortCriteria(string entityName, string sortColumns, string lastOrder, int queryId) { if (string.IsNullOrWhiteSpace(entityName)) { return(false); } if (string.IsNullOrWhiteSpace(sortColumns)) { return(true); } var query = _queryService.GetQuery(queryId); query.SortCriteria.Clear(); var index = 0; foreach (var sortColumn in (sortColumns + " " + lastOrder).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { var sortInfo = sortColumn.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); query.SortCriteria.Add(new SortCriterionRecord { Category = entityName + "ContentFields", Type = entityName + "." + sortInfo.First() + ".", State = FormParametersHelper.ToString(new Dictionary <string, string> { { "Sort", (sortInfo.Last() == "asc").ToString().ToLower() } }), Description = sortInfo.First(), Position = ++index }); } return(true); }
private void LayoutStaffProfileQuery(QueryPart staffProfileQuery) { var layoutDictionary = new Dictionary <string, string>(); layoutDictionary.Add("QueryId", staffProfileQuery.Id.ToString()); layoutDictionary.Add("Category", "Html"); layoutDictionary.Add("Type", "List"); layoutDictionary.Add("Description", "List"); layoutDictionary.Add("Display", "0"); layoutDictionary.Add("DisplayType", "Summary"); LayoutRecord layout = staffProfileQuery.Layouts.FirstOrDefault(); if (layout == null) { layout = new LayoutRecord() { Category = "Html", Type = "List", Description = "List", Display = 0, DisplayType = "Summary", }; staffProfileQuery.Layouts.Add(layout); } layout.State = FormParametersHelper.ToString(layoutDictionary); }
public void ResizeMediaUrl(dynamic Shape, dynamic Display, TextWriter Output, ContentItem ContentItem, string Path, int Width, int Height, string Mode, string Alignment, string PadColor) { var state = new Dictionary <string, string> { { "Width", Width.ToString(CultureInfo.InvariantCulture) }, { "Height", Height.ToString(CultureInfo.InvariantCulture) }, { "Mode", Mode }, { "Alignment", Alignment }, { "PadColor", PadColor }, }; var filter = new FilterRecord { Category = "Transform", Type = "Resize", State = FormParametersHelper.ToString(state) }; var profile = "Transform_Resize" + "_w_" + Convert.ToString(Width) + "_h_" + Convert.ToString(Height) + "_m_" + Convert.ToString(Mode) + "_a_" + Convert.ToString(Alignment) + "_c_" + Convert.ToString(PadColor); MediaUrl(Shape, Display, Output, profile, Path, ContentItem, filter); }
public ActionResult RenderActivity(ActivityViewModel model) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows"))) { return(new HttpUnauthorizedResult()); } var activity = _activitiesManager.GetActivityByName(model.Name); if (activity == null) { return(HttpNotFound()); } dynamic shape = New.Activity(activity); if (model.State != null) { var state = FormParametersHelper.ToDynamic(FormParametersHelper.ToString(model.State)); shape.State(state); } else { shape.State(FormParametersHelper.FromJsonString("{}")); } shape.Metadata.Alternates.Add("Activity__" + activity.Name); return(new ShapeResult(this, shape)); }
// the AdminService attribute prevents the PolicyFilter to check policies // when a file is called through this action. public RedirectResult Image(string Path, int?Width, int?Height, string Mode, string Alignment, string PadColor) { var httpContext = _httpContextAccessor.Current(); int n = 0; string url; bool isNumeric = int.TryParse(Path, out n); if (isNumeric) { MediaPart mediaPart = ((ContentItem)_orchardServices.ContentManager.Get(n)).As <MediaPart>(); Path = mediaPart.MediaUrl; } if (Width == null || Height == null) { var baseUrl = httpContext.Request.ToApplicationRootUrlString(); var applicationPath = httpContext.Request.ApplicationPath ?? String.Empty; if (Path.StartsWith(applicationPath, StringComparison.OrdinalIgnoreCase)) { Path = Path.Substring(applicationPath.Length); } url = String.Concat(baseUrl, Path); } else { int notNullWidth = Width.GetValueOrDefault(); int notNullHeight = Height.GetValueOrDefault(); var state = new Dictionary <string, string> { { "Width", notNullWidth.ToString(CultureInfo.InvariantCulture) }, { "Height", notNullHeight.ToString(CultureInfo.InvariantCulture) }, { "Mode", Mode }, { "Alignment", Alignment }, { "PadColor", PadColor }, }; var filter = new FilterRecord { Category = "Transform", Type = "Resize", State = FormParametersHelper.ToString(state) }; var profile = "Transform_Resize" + "_w_" + Convert.ToString(Width) + "_h_" + Convert.ToString(Height) + "_m_" + Convert.ToString(Mode) + "_a_" + Convert.ToString(Alignment) + "_c_" + Convert.ToString(PadColor); Path = HttpUtility.UrlDecode(Path); // url = _imageProfileManager.Value.GetImageProfileUrl(Path, profile, filter); url = _imageProfileManager.GetImageProfileUrl(Path, profile, filter); } if (url == null) { return(null); } return(Redirect(url)); }
public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)] int filterId, FormCollection formCollection) { var group = _groupRepository.Get(id); var filter = _projectionManager.DescribeFilters().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault(); var model = new FilterEditViewModel(); TryUpdateModel(model); // validating form values _formManager.Validate(new ValidatingContext { FormName = filter.Form, ModelState = ModelState, ValueProvider = ValueProvider }); if (ModelState.IsValid) { var filterRecord = group.Filters.Where(f => f.Id == filterId).FirstOrDefault(); // add new filter record if it's a newly created filter if (filterRecord == null) { filterRecord = new FilterRecord { Category = category, Type = type, Position = group.Filters.Count }; group.Filters.Add(filterRecord); } var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // save form parameters filterRecord.State = FormParametersHelper.ToString(dictionary); filterRecord.Description = model.Description; return(RedirectToAction("Edit", "Admin", new { group.QueryPartRecord.Id })); } // model is invalid, display it again var form = _formManager.Build(filter.Form); _formManager.Bind(form, formCollection); var viewModel = new FilterEditViewModel { Id = id, Description = model.Description, Filter = filter, Form = form }; return(View(viewModel)); }
public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)] int sortCriterionId, FormCollection formCollection) { var query = _queryService.GetQuery(id); var sortCriterion = _projectionManager.DescribeSortCriteria().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type); var model = new SortCriterionEditViewModel(); TryUpdateModel(model); // validating form values _formManager.Validate(new ValidatingContext { FormName = sortCriterion.Form, ModelState = ModelState, ValueProvider = ValueProvider }); if (ModelState.IsValid) { var sortCriterionRecord = query.SortCriteria.FirstOrDefault(f => f.Id == sortCriterionId); // add new sort criteria record if it's a newly created one if (sortCriterionRecord == null) { sortCriterionRecord = new SortCriterionRecord { Category = category, Type = type, Position = query.SortCriteria.Count }; query.SortCriteria.Add(sortCriterionRecord); } var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // save form parameters sortCriterionRecord.State = FormParametersHelper.ToString(dictionary); sortCriterionRecord.Description = model.Description; return(RedirectToAction("Edit", "Admin", new { id })); } // model is invalid, display it again var form = _formManager.Build(sortCriterion.Form); _formManager.Bind(form, formCollection); var viewModel = new SortCriterionEditViewModel { Id = id, Description = model.Description, SortCriterion = sortCriterion, Form = form }; return(View(viewModel)); }
public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)] int actionId, FormCollection formCollection) { var rule = _rulesServices.GetRule(id); var actionRecord = rule.Actions.FirstOrDefault(a => a.Id == actionId); // add new action record if it's a newly created action if (actionRecord == null) { actionRecord = new ActionRecord { Category = category, Type = type, Position = rule.Actions.Count }; rule.Actions.Add(actionRecord); } var action = _rulesManager.DescribeActions().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type); // validating form values _formManager.Validate(new ValidatingContext { FormName = action.Form, ModelState = ModelState, ValueProvider = ValueProvider }); if (ModelState.IsValid) { var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // save form parameters actionRecord.Parameters = FormParametersHelper.ToString(dictionary); return(RedirectToAction("Edit", "Admin", new { id })); } // model is invalid, display it again var form = _formManager.Build(action.Form); // Cancel the current transaction to prevent records from begin created Services.TransactionManager.Cancel(); AddSubmitButton(form); _formManager.Bind(form, formCollection); var viewModel = new EditActionViewModel { Id = id, Action = action, Form = form }; return(View(viewModel)); }
public IEnumerable <JObject> Post(string id, FilterViewModel model) { var pluralService = PluralizationService.CreateService(new CultureInfo("en-US")); if (pluralService.IsPlural(id)) { id = pluralService.Singularize(id); } var groupRecord = new FilterGroupRecord(); _filterGroupRepository.Create(groupRecord); _entityFilterRepository.Create(new EntityFilterRecord { EntityName = id, FilterGroupRecord = groupRecord, Title = model.Title }); foreach (var filter in model.Filters) { if (filter.FormData.Length == 0) { continue; } var record = new FilterRecord { Category = id + "ContentFields", Type = filter.Type, }; var dictionary = new Dictionary <string, string>(); foreach (var data in filter.FormData) { if (dictionary.ContainsKey(data.Name)) { dictionary[data.Name] += "&" + data.Value; } else { dictionary.Add(data.Name, data.Value); } } record.State = FormParametersHelper.ToString(dictionary); groupRecord.Filters.Add(record); } return(Get(id)); }
private static void FilterStaffProfileQuery(QueryPart staffProfileQuery) { var filterDictionary = new Dictionary <string, string>(); filterDictionary.Add("ContentTypes", "StaffProfile"); filterDictionary.Add("Description", "Staff Profiles"); var state = FormParametersHelper.ToString(filterDictionary); staffProfileQuery.FilterGroups[0].Filters.Add(new FilterRecord { Category = "Content", Description = "Staff Profiles", Position = 0, State = state, Type = "ContentTypes" }); }
public ActionResult CreatePost(LayoutEditViewModel model, FormCollection formCollection) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries"))) { return(new HttpUnauthorizedResult()); } // validating form values model.Layout = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == model.Category && x.Type == model.Type); _formManager.Validate(new ValidatingContext { FormName = model.Layout.Form, ModelState = ModelState, ValueProvider = ValueProvider }); var form = _formManager.Build(model.Layout.Form) ?? Services.New.EmptyForm(); _formManager.Bind(form, formCollection); model.Form = form; if (ModelState.IsValid) { var layoutRecord = new LayoutRecord { Category = model.Category, Type = model.Type }; var query = _queryService.GetQuery(model.QueryId); query.Layouts.Add(layoutRecord); var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // save form parameters layoutRecord.State = FormParametersHelper.ToString(dictionary); layoutRecord.Description = model.Description; layoutRecord.Display = model.Display; layoutRecord.DisplayType = model.DisplayType; Services.ContentManager.Flush(); Services.Notifier.Information(T("Layout Created")); return(RedirectToAction("Edit", new { id = layoutRecord.Id })); } return(View(model)); }
public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)] int eventId, FormCollection formCollection) { var rule = _rulesServices.GetRule(id); var eventRecord = rule.Events.Where(a => a.Id == eventId).FirstOrDefault(); // add new event record if it's a newly created event if (eventRecord == null) { eventRecord = new EventRecord { Category = category, Type = type }; rule.Events.Add(eventRecord); } var e = _rulesManager.DescribeEvents().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault(); // validating form values _formManager.Validate(new ValidatingContext { FormName = e.Form, ModelState = ModelState, ValueProvider = ValueProvider }); if (ModelState.IsValid) { var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // save form parameters eventRecord.Parameters = FormParametersHelper.ToString(dictionary); return(RedirectToAction("Edit", "Admin", new { id })); } // model is invalid, display it again var form = _formManager.Build(e.Form); AddSubmitButton(form); _formManager.Bind(form, formCollection); var viewModel = new EditEventViewModel { Id = id, Event = e, Form = form }; return(View(viewModel)); }
private string GetResizeUrl(string path, string width) { var state = new Dictionary <string, string> { { "Width", width.ToString(CultureInfo.InvariantCulture) }, { "Height", "0" } }; var filter = new FilterRecord { Category = "Transform", Type = "Resize", State = FormParametersHelper.ToString(state) }; var profile = "Transform_Resize" + "_w_" + Convert.ToString(width) + "_h_" + Convert.ToString(0); return(_imageProfileManager.Value.GetImageProfileUrl(path, profile, filter)); }
private static string GetLayoutState(int queryId, int columnCount, string desc) { var datas = new Dictionary <string, string> { { "QueryId", queryId.ToString(CultureInfo.InvariantCulture) }, { "Category", "Html" }, { "Type", "ngGrid" }, { "Description", desc }, { "Display", "1" }, { "DisplayType", "Summary" }, { "Alignment", "horizontal" }, { "Columns", columnCount.ToString(CultureInfo.InvariantCulture) }, { "GridId", string.Empty }, { "GridClass", string.Empty }, { "RowClass", string.Empty } }; var re = FormParametersHelper.ToString(datas); return(re); }
private FilterRecord Filter( int Width, int Height, string Mode, string Alignment, string PadColor) { var state = new Dictionary <string, string> { { "Width", Width.ToString(CultureInfo.InvariantCulture) }, { "Height", Height.ToString(CultureInfo.InvariantCulture) }, { "Mode", Mode }, { "Alignment", Alignment }, { "PadColor", PadColor }, }; return(new FilterRecord { Category = "Transform", Type = "Resize", State = FormParametersHelper.ToString(state) }); }
private static void SortStaffProfileQuery(QueryPart staffProfileQuery) { var sortDictionary = new Dictionary <string, string>(); sortDictionary.Add("Description", "Staff Group"); sortDictionary.Add("Sort", "false"); //sort by name var profileNameCriteria = staffProfileQuery.SortCriteria.FirstOrDefault(); if (profileNameCriteria == null) { profileNameCriteria = new SortCriterionRecord { Category = "TitlePartRecord", Type = "Title", Description = "Profile Name", Position = 1 }; } profileNameCriteria.State = FormParametersHelper.ToString(sortDictionary); staffProfileQuery.SortCriteria.Add(profileNameCriteria); }
private IList <FilterRecord> CreateFilters(string entityName, ListQueryModel model, out string filterDescription) { IList <FilterRecord> filterRecords; filterDescription = string.Empty; if (model.FilterGroupId == 0) { var filterDescriptors = _projectionManager.DescribeFilters() .Where(x => x.Category == entityName + "ContentFields") .SelectMany(x => x.Descriptors).ToList(); filterRecords = new List <FilterRecord>(); if (model.IsRelationList) { if (model.RelationType == "OneToMany") { var settings = new Dictionary <string, string> { { "Operator", "MatchesAny" }, { "Value", model.CurrentItem.ToString("D") } }; var relationFilter = new FilterRecord { Category = entityName + "ContentFields", Type = entityName + "." + model.RelationId + ".", State = FormParametersHelper.ToString(settings), Description = "Only show entries related to current item." }; filterRecords.Add(relationFilter); var descriptor = filterDescriptors.First(x => x.Type == relationFilter.Type); filterDescription += descriptor.Display(new FilterContext { State = FormParametersHelper.ToDynamic(relationFilter.State) }).Text; } } foreach (var filter in model.Filters) { if (filter.FormData.Length == 0) { continue; } var record = new FilterRecord { Category = entityName + "ContentFields", Type = filter.Type, }; var dictionary = new Dictionary <string, string>(); foreach (var data in filter.FormData) { if (dictionary.ContainsKey(data.Name)) { dictionary[data.Name] += "&" + data.Value; } else { dictionary.Add(data.Name, data.Value); } } record.State = FormParametersHelper.ToString(dictionary); filterRecords.Add(record); var descriptor = filterDescriptors.First(x => x.Type == filter.Type); filterDescription += descriptor.Display(new FilterContext { State = FormParametersHelper.ToDynamic(record.State) }).Text; } } else { filterRecords = _filterGroupRepository.Get(model.FilterGroupId).Filters; } return(filterRecords); }
public ActionResult EditPost(LayoutEditViewModel model, FormCollection formCollection) { // Validating form values. var layout = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == model.Category && x.Type == model.Type); _formManager.Validate(new ValidatingContext { FormName = layout.Form, ModelState = ModelState, ValueProvider = ValueProvider }); var form = _formManager.Build(layout.Form) ?? Services.New.EmptyForm(); _formManager.Bind(form, formCollection); model.Layout = layout; model.Form = form; var layoutRecord = _repository.Get(model.Id); if (ModelState.IsValid) { var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // Save form parameters. layoutRecord.State = FormParametersHelper.ToString(dictionary); layoutRecord.Description = model.Description; layoutRecord.Display = model.Display; layoutRecord.DisplayType = model.DisplayType; layoutRecord.GroupProperty = layoutRecord.Properties.FirstOrDefault(x => x.Id == model.GroupPropertyId); Services.Notifier.Success(T("Layout Saved")); return(RedirectToAction("Edit", new { id = layoutRecord.Id })); } #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 }); } } model.Properties = fieldEntries.OrderBy(f => f.Position); #endregion return(View(model)); }
public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)] int propertyId, FormCollection formCollection) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage queries"))) { return(new HttpUnauthorizedResult()); } var layout = _layoutRepository.Get(id); var property = _projectionManager.DescribeProperties().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault(); var model = new PropertyEditViewModel(); TryUpdateModel(model); // validating form values _formManager.Validate(new ValidatingContext { FormName = property.Form, ModelState = ModelState, ValueProvider = ValueProvider }); if (ModelState.IsValid) { var propertyRecord = layout.Properties.Where(f => f.Id == propertyId).FirstOrDefault(); // add new property record if it's a newly created property if (propertyRecord == null) { propertyRecord = new PropertyRecord { Category = category, Type = type, Position = layout.Properties.Count }; layout.Properties.Add(propertyRecord); } var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // save form parameters propertyRecord.State = FormParametersHelper.ToString(dictionary); propertyRecord.Description = model.Description; propertyRecord.CreateLabel = model.CreateLabel; propertyRecord.ExcludeFromDisplay = model.ExcludeFromDisplay; propertyRecord.Label = model.Label; propertyRecord.LinkToContent = model.LinkToContent; propertyRecord.CustomizeLabelHtml = model.CustomizeLabelHtml; propertyRecord.CustomizePropertyHtml = model.CustomizePropertyHtml; propertyRecord.CustomizeWrapperHtml = model.CustomizeWrapperHtml; propertyRecord.CustomLabelCss = model.CustomLabelCss; propertyRecord.CustomLabelTag = model.CustomLabelTag; propertyRecord.CustomPropertyCss = model.CustomPropertyCss; propertyRecord.CustomPropertyTag = model.CustomPropertyTag; propertyRecord.CustomWrapperCss = model.CustomWrapperCss; propertyRecord.CustomWrapperTag = model.CustomWrapperTag; propertyRecord.NoResultText = model.NoResultText; propertyRecord.ZeroIsEmpty = model.ZeroIsEmpty; propertyRecord.HideEmpty = model.HideEmpty; propertyRecord.RewriteOutput = model.RewriteOutput; propertyRecord.RewriteText = model.RewriteText; propertyRecord.StripHtmlTags = model.StripHtmlTags; propertyRecord.TrimLength = model.TrimLength; propertyRecord.AddEllipsis = model.AddEllipsis; propertyRecord.MaxLength = model.MaxLength; propertyRecord.TrimOnWordBoundary = model.TrimOnWordBoundary; propertyRecord.PreserveLines = model.PreserveLines; propertyRecord.TrimWhiteSpace = model.TrimWhiteSpace; return(RedirectToAction("Edit", "Layout", new { id })); } // model is invalid, display it again var form = _formManager.Build(property.Form); _formManager.Bind(form, formCollection); var viewModel = new PropertyEditViewModel { Id = id, Description = model.Description, Property = property, Form = form }; return(View(viewModel)); }