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

Responsive Razor Pages View Location #297

Merged
merged 30 commits into from
Feb 14, 2020
Merged

Responsive Razor Pages View Location #297

merged 30 commits into from
Feb 14, 2020

Conversation

wangkanai
Copy link
Owner

@wangkanai wangkanai commented Feb 3, 2020

Reference #115

@wangkanai
Copy link
Owner Author

This PR is taking a lot of my time more than expected. Might need to move on and come back to later.
If anybody could help out would be much appreciated.

@wangkanai
Copy link
Owner Author

wangkanai commented Feb 5, 2020

@rynowak would you mind helping me out. Much appreciate if you can, because you are the original creator of PageViewLocationExpander.cs

I can ViewLocationExpander the _layout.cshtml, but not the page itself. Which i can't make out why it acting like this.

Mobile view

image

Tablet view

image

Desktop default

image

The ExpandPageHierarchy() result looks right. The page view location with the device file extension is correct. The layout work as expected. Just don't understand why the page device file extension is getting resolve to correct file.

image

wangkanai referenced this pull request in dotnet/aspnetcore Feb 5, 2020
The View Engine now needs to know about pages :(. This isn't ideal but the
view engine needs to know what set of search paths to use. This was
already hardcoded for controllers vs controllers + areas. It felt right to
further hardcode instead of introduce a wierd abstraction that we only
use.

Additionally pages use a view location expander to implement an ascending
directory search.
@wangkanai wangkanai linked an issue Feb 5, 2020 that may be closed by this pull request
@wangkanai wangkanai modified the milestones: 3.0 Alpha07, 3.0 Alpha08 Feb 6, 2020
yield return location.Replace("{0}", "{0}." + device);
// Fallback to the original default view
yield return location;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you manage to figure this out? Anything I can help with still?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please please help! I have my head spinning for a few days on this already. Much appreciated :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I'll take a look tomorrow.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I see what's going on here.

We don't use view location expanders to locate the "view" for a Razor Page because we've already found it. The page itself is the "view" so we don't go through a lookup process. What you could do instead is use routing a select a different page.

The other problem that's solved by doing this selection in the routing layer is one you might not have noticed. Because you defined a page with the filename Index.mobile.cshtml that means that it will respond to the url /Index.mobile which is probably not what you wanted. Routing for pages is customizable to address all of this.

image
image

I've got a branch where I've coded this up. I'll send you a link, and I'm happy to answer whatever questions you have about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rynowak@692377f

This code awesome, its open my perspective.
I see you a create ResponsiveAttribute, but see you use anywhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the convention for metadata types to use an attribute type. This would work for controllers as well. So if you had different action methods based on the device in use, that would "just work" with a controller as well.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the explanation.

This also me wanna to revisit another issue #243 Responsive Option to include Web Api Controllers. By using conventions pattern might be a better way then to pass in options.

@wangkanai
Copy link
Owner Author

Not working for Razor Pages that are in Areas.

  • Next to do list of the day.

image

return false;
}

public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CandidateSet is another investing thing that need my further attention and study later.

https://github.com/dotnet/aspnetcore/blob/master/src/Http/Routing/src/Matching/CandidateSet.cs

@@ -0,0 +1,3 @@
@using RazorApp
@namespace RazorApp.Pages
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong namespace and causing render issues

{
if (!location.Contains("/{1}/")
&& !location.Contains("/Shared/")
&& !location.Contains("/Areas/")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe another place to determine the issue.

@wangkanai wangkanai mentioned this pull request Feb 12, 2020
@wangkanai wangkanai changed the title Responsive Razor Pages view location expander Responsive Razor Pages View Location Feb 12, 2020
internal class ResponsivePageMatcherPolicy : MatcherPolicy, IEndpointComparerPolicy, IEndpointSelectorPolicy
{
public ResponsivePageMatcherPolicy()
=> Comparer = EndpointMetadataComparer<IResponsiveMetadata>.Default;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another thing that i need to investigate more EndpointMetadataComparer

https://github.com/dotnet/aspnetcore/blob/master/src/Http/Routing/src/Matching/EndpointMetadataComparer.cs

@wangkanai wangkanai linked an issue Feb 12, 2020 that may be closed by this pull request
wangkanai and others added 2 commits February 12, 2020 13:48
Merged with #331 for OperatingSystem change to Platform
@wangkanai
Copy link
Owner Author

Investigate the following for convention for Areas

@wangkanai
Copy link
Owner Author

wangkanai commented Feb 14, 2020

Got a working concept with responsive razor pages using areas coming in with PR #339.

mobile

image

tablet

image

Need to add unit tests and refactor later
Working concept with responsive razor pages using areas
@wangkanai
Copy link
Owner Author

@rynowak finally got it working for razor pages in areas too now.Thank you very much for your help to complete this feature of device responsive view for razor pages.

Much appreciated 🥇

@wangkanai wangkanai merged commit 26b625e into dev Feb 14, 2020
@wangkanai wangkanai deleted the pages branch February 14, 2020 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Responsive Razor Pages in Areas not working Responsive Razor Pages
2 participants