Blog presentation
This commit is contained in:
@ -16,6 +16,7 @@ using Microsoft.Extensions.Options;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Diagnostics;
|
||||
using Yavsc.ViewModels.Blog;
|
||||
using System.Collections;
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
@ -45,7 +46,7 @@ namespace Yavsc.Controllers
|
||||
public async Task<IActionResult> Index(string id)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(id)) {
|
||||
return await UserPosts(id);
|
||||
return View("UserPosts", await UserPosts(id));
|
||||
}
|
||||
return View();
|
||||
}
|
||||
@ -63,13 +64,10 @@ namespace Yavsc.Controllers
|
||||
).ToList());
|
||||
}
|
||||
|
||||
[Route("~/Blog/{userName}/{pageLen?}/{pageNum?}")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> UserPosts(string userName, int pageLen=10, int pageNum=0)
|
||||
private async Task<IEnumerable<BlogPost>> UserPosts(string userName, int pageLen=10, int pageNum=0)
|
||||
{
|
||||
string posterId = (await _context.Users.SingleOrDefaultAsync(u=>u.UserName == userName))?.Id ?? null ;
|
||||
var result = _context.UserPosts(posterId, User.Identity.Name);
|
||||
return View("Index", result.ToArray().Skip(pageLen*pageNum).Take(pageLen).OrderByDescending(p => p.DateCreated).ToList().GroupBy(p=> p.Title ));
|
||||
return _context.UserPosts(posterId, User.Identity.Name);
|
||||
}
|
||||
// GET: Blog/Details/5
|
||||
[AllowAnonymous]
|
||||
|
@ -14,7 +14,7 @@ namespace Yavsc.Helpers
|
||||
{
|
||||
return user.FindFirstValue("sub");
|
||||
}
|
||||
|
||||
|
||||
public static string GetUserName(this ClaimsPrincipal user)
|
||||
{
|
||||
return user.FindFirstValue(ClaimTypes.Name);
|
||||
@ -27,21 +27,28 @@ namespace Yavsc.Helpers
|
||||
|
||||
public static IEnumerable<BlogPost> UserPosts(this ApplicationDbContext dbContext, string posterId, string readerId)
|
||||
{
|
||||
long[] readerCirclesMemberships = dbContext.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == readerId))
|
||||
.Select(c=>c.Id).ToArray();
|
||||
var result = (readerId!=null)
|
||||
?
|
||||
dbContext.Blogspot.Include(
|
||||
b => b.Author
|
||||
).Include(p=>p.ACL).Where(x => x.Author.Id == posterId &&
|
||||
(x.Visible &&
|
||||
(x.ACL.Count==0 || x.ACL.Any(a=> readerCirclesMemberships.Contains(a.CircleId)))))
|
||||
:
|
||||
dbContext.Blogspot.Include(
|
||||
if (readerId == null)
|
||||
{
|
||||
var userPosts = dbContext.Blogspot.Include(
|
||||
b => b.Author
|
||||
).Where(x => x.Author.Id == posterId && x.Visible);
|
||||
// BlogIndexKey
|
||||
return result;
|
||||
).Where(x => ((x.AuthorId == posterId) && (x.Visible))).ToArray();
|
||||
return userPosts;
|
||||
}
|
||||
else
|
||||
{
|
||||
long[] readerCirclesMemberships =
|
||||
dbContext.Circle.Include(c => c.Members)
|
||||
.Where(c => c.Members.Any(m => m.MemberId == readerId))
|
||||
.Select(c => c.Id).ToArray();
|
||||
return dbContext.Blogspot.Include(
|
||||
b => b.Author
|
||||
).Include(p => p.ACL).Where(x => x.Author.Id == posterId &&
|
||||
(x.Visible &&
|
||||
(x.ACL.Count == 0 || x.ACL.Any(a => readerCirclesMemberships.Contains(a.CircleId)))));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ namespace Yavsc.Models
|
||||
}
|
||||
|
||||
builder.Entity<Activity>().Property(a=>a.ParentCode).IsRequired(false);
|
||||
builder.Entity<BlogPost>().HasOne(p => p.Author).WithMany(a => a.Posts);
|
||||
//builder.Entity<BlogPost>().HasOne(p => p.Author).WithMany(a => a.Posts);
|
||||
|
||||
}
|
||||
|
||||
|
@ -66,19 +66,20 @@ $('span.field-validation-valid[data-valmsg-for="Content"]').html(
|
||||
</style>
|
||||
}
|
||||
<div class="container">
|
||||
<h1 class="blogtitle" ismarkdown>@Model.Title</h1>
|
||||
<img class="blogphoto" alt="" src="@Model.Photo" >
|
||||
<div class="blogpost">
|
||||
@Html.DisplayForModel()
|
||||
</div>
|
||||
<div class="blogpost">
|
||||
<h1 class="blogtitle" ismarkdown>@Model.Title</h1>
|
||||
<img class="blogphoto" alt="" src="@Model.Photo" >
|
||||
@Html.DisplayFor(m=>m.Author)
|
||||
@Html.DisplayFor(m=>m.Content)
|
||||
</div>
|
||||
|
||||
<div id="comments">
|
||||
@if (Model.Comments!=null) {
|
||||
foreach (var comment in Model.Comments.Where(c=>c.ParentId==null)) {
|
||||
@Html.DisplayFor(model=>comment,"Comment","Comment")
|
||||
<div id="comments">
|
||||
@if (Model.Comments!=null) {
|
||||
foreach (var comment in Model.Comments.Where(c=>c.ParentId==null)) {
|
||||
@Html.DisplayFor(model=>comment,"Comment","Comment")
|
||||
}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@if (User.GetUserId()!=null) {
|
||||
<div class="form-horizontal">
|
||||
<div class="input-group" >
|
||||
@ -96,9 +97,8 @@ $('span.field-validation-valid[data-valmsg-for="Content"]').html(
|
||||
<p><i>Vous devez être identifié pour commenter.</i> </p>
|
||||
}
|
||||
|
||||
</div>
|
||||
@if ((await AuthorizationService.AuthorizeAsync(User, Model, new EditPermission())).Succeeded) {
|
||||
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-link">Edit</a>
|
||||
}
|
||||
<a asp-action="Index" class="btn btn-link">Back to List</a>
|
||||
@if ((await AuthorizationService.AuthorizeAsync(User, Model, new EditPermission())).Succeeded) {
|
||||
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-link">Edit</a>
|
||||
}
|
||||
<a asp-action="Index" class="btn btn-link">Back to List</a>
|
||||
</div>
|
||||
|
@ -155,9 +155,9 @@
|
||||
@(((double)Model.DiskUsage/Model.DiskQuota).ToString("%#0")) :
|
||||
</text>
|
||||
}
|
||||
<text>
|
||||
<code>
|
||||
@(Model.DiskUsage.ToString("0,#")) / @(Model.DiskQuota.ToString("0,#"))
|
||||
</text>
|
||||
</code>
|
||||
</dd>
|
||||
<dt>Identifiant utilisateur</dt>
|
||||
<dd>
|
||||
|
@ -1,18 +1,19 @@
|
||||
@model IEnumerable<IGrouping<string,BlogPost>>
|
||||
|
||||
@if (User.IsSignedIn()) {
|
||||
|
||||
<label>
|
||||
<input type="checkbox" id="_cbv" checked/>Invisibles, posts privés</label>
|
||||
<script>
|
||||
$("#_cbv").change(function() {
|
||||
<script type="text/javascript">
|
||||
|
||||
$('#_cbv').change(function()
|
||||
{
|
||||
if (this.checked) {
|
||||
$("tr.hiddenpost").removeClass("hidden");
|
||||
$('tr.hiddenpost').removeClass("hidden");
|
||||
} else {
|
||||
$("tr.hiddenpost").addClass("hidden");
|
||||
$('tr.hiddenpost').addClass("hidden");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
}
|
||||
|
||||
<table class="table">
|
||||
@ -34,7 +35,7 @@
|
||||
<td>
|
||||
<asciidoc summary="256">@item.Content</asciidoc>
|
||||
@if (trunked) { <a asp-action="Details" asp-route-id="@item.Id" class="bloglink">...</a> }
|
||||
<span style="font-size:x-small;">(@Html.DisplayFor(m => item.Author)</span>,
|
||||
<span style="font-size:x-small;">@Html.DisplayFor(m => item.Author)</span>
|
||||
<span style="font-size:xx-small;">
|
||||
posté le @item.DateCreated.ToString("dddd d MMM yyyy à H:mm")
|
||||
@if ((item.DateModified - item.DateCreated).Minutes > 0){
|
||||
|
@ -1,14 +1,14 @@
|
||||
@model ApplicationUser
|
||||
@{
|
||||
var avuri = "/Avatars/"+Model.UserName+".s.png";
|
||||
var userPosted = Model.Posts!=null && Model.Posts.Count()>1;
|
||||
var userPosted = Model.Posts!=null && Model.Posts.Count()>=1;
|
||||
}
|
||||
<div class="userinfo">
|
||||
@if (userPosted) { <a asp-controller="Blogspot" asp-action="UserPosts"
|
||||
@if (userPosted) { <a asp-controller="Blogspot" asp-action="Index"
|
||||
asp-route-id="@Model.UserName" class="btn btn-primary">
|
||||
<img src="@avuri" asp-append-version="true" class="smalltofhol" alt="" title="@Model.UserName"/>
|
||||
<img src="@avuri" asp-append-version="true" class="smalltofhol" alt="@Model.UserName" title="@Model.UserName"/>
|
||||
</a>
|
||||
}else {
|
||||
Html.LabelFor(m=>m.UserName);
|
||||
} else {
|
||||
Html.DisplayFor(m=>m.UserName);
|
||||
}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user