Browse Source

blog route path optional

resolves https://github.com/abpframework/abp/issues/1312
pull/1331/head
Yunus Emre Kalkan 7 years ago
parent
commit
7e07f11453
  1. 5
      modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs
  2. 31
      modules/blogging/src/Volo.Blogging.Web/BloggingUrlOptions.cs
  3. 16
      modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs
  4. 3
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs
  5. 9
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js

5
modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs

@ -60,6 +60,11 @@ namespace Volo.BloggingTestApp
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.BuildConfiguration(); var configuration = context.Services.BuildConfiguration();
Configure<BloggingUrlOptions>(options =>
{
options.RoutePrefix = null;
});
Configure<DbConnectionOptions>(options => Configure<DbConnectionOptions>(options =>
{ {
#if MONGODB #if MONGODB

31
modules/blogging/src/Volo.Blogging.Web/BloggingUrlOptions.cs

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Volo.Blogging
{
public class BloggingUrlOptions
{
private string _routePrefix = "blog";
/// <summary>
/// Default value: "blog";
/// </summary>
public string RoutePrefix
{
get => GetFormattedRoutePrefix();
set => _routePrefix = value;
}
private string GetFormattedRoutePrefix()
{
if (string.IsNullOrWhiteSpace(_routePrefix))
{
return "/";
}
return _routePrefix.EnsureEndsWith('/').EnsureStartsWith('/');
}
}
}

16
modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs

@ -1,6 +1,7 @@
using Localization.Resources.AbpUi; using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
@ -63,11 +64,16 @@ namespace Volo.Blogging
Configure<RazorPagesOptions>(options => Configure<RazorPagesOptions>(options =>
{ {
//TODO: Make configurable! var urlOptions = context.Services
options.Conventions.AddPageRoute("/Blog/Posts/Index", "blog/{blogShortName}"); .GetRequiredServiceLazy<IOptions<BloggingUrlOptions>>()
options.Conventions.AddPageRoute("/Blog/Posts/Detail", "blog/{blogShortName}/{postUrl}"); .Value.Value;
options.Conventions.AddPageRoute("/Blog/Posts/Edit", "blog/{blogShortName}/posts/{postId}/edit");
options.Conventions.AddPageRoute("/Blog/Posts/New", "blog/{blogShortName}/posts/new"); var routePrefix = urlOptions.RoutePrefix;
options.Conventions.AddPageRoute("/Blog/Posts/Index", routePrefix + "{blogShortName}");
options.Conventions.AddPageRoute("/Blog/Posts/Detail", routePrefix + "{blogShortName}/{postUrl}");
options.Conventions.AddPageRoute("/Blog/Posts/Edit", routePrefix + "{blogShortName}/posts/{postId}/edit");
options.Conventions.AddPageRoute("/Blog/Posts/New", routePrefix + "{blogShortName}/posts/new");
}); });
} }
} }

3
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs

@ -62,7 +62,8 @@ namespace Volo.Blogging.Pages.Blog.Posts
var editedPost = await _postAppService.UpdateAsync(Post.Id, post); var editedPost = await _postAppService.UpdateAsync(Post.Id, post);
var blog = await _blogAppService.GetAsync(editedPost.BlogId); var blog = await _blogAppService.GetAsync(editedPost.BlogId);
return Redirect(Url.Content($"~/blog/{WebUtility.UrlEncode(blog.ShortName)}/{WebUtility.UrlEncode(editedPost.Url)}")); // return Redirect(Url.Content($"~/blog/{WebUtility.UrlEncode(blog.ShortName)}/{WebUtility.UrlEncode(editedPost.Url)}"));
return RedirectToPage("/Blog/Posts/Detail", new { blogShortName = blog.ShortName, postUrl = editedPost.Url });
} }
} }

9
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js

@ -88,7 +88,7 @@
if (deleteCommentId != '' && deleteCommentId !== undefined) { if (deleteCommentId != '' && deleteCommentId !== undefined) {
abp.message.confirm( abp.message.confirm(
l('PostDeletionWarningMessage'), // TODO: localize l('PostDeletionWarningMessage'),
l('AreYouSure'), l('AreYouSure'),
function (isConfirmed) { function (isConfirmed) {
if (isConfirmed) { if (isConfirmed) {
@ -97,7 +97,9 @@
url: "/Blog/Posts/Delete", url: "/Blog/Posts/Delete",
data: { id: deleteCommentId }, data: { id: deleteCommentId },
success: function () { success: function () {
window.location.replace('/Blog/' + blogShortName); var url = window.location.pathname;
var postNameBeginning = url.lastIndexOf('/');
window.location.replace(url.substring(0, postNameBeginning));
} }
}); });
} }
@ -105,9 +107,6 @@
); );
} }
}); });
$('#DeletePostRouteLink').click(function (event) {
console.log("goooo");
});
$('.updateLink').click(function (event) { $('.updateLink').click(function (event) {
event.preventDefault(); event.preventDefault();

Loading…
Cancel
Save