Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use <style at="Head" in DisplayDriver<Navbar> #14743

Closed
hyzx86 opened this issue Nov 22, 2023 · 9 comments · Fixed by #14747
Closed

Unable to use <style at="Head" in DisplayDriver<Navbar> #14743

hyzx86 opened this issue Nov 22, 2023 · 9 comments · Fixed by #14747
Labels
Milestone

Comments

@hyzx86
Copy link
Contributor

hyzx86 commented Nov 22, 2023

How to use NavbarTop after removal Using <style at="Head"

A while back I asked a question about how to introduce styles in the top menu bar

#13603

At the suggestion of @ns8482e I changed the code to the following

public class AdminSystemLogViewerShapes : IShapeTableProvider
{
    public void Discover(ShapeTableBuilder builder)
    {
        builder.Describe("Layout")
            .OnCreated(async context =>
            {
                if (context.Shape is IZoneHolding layout)
                {
                    var httpContextAccessor = context.ServiceProvider.GetRequiredService<IHttpContextAccessor>();
                    if (!AdminAttribute.IsApplied(httpContextAccessor.HttpContext))
                    {
                        return;
                    }
                    var auth = context.ServiceProvider.GetRequiredService<IAuthorizationService>();
                    if (!await auth.AuthorizeAsync(httpContextAccessor.HttpContext.User, PermissionsProvider.AccessSystemLog))
                    {
                        return;
                    }
                    await layout.Zones["NavbarTop"].AddAsync(new ShapeViewModel("AdminSystemLogViewer"));
                }
            });
    }
}

However, NavbarTop was removed in OC 1.8, I changed it to DisplayDriver<Navbar> based on other menu buttons

But the problem came back. Still unable to import styles to Head

    public class AdminSystemLogViewerShapes : DisplayDriver<Navbar>
    {
        private readonly IAuthorizationService _auth;
        private readonly IHttpContextAccessor _httpContextAccessor;
        public AdminSystemLogViewerShapes(IAuthorizationService auth, IHttpContextAccessor httpContextAccessor)
        {
            _auth = auth;
            _httpContextAccessor = httpContextAccessor;
        }

        public override async Task<IDisplayResult> DisplayAsync(Navbar model, BuildDisplayContext context)
        {
            if (!await _auth.AuthorizeAsync(_httpContextAccessor.HttpContext.User, PermissionsProvider.AccessSystemLog))
            {
                return null;
            }
            return View("AdminSystemLogViewer", model)
                .Location("DetailAdmin", "Content:1");
        }
    

    }
@MikeAlhayek
Copy link
Member

MikeAlhayek commented Nov 22, 2023

Have you tried adding style to your view?

<style at="Head">
 
</style>

@hyzx86
Copy link
Contributor Author

hyzx86 commented Nov 23, 2023

Have you tried adding style to your view?

<style at="Head">
 
</style>

Will this repeatedly render the elements?

@hyzx86
Copy link
Contributor Author

hyzx86 commented Nov 23, 2023

Hi @MikeAlhayek
I want to render link elments jsut like this:

    <style asp-name="amis"></style>
    <style asp-name="amis-cxd"></style>
    <style asp-name="amis-helper"></style>
    <style asp-name="amis-iconfont"></style>

they can't work in a style block , I think ~

<style at="Head">
    <style asp-name="amis"></style>
    <style asp-name="amis-cxd"></style>
    <style asp-name="amis-helper"></style>
    <style asp-name="amis-iconfont"></style>
</style>

@MikeAlhayek
Copy link
Member

This should work

    <style asp-name="amis"></style>
    <style asp-name="amis-cxd"></style>
    <style asp-name="amis-helper"></style>
    <style asp-name="amis-iconfont"></style>

However, it does not work because the Navbar shape is created after the head resources is already rendered. PR #14743 should fix this.

But, for now try injecting the resource into Foot instead. Foot has not yet been rendered so it should work.

    <style at="Foot" asp-name="amis"></style>
    <style at="Foot" asp-name="amis-cxd"></style>
    <style at="Foot" asp-name="amis-helper"></style>
    <style at="Foot" asp-name="amis-iconfont"></style>

@hyzx86
Copy link
Contributor Author

hyzx86 commented Nov 24, 2023

Hi @MikeAlhayek
Has PR #14747 been released with version 1.8.0-preview-17813?
After I updated the version dependency, it still didn't work

<style at="Head" asp-name="amis"></style>
<style at="Head" asp-name="amis-cxd"></style>
<style at="Head" asp-name="amis-helper"></style>
<style at="Head" asp-name="amis-iconfont"></style>

@MikeAlhayek
Copy link
Member

@hyzx86 it should be included in 17809+ so you should have seen the fix. Are you use a custom theme or layout?

@hyzx86
Copy link
Contributor Author

hyzx86 commented Nov 25, 2023

Are you use a custom theme or layout?

Yes ,but my custom theme is baseon TheAdmin and only override the Layout-Login.cshtml

image

@hyzx86
Copy link
Contributor Author

hyzx86 commented Nov 25, 2023

It still not work , even I change theme to TheAdmin
image

@MikeAlhayek
Copy link
Member

MikeAlhayek commented Nov 25, 2023

@hyzx86 strange. It worked when I submitted the PR. Now, I cleaned up my local environment and it returns different result. Maybe some weird caching problem I had locally.

Anyhow, I submitted another PR #14755 and it seems to be working as it should. If you like, please add a layout file in to your custom theme with the same change as done in #14755 and see if that fixes the problem.

@MikeAlhayek MikeAlhayek added this to the 1.x milestone Dec 7, 2023
@MikeAlhayek MikeAlhayek modified the milestones: 1.x, 1.8 Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants