Blog presentation

This commit is contained in:
Paul Schneider
2024-12-03 01:44:58 +00:00
parent a4932d08f1
commit f91f000405
7 changed files with 58 additions and 52 deletions

View File

@ -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]

View File

@ -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)
.Select(c=>c.Id).ToArray(); {
var result = (readerId!=null) var userPosts = dbContext.Blogspot.Include(
?
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(
b => b.Author b => b.Author
).Where(x => x.Author.Id == posterId && x.Visible); ).Where(x => ((x.AuthorId == posterId) && (x.Visible))).ToArray();
// BlogIndexKey return userPosts;
return result; }
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)))));
}
} }
} }
} }

View File

@ -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);
} }

View File

@ -66,19 +66,20 @@ $('span.field-validation-valid[data-valmsg-for="Content"]').html(
</style> </style>
} }
<div class="container"> <div class="container">
<h1 class="blogtitle" ismarkdown>@Model.Title</h1> <div class="blogpost">
<img class="blogphoto" alt="" src="@Model.Photo" > <h1 class="blogtitle" ismarkdown>@Model.Title</h1>
<div class="blogpost"> <img class="blogphoto" alt="" src="@Model.Photo" >
@Html.DisplayForModel() @Html.DisplayFor(m=>m.Author)
</div> @Html.DisplayFor(m=>m.Content)
</div>
<div id="comments"> <div id="comments">
@if (Model.Comments!=null) { @if (Model.Comments!=null) {
foreach (var comment in Model.Comments.Where(c=>c.ParentId==null)) { foreach (var comment in Model.Comments.Where(c=>c.ParentId==null)) {
@Html.DisplayFor(model=>comment,"Comment","Comment") @Html.DisplayFor(model=>comment,"Comment","Comment")
}
} }
} </div>
</div>
@if (User.GetUserId()!=null) { @if (User.GetUserId()!=null) {
<div class="form-horizontal"> <div class="form-horizontal">
<div class="input-group" > <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> <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> }
} <a asp-action="Index" class="btn btn-link">Back to List</a>
<a asp-action="Index" class="btn btn-link">Back to List</a>
</div> </div>

View File

@ -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>

View File

@ -1,18 +1,19 @@
@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>
} }
<table class="table"> <table class="table">
@ -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){ 

View File

@ -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>