Admin plugin route

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Skyler thank you very much for your help. I finally got it working!

Now that I understand what is going on, I will post how I got mine working in hopes this will help someone else out.

In the end it was as simple as extending my custom url to always have at least 5 parts. This allowed my custom route to by-pass the AdminAreaRegistration area route which only uses 4 parts.  I could find no other easy way to allow my route to run from within my plugin.

Resolved to AdminAreaRegistration (didn't work as intended):
Admin/Dealer
Admin/Plugin/Dealer/
Admin/Plugin/Dealer/Admin

Resolved to RouteProvider (worked as intended)
Admin/Plugin/Dealer/Admin/List

Even though my action (List) was set to default, I still needed to include it in the url.

My final admin custom route is included here for reference:
 routes.MapRoute(
   "Nop.Plugin.Misc.DealersAdmin",
   "Admin/Plugin/Dealer/Admin/{action}/{id}",
   new { controller = "DealerAdmin", action = "List", id = "" },
   new[] { "Nop.Plugin.Misc.Dealers.Controllers" }
).DataTokens.Add("Area", "Admin");

Note: This help is only if you want your custom admin plugin to start with "Admin". If you want to use a url that doesn't start with "Admin" (like "Myplugin/Admin/etc") you don't need to go through this trouble as your url won't get picked up by the Admin area route.

Note regarding DataTokens:
The advice from 7Spikes noted here is very helpful, but really threw me off as I misunderstood what it was doing. I thought adding the DataTokens was somehow fixing the routing issue, but from what I can tell now, what it does is allows all the other urls on in the nav to be displayed properly. For example, without adding the DataToken, when on my plugin admin page, the default nop affiliate link would show as "Affiliate/List". After adding the DataToken, the link would show as "Admin/Affiliate/List". (strangely the "Affiliate/Link" url worked in admin properly anyway)
12 years ago
I've finally managed it too. Somewhere in the progress I copied the classname in the route registration.. Oops!
Thx for the help!
12 years ago
Would someone please provide a basic template (or even outline) of how to create an Admin Plugin.  I would just like my "standalone" functionality to be callable from a menu item on the Admin menu.

Also, BuildMenuItem requires Telerik
        public void BuildMenuItem(Telerik.Web.Mvc.UI.MenuItemBuilder menuItemBuilder)

This would seem to preclude ability for  someone to create a non-open-source plugin.
Can the team provide a "wrapper" of some kind, so that the basic menu properties can be passed in without the Telerik class?
12 years ago
Hi New York.

Take a look at this plugin http://noppreciousmetals.codeplex.com
Matt and I are working on it together, and it does let you see the possibilities nopCommerce has to extend or change nopCommerce.

Also, you might want to take a look at http://blog.csharpwebdeveloper.com/ it contains various posts about the subject
12 years ago
But... you are right. You can't use Telerik without license when you don't want to make your code opensource..
Probably the best thing would be. Make a wrapper -> make that open source -> use the open source wrapper in your code.. and use jqGrid in your own add-on
12 years ago
stephen.maij wrote:
But... you are right. You can't use Telerik without license when you don't want to make your code opensource..
Probably the best thing would be. Make a wrapper -> make that open source -> use the open source wrapper in your code.. and use jqGrid in your own add-on


You could write a plugin that manages admin menu items. Then you can either make it a prerequisite to your plugin or have a less than ideal navigation that is turned off when the other plugin is installed.
12 years ago
stephen.maij wrote:
Hi New York.

Take a look at this plugin http://noppreciousmetals.codeplex.com
Matt and I are working on it together, and it does let you see the possibilities nopCommerce has to extend or change nopCommerce.

Also, you might want to take a look at http://blog.csharpwebdeveloper.com/ it contains various posts about the subject


Thanks.  I had just got it working before I saw your post.  I see now that Admin plugin is really like any other, but it just was not clear as to which class inherits from IAdminMenuPlugin
12 years ago
stephen.maij wrote:

But... you are right. You can't use Telerik without license when you don't want to make your code opensource..
Probably the best thing would be. Make a wrapper -> make that open source -> use the open source wrapper in your code.. and use jqGrid in your own add-on


I wonder if the WebGrid helper would work ok

http://weblogs.asp.net/shijuvarghese/archive/2010/10/08/using-the-webgrid-helper-in-asp-net-mvc-3-beta.aspx


skyler.severns wrote:
You could write a plugin that manages admin menu items. Then you can either make it a prerequisite to your plugin or have a less than ideal navigation that is turned off when the other plugin is installed.


It would be real nice if the nopTeam could just add a wrapper method.  It only needs 3 params  - Text, Url, ImageUrl

menuItemBuilder.Text("...").Url("...").ImageUrl(...
12 years ago
Geralt wrote:
Skyler thank you very much for your help. I finally got it working!

Now that I understand what is going on, I will post how I got mine working in hopes this will help someone else out.

In the end it was as simple as extending my custom url to always have at least 5 parts. This allowed my custom route to by-pass the AdminAreaRegistration area route which only uses 4 parts.  I could find no other easy way to allow my route to run from within my plugin.

Resolved to AdminAreaRegistration (didn't work as intended):
Admin/Dealer
Admin/Plugin/Dealer/
Admin/Plugin/Dealer/Admin

Resolved to RouteProvider (worked as intended)
Admin/Plugin/Dealer/Admin/List

Even though my action (List) was set to default, I still needed to include it in the url.

My final admin custom route is included here for reference:
 routes.MapRoute(
   "Nop.Plugin.Misc.DealersAdmin",
   "Admin/Plugin/Dealer/Admin/{action}/{id}",
   new { controller = "DealerAdmin", action = "List", id = "" },
   new[] { "Nop.Plugin.Misc.Dealers.Controllers" }
).DataTokens.Add("Area", "Admin");

Note: This help is only if you want your custom admin plugin to start with "Admin". If you want to use a url that doesn't start with "Admin" (like "Myplugin/Admin/etc") you don't need to go through this trouble as your url won't get picked up by the Admin area route.

Note regarding DataTokens:
The advice from 7Spikes noted here is very helpful, but really threw me off as I misunderstood what it was doing. I thought adding the DataTokens was somehow fixing the routing issue, but from what I can tell now, what it does is allows all the other urls on in the nav to be displayed properly. For example, without adding the DataToken, when on my plugin admin page, the default nop affiliate link would show as "Affiliate/List". After adding the DataToken, the link would show as "Admin/Affiliate/List". (strangely the "Affiliate/Link" url worked in admin properly anyway)


What does your menuItemBuilder.Url()  look like?


This is my RegisterRoutes  (DataTokens commented out, but see below)
    
        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                "Plugin.Misc.MyPlugin.Configure",
                "Plugins/MyPlugin/{action}",
                new { controller = "MyPlugin", action = "Configure" },
                new[] { "Nop.Plugin.Misc.MyPlugin.Controllers" }
            ); //.DataTokens.Add("Area", "Admin");
        }
      
But, I also have an additional form in my View

    @using (Html.BeginForm("MyAction", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
  
which generates the following
  
    <form action="/MyPlugin/MyAction" enctype="multipart/form-data" method="post">      

This is what the menu urls look like before I select anything    

My Plugin
    http://localhost:7872/Plugins/MyPlugin/Configure
example - System/Log
    http://localhost:7872/Admin/Log/List
    
Once I select my menu item, then all the menu items lose the Admin/ prefix

Yet, this url still works
    http://localhost:7872/Log/List
but this one does (and most others) do not
    http://localhost:7872/Common/SystemInfo    
    
Of course, manually typing url with Admin prefix works
    http://localhost:7872/Admin/Common/SystemInfo
and then afterwards the menu items all have the Admin prefix again (until I select my item)

If I put in the DataTokens, then all the Admin menus have Admin prefix and work fine, BUT... my Form submit now gets 404 error.
because it's been prefixed with Admin
http://localhost:7872/Admin/MyPlugin/MyAction
12 years ago
New York wrote:
What does your menuItemBuilder.Url()  look like?

My current menuItemBuilder.Url has:
menuItemBuilder.Url("/Admin/Plugin/Dealer/Admin/List");]
I have the extra admin in their to force the 5 parts, but it fits my pluging naming conventions anyway since to seperate the public/admin files I have used filenames like "DealerModel.cs"/"DealerAdminModel.cs", "DealerController.cs"/"DealerAdminController.cs" respectively.

I tried recreating what your route looks like and ran into the same problem your having. I changed my admin plugin itembuilder to:
menuItemBuilder.Url("/Plugin/Dealer/List");
And the maproute to:
"Plugin/Dealer/{action}/{id}"
The other navigation urls worked fine (added Admin/ to them properly), and my plugin had the correct url listed in the navigation ("Plugin/Dealer/List") and worked when I visited the listing page. However, the create button on the list page that I changed to match your route...
 <a href="@Url.Action("Create", "Plugin/Dealer")" class="t-button">@T("Admin.Common.AddNew")</a>
...was displayed as "Admin/Plugin/Dealer/Create"--like your form it was still adding the Admin to the front.

Is it an option for you to just change the admin url your using? If you need to use the specific url your using I'm sure we can figure out how to keep the default area admin out of it (Skyler's example post shows his plugin is using urls that don't start with Admin - "adyen/admin/account", so I'm sure it's possible). But if it doesn't matter, I haven't had a single issue with mapping urls since I stopped trying to use "Admin/Dealer" and changed my route to a 5 part url starting with admin (another formatting example of how to use a 5 part url is "admin/Plugins/SevenSpikes/HomePageSlidersAdmin/List" from the SevenSpikes plugins).
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.