Ejemplo n.º 1
0
        public override IEnumerable<TemplateViewModel> PartEditor(ContentPartDefinition definition) {
            if (definition.Name != "BodyPart")
                yield break;

            var model = definition.Settings.GetModel<BodyPartSettings>();
            yield return DefinitionTemplate(model);
        }
Ejemplo n.º 2
0
 public EditPartViewModel(ContentPartDefinition contentPartDefinition)
 {
     Name = contentPartDefinition.Name;
     Fields = contentPartDefinition.Fields.Select((f, i) => new EditPartFieldViewModel(i, f) { Part = this }).ToList();
     Settings = contentPartDefinition.Settings;
     _Definition = contentPartDefinition;
 }
Ejemplo n.º 3
0
 public override void ApplyFilter(FilterContext context, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
     var op = (OptionSetOperator) Enum.Parse(typeof (OptionSetOperator), (string) context.State.Operator);
     string value = context.State.Value;
     var valueArr = value != null
         ? value.Split('&').Select(int.Parse).ToArray()
         : new[] {0};
     switch (op) {
         case OptionSetOperator.MatchesAny:
             Action<IAliasFactory> selectorAny = alias => alias.ContentPartRecord<OptionItemContainerPartRecord>().Property("OptionItems", "opits").Property("OptionItemRecord", "opcpr");
             Action<IHqlExpressionFactory> filterAny = x => x.InG("Id", valueArr);
             context.Query.Where(selectorAny, filterAny);
             break;
         case OptionSetOperator.MatchesAll:
             foreach (var id in valueArr) {
                 var optionId = id;
                 Action<IAliasFactory> selectorAll =
                     alias => alias.ContentPartRecord<OptionItemContainerPartRecord>().Property("OptionItems", "opit" + optionId);
                 Action<IHqlExpressionFactory> filterAll = x => x.Eq("OptionItemRecord.Id", optionId);
                 context.Query.Where(selectorAll, filterAll);
             }
             break;
         case OptionSetOperator.NotMatchesAny:
             Action<IAliasFactory> selectorNotAny = alias => alias.ContentPartRecord<OptionItemContainerPartRecord>().Property("OptionItems", "opits").Property("OptionItemRecord", "opcpr");
             Action<IHqlExpressionFactory> filterNotAny = x => x.Not(y => y.InG("Id", valueArr));
             context.Query.Where(selectorNotAny, filterNotAny);
             break;
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public LocalizedString DisplaySortCriterion(SortCriterionContext context, ContentPartDefinition part, ContentPartFieldDefinition fieldDefinition) {
            bool ascending = (bool)context.State.Sort;

            return ascending
                       ? T("Ordered by field {0}, ascending", fieldDefinition.Name)
                       : T("Ordered by field {0}, descending", fieldDefinition.Name);

        }
 public Task BuildPartEditorAsync(ContentPartDefinition model, BuildEditorContext context)
 {
     return _partDisplayDrivers.InvokeAsync(async contentDisplay =>
     {
         var result = await contentDisplay.BuildEditorAsync(model, context);
         if (result != null)
             result.Apply(context);
     }, Logger);
 }
 public XElement Export(ContentPartDefinition partDefinition) {
     var partElement = NewElement(partDefinition.Name, partDefinition.Settings);
     foreach(var partField in partDefinition.Fields) {
         var attributeName = partField.Name + "." + partField.FieldDefinition.Name;
         var partFieldElement = NewElement(attributeName, partField.Settings);
         partElement.Add(partFieldElement);
     }
     return partElement;
 }
 public ContentPartDefinitionBuilder(ContentPartDefinition existing) {
     if (existing == null) {
         _fields = new List<ContentPartFieldDefinition>();
         _settings = new SettingsDictionary();
     }
     else {
         _name = existing.Name;
         _fields = existing.Fields.ToList();
         _settings = new SettingsDictionary(existing.Settings.ToDictionary(kv => kv.Key, kv => kv.Value));
     }
 }
        public override async Task<IDisplayResult> UpdateAsync(ContentPartDefinition contentPartDefinition, UpdatePartEditorContext context)
        {
            var model = new ContentPartSettingsViewModel();

            if (await context.Updater.TryUpdateModelAsync(model, Prefix))
            {
                context.Builder.Attachable(model.Attachable);
                context.Builder.WithDescription(model.Description);
            }

            return Edit(contentPartDefinition, context.Updater);
        }
        public override IDisplayResult Edit(ContentPartDefinition contentPartDefinition)
        {
            return Shape<ContentPartSettingsViewModel>("ContentPartSettings_Edit", model =>
            {
                var settings = contentPartDefinition.Settings.ToObject<ContentPartSettings>();

                model.Attachable = settings.Attachable;
                model.Description = settings.Description;

                return Task.CompletedTask;
            }).Location("Content");
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Exports a content part definition to a XML format.
        /// </summary>
        /// <param name="contentPartDefinition">The part definition to be exported.</param>
        /// <returns>The content part definition in a XML format.</returns>
        public XElement Export(ContentPartDefinition contentPartDefinition) {
            Argument.ThrowIfNull(contentPartDefinition, "contentPartDefinition");

            var partElement = NewElement(contentPartDefinition.Name, contentPartDefinition.Settings);
            foreach (var partField in contentPartDefinition.Fields.OrderBy(x => x.Name)) {
                var attributeName = string.Format("{0}.{1}", partField.Name, partField.FieldDefinition.Name);
                var partFieldElement = NewElement(attributeName, partField.Settings);
                partElement.Add(partFieldElement);
            }

            return partElement;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Exports a content part definition to a XML format.
        /// </summary>
        /// <param name="contentPartDefinition">The part definition to be exported.</param>
        /// <returns>The content part definition in a XML format.</returns>
        public XElement Export(ContentPartDefinition contentPartDefinition)
        {
            Argument.ThrowIfNull(contentPartDefinition, nameof(contentPartDefinition));

            var partElement = NewElement(contentPartDefinition.Name, contentPartDefinition.Settings);
            foreach (var partField in contentPartDefinition.Fields) {
                var attributeName = $"{partField.Name}.{partField.FieldDefinition.Name}";
                var partFieldElement = NewElement(attributeName, partField.Settings);
                partElement.Add(partFieldElement);
            }

            return partElement;
        }
Ejemplo n.º 13
0
 public ContentTypeDefinitionBuilder WithPart(ContentPartDefinition partDefinition, Action<ContentTypePartDefinitionBuilder> configuration) {
     var existingPart = _parts.SingleOrDefault(x => x.PartDefinition.Name == partDefinition.Name);
     if (existingPart != null) {
         _parts.Remove(existingPart);
     }
     else {
         existingPart = new ContentTypePartDefinition(partDefinition, new SettingsDictionary());
     }
     var configurer = new PartConfigurerImpl(existingPart);
     configuration(configurer);
     _parts.Add(configurer.Build());
     return this;
 }
Ejemplo n.º 14
0
        public void ApplyFilter(FilterContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
            var propertyName = String.Join(".", part.Name, field.Name, storageName ?? "");

            // use an alias with the join so that two filters on the same Field Type wont collide
            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

            // generate the predicate based on the editor which has been used
            Action<IHqlExpressionFactory> predicate = fieldTypeEditor.GetFilterPredicate(context.State);

            // combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService
            Action<IHqlExpressionFactory> andPredicate = x => x.And(y => y.Eq("PropertyName", propertyName), predicate);

            // apply where clause
            context.Query = context.Query.Where(relationship, andPredicate);
        }
        public ContentPartDefinitionBuilder(ContentPartDefinition existing)
        {
            _part = existing;

            if (existing == null)
            {
                _fields = new List<ContentPartFieldDefinition>();
                _settings = new JObject();
            }
            else
            {
                _name = existing.Name;
                _fields = existing.Fields.ToList();
                _settings = new JObject(existing.Settings);
            }
        }
Ejemplo n.º 16
0
        public void ApplySortCriterion(SortCriterionContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
            bool ascending = Convert.ToBoolean(context.State.Sort);
            var propertyName = String.Join(".", part.Name, field.Name, storageName ?? "");

            // use an alias with the join so that two filters on the same Field Type wont collide
            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

            // generate the predicate based on the editor which has been used
            Action<IHqlExpressionFactory> predicate = y => y.Eq("PropertyName", propertyName);

            // combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService

            // apply where clause
            context.Query = context.Query.Where(relationship, predicate);
            
            // apply sort
            context.Query = ascending 
                ? context.Query.OrderBy(relationship, x => x.Asc("Value")) 
                : context.Query.OrderBy(relationship, x => x.Desc("Value"));
        }
Ejemplo n.º 17
0
 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);
 }
Ejemplo n.º 18
0
 public FieldConfigurerImpl(ContentPartFieldDefinition field, ContentPartDefinition part)
     : base(field) {
     _fieldDefinition = field.FieldDefinition;
     _fieldName = field.Name;
     _partDefinition = part;
 }
 public void StorePartDefinition(ContentPartDefinition contentPartDefinition)
 {
     Apply(contentPartDefinition, Acquire(contentPartDefinition));
     UpdateContentDefinitionRecord();
 }
 public void StorePartDefinition(ContentPartDefinition contentPartDefinition) {
     _signals.Trigger(ContentDefinitionSignal);
     Apply(contentPartDefinition, Acquire(contentPartDefinition));
 }
 private ContentPartDefinitionRecord Acquire(ContentPartDefinition contentPartDefinition) {
     var result = _partDefinitionRepository.Table.SingleOrDefault(x => x.Name == contentPartDefinition.Name);
     if (result == null) {
         result = new ContentPartDefinitionRecord { Name = contentPartDefinition.Name };
         _partDefinitionRepository.Create(result);
     }
     return result;
 }
Ejemplo n.º 22
0
 private ContentPartDefinitionRecord Acquire(ContentPartDefinition contentPartDefinition)
 {
     var result = GetContentDefinitionRecord().ContentPartDefinitionRecords.SingleOrDefault(x => x.Name == contentPartDefinition.Name);
     if (result == null)
     {
         result = new ContentPartDefinitionRecord { Name = contentPartDefinition.Name, };
         GetContentDefinitionRecord().ContentPartDefinitionRecords.Add(result);
     }
     return result;
 }
Ejemplo n.º 23
0
        public LocalizedString DisplayFilter(FilterContext context, ContentPartDefinition part, ContentPartFieldDefinition fieldDefinition) {
            string op = context.State.Operator;
            string value = context.State.Value;

            return T("Field {0} {1} \"{2}\"", fieldDefinition.Name, op, value);
        }
Ejemplo n.º 24
0
        private ContentPartDefinitionRecord Acquire(ContentPartDefinition contentPartDefinition)
        {
            var result = _contentStorageManager
                .Query<ContentPartDefinitionRecord>(x => x.Name == contentPartDefinition.Name)
                .SingleOrDefault();

            if (result == null) {
                result = new ContentPartDefinitionRecord { Name = contentPartDefinition.Name };
                _contentStorageManager.Store(result);
            }
            return result;
        }
Ejemplo n.º 25
0
 public PartConfigurerImpl(ContentTypePartDefinition part)
     : base(part) {
     _partDefinition = part.PartDefinition;
 }
Ejemplo n.º 26
0
        private void Apply(ContentPartDefinition model, ContentPartDefinitionRecord record)
        {
            record.Settings = model.Settings;

            var toRemove = record.ContentPartFieldDefinitionRecords
                .Where(partFieldDefinitionRecord => !model.Fields.Any(partField => partFieldDefinitionRecord.Name == partField.Name))
                .ToList();

            foreach (var remove in toRemove)
            {
                record.ContentPartFieldDefinitionRecords.Remove(remove);
            }

            foreach (var field in model.Fields)
            {
                var fieldName = field.Name;
                var partFieldRecord = record.ContentPartFieldDefinitionRecords.SingleOrDefault(r => r.Name == fieldName);
                if (partFieldRecord == null)
                {
                    partFieldRecord = new ContentPartFieldDefinitionRecord
                    {
                        ContentFieldDefinitionRecord = Acquire(field.FieldDefinition),
                        Name = field.Name
                    };
                    record.ContentPartFieldDefinitionRecords.Add(partFieldRecord);
                }
                Apply(field, partFieldRecord);
            }
        }
Ejemplo n.º 27
0
 public ContentTypePartDefinition(ContentPartDefinition contentPartDefinition, JObject settings)
 {
     PartDefinition = contentPartDefinition;
     Settings = settings;
 }
Ejemplo n.º 28
0
 public void StorePartDefinition(ContentPartDefinition contentPartDefinition)
 {
     Apply(contentPartDefinition, Acquire(contentPartDefinition));
 }
Ejemplo n.º 29
0
 public override IEnumerable<TemplateViewModel> PartEditor(ContentPartDefinition definition)
 {
     var model = definition.Settings.GetModel<ContentPartSettings>();
     yield return DefinitionTemplate(model);
 }
 public void StorePartDefinition(ContentPartDefinition contentPartDefinition) {
     Apply(contentPartDefinition, Acquire(contentPartDefinition));
     TriggerContentDefinitionSignal();
 }