Esempio n. 1
0
 public static ContentPartDefinitionBuilder WithTextField(this ContentPartDefinitionBuilder p, string name, string displayName, string position)
 {
     return(p.WithField(name, f => f
                        .OfType(nameof(TextField))
                        .WithDisplayName(displayName)
                        .WithPosition(position)
                        ));
 }
        public static void AlterPartDefinition(this IContentDefinitionManager manager, string name, Action <ContentPartDefinitionBuilder> alteration)
        {
            var partDefinition = manager.GetPartDefinition(name) ?? new ContentPartDefinition(name);
            var builder        = new ContentPartDefinitionBuilder(partDefinition);

            alteration(builder);
            manager.StorePartDefinition(builder.Build());
        }
Esempio n. 3
0
        public override IEnumerable <TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel)
        {
            var model = new ContentPartLayoutSettings();

            updateModel.TryUpdateModel(model, "ContentPartLayoutSettings", null, null);
            builder.Placeable(model.Placeable);
            yield return(DefinitionTemplate(model));
        }
        public static async Task AlterPartDefinitionAsync(this IContentDefinitionManager manager, string name, Func <ContentPartDefinitionBuilder, Task> alterationAsync)
        {
            var partDefinition = manager.LoadPartDefinition(name) ?? new ContentPartDefinition(name);
            var builder        = new ContentPartDefinitionBuilder(partDefinition);

            await alterationAsync(builder);

            manager.StorePartDefinition(builder.Build());
        }
Esempio n. 5
0
        public override IEnumerable <TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel)
        {
            var model = new ContentPartSettings();

            updateModel.TryUpdateModel(model, "ContentPartSettings", null, null);
            builder.Attachable(model.Attachable);
            builder.WithDescription(model.Description);
            yield return(DefinitionTemplate(model));
        }
Esempio n. 6
0
 public static ContentPartDefinitionBuilder WithBooleanField(this ContentPartDefinitionBuilder p, string name, string displayName, string position, BooleanFieldSettings settings)
 {
     return(p.WithField(name, f => f
                        .OfType(nameof(BooleanField))
                        .WithDisplayName(displayName)
                        .WithPosition(position)
                        .WithSettings(settings)
                        ));
 }
Esempio n. 7
0
 public static ContentPartDefinitionBuilder WithSwitchBooleanField(this ContentPartDefinitionBuilder p, string name, string displayName, string position)
 {
     return(p.WithField(name, f => f
                        .OfType(nameof(BooleanField))
                        .WithEditor("Switch")
                        .WithDisplayName(displayName)
                        .WithPosition(position)
                        ));
 }
Esempio n. 8
0
 public static ContentPartDefinitionBuilder WithTextFieldPredefinedList(this ContentPartDefinitionBuilder p, string name, string displayName, string position, TextFieldPredefinedListEditorSettings settings)
 {
     return(p.WithField(name, f => f
                        .OfType(nameof(TextField))
                        .WithDisplayName(displayName)
                        .WithEditor("PredefinedList")
                        .WithPosition(position)
                        .WithSettings(settings)
                        ));
 }
 public static ContentPartDefinitionBuilder WithTeamCaptainField(this ContentPartDefinitionBuilder p, string position)
 {
     return(p.WithField("TeamCaptain", f => f
                        .OfType(nameof(UserPickerField))
                        .WithDisplayName("Team Captain")
                        .WithPosition(position)
                        .WithSettings(new UserPickerFieldSettings()
     {
         DisplayedRoles = new string[] { "Hacker" }
     })
                        ));
 }
 public static ContentPartDefinitionBuilder WithChallengeField(this ContentPartDefinitionBuilder p, string position)
 {
     return(p.WithField("Challenge", f => f
                        .OfType(nameof(ContentPickerField))
                        .WithDisplayName("Challenge")
                        .WithPosition(position)
                        .WithSettings(new ContentPickerFieldSettings()
     {
         DisplayedContentTypes = new string[] { "Challenge" }
     })
                        ));
 }
Esempio n. 11
0
 public static ContentPartDefinitionBuilder WithMarkdownField(this ContentPartDefinitionBuilder p, string name, string displayName, string hint, string position)
 {
     return(p.WithField(name, f => f
                        .OfType(nameof(MarkdownField))
                        .WithEditor("Wysiwyg")
                        .WithDisplayName(displayName)
                        .WithPosition(position)
                        .WithSettings(new MarkdownFieldSettings()
     {
         Hint = hint
     })
                        ));
 }
Esempio n. 12
0
        public override IEnumerable <TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel)
        {
            if (builder.Name != "BodyPart")
            {
                yield break;
            }

            var model = new BodyPartSettings();

            updateModel.TryUpdateModel(model, "BodyPartSettings", null, null);
            builder.WithSetting("BodyPartSettings.FlavorDefault", !string.IsNullOrWhiteSpace(model.FlavorDefault) ? model.FlavorDefault : null);
            yield return(DefinitionTemplate(model));
        }
