public dynamic Render(PropertyContext context, ContentItem contentItem, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) { var p = contentItem.Parts.FirstOrDefault( x => x.PartDefinition.Name == part.Name); if(p == null) { return String.Empty; } var f = p.Fields.FirstOrDefault(x => x.Name == field.Name); if(f == null) { return String.Empty; } object value = null; _contentFieldValueProviders.Invoke(provider => { var result = provider.GetValue(contentItem, f); if (result != null) { value = result; } }, Logger); if (value == null) { value = f.Storage.Get<object>(storageName); } if (value == null) { return null; } // call specific formatter rendering return _propertyFormater.Format(storageType, value, context.State); }
public bool CompareContent(ContentItem preContentItem, ContentItem newContentItem) { _defferences.Clear(); var part = newContentItem.Parts.FirstOrDefault(p => p.PartDefinition.Name.Contains(preContentItem.ContentType)); if (part == null) return false; var fieldContext = new PropertyContext { State = FormParametersHelper.ToDynamic(string.Empty) }; string category = newContentItem.ContentType + "ContentFields"; var allFielDescriptors = _projectionManager.DescribeProperties().Where(p => p.Category == category).SelectMany(x => x.Descriptors).ToList(); foreach (var field in part.Fields) { if (!field.PartFieldDefinition.Settings.ContainsKey(isAuditKey)) continue; bool isAudit = bool.Parse(field.PartFieldDefinition.Settings[isAuditKey]); if (!isAudit) continue; if (_defferences.Keys.Contains(field.Name)) continue; var descriptor = allFielDescriptors.FirstOrDefault(d => d.Name.Text == field.Name + ":Value"); if (descriptor == null) continue; var preValue = descriptor.Property(fieldContext, preContentItem); var newValue = descriptor.Property(fieldContext, newContentItem); if (preValue != null && !string.IsNullOrEmpty(preValue.ToString()) && (newValue == null || string.IsNullOrEmpty(newValue.ToString()))) { _defferences.Add(field.Name, string.Format("Deleted {1} in {0}.", field.Name, preValue)); } else if (preValue != null && newValue.ToString() != preValue.ToString() || preValue == null && newValue != null && !string.IsNullOrEmpty(newValue.ToString())) { _defferences.Add(field.Name, string.Format("Changed {0} from {1} to {2}.", field.Name, preValue, newValue)); } } return _defferences.Count == 1; }
public dynamic Render(PropertyContext context, PropertyInfo property, ContentItem contentItem) { // creating type for ContentPart<TRecord>, where TRecord is the type of the property var partRecordType = typeof (ContentPart<>).MakeGenericType(new [] {property.DeclaringType}); // get the part for this ContentPart<TRecord> var part = contentItem.Parts.FirstOrDefault(p => partRecordType.IsAssignableFrom(p.GetType())); var record = partRecordType.GetProperty("Record").GetValue(part, null); var value = property.GetValue(record, null); if(value == null) { return null; } // call specific formatter rendering return _propertyFormater.Format(property.PropertyType, value, context.State); }
private IEnumerable<JObject> GetLayoutComponents(ProjectionPart part, int skipCount, int pageCount) { // query var query = part.Record.QueryPartRecord; // applying layout var layout = part.Record.LayoutRecord; var tokens = new Dictionary<string, object> {{"Content", part.ContentItem}}; var allFielDescriptors = _projectionManager.DescribeProperties().ToList(); var fieldDescriptors = layout.Properties.OrderBy(p => p.Position).Select(p => allFielDescriptors.SelectMany(x => x.Descriptors).Select(d => new {Descriptor = d, Property = p}).FirstOrDefault(x => x.Descriptor.Category == p.Category && x.Descriptor.Type == p.Type)).ToList(); fieldDescriptors = fieldDescriptors.Where(c => c != null).ToList(); var tokenizedDescriptors = fieldDescriptors.Select(fd => new {fd.Descriptor, fd.Property, State = FormParametersHelper.ToDynamic(_tokenizer.Replace(fd.Property.State, tokens))}).ToList(); // execute the query var contentItems = _projectionManager.GetContentItems(query.Id, skipCount, pageCount).ToList(); // sanity check so that content items with ProjectionPart can't be added here, or it will result in an infinite loop contentItems = contentItems.Where(x => !x.Has<ProjectionPart>()).ToList(); var layoutComponents = contentItems.Select( contentItem => { var result = new JObject(); result["ContentId"] = contentItem.Id; tokenizedDescriptors.ForEach( d => { var fieldContext = new PropertyContext { State = d.State, Tokens = tokens }; var shape = d.Descriptor.Property(fieldContext, contentItem); string text = (shape == null) ? string.Empty : shape.ToString(); var filedName = d.Property.GetFiledName(); result[filedName] = text; }); return result; }).ToList(); return layoutComponents; }
public LocalizedString DisplayFilter(PropertyContext context, ContentPartDefinition part, ContentPartFieldDefinition fieldDefinition, string storageName) { return T("Field {0}: {1}", fieldDefinition.Name, String.IsNullOrEmpty(storageName) ? T("Default value").Text : storageName); }
public dynamic RenderProperty(PropertyContext context, ContentItem contentItem) { return _contentManager.GetItemMetadata(contentItem).DisplayText; }
public LocalizedString DisplayProperty(PropertyContext context) { return T("Content: Display Text"); }
public dynamic RenderProperty(PropertyContext context, ContentItem contentItem) { // don't return empty otherwise the layout won't render the rewritten value return " "; }
public LocalizedString DisplayProperty(PropertyContext context) { return T("Content: Custom Value"); }
public LocalizedString Display(PropertyContext context, PropertyInfo property) { return T("{0} {1}", property.DeclaringType.Name, property.Name); }
public string Execute(int queryId) { var projection = this.Services.ContentManager.Query<ProjectionPart>() .Where<ProjectionPartRecord>(e => e.QueryPartRecord.Id == queryId) .List() .FirstOrDefault(); var layout = projection.Record.LayoutRecord; LayoutDescriptor layoutDescriptor = layout == null ? null : _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == layout.Category && x.Type == layout.Type); var tokens = new Dictionary<string, object> { { "Content", projection.ContentItem } }; var allFielDescriptors = _projectionManager.DescribeProperties().ToList(); var fieldDescriptors = layout.Properties.OrderBy(p => p.Position).Select(p => allFielDescriptors.SelectMany(x => x.Descriptors).Select(d => new { Descriptor = d, Property = p }).FirstOrDefault(x => x.Descriptor.Category == p.Category && x.Descriptor.Type == p.Type)).ToList(); var tokenizedDescriptors = fieldDescriptors.Select(fd => new { fd.Descriptor, fd.Property, State = FormParametersHelper.ToDynamic(tokenizer.Replace(fd.Property.State, tokens)) }).ToList(); var limit = projection.Record.MaxItems; var items = _projectionManager.GetContentItems(queryId, 0, limit).ToList(); //var container = _contentManager.Get<Orchard.Projections.Models.QueryPart>(projection.Record.QueryPartRecord.Id); var inspector = new ItemInspector(projection, Services.ContentManager.GetItemMetadata(projection), _htmlFilters); StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); var display = displayHelperFactory.CreateHelper(new ViewContext { HttpContext = workContextAccessor.GetContext().HttpContext }, new ViewDataContainer()); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("title"); jsonWriter.WriteValue(inspector.Title); jsonWriter.WritePropertyName("description"); jsonWriter.WriteValue(inspector.Description); jsonWriter.WritePropertyName("Items"); jsonWriter.WriteStartArray(); foreach (var contentItem in items) { var contentItemMetadata = Services.ContentManager.GetItemMetadata(contentItem); var propertyDescriptors = tokenizedDescriptors.Select(d => { var fieldContext = new PropertyContext { State = d.State, Tokens = tokens }; return new { d.Property, Shape = d.Descriptor.Property(fieldContext, contentItem) }; }); var properties = Services.New.Properties( Items: propertyDescriptors.Select( pd => Services.New.PropertyWrapper( Item: pd.Shape, Property: pd.Property, ContentItem: contentItem, ContentItemMetadata: contentItemMetadata ) ) ); var itemInspector = new ItemInspector(contentItem, contentItemMetadata, _htmlFilters); jsonWriter.WriteStartObject(); //jsonWriter.WriteComment("title"); //jsonWriter.WritePropertyName("title"); //jsonWriter.WriteValue(itemInspector.Title); //jsonWriter.WritePropertyName("description"); //jsonWriter.WriteValue(itemInspector.Description); var propertyShapes = ((IEnumerable<dynamic>)properties.Items) .Select(e => new { Property = ((PropertyRecord)e.Property), Description = ((PropertyRecord)e.Property).Description, Proxy = e, Content = Convert.ToString(display(e)) }) .ToList(); foreach (var field in propertyShapes) { jsonWriter.WritePropertyName(field.Description); jsonWriter.WriteValue(field.Content); } jsonWriter.WriteEndObject(); } jsonWriter.WriteEndArray(); jsonWriter.WriteEndObject(); } return sb.ToString(); // var projectionId = context.ValueProvider.GetValue("projection"); // if (projectionId == null) // return; // var limitValue = context.ValueProvider.GetValue("limit"); // var limit = 20; // if (limitValue != null) // limit = (int)limitValue.ConvertTo(typeof(int)); // var containerId = (int)projectionId.ConvertTo(typeof(int)); // var container = _contentManager.Get<ProjectionPart>(containerId); // if (container == null) // { // return; // } // var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container), _htmlFilters); }