Code Monkey home page Code Monkey logo

Comments (3)

fgilde avatar fgilde commented on August 18, 2024

Yes, you can use the MetaConfiguration in general for customize property and behaviours of your model or sub model independent if a dialog from collection edit is used or the form directly.

Here for exampel if UserModel should be configured to use a password field for the password property

public class UserModelMetaConfiguration: IObjectMetaConfiguration<UserModel>
{
    public Task ConfigureAsync(ObjectEditMeta<UserModel> meta)
    {
        meta.Properties(m => m.FirstName, m => m.LastName)
            .WrapInMudItem(mudItem => mudItem.xs = 6);
        meta.Property(m => m.Password)
            .RenderWith<MudTextField<string>, string>(field => field.Value, field =>
            {
                field.InputType = InputType.Password;
            })
            .WrapInMudItem(mudItem => mudItem.xs = 12);
        return Task.CompletedTask;
    }
}

Sample

For size or dialog options in general you can set them only to MudExCollectionEdit. That means if the collection is used inside of an editable model you need to specify this as well in the meta configuration, but I will add a possibility to forward from MudExObjectEdit. However you can do currently with a MetaConfoguration as well.
For Example if you have a class like this with a collection of Users in this case

public class SomeClassWithUser
{
    
    public List<UserModel> Users { get; set; }

You can create you meta config like this

public class SomeClassWithUserMetaConfiguration : IObjectMetaConfiguration<SomeClassWithUser>
{
    public Task ConfigureAsync(ObjectEditMeta<SomeClassWithUser> meta)
    {
        DialogOptionsEx dialogOptionsEx = new DialogOptionsEx()
        {
            MaximizeButton = true,
            CloseButton = true,
            FullHeight = true,
            CloseOnEscapeKey = true,
            MaxWidth = MaxWidth.Medium,
            FullWidth = true,
            DragMode = MudDialogDragMode.Simple,
            Animations = new[] { AnimationType.SlideIn },
            Position = DialogPosition.CenterRight,
            DisableSizeMarginY = true,
            DisablePositionMargin = true
        };
        meta.Properties(m => m.Users)
            .RenderWith<MudExCollectionEditor<UserModel>, ICollection<UserModel>>(ce => ce.Items)
            .WithAdditionalAttribute(nameof(MudExCollectionEditor<UserModel>.DialogOptions), dialogOptionsEx);

        return Task.CompletedTask;
    }
}

from mudblazor.extensions.

franklupo avatar franklupo commented on August 18, 2024

Well but it works partly for me.
I have a generic object that I don't know about.
in the Configure(ObjectEditMeta meta) method I apply changes to all my properties, if I change the type of password, fix the label and more. When I encounter a property of type ICollection I apply the modification of the dialog you recommended, but the properties that are displayed in the dialog I don't know how to modify.

How can I do?

Best regards

from mudblazor.extensions.

fgilde avatar fgilde commented on August 18, 2024

That should not be a problem. You also can configure the meta. You dont need to use the Configure Method on the MudExObjectEdit component. You can also just implement the IObjectMetaConfiguration interface.

What I'm for example doing is this. I have a base Config for my Dto's

public abstract class BaseDtoMetaConfiguration<T, TId> : IObjectMetaConfiguration<T> where T : IDtoBase<TId>
{
    public virtual Task ConfigureAsync(ObjectEditMeta<T> meta)
    {
        meta.Property(x => x.Id)
            .WithAdditionalAttributes(true,new KeyValuePair<string, object>(nameof(MudBaseInput<TId>.Disabled), true))
            .WithOrder(0);
        if (meta.Value.IsNew)
            meta.Property(x => x.Id).Ignore();
        meta.Property(x => x.IsNew).Ignore();
        meta.WrapEachInMudItem(i =>
        {
            i.xs = 12;
            i.md = 6;
        });
        return Task.CompletedTask;
    }
}

And then for all my Dtos I create a small config.

public class IcdDtoMetaConfiguration: BaseDtoMetaConfiguration<IcdDto, int>
{
    public override Task ConfigureAsync(ObjectEditMeta<IcdDto> meta)
    {
        meta.Property(dto => dto.Name).WrapInMudItem(i => i.md = 12);
        meta.Property(dto => dto.IcdVersion).Ignore();
        return base.ConfigureAsync(meta);
    }
}

And then its independent where and why you model is rendered later on, your config will work.

Also you can configure all Collections inside of a MetaConfig. Independent if youre using the interface or the delegate on the component you can just query your properties and do something for all collections.

    private static bool IsCollection(Type type)
        => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ICollection<>) || type.GetInterfaces().Any(IsCollection);

meta.AllProperties.Where(oem => IsCollection(oem.PropertyInfo.PropertyType)).RenderWith(...);

And if all of this doesnt help, you can also Registering global type defaults with the static class RenderDataDefaults.

RenderDataDefaults.RegisterDefault<ICollection<string>, MudExCollectionEditor<string>>(f => f.Items);

Then all ICollections of string will be rendered with the desired configuration if no other meta config is provided.

from mudblazor.extensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.