Esempio n. 13
0
 public static ContentPartDefinitionBuilder WithBooleanField(
     this ContentPartDefinitionBuilder builder,
     string name,
     bool @default,
     string hint = "")
 {
     return(builder.WithField(
                name,
                fieldBuilder =>
                fieldBuilder.OfType("BooleanField")
                .WithSetting("BooleanFieldSettings.Hint", hint)
                .WithSetting("BooleanFieldSettings.DefaultValue", @default.ToString(CultureInfo.InvariantCulture))));
 }
        public override IEnumerable <TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel)
        {
            if (builder.Name != "ContainerPart")
            {
                yield break;
            }

            var model = new ContainerPartSettings();

            updateModel.TryUpdateModel(model, "ContainerPartSettings", null, null);
            builder.WithSetting("ContainerPartSettings.PageSizeDefault", model.PageSizeDefault.ToString());
            builder.WithSetting("ContainerPartSettings.PaginatedDefault", model.PaginatedDefault.ToString());
            yield return(DefinitionTemplate(model));
        }
Esempio n. 15
0
 public static ContentPartDefinitionBuilder WithMultiValueTextField(this ContentPartDefinitionBuilder p, string name, string displayName, string position, ListValueOption[] options, MultiValueEditorOption editor = MultiValueEditorOption.Dropdown)
 {
     return(p.WithField(name, field => field
                        .OfType("MultiValueTextField")
                        .WithDisplayName(displayName)
                        .WithEditor("PredefinedList")
                        .WithPosition(position)
                        .WithSettings(new MultiValueTextFieldEditorSettings
     {
         Options = options,
         Editor = editor
     })
                        ));
 }
Esempio n. 16
0
        public void ShouldReturnProviderByName()
        {
            var part1Definition = new ContentPartDefinitionBuilder()
                                  .WithField("Hello", fb => fb.OfType("Text").WithSetting("Storage", "TestProvName"))
                                  .Build();
            var part2Definition = new ContentPartDefinitionBuilder()
                                  .WithField("World", fb => fb.OfType("Text").WithSetting("Storage", "Infoset"))
                                  .Build();

            var provider1 = _selector.GetProvider(part1Definition.Fields.Single());
            var provider2 = _selector.GetProvider(part2Definition.Fields.Single());

            Assert.That(provider1.ProviderName, Is.EqualTo("TestProvName"));
            Assert.That(provider2.ProviderName, Is.EqualTo("Infoset"));
        }
Esempio n. 17
0
        public static ContentPartDefinitionBuilder WithTextField(
            this ContentPartDefinitionBuilder builder,
            string name,
            Flavour flavor,
            bool required = true,
            string hint   = "")
        {
            var strFlavor = flavor.ToString().SplitCamel();

            return(builder.WithField(
                       name,
                       fieldBuilder =>
                       fieldBuilder.OfType("TextField")
                       .WithSetting("TextFieldSettings.Required", required.ToString(CultureInfo.InvariantCulture))
                       .WithSetting("TextFieldSettings.Flavor", strFlavor)
                       .WithSetting("TextFieldSettings.Hint", hint)));
        }
Esempio n. 18
0
        /// <summary>
        /// Merges a given content part definition provided in a XML format into a content part definition builder.
        /// </summary>
        /// <param name="element">The XML content type definition.</param>
        /// <param name="contentPartDefinitionBuilder">The content part definition builder.</param>
        public void Merge(XElement element, ContentPartDefinitionBuilder contentPartDefinitionBuilder)
        {
            Argument.ThrowIfNull(element, nameof(element));
            Argument.ThrowIfNull(contentPartDefinitionBuilder, nameof(contentPartDefinitionBuilder));

            // Merge name
            contentPartDefinitionBuilder.Named(XmlConvert.DecodeName(element.Name.LocalName));

            // Merge settings
            foreach (var setting in _settingsFormatter.Map(element))
            {
                contentPartDefinitionBuilder.WithSetting(setting.Key, setting.Value);
            }

            // Merge fields
            foreach (var iter in element.Elements())
            {
                var fieldElement    = iter;
                var fieldParameters = XmlConvert.DecodeName(fieldElement.Name.LocalName).Split(new[] { '.' }, 2);
                var fieldName       = fieldParameters.FirstOrDefault();
                var fieldType       = fieldParameters.Skip(1).FirstOrDefault();
                if (fieldName == "remove")
                {
                    var nameAttribute = fieldElement.Attribute("name");
                    if (nameAttribute != null)
                    {
                        contentPartDefinitionBuilder.RemoveField(nameAttribute.Value);
                    }
                }
                else
                {
                    contentPartDefinitionBuilder.WithField(
                        fieldName,
                        fieldBuilder =>
                    {
                        fieldBuilder.OfType(fieldType);
                        foreach (var setting in _settingsFormatter.Map(fieldElement))
                        {
                            fieldBuilder.WithSetting(setting.Key, setting.Value);
                        }
                    });
                }
            }
        }
