EasyData icon indicating copy to clipboard operation
EasyData copied to clipboard

Detect all easy data maps

Open Alerinos opened this issue 2 years ago • 0 comments

Hi, my system is split into plugins. Each plug-in has a separate database. Easy data is loaded during initialization. I have a separate project as a dashboard, everything happens automatically there. Unfortunately, it needs a method to discover all MapEasyData endpoints.

                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapEasyData(options =>
                    {
                        options.Endpoint = "/_crud/culture";
                        options.UseDbContext<Stand.Plugins.Culture.Context>(opts =>
                        {
                            opts.CustomizeModel(model =>
                            {
                                model.Entity<Stand.Plugins.Culture.Models.Country>()
                                    .Attribute(o => o.Language).SetShowInLookup(true);
                            });
                        });
                    });

                    endpoints.MapEasyData(options =>
                    {
                        options.Endpoint = "/_crud/places";
                        options.UseDbContext<Stand.Plugins.Places.Context>();
                    });
                });

How can I do this? I need it to generate navigation, so if we have 10 endpoints, I can do this:

foreach(var map in EasyData.GetAllEndPoints){
<a href="database/{map.Name}">{map.Name}</a>
}

My database.razor:

@page "/database/{module}/{url?}"
@layout MainLayout
@implements IAsyncDisposable
@inject IJSRuntime JSRuntime

@attribute [Authorize] 

<Card Bordered="true">
    <div id="EasyDataContainer"></div>
</Card>

@code {

    [Parameter]
    public string Module { get; set; } = "";

    [Parameter]
    public string Url { get; set; } = "";

    private bool first = true;

    protected override async Task OnParametersSetAsync()
    {
        if(first == false)
        {
            await this.OnAfterRenderAsync(true);
        }

        //JSRuntime.InvokeVoidAsync("blazorExtensions.EasyData", Module);
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender) {
            await JSRuntime.InvokeVoidAsync("stopEasyData");
            await JSRuntime.InvokeVoidAsync("runEasyData", Module.ToLower());
            first = false;
        }
        await base.OnAfterRenderAsync(firstRender);
    }
    
    private bool _disposed = false;

    public async ValueTask DisposeAsync()
    {
        if (!_disposed)
        {
            _disposed = true;

            await JSRuntime.InvokeVoidAsync("stopEasyData");
        }
    }

}

Alerinos avatar Sep 21 '22 12:09 Alerinos