Skip to content

Commit 236de82

Browse files
committed
Resolved #38: Don't use absolute path for actions in MVC template. Minor improvements.
1 parent 932f1b9 commit 236de82

File tree

8 files changed

+65
-12
lines changed

8 files changed

+65
-12
lines changed

src/AbpCompanyName.AbpProjectName.WebMpa/AbpCompanyName.AbpProjectName.WebMpa.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@
449449
<Compile Include="Models\Layout\TopMenuViewModel.cs" />
450450
<Compile Include="Properties\AssemblyInfo.cs" />
451451
<Compile Include="Views\AbpProjectNameWebViewPageBase.cs" />
452+
<Compile Include="Views\UrlChecker.cs" />
452453
</ItemGroup>
453454
<ItemGroup>
454455
<Content Include="Views\web.config" />

src/AbpCompanyName.AbpProjectName.WebMpa/App_Start/AbpProjectNameNavigationProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ public override void SetNavigation(INavigationProviderContext context)
1919
new MenuItemDefinition(
2020
"Home",
2121
L("HomePage"),
22-
url: "/",
22+
url: "",
2323
icon: "fa fa-home",
2424
requiresAuthentication: true
2525
)
2626
).AddItem(
2727
new MenuItemDefinition(
2828
"Tenants",
2929
L("Tenants"),
30-
url: "/Tenants",
30+
url: "Tenants",
3131
icon: "fa fa-globe",
3232
requiredPermissionName: PermissionNames.Pages_Tenants
3333
)
3434
).AddItem(
3535
new MenuItemDefinition(
3636
"Users",
3737
L("Users"),
38-
url: "/Users",
38+
url: "Users",
3939
icon: "fa fa-users",
4040
requiredPermissionName: PermissionNames.Pages_Users
4141
)
4242
).AddItem(
4343
new MenuItemDefinition(
4444
"About",
4545
L("About"),
46-
url: "/About",
46+
url: "About",
4747
icon: "fa fa-info"
4848
)
4949
);

src/AbpCompanyName.AbpProjectName.WebMpa/Views/Layout/_TopMenu.cshtml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
@using Abp.Collections.Extensions
2+
@using AbpCompanyName.AbpProjectName.WebMpa.Views
23
@model AbpCompanyName.AbpProjectName.WebMpa.Models.Layout.TopMenuViewModel
4+
@{
5+
var calculateMenuUrl = new Func<string, string>((url) =>
6+
{
7+
if (string.IsNullOrEmpty(url))
8+
{
9+
return ApplicationPath;
10+
}
11+
12+
if (UrlChecker.IsRooted(url))
13+
{
14+
return url;
15+
}
16+
17+
return ApplicationPath + url;
18+
});
19+
}
320
@foreach (var menuItem in Model.MainMenu.Items)
421
{
522
<li class="@(Model.ActiveMenuItemName == menuItem.Name ? "active" : "")">
623
@if (menuItem.Items.IsNullOrEmpty())
724
{
8-
<a href="@menuItem.Url">
25+
<a href="@calculateMenuUrl(menuItem.Url)">
926
@if (!string.IsNullOrWhiteSpace(menuItem.Icon))
1027
{
1128
<i class="@menuItem.Icon"></i>
@@ -26,7 +43,7 @@
2643
@foreach (var subMenuItem in menuItem.Items)
2744
{
2845
<li>
29-
<a href="@subMenuItem.Url">
46+
<a href="@calculateMenuUrl(subMenuItem.Url)">
3047
@if (!string.IsNullOrWhiteSpace(subMenuItem.Icon))
3148
{
3249
<i class="@subMenuItem.Icon"></i>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace AbpCompanyName.AbpProjectName.WebMpa.Views
4+
{
5+
public static class UrlChecker
6+
{
7+
private static readonly Regex UrlWithProtocolRegex = new Regex("^.{1,10}://.*$");
8+
9+
public static bool IsRooted(string url)
10+
{
11+
if (url.StartsWith("/"))
12+
{
13+
return true;
14+
}
15+
16+
if (UrlWithProtocolRegex.IsMatch(url))
17+
{
18+
return true;
19+
}
20+
21+
return false;
22+
}
23+
}
24+
}

src/AbpCompanyName.AbpProjectName.WebMpa/js/main.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
(function($) {
22

3-
if (!$) {
4-
return;
5-
}
6-
3+
//Notification handler
74
abp.event.on('abp.notifications.received', function (userNotification) {
8-
console.log(userNotification);
5+
abp.notifications.showUiNotifyForUserNotification(userNotification);
96
});
107

8+
//serializeFormToObject plugin for jQuery
119
$.fn.serializeFormToObject = function () {
1210
//serialize to array
1311
var data = $(this).serializeArray();
@@ -24,4 +22,11 @@
2422
return obj;
2523
}
2624

25+
//Configure blockUI
26+
(function ($) {
27+
if ($.blockUI) {
28+
$.blockUI.defaults.baseZ = 2000;
29+
}
30+
})(jQuery);
31+
2732
})(jQuery);

src/AbpCompanyName.AbpProjectName.WebSpaAngular/AbpCompanyName.AbpProjectName.WebSpaAngular.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@
310310
<Content Include="App\Main\views\users\index.js" />
311311
<Content Include="App\Main\views\tenants\createModal.js" />
312312
<Content Include="App\Main\views\tenants\index.js" />
313+
<Content Include="App\Main\_libconfig.js" />
313314
<Content Include="Common\Scripts\helpers.js" />
314315
<Content Include="Content\bootstrap-cosmo.min.css" />
315316
<Content Include="Content\bootstrap-theme.css" />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(function ($) {
2+
if ($.blockUI) {
3+
$.blockUI.defaults.baseZ = 2000;
4+
}
5+
})(jQuery);

src/AbpCompanyName.AbpProjectName.WebSpaAngular/App/Main/views/layout/header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
};
2929

3030
abp.event.on('abp.notifications.received', function (userNotification) {
31-
console.log(userNotification);
31+
abp.notifications.showUiNotifyForUserNotification(userNotification);
3232
});
3333
}
3434
]);

0 commit comments

Comments
 (0)