MEF
This commit is contained in:
@ -113,7 +113,7 @@ public class BlogSpotService
|
|||||||
_context.SaveChanges(user.GetUserId());
|
_context.SaveChanges(user.GetUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<IGrouping<string, IBlogPost>>> IndexByTitle(ClaimsPrincipal user, string id, int skip = 0, int take = 25)
|
public async Task<IEnumerable<IBlogPost>> Index(ClaimsPrincipal user, string id, int skip = 0, int take = 25)
|
||||||
{
|
{
|
||||||
IEnumerable<IBlogPost> posts;
|
IEnumerable<IBlogPost> posts;
|
||||||
|
|
||||||
@ -149,9 +149,8 @@ public class BlogSpotService
|
|||||||
.Select(p => p.BlogPost).ToArray();
|
.Select(p => p.BlogPost).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = posts.OrderByDescending(p => p.DateCreated);
|
var data = posts.OrderByDescending(p => p.DateModified);
|
||||||
var grouped = data.GroupBy(p => p.Title).Skip(skip).Take(take);
|
return data;
|
||||||
return grouped;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Delete(ClaimsPrincipal user, long id)
|
public async Task Delete(ClaimsPrincipal user, long id)
|
||||||
@ -174,7 +173,7 @@ public class BlogSpotService
|
|||||||
return _context.UserPosts(posterId, readerId);
|
return _context.UserPosts(posterId, readerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public object? ByTitle(string title)
|
public object? GetTitle(string title)
|
||||||
{
|
{
|
||||||
return _context.BlogSpot.Include(
|
return _context.BlogSpot.Include(
|
||||||
b => b.Author
|
b => b.Author
|
||||||
@ -190,4 +189,5 @@ public class BlogSpotService
|
|||||||
.Include(b => b.ACL)
|
.Include(b => b.ACL)
|
||||||
.SingleOrDefaultAsync(x => x.Id == value);
|
.SingleOrDefaultAsync(x => x.Id == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ namespace Yavsc.Controllers
|
|||||||
await blogSpotService.UserPosts(id, User.GetUserId(),
|
await blogSpotService.UserPosts(id, User.GetUserId(),
|
||||||
skip, take));
|
skip, take));
|
||||||
}
|
}
|
||||||
IEnumerable<IGrouping<string,IBlogPost>> byTitle = await this.blogSpotService.IndexByTitle(User, id, skip, take);
|
IEnumerable<IBlogPost> index = await this.blogSpotService.Index(User, id, skip, take);
|
||||||
return View(byTitle);
|
return View(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("~/Title/{id?}")]
|
[Route("~/Title/{id?}")]
|
||||||
@ -56,7 +56,7 @@ namespace Yavsc.Controllers
|
|||||||
public IActionResult Title(string id)
|
public IActionResult Title(string id)
|
||||||
{
|
{
|
||||||
ViewData["Title"] = id;
|
ViewData["Title"] = id;
|
||||||
return View("Title", blogSpotService.ByTitle(id));
|
return View("Title", blogSpotService.GetTitle(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IEnumerable<BlogPost>> UserPosts(string userName, int pageLen = 10, int pageNum = 0)
|
private async Task<IEnumerable<BlogPost>> UserPosts(string userName, int pageLen = 10, int pageNum = 0)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using AsciiDocNet;
|
using AsciiDocNet;
|
||||||
|
using Microsoft.AspNetCore.Html;
|
||||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||||
|
|
||||||
namespace Yavsc.Helpers
|
namespace Yavsc.Helpers
|
||||||
@ -8,17 +9,28 @@ namespace Yavsc.Helpers
|
|||||||
{
|
{
|
||||||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
|
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
|
||||||
{
|
{
|
||||||
if (context.AllAttributes.ContainsName("summary"))
|
|
||||||
{
|
|
||||||
var summaryLength = context.AllAttributes["summary"].Value;
|
|
||||||
}
|
|
||||||
await base.ProcessAsync(context, output);
|
await base.ProcessAsync(context, output);
|
||||||
var content = await output.GetChildContentAsync();
|
var content = await output.GetChildContentAsync();
|
||||||
string text = content.GetContent();
|
string text = content.GetContent();
|
||||||
if (string.IsNullOrWhiteSpace(text)) return;
|
if (string.IsNullOrWhiteSpace(text)) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (context.AllAttributes.ContainsName("summary"))
|
||||||
|
{
|
||||||
|
var summaryLength = context.AllAttributes["summary"].Value;
|
||||||
|
if (summaryLength is HtmlString sumLenStr)
|
||||||
|
{
|
||||||
|
if (int.TryParse(sumLenStr.Value, out var sumLen))
|
||||||
|
{
|
||||||
|
if (text.Length > sumLen)
|
||||||
|
{
|
||||||
|
text = text.Substring(0, sumLen) + "(...)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Document document = Document.Parse(text);
|
Document document = Document.Parse(text);
|
||||||
var html = document.ToHtml(2);
|
var html = document.ToHtml(2);
|
||||||
using var stringWriter = new StringWriter();
|
using var stringWriter = new StringWriter();
|
||||||
|
@ -60,10 +60,14 @@ $('#commentValidation').html(
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
}
|
}
|
||||||
<div class="container">
|
|
||||||
<div class="blogpost">
|
<div class="post">
|
||||||
<h1 class="blogtitle" ismarkdown>@Model.Title</h1>
|
<div class="float-left">
|
||||||
<img class="blogphoto" alt="" src="@Model.Photo" >
|
<img alt="" src="@Model.Photo" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h1 ismarkdown>@Model.Title</h1>
|
||||||
|
|
||||||
@Html.DisplayFor(m=>m.Author)
|
@Html.DisplayFor(m=>m.Author)
|
||||||
<asciidoc>@Html.DisplayFor(m=>m.Content)</asciidoc>
|
<asciidoc>@Html.DisplayFor(m=>m.Content)</asciidoc>
|
||||||
|
|
||||||
@ -98,4 +102,4 @@ $('#commentValidation').html(
|
|||||||
<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>
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
@model IEnumerable<IGrouping<string,IBlogPost>>
|
@model IEnumerable<IBlogPost>
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Blogs, l'index";
|
ViewData["Title"] = "Blogs, l'index";
|
||||||
}
|
}
|
||||||
@ -43,59 +43,51 @@
|
|||||||
<a asp-action="Create">Create a new article</a>
|
<a asp-action="Create">Create a new article</a>
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="container">
|
|
||||||
|
|
||||||
<table class="table">
|
<div class="blog">
|
||||||
|
@{
|
||||||
|
int maxTextLen = 75;
|
||||||
|
foreach (var post in Model) {
|
||||||
|
<div class="post">
|
||||||
|
|
||||||
@foreach (var group in Model) {
|
|
||||||
var title = group.Key ?? "@";
|
|
||||||
string secondclass="";
|
|
||||||
var first = group.First();
|
|
||||||
int maxTextLen = 256;
|
|
||||||
|
|
||||||
<tr><td colspan="3">
|
<div class="float-left" >
|
||||||
<a asp-action="Title" asp-route-id="@group.Key" >@title</a></td></tr>
|
<a asp-action="Details" asp-route-id="@post.Id" class="bloglink" style="display: float-left;">
|
||||||
@foreach (var item in group) {
|
<img src="@post.Photo" >
|
||||||
var trunked = item.Content?.Length > maxTextLen;
|
</a>
|
||||||
<tr>
|
</div>
|
||||||
<td><a asp-action="Details" asp-route-id="@item.Id" class="bloglink">
|
<h3>@post.Title</h3>
|
||||||
<img src="@item.Photo" class="blogphoto"></a>
|
<div>
|
||||||
</td>
|
<a asp-action="Details" asp-route-id="@post.Id">
|
||||||
<td>
|
<asciidoc summary="@maxTextLen">@post.Content</asciidoc></a>
|
||||||
<asciidoc summary="@maxTextLen">@item.Content</asciidoc>
|
<span style="font-size:x-small;">@Html.DisplayFor(m => post.Author)</span>
|
||||||
@if (trunked) { <a asp-action="Details" asp-route-id="@item.Id" class="bloglink">...</a> }
|
<span style="font-size:xx-small;">
|
||||||
<span style="font-size:x-small;">@Html.DisplayFor(m => item.Author)</span>
|
posté le @post.DateCreated.ToString("dddd d MMM yyyy à H:mm")
|
||||||
<span style="font-size:xx-small;">
|
@if ((post.DateModified - post.DateCreated).Minutes > 0){
|
||||||
posté le @item.DateCreated.ToString("dddd d MMM yyyy à H:mm")
|
@:- Modifié le @post.DateModified.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")
|
</span>
|
||||||
})
|
</div>
|
||||||
</span>
|
<div class="actiongroup">
|
||||||
</td>
|
@if ((await AuthorizationService.AuthorizeAsync(User, post, new ReadPermission())).Succeeded)
|
||||||
<td>
|
{
|
||||||
<ul class="actiongroup">
|
<a asp-action="Details" asp-route-id="@post.Id" class="btn btn-light">Details</a>
|
||||||
@if ((await AuthorizationService.AuthorizeAsync(User, item, new ReadPermission())).Succeeded) {
|
}
|
||||||
<li>
|
else
|
||||||
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-lg">Details</a>
|
{
|
||||||
</li>
|
<a asp-action="Details" asp-route-id="@post.Id" class="btn btn-light">Details</a>
|
||||||
}
|
}
|
||||||
else {
|
@if ((await AuthorizationService.AuthorizeAsync(User, post, new EditPermission())).Succeeded)
|
||||||
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-lg">Details DEBUG</a>
|
{
|
||||||
}
|
<a asp-action="Edit" asp-route-id="@post.Id" class="btn btn-default">Edit</a>
|
||||||
@if ((await AuthorizationService.AuthorizeAsync(User, item, new EditPermission())).Succeeded) {
|
|
||||||
<li><a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-default">Edit</a>
|
<a asp-action="Delete" asp-route-id="@post.Id" class="btn btn-danger">Delete</a>
|
||||||
</li>
|
|
||||||
<li><a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Delete</a>
|
}
|
||||||
</li>
|
</div>
|
||||||
}
|
</div>
|
||||||
</ul>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</table>
|
</div>
|
||||||
|
|
||||||
@if(Model.Count()==0){<p>Néant</p>}
|
@if(Model.Count()==0){<p>Néant</p>}
|
||||||
|
|
||||||
</div>
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<ul class="actiongroup">
|
<ul class="actiongroup">
|
||||||
@if ((await AuthorizationService.AuthorizeAsync(User, item, new ReadPermission())).Succeeded) {
|
@if ((await AuthorizationService.AuthorizeAsync(User, item, new ReadPermission())).Succeeded) {
|
||||||
<li>
|
<li>
|
||||||
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-lg">Details</a>
|
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-light">Details</a>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
@if ((await AuthorizationService.AuthorizeAsync(User, item, new EditPermission())).Succeeded) {
|
@if ((await AuthorizationService.AuthorizeAsync(User, item, new EditPermission())).Succeeded) {
|
||||||
|
@ -20,9 +20,9 @@
|
|||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
<input type="submit" class="btn btn-lg btn-success" name="submit.Grant" value="Grant" />
|
<input type="submit" class="btn btn-light btn-success" name="submit.Grant" value="Grant" />
|
||||||
<input type="submit" class="btn btn-lg btn-danger" name="submit.Deny" value="Deny" />
|
<input type="submit" class="btn btn-light btn-danger" name="submit.Deny" value="Deny" />
|
||||||
<input type="submit" class="btn btn-lg btn-success" name="submit.Login" value="Sign in as different user" />
|
<input type="submit" class="btn btn-light btn-success" name="submit.Login" value="Sign in as different user" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
@ -14,6 +14,6 @@
|
|||||||
<input type="hidden" name="@parameter.Key" value="@parameter.Value" />
|
<input type="hidden" name="@parameter.Key" value="@parameter.Value" />
|
||||||
}
|
}
|
||||||
|
|
||||||
<input class="btn btn-lg btn-success" name="Authorize" type="submit" value="Yeah, sure" />
|
<input class="btn btn-light btn-success" name="Authorize" type="submit" value="Yeah, sure" />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-md-offset-2 col-md-10">
|
<div class="col-md-offset-2 col-md-10">
|
||||||
<button type="submit" class="btn btn-lg btn-success" name="submit.Signin">Login</button>
|
<button type="submit" class="btn btn-light btn-success" name="submit.Signin">Login</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p>
|
<p>
|
||||||
|
@ -30,5 +30,21 @@ input[type='checkbox'] {
|
|||||||
min-height: 1em; }
|
min-height: 1em; }
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
background-color: #000000cf;
|
background-color: #00000040;
|
||||||
color: #ffffff; }
|
color: #fff;
|
||||||
|
border-radius: 2em; }
|
||||||
|
|
||||||
|
.post {
|
||||||
|
background-color: #000000dd;
|
||||||
|
color: #d1d1d1;
|
||||||
|
padding: 2.3em;
|
||||||
|
border-radius: 2em;
|
||||||
|
border: solid #441515a4 2pt; }
|
||||||
|
|
||||||
|
div.actiongroup {
|
||||||
|
float: right;
|
||||||
|
margin: .5em; }
|
||||||
|
|
||||||
|
div.float-left {
|
||||||
|
float: left;
|
||||||
|
margin: .5em; }
|
||||||
|
@ -45,6 +45,27 @@ input[type='checkbox'] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
background-color: #000000cf;
|
background-color: #00000040;
|
||||||
color:#ffffff;
|
color: #fff;
|
||||||
|
border-radius: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post {
|
||||||
|
background-color: #000000dd;
|
||||||
|
color:#d1d1d1;
|
||||||
|
padding: 2.3em;
|
||||||
|
border-radius: 2em;
|
||||||
|
border: solid #441515a4 2pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actiongroup
|
||||||
|
{
|
||||||
|
float: right;
|
||||||
|
margin:.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.float-left
|
||||||
|
{
|
||||||
|
float: left;
|
||||||
|
margin:.5em;
|
||||||
}
|
}
|
||||||
|
@ -19,26 +19,26 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<form action="~/Home/GetUserInfo" method="post">
|
<form action="~/Home/GetUserInfo" method="post">
|
||||||
<button class="btn btn-lg btn-warning" type="submit">Get user info</button>
|
<button class="btn btn-light btn-warning" type="submit">Get user info</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form action="~/Home/GetApiCall" method="post">
|
<form action="~/Home/GetApiCall" method="post">
|
||||||
<button class="btn btn-lg btn-warning" type="submit">Api Call</button>
|
<button class="btn btn-light btn-warning" type="submit">Api Call</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form action="~/Home/PostDeviceInfo" method="post">
|
<form action="~/Home/PostDeviceInfo" method="post">
|
||||||
<button class="btn btn-lg btn-warning" type="submit">Post device info</button>
|
<button class="btn btn-light btn-warning" type="submit">Post device info</button>
|
||||||
</form>
|
</form>
|
||||||
<form action="~/Home/PostFiles/?subdir=test" method="post" enctype="multipart/form-data">
|
<form action="~/Home/PostFiles/?subdir=test" method="post" enctype="multipart/form-data">
|
||||||
Envoyer vers le dossier "test" <input type="file" name="file" multiple/>
|
Envoyer vers le dossier "test" <input type="file" name="file" multiple/>
|
||||||
<button class="btn btn-lg btn-warning" type="submit">Post files</button>
|
<button class="btn btn-light btn-warning" type="submit">Post files</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<a class="btn btn-lg btn-danger" href="/signout">Sign out</a>
|
<a class="btn btn-light btn-danger" href="/signout">Sign out</a>
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
<h1>Welcome, anonymous</h1>
|
<h1>Welcome, anonymous</h1>
|
||||||
<a class="btn btn-lg btn-success" href="/signin">Sign in</a>
|
<a class="btn btn-light btn-success" href="/signin">Sign in</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user