Menu questions

Mar 20, 2013 at 4:21 AM
Edited Mar 20, 2013 at 6:45 AM
I am getting to really like this framework. But I do have some issues trying to figure it out. I am hoping that my questions will help me as well as others who are playing with it.

I am looking at the ViewAction class in Mvvm and trying to figure out which parameter does what and how. For example, if I want a checkbox or icon with the menu, how do I specify it? My guess is that the VisualResourceKey is used to specify the icon, but then how do I specify a checkmark? Or a line to separate items?

Also, how do you see the userRoles being used? I have code in the CODEFrameworkPrincipal class to set the roles and implemented an IsInRole (as well as a LogOut) method. But not quite sure how to specify the roles when a menu item may be supported by more than one role, but not all of them. I think clarification on how you see the roles being used vs. how I (or anyone) may figure they are used would be nice.

And, on that same note, a role may determine if a menu item is visible, but greyed out, not visible, or visible and clickable. I am guessing I use canExecute to enable/disable and the roles to determine if they are visible. But then I also have a visible setting. So I am trying to figure out when I should use which value.

I am also at a loss as to why the SwitchThemeViewAction does not support the categoryOrder (and other) attribute(s) that is (are) in the ViewAction class. This makes it hard to put the layout option where I would like.... The only options I can see is to either not use the SwitchThemeViewAction option, replace it with one based on ViewAction, or modify the FW (which I really don't want to do.) Now I am wondering what other ViewActions are in use that are limited like this.....

And, of course, some documentation on the ViewModel which indicates how you envision some of the properties being used would be nice - the current comments are rather redundant (i.e. for BeginGroup, the description is "Indicates whether this is a new group of actions" - well, the member name gives me that info already, but it still doesn't tell me how you see it being used...

Thanks
Coordinator
Mar 20, 2013 at 5:31 PM
OK, that is a loaded question :-)

Some of the things you mention here (view action order) are just not supported by the current battleship theme, but will be in the next build (see other messages).

Other aspects are completely dependent on the theme applied. So for instance, the Metro theme chooses to show the associated graphical resource in tiles on the start screen or in the round buttons at the bottom for regular views, but not at all for top level views which just have the square buttons with text only. This is all driven by the standards for Metro UIs, but of course you can always change that. For instance, you can change the buttons for top level views and add an element in addition to the text caption, so the resource does show up.

Other styles can choose to use this information completely different. So in the battleship theme for instance, view actions usually go into menus or toolbars. If there are visual resources, then they should show up in the menu (although in your current build they do not but in the next build they will...). For toolbars, depending on the significance of the action, the theme should probably sometimes show just an icon (or, if there is no icon, then just the text), and sometimes (for the view actions with a high significance) text + icon if it is available.

The roles basically go back to standard .NET roles. When a view action is used by the framework, it looks if there are roles specified. If so, it uses standard .NET infrastructure to say "is this user in one of the specified roles" and if so, the theme shows the action. If not, the theme typically either chooses to hide the action entirely (that would probably the more common approach) or to disable it. Again, this is up to the view. (This kind of flexibility is very desirable IMO, but it also makes it much harder to explain what exactly is going to happen in what scenario :-)). So that leaves the question where the roles are defined. In .NET, every running thread has a Principal object (and new threads inherit the existing principal from the thread that spawned it, basically). That principal is used to determine what roles the current user is in. So what is this principal object? It totally depends! There are standard principals .NET provides (such as for Active Directory users) and there can be custom principal objects. For instance, if you wanted to create your own database of users, you can create your own principal that is used by the app/thread/app domain and when used, that custom principal goes and checks what the user can do (what roles the user is in) usually by calling a service or querying a database. The default setup for CODE Framework projects includes a starting point for such a principal. Take a look at the login stuff in the controller and the view models it uses and so forth.

Markus
Mar 20, 2013 at 6:24 PM
Markus,

Many of my questions are based on the knowledge that you are working on the battleship theme - which I have to use for my current project.

I have been playing with the CODE principal and (as indicated above) already added support for the inRoles. My question was primarily how the framework ,emu styles interpreted the user role and if multiple roles could be referenced.

For example, if a given menu option were only available to sys admins, managers, and executives, can I specify all three roles in the ViewAction declaration? Or do I need to have a specific role for a given option with no overlap?

I believe I can use the canExecute to make something greyed out (or not) and the inRoles to make it visible or not. Please let me know if I am wrong here.

Thanks

ps. It's amazing how complicated something looks when you first delve into it - and yet how simple it looks when you understand it.... :)
Coordinator
Mar 20, 2013 at 9:11 PM
You could just set the role to "Admin, Manager, Executive" to make this work.

Markus