MEF
This commit is contained in:
@ -113,7 +113,7 @@ public class BlogSpotService
|
||||
_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;
|
||||
|
||||
@ -149,9 +149,8 @@ public class BlogSpotService
|
||||
.Select(p => p.BlogPost).ToArray();
|
||||
}
|
||||
|
||||
var data = posts.OrderByDescending(p => p.DateCreated);
|
||||
var grouped = data.GroupBy(p => p.Title).Skip(skip).Take(take);
|
||||
return grouped;
|
||||
var data = posts.OrderByDescending(p => p.DateModified);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task Delete(ClaimsPrincipal user, long id)
|
||||
@ -174,7 +173,7 @@ public class BlogSpotService
|
||||
return _context.UserPosts(posterId, readerId);
|
||||
}
|
||||
|
||||
public object? ByTitle(string title)
|
||||
public object? GetTitle(string title)
|
||||
{
|
||||
return _context.BlogSpot.Include(
|
||||
b => b.Author
|
||||
@ -190,4 +189,5 @@ public class BlogSpotService
|
||||
.Include(b => b.ACL)
|
||||
.SingleOrDefaultAsync(x => x.Id == value);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ namespace Yavsc.Controllers
|
||||
await blogSpotService.UserPosts(id, User.GetUserId(),
|
||||
skip, take));
|
||||
}
|
||||
IEnumerable<IGrouping<string,IBlogPost>> byTitle = await this.blogSpotService.IndexByTitle(User, id, skip, take);
|
||||
return View(byTitle);
|
||||
IEnumerable<IBlogPost> index = await this.blogSpotService.Index(User, id, skip, take);
|
||||
return View(index);
|
||||
}
|
||||
|
||||
[Route("~/Title/{id?}")]
|
||||
@ -56,7 +56,7 @@ namespace Yavsc.Controllers
|
||||
public IActionResult Title(string 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)
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using AsciiDocNet;
|
||||
using Microsoft.AspNetCore.Html;
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
|
||||
namespace Yavsc.Helpers
|
||||
@ -8,17 +9,28 @@ namespace Yavsc.Helpers
|
||||
{
|
||||
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);
|
||||
var content = await output.GetChildContentAsync();
|
||||
string text = content.GetContent();
|
||||
if (string.IsNullOrWhiteSpace(text)) return;
|
||||
|
||||
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);
|
||||
var html = document.ToHtml(2);
|
||||
using var stringWriter = new StringWriter();
|
||||
|
@ -60,10 +60,14 @@ $('#commentValidation').html(
|
||||
}
|
||||
</style>
|
||||
}
|
||||
<div class="container">
|
||||
<div class="blogpost">
|
||||
<h1 class="blogtitle" ismarkdown>@Model.Title</h1>
|
||||
<img class="blogphoto" alt="" src="@Model.Photo" >
|
||||
|
||||
<div class="post">
|
||||
<div class="float-left">
|
||||
<img alt="" src="@Model.Photo" >
|
||||
</div>
|
||||
|
||||
<h1 ismarkdown>@Model.Title</h1>
|
||||
|
||||
@Html.DisplayFor(m=>m.Author)
|
||||
<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="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";
|
||||
}
|
||||
@ -43,59 +43,51 @@
|
||||
<a asp-action="Create">Create a new article</a>
|
||||
</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">
|
||||
<a asp-action="Title" asp-route-id="@group.Key" >@title</a></td></tr>
|
||||
@foreach (var item in group) {
|
||||
var trunked = item.Content?.Length > maxTextLen;
|
||||
<tr>
|
||||
<td><a asp-action="Details" asp-route-id="@item.Id" class="bloglink">
|
||||
<img src="@item.Photo" class="blogphoto"></a>
|
||||
</td>
|
||||
<td>
|
||||
<asciidoc summary="@maxTextLen">@item.Content</asciidoc>
|
||||
@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: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")
|
||||
})
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<ul class="actiongroup">
|
||||
@if ((await AuthorizationService.AuthorizeAsync(User, item, new ReadPermission())).Succeeded) {
|
||||
<li>
|
||||
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-lg">Details</a>
|
||||
</li>
|
||||
}
|
||||
else {
|
||||
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-lg">Details DEBUG</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>
|
||||
</li>
|
||||
<li><a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Delete</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<div class="float-left" >
|
||||
<a asp-action="Details" asp-route-id="@post.Id" class="bloglink" style="display: float-left;">
|
||||
<img src="@post.Photo" >
|
||||
</a>
|
||||
</div>
|
||||
<h3>@post.Title</h3>
|
||||
<div>
|
||||
<a asp-action="Details" asp-route-id="@post.Id">
|
||||
<asciidoc summary="@maxTextLen">@post.Content</asciidoc></a>
|
||||
<span style="font-size:x-small;">@Html.DisplayFor(m => post.Author)</span>
|
||||
<span style="font-size:xx-small;">
|
||||
posté le @post.DateCreated.ToString("dddd d MMM yyyy à H:mm")
|
||||
@if ((post.DateModified - post.DateCreated).Minutes > 0){
|
||||
@:- Modifié le @post.DateModified.ToString("dddd d MMM yyyy à H:mm")
|
||||
})
|
||||
</span>
|
||||
</div>
|
||||
<div class="actiongroup">
|
||||
@if ((await AuthorizationService.AuthorizeAsync(User, post, new ReadPermission())).Succeeded)
|
||||
{
|
||||
<a asp-action="Details" asp-route-id="@post.Id" class="btn btn-light">Details</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a asp-action="Details" asp-route-id="@post.Id" class="btn btn-light">Details</a>
|
||||
}
|
||||
@if ((await AuthorizationService.AuthorizeAsync(User, post, new EditPermission())).Succeeded)
|
||||
{
|
||||
<a asp-action="Edit" asp-route-id="@post.Id" class="btn btn-default">Edit</a>
|
||||
|
||||
<a asp-action="Delete" asp-route-id="@post.Id" class="btn btn-danger">Delete</a>
|
||||
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@if(Model.Count()==0){<p>Néant</p>}
|
||||
|
||||
</div>
|
||||
|
@ -28,7 +28,7 @@
|
||||
<ul class="actiongroup">
|
||||
@if ((await AuthorizationService.AuthorizeAsync(User, item, new ReadPermission())).Succeeded) {
|
||||
<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>
|
||||
}
|
||||
@if ((await AuthorizationService.AuthorizeAsync(User, item, new EditPermission())).Succeeded) {
|
||||
|
@ -20,9 +20,9 @@
|
||||
}
|
||||
</ul>
|
||||
<p>
|
||||
<input type="submit" class="btn btn-lg 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-lg btn-success" name="submit.Login" value="Sign in as different user" />
|
||||
<input type="submit" class="btn btn-light btn-success" name="submit.Grant" value="Grant" />
|
||||
<input type="submit" class="btn btn-light btn-danger" name="submit.Deny" value="Deny" />
|
||||
<input type="submit" class="btn btn-light btn-success" name="submit.Login" value="Sign in as different user" />
|
||||
</p>
|
||||
|
||||
</form>
|
||||
|
@ -14,6 +14,6 @@
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -37,7 +37,7 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<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>
|
||||
<p>
|
||||
|
@ -30,5 +30,21 @@ input[type='checkbox'] {
|
||||
min-height: 1em; }
|
||||
|
||||
.container {
|
||||
background-color: #000000cf;
|
||||
color: #ffffff; }
|
||||
background-color: #00000040;
|
||||
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 {
|
||||
background-color: #000000cf;
|
||||
color:#ffffff;
|
||||
background-color: #00000040;
|
||||
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">
|
||||
<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 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 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 action="~/Home/PostFiles/?subdir=test" method="post" enctype="multipart/form-data">
|
||||
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>
|
||||
|
||||
<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 {
|
||||
<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>
|
||||
|
Reference in New Issue
Block a user