blog index
This commit is contained in:
@ -11,6 +11,7 @@ using Microsoft.Extensions.OptionsModel;
|
|||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.ViewModels.Auth;
|
using Yavsc.ViewModels.Auth;
|
||||||
using Microsoft.AspNet.Mvc.Rendering;
|
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
|
// 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();
|
.Select(c=>c.Id).ToArray();
|
||||||
IQueryable<Blog> posts ;
|
IQueryable<Blog> posts ;
|
||||||
if (usercircles != null) {
|
if (usercircles != null) {
|
||||||
posts = _context.Blogspot.Include(
|
posts = _context.Blogspot.Include(b => b.Author)
|
||||||
b => b.Author
|
.Include(p=>p.ACL)
|
||||||
).Include(p=>p.ACL).Where(p=> p.AuthorId == uid || p.Visible && (p.ACL.Count == 0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId))));
|
.Where(p=> p.AuthorId == uid || p.Visible &&
|
||||||
/* posts = _context.Blogspot.Include(
|
(p.ACL.Count == 0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId))))
|
||||||
b => b.Author
|
;
|
||||||
).Include(p=>p.ACL).Where(p=>p.Visible || p.ACL.Any(a => usercircles.Contains(a.Allowed)
|
|
||||||
)); */
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
posts = _context.Blogspot.Include(
|
posts = _context.Blogspot.Include(b => b.Author)
|
||||||
b => b.Author
|
.Include(p=>p.ACL).Where(p=>p.AuthorId == uid || p.Visible && p.ACL.Count == 0);
|
||||||
).Include(p=>p.ACL).Where(p=>p.AuthorId == uid || p.Visible && p.ACL.Count == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return View(posts
|
return View(posts.OrderByDescending( p=> p.DateModified)
|
||||||
.OrderByDescending(p => p.DateCreated)
|
.GroupBy(p=> new BlogIndexKey { Title = p.Title, AuthorId = p.AuthorId } ).Skip(skip).Take(maxLen));
|
||||||
.Skip(skip).Take(maxLen).GroupBy(p=>p.Title));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("/Title/{id?}")]
|
[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";
|
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>
|
<h2>@ViewData["Title"]</h2>
|
||||||
<p class="text-success">@ViewData["StatusMessage"]</p>
|
<p class="text-success">@ViewData["StatusMessage"]</p>
|
||||||
@if (User.IsSignedIn()) {
|
@if (User.IsSignedIn()) {
|
||||||
@ -23,49 +52,68 @@
|
|||||||
}
|
}
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="3">
|
<th>
|
||||||
@SR["Title"]
|
@SR["Title"]
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
apperçu
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@foreach (var group in Model) {
|
@foreach (var group in Model) {
|
||||||
var title = group.Key;
|
var title = group.Key.Title;
|
||||||
@foreach (var item in group) {
|
string secondclass="";
|
||||||
var trclass = (item.Visible)?"visiblepost":"hiddenpost";
|
var first = group.First();
|
||||||
<tr class="@trclass">
|
string trclass = (first.Visible) ? "visiblepost" : "hiddenpost";
|
||||||
<td><a asp-action="Details" asp-route-id="@item.Id" class="bloglink">
|
<tr class="@trclass">
|
||||||
<img src="@item.Photo" class="smalltofhol"></a>
|
<td><a asp-action="Details" asp-route-id="@first.Id" class="bloglink">
|
||||||
<a asp-action="Title" asp-route-id="@item.Title">
|
<img src="@first.Photo" class="smalltofhol"></a>
|
||||||
<markdown>@item.Title</markdown></a>
|
<a asp-action="Title" asp-route-id="@title">
|
||||||
|
<markdown>@first.Title</markdown></a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<markdown>@((item.Content?.Length > 120) ? item.Content.Substring(0, 120) + " ..." : item.Content)</markdown>
|
<markdown>@((first.Content?.Length > 120) ? first.Content.Substring(0, 120) + " ..." : first.Content)</markdown>
|
||||||
<span style="font-size:x-small;">(@item.Author.UserName </span>,
|
<span style="font-size:x-small;">(@first.Author.UserName </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 @first.DateCreated.ToString("dddd d MMM yyyy à H:mm")
|
||||||
@if ((item.DateModified - item.DateCreated).Minutes > 0){
|
@if ((first.DateModified - first.DateCreated).Minutes > 0){
|
||||||
@:- Modifié le @item.DateModified.ToString("dddd d MMM yyyy à H:mm")
|
@:- Modifié le @first.DateModified.ToString("dddd d MMM yyyy à H:mm")
|
||||||
})
|
})
|
||||||
</span>
|
</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>
|
||||||
<td>
|
<td>
|
||||||
<ul class="actiongroup">
|
<ul class="actiongroup">
|
||||||
@if (await AuthorizationService.AuthorizeAsync(User, item, new ViewRequirement())) {
|
@if (await AuthorizationService.AuthorizeAsync(User, first, new ViewRequirement())) {
|
||||||
<li>
|
<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>
|
</li>
|
||||||
}
|
}
|
||||||
@if (await AuthorizationService.AuthorizeAsync(User, item, new EditRequirement())) {
|
@if (await AuthorizationService.AuthorizeAsync(User, first, new EditRequirement())) {
|
||||||
<li><a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-default">@SR["Edit"]</a>
|
<li><a asp-action="Edit" asp-route-id="@first.Id" class="btn btn-default">@SR["Edit"]</a>
|
||||||
</li>
|
</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>
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,10 +30,12 @@
|
|||||||
@using Yavsc.ViewModels.Administration;
|
@using Yavsc.ViewModels.Administration;
|
||||||
@using Yavsc.ViewModels.Relationship;
|
@using Yavsc.ViewModels.Relationship;
|
||||||
@using Yavsc.ViewModels.Workflow;
|
@using Yavsc.ViewModels.Workflow;
|
||||||
|
@using Yavsc.ViewModels.Blogspot;
|
||||||
|
|
||||||
@inject IViewLocalizer LocString
|
@inject IViewLocalizer LocString
|
||||||
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
|
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
|
||||||
@addTagHelper "*, Yavsc"
|
@addTagHelper "*, Yavsc"
|
||||||
|
|
||||||
@inject IStringLocalizer<Yavsc.Resources.YavscLocalisation> SR
|
@inject IStringLocalizer<Yavsc.Resources.YavscLocalisation> SR
|
||||||
@inject IAuthorizationService AuthorizationService
|
@inject IAuthorizationService AuthorizationService
|
||||||
@inject IOptions<GoogleAuthSettings> GoogleSettings
|
@inject IOptions<GoogleAuthSettings> GoogleSettings
|
||||||
|
Reference in New Issue
Block a user