Esempio n. 19
0
        public static ContentPartDefinitionBuilder WithMediaLibraryPickerField(
            this ContentPartDefinitionBuilder builder,
            string name,
            bool required = true,
            bool multiple = false,
            string hint   = "",
            string displayedContentTypes = "jpg jpeg png gif")
        {
            var displayName = name.SplitCamel();

            // default implementation of Media library picker field - create overloads for more options
            return(builder.WithField(
                       name,
                       fieldBuilder =>
                       fieldBuilder.OfType("MediaLibraryPickerField")
                       .WithDisplayName(displayName)
                       .WithSetting("MediaLibraryPickerFieldSettings.Required", required.ToString(CultureInfo.InvariantCulture))
                       .WithSetting("MediaLibraryPickerFieldSettings.DisplayedContentTypes", displayedContentTypes)
                       .WithSetting("MediaLibraryPickerFieldSettings.Multiple", multiple.ToString(CultureInfo.InvariantCulture))
                       .WithSetting("MediaLibraryPickerFieldSettings.Hint", hint)));
        }
Esempio n. 20
0
        public static ContentPartDefinitionBuilder WithContentPickerField(
            this ContentPartDefinitionBuilder builder,
            string name,
            string hint                    = null,
            bool isRequired                = false,
            bool allowMultiple             = false,
            bool showContentTab            = true,
            string[] displayedContentTypes = null)
        {
            var displayName  = name.SplitCamel();
            var contentTypes = displayedContentTypes != null?string.Join(",", displayedContentTypes) : null;

            return(builder.WithField(
                       name,
                       cfg => cfg.OfType(typeof(ContentPickerField).Name)
                       .WithDisplayName(displayName)
                       .WithSetting("ContentPickerFieldSettings.Hint", hint)
                       .WithSetting("ContentPickerFieldSettings.Required", isRequired.ToString(CultureInfo.InvariantCulture))
                       .WithSetting("ContentPickerFieldSettings.Multiple", allowMultiple.ToString(CultureInfo.InvariantCulture))
                       .WithSetting("ContentPickerFieldSettings.ShowContentTab", showContentTab.ToString(CultureInfo.InvariantCulture))
                       .WithSetting("ContentPickerFieldSettings.DisplayedContentTypes", contentTypes)));
        }
Esempio n. 21
0
        public static ContentPartDefinitionBuilder WithLinkField(
            this ContentPartDefinitionBuilder builder,
            string fieldName,
            string displayName        = null,
            bool required             = false,
            TargetMode targetMode     = TargetMode.None,
            LinkTextMode linkTextMode = LinkTextMode.Optional,
            string hint = "")
        {
            return(builder.WithField(
                       fieldName,
                       fieldBuilder => {
                fieldBuilder.OfType("LinkField")
                .WithSetting("LinkFieldSettings.Hint", hint)
                .WithSetting("LinkFieldSettings.Required", required.ToString(CultureInfo.InvariantCulture))
                .WithSetting("LinkFieldSettings.TargetMode", targetMode.ToString())
                .WithSetting("LinkFieldSettings.LinkTextMode", linkTextMode.ToString());

                if (displayName.HasValue())
                {
                    fieldBuilder.WithDisplayName(displayName);
                }
            }));
        }
Esempio n. 22
0
 public static ContentPartDefinitionBuilder WithDescription(this ContentPartDefinitionBuilder builder, string description)
 {
     return(builder.WithSetting("ContentPartSettings.Description", description));
 }
Esempio n. 23
0
 public static ContentPartDefinitionBuilder Attachable(this ContentPartDefinitionBuilder builder, bool attachable = true)
 {
     return(builder.WithSetting("ContentPartSettings.Attachable", attachable.ToString()));
 }
 public static ContentPartDefinitionBuilder WithDefaultPosition(this ContentPartDefinitionBuilder builder, string position)
 {
     return(builder.MergeSettings <ContentPartSettings>(x => x.DefaultPosition = position));
 }
Esempio n. 25
0
 public static ContentPartDefinitionBuilder Placeable(this ContentPartDefinitionBuilder builder, bool placeable = true)
 {
     return(builder.WithSetting("ContentPartLayoutSettings.Placeable", placeable.ToString()));
 }
Esempio n. 26
0
 public virtual IEnumerable <TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel)
 {
     return(Enumerable.Empty <TemplateViewModel>());
 }
 public static ContentPartDefinitionBuilder Attachable(this ContentPartDefinitionBuilder builder, bool attachable = true)
 {
     return(builder.MergeSettings <ContentPartSettings>(x => x.Attachable = attachable));
 }
 public static ContentPartDefinitionBuilder WithDisplayName(this ContentPartDefinitionBuilder builder, string description)
 {
     return(builder.WithSetting(nameof(ContentPartSettings.DisplayName), description));
 }
 public static ContentPartDefinitionBuilder WithDefaultPosition(this ContentPartDefinitionBuilder builder, string position)
 {
     return(builder.WithSetting(nameof(ContentPartSettings.DefaultPosition), position));
 }
Esempio n. 30
0
 public static ContentPartDefinitionBuilder Reusable(this ContentPartDefinitionBuilder builder, bool reusable = true)
 {
     return(builder.WithSetting(nameof(ContentPartSettings.Reusable), reusable.ToString()));
 }