blog index
This commit is contained in:
@ -11,6 +11,7 @@ using Microsoft.Extensions.OptionsModel;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Yavsc.ViewModels.Blogspot;
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
@ -47,23 +48,19 @@ namespace Yavsc.Controllers
|
||||
.Select(c=>c.Id).ToArray();
|
||||
IQueryable<Blog> posts ;
|
||||
if (usercircles != null) {
|
||||
posts = _context.Blogspot.Include(
|
||||
b => b.Author
|
||||
).Include(p=>p.ACL).Where(p=> p.AuthorId == uid || p.Visible && (p.ACL.Count == 0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId))));
|
||||
/* posts = _context.Blogspot.Include(
|
||||
b => b.Author
|
||||
).Include(p=>p.ACL).Where(p=>p.Visible || p.ACL.Any(a => usercircles.Contains(a.Allowed)
|
||||
)); */
|
||||
posts = _context.Blogspot.Include(b => b.Author)
|
||||
.Include(p=>p.ACL)
|
||||
.Where(p=> p.AuthorId == uid || p.Visible &&
|
||||
(p.ACL.Count == 0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId))))
|
||||
;
|
||||
}
|
||||
else {
|
||||
posts = _context.Blogspot.Include(
|
||||
b => b.Author
|
||||
).Include(p=>p.ACL).Where(p=>p.AuthorId == uid || p.Visible && p.ACL.Count == 0);
|
||||
posts = _context.Blogspot.Include(b => b.Author)
|
||||
.Include(p=>p.ACL).Where(p=>p.AuthorId == uid || p.Visible && p.ACL.Count == 0);
|
||||
}
|
||||
|
||||
return View(posts
|
||||
.OrderByDescending(p => p.DateCreated)
|
||||
.Skip(skip).Take(maxLen).GroupBy(p=>p.Title));
|
||||
return View(posts.OrderByDescending( p=> p.DateModified)
|
||||
.GroupBy(p=> new BlogIndexKey { Title = p.Title, AuthorId = p.AuthorId } ).Skip(skip).Take(maxLen));
|
||||
}
|
||||
|
||||
[Route("/Title/{id?}")]
|
||||
|
31
Yavsc/ViewModels/Blogspot/BlogIndexKey.cs
Normal file
31
Yavsc/ViewModels/Blogspot/BlogIndexKey.cs
Normal file
@ -0,0 +1,31 @@
|
||||
namespace Yavsc.ViewModels.Blogspot
|
||||
{
|
||||
public class BlogIndexKey
|
||||
{
|
||||
public string AuthorId { get; set; }
|
||||
public string Title { get; set; }
|
||||
// override object.Equals
|
||||
public override bool Equals (object obj)
|
||||
{
|
||||
//
|
||||
// See the full list of guidelines at
|
||||
// http://go.microsoft.com/fwlink/?LinkID=85237
|
||||
// and also the guidance for operator== at
|
||||
// http://go.microsoft.com/fwlink/?LinkId=85238
|
||||
//
|
||||
|
||||
if (obj == null || GetType() != obj.GetType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var blogindexkey = (BlogIndexKey)obj;
|
||||
return Title == blogindexkey.Title && AuthorId == blogindexkey.AuthorId;
|
||||
}
|
||||
|
||||
// override object.GetHashCode
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Title.GetHashCode() * AuthorId.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,37 @@
|
||||
@model IEnumerable<IGrouping<string,Blog>>
|
||||
@model IEnumerable<IGrouping<BlogIndexKey,Blog>>
|
||||
@{
|
||||
ViewData["Title"] = "Blogs, l'index";
|
||||
// Regroup!?!
|
||||
@foreach (var group in Model) {
|
||||
}
|
||||
}
|
||||
@section header {
|
||||
<style>
|
||||
.collapsed {
|
||||
height: 1em;
|
||||
}
|
||||
.sametitle {
|
||||
overflow: hidden;
|
||||
transition: height 1s;
|
||||
}
|
||||
td {
|
||||
transition: height 1s;
|
||||
}
|
||||
</style>
|
||||
}
|
||||
@section scripts {
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$(".sametitle").addClass("collapsed")
|
||||
.on("mouseover",function(){
|
||||
$(this).removeClass("collapsed")
|
||||
}).on("mouseout",function(){
|
||||
$(this).addClass("collapsed")
|
||||
});
|
||||
}
|
||||
)
|
||||
</script>
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"]</h2>
|
||||
<p class="text-success">@ViewData["StatusMessage"]</p>
|
||||
@if (User.IsSignedIn()) {
|
||||
@ -23,49 +52,68 @@
|
||||
}
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th colspan="3">
|
||||
<th>
|
||||
@SR["Title"]
|
||||
</th>
|
||||
<th>
|
||||
apperçu
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
|
||||
@foreach (var group in Model) {
|
||||
var title = group.Key;
|
||||
@foreach (var item in group) {
|
||||
var trclass = (item.Visible)?"visiblepost":"hiddenpost";
|
||||
<tr class="@trclass">
|
||||
<td><a asp-action="Details" asp-route-id="@item.Id" class="bloglink">
|
||||
<img src="@item.Photo" class="smalltofhol"></a>
|
||||
<a asp-action="Title" asp-route-id="@item.Title">
|
||||
<markdown>@item.Title</markdown></a>
|
||||
var title = group.Key.Title;
|
||||
string secondclass="";
|
||||
var first = group.First();
|
||||
string trclass = (first.Visible) ? "visiblepost" : "hiddenpost";
|
||||
<tr class="@trclass">
|
||||
<td><a asp-action="Details" asp-route-id="@first.Id" class="bloglink">
|
||||
<img src="@first.Photo" class="smalltofhol"></a>
|
||||
<a asp-action="Title" asp-route-id="@title">
|
||||
<markdown>@first.Title</markdown></a>
|
||||
</td>
|
||||
<td>
|
||||
<markdown>@((item.Content?.Length > 120) ? item.Content.Substring(0, 120) + " ..." : item.Content)</markdown>
|
||||
<span style="font-size:x-small;">(@item.Author.UserName </span>,
|
||||
<markdown>@((first.Content?.Length > 120) ? first.Content.Substring(0, 120) + " ..." : first.Content)</markdown>
|
||||
<span style="font-size:x-small;">(@first.Author.UserName </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){
|
||||
@:- Modifié le @item.DateModified.ToString("dddd d MMM yyyy à H:mm")
|
||||
posté le @first.DateCreated.ToString("dddd d MMM yyyy à H:mm")
|
||||
@if ((first.DateModified - first.DateCreated).Minutes > 0){
|
||||
@:- Modifié le @first.DateModified.ToString("dddd d MMM yyyy à H:mm")
|
||||
})
|
||||
</span>
|
||||
|
||||
@if (group.Count()>1) {
|
||||
<div class="sametitle">
|
||||
Au même titre:
|
||||
<table>
|
||||
|
||||
@foreach (var item in group.Skip(1)) {
|
||||
trclass = ((item.Visible)?"visiblepost":"hiddenpost");
|
||||
|
||||
<tr class="@trclass"><td>le @item.DateModified.ToString("dddd d MMM yyyy à H:mm")</td>
|
||||
<td><markdown>@((item.Content?.Length > 120) ? item.Content.Substring(0, 120) + " ..." : item.Content)</markdown>
|
||||
</td>
|
||||
<td> <a asp-action="Details" asp-route-id="@item.Id" class="btn btn-lg">Details</a>
|
||||
</td></tr>
|
||||
} </table></div>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<ul class="actiongroup">
|
||||
@if (await AuthorizationService.AuthorizeAsync(User, item, new ViewRequirement())) {
|
||||
@if (await AuthorizationService.AuthorizeAsync(User, first, new ViewRequirement())) {
|
||||
<li>
|
||||
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-lg">Details</a>
|
||||
<a asp-action="Details" asp-route-id="@first.Id" class="btn btn-lg">Details</a>
|
||||
</li>
|
||||
}
|
||||
@if (await AuthorizationService.AuthorizeAsync(User, item, new EditRequirement())) {
|
||||
<li><a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-default">@SR["Edit"]</a>
|
||||
@if (await AuthorizationService.AuthorizeAsync(User, first, new EditRequirement())) {
|
||||
<li><a asp-action="Edit" asp-route-id="@first.Id" class="btn btn-default">@SR["Edit"]</a>
|
||||
</li>
|
||||
<li><a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">@SR["Delete"]</a>
|
||||
<li><a asp-action="Delete" asp-route-id="@first.Id" class="btn btn-danger">@SR["Delete"]</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</table>
|
||||
|
||||
|
||||
|
@ -30,10 +30,12 @@
|
||||
@using Yavsc.ViewModels.Administration;
|
||||
@using Yavsc.ViewModels.Relationship;
|
||||
@using Yavsc.ViewModels.Workflow;
|
||||
@using Yavsc.ViewModels.Blogspot;
|
||||
|
||||
@inject IViewLocalizer LocString
|
||||
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
|
||||
@addTagHelper "*, Yavsc"
|
||||
|
||||
@inject IStringLocalizer<Yavsc.Resources.YavscLocalisation> SR
|
||||
@inject IAuthorizationService AuthorizationService
|
||||
@inject IOptions<GoogleAuthSettings> GoogleSettings
|
||||
|
Reference in New Issue
Block a user