Blog presentation
This commit is contained in:
@ -16,6 +16,7 @@ using Microsoft.Extensions.Options;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Yavsc.ViewModels.Blog;
|
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
|
// 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)
|
public async Task<IActionResult> Index(string id)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(id)) {
|
if (!string.IsNullOrEmpty(id)) {
|
||||||
return await UserPosts(id);
|
return View("UserPosts", await UserPosts(id));
|
||||||
}
|
}
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
@ -63,13 +64,10 @@ namespace Yavsc.Controllers
|
|||||||
).ToList());
|
).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("~/Blog/{userName}/{pageLen?}/{pageNum?}")]
|
private async Task<IEnumerable<BlogPost>> UserPosts(string userName, int pageLen=10, int pageNum=0)
|
||||||
[AllowAnonymous]
|
|
||||||
public async Task<IActionResult> UserPosts(string userName, int pageLen=10, int pageNum=0)
|
|
||||||
{
|
{
|
||||||
string posterId = (await _context.Users.SingleOrDefaultAsync(u=>u.UserName == userName))?.Id ?? null ;
|
string posterId = (await _context.Users.SingleOrDefaultAsync(u=>u.UserName == userName))?.Id ?? null ;
|
||||||
var result = _context.UserPosts(posterId, User.Identity.Name);
|
return _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 ));
|
|
||||||
}
|
}
|
||||||
// GET: Blog/Details/5
|
// GET: Blog/Details/5
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
@ -27,21 +27,28 @@ namespace Yavsc.Helpers
|
|||||||
|
|
||||||
public static IEnumerable<BlogPost> UserPosts(this ApplicationDbContext dbContext, string posterId, string readerId)
|
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))
|
if (readerId == null)
|
||||||
|
{
|
||||||
|
var userPosts = dbContext.Blogspot.Include(
|
||||||
|
b => b.Author
|
||||||
|
).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();
|
.Select(c => c.Id).ToArray();
|
||||||
var result = (readerId!=null)
|
return dbContext.Blogspot.Include(
|
||||||
?
|
|
||||||
dbContext.Blogspot.Include(
|
|
||||||
b => b.Author
|
b => b.Author
|
||||||
).Include(p => p.ACL).Where(x => x.Author.Id == posterId &&
|
).Include(p => p.ACL).Where(x => x.Author.Id == posterId &&
|
||||||
(x.Visible &&
|
(x.Visible &&
|
||||||
(x.ACL.Count==0 || x.ACL.Any(a=> readerCirclesMemberships.Contains(a.CircleId)))))
|
(x.ACL.Count == 0 || x.ACL.Any(a => readerCirclesMemberships.Contains(a.CircleId)))));
|
||||||
:
|
|
||||||
dbContext.Blogspot.Include(
|
|
||||||
b => b.Author
|
}
|
||||||
).Where(x => x.Author.Id == posterId && x.Visible);
|
|
||||||
// BlogIndexKey
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ namespace Yavsc.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
builder.Entity<Activity>().Property(a=>a.ParentCode).IsRequired(false);
|
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,10 +66,11 @@ $('span.field-validation-valid[data-valmsg-for="Content"]').html(
|
|||||||
</style>
|
</style>
|
||||||
}
|
}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div class="blogpost">
|
||||||
<h1 class="blogtitle" ismarkdown>@Model.Title</h1>
|
<h1 class="blogtitle" ismarkdown>@Model.Title</h1>
|
||||||
<img class="blogphoto" alt="" src="@Model.Photo" >
|
<img class="blogphoto" alt="" src="@Model.Photo" >
|
||||||
<div class="blogpost">
|
@Html.DisplayFor(m=>m.Author)
|
||||||
@Html.DisplayForModel()
|
@Html.DisplayFor(m=>m.Content)
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="comments">
|
<div id="comments">
|
||||||
@ -96,7 +97,6 @@ $('span.field-validation-valid[data-valmsg-for="Content"]').html(
|
|||||||
<p><i>Vous devez être identifié pour commenter.</i> </p>
|
<p><i>Vous devez être identifié pour commenter.</i> </p>
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
|
||||||
@if ((await AuthorizationService.AuthorizeAsync(User, Model, new EditPermission())).Succeeded) {
|
@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="Edit" asp-route-id="@Model.Id" class="btn btn-link">Edit</a>
|
||||||
}
|
}
|
||||||
|
@ -155,9 +155,9 @@
|
|||||||
@(((double)Model.DiskUsage/Model.DiskQuota).ToString("%#0")) :
|
@(((double)Model.DiskUsage/Model.DiskQuota).ToString("%#0")) :
|
||||||
</text>
|
</text>
|
||||||
}
|
}
|
||||||
<text>
|
<code>
|
||||||
@(Model.DiskUsage.ToString("0,#")) / @(Model.DiskQuota.ToString("0,#"))
|
@(Model.DiskUsage.ToString("0,#")) / @(Model.DiskQuota.ToString("0,#"))
|
||||||
</text>
|
</code>
|
||||||
</dd>
|
</dd>
|
||||||
<dt>Identifiant utilisateur</dt>
|
<dt>Identifiant utilisateur</dt>
|
||||||
<dd>
|
<dd>
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
@model IEnumerable<IGrouping<string,BlogPost>>
|
@model IEnumerable<IGrouping<string,BlogPost>>
|
||||||
|
|
||||||
@if (User.IsSignedIn()) {
|
@if (User.IsSignedIn()) {
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" id="_cbv" checked/>Invisibles, posts privés</label>
|
<input type="checkbox" id="_cbv" checked/>Invisibles, posts privés</label>
|
||||||
<script>
|
<script type="text/javascript">
|
||||||
$("#_cbv").change(function() {
|
|
||||||
|
$('#_cbv').change(function()
|
||||||
|
{
|
||||||
if (this.checked) {
|
if (this.checked) {
|
||||||
$("tr.hiddenpost").removeClass("hidden");
|
$('tr.hiddenpost').removeClass("hidden");
|
||||||
} else {
|
} else {
|
||||||
$("tr.hiddenpost").addClass("hidden");
|
$('tr.hiddenpost').addClass("hidden");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@ -34,7 +35,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<asciidoc summary="256">@item.Content</asciidoc>
|
<asciidoc summary="256">@item.Content</asciidoc>
|
||||||
@if (trunked) { <a asp-action="Details" asp-route-id="@item.Id" class="bloglink">...</a> }
|
@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;">
|
<span style="font-size:xx-small;">
|
||||||
posté le @item.DateCreated.ToString("dddd d MMM yyyy à H:mm")
|
posté le @item.DateCreated.ToString("dddd d MMM yyyy à H:mm")
|
||||||
@if ((item.DateModified - item.DateCreated).Minutes > 0){
|
@if ((item.DateModified - item.DateCreated).Minutes > 0){
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
@model ApplicationUser
|
@model ApplicationUser
|
||||||
@{
|
@{
|
||||||
var avuri = "/Avatars/"+Model.UserName+".s.png";
|
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">
|
<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">
|
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>
|
</a>
|
||||||
} else {
|
} else {
|
||||||
Html.LabelFor(m=>m.UserName);
|
Html.DisplayFor(m=>m.UserName);
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user