Added Drafts and Review Pages (WIP)

This commit is contained in:
Mia Rose Winter 2024-01-18 16:19:12 +01:00
parent 021e5c5b71
commit cc0c75e5d0
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
5 changed files with 77 additions and 3 deletions

View file

@ -11,9 +11,15 @@
<li><NavLink href="" Match="NavLinkMatch.All">Home</NavLink></li> <li><NavLink href="" Match="NavLinkMatch.All">Home</NavLink></li>
<AuthorizeView Policy="ArticleEditPermissions"> <AuthorizeView Policy="ArticleEditPermissions">
<Authorized> <Authorized>
<li><NavLink href="article/new">New Article</NavLink></li> <li><NavLink href="article/new">New Article</NavLink></li>
<li><NavLink href="drafts">Drafts</NavLink></li>
</Authorized> </Authorized>
</AuthorizeView> </AuthorizeView>
<AuthorizeView Policy="ArticleReviewPermissions">
<Authorized>
<li><NavLink href="review">In Review</NavLink></li>
</Authorized>
</AuthorizeView>
<AuthorizeView Policy="RoleAssignPermissions"> <AuthorizeView Policy="RoleAssignPermissions">
<Authorized> <Authorized>
<li><NavLink href="manage/users">Manage users</NavLink></li> <li><NavLink href="manage/users">Manage users</NavLink></li>

View file

@ -124,8 +124,7 @@
article = new Article { article = new Article {
Title = Model.Title!, Title = Model.Title!,
Body = Model.Body!, Body = Model.Body!,
Author = User, Author = User
Status = ArticleStatus.Published // TODO remove
}; };
await context.AddAsync(article); await context.AddAsync(article);
} }

View file

@ -0,0 +1,37 @@
@page "/drafts"
@using Microsoft.EntityFrameworkCore
@using Wave.Data
@using Microsoft.AspNetCore.Identity
@attribute [Authorize(Policy = "ArticleEditPermissions")]
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
@inject UserManager<ApplicationUser> UserManager
@inject IStringLocalizer<Drafts> Localizer
<div class="flex gap-x-8 gap-y-4">
@foreach (var article in Articles) {
<ArticleTile Article="article" />
}
@if (Articles.Count < 1) {
<p>@Localizer["NoArticles"]</p>
}
</div>
@code {
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
private List<Article> Articles { get; } = [];
protected override async Task OnInitializedAsync() {
await using var context = await ContextFactory.CreateDbContextAsync();
string userId = UserManager.GetUserId(HttpContext.User)!;
Articles.AddRange(await
context.Set<Article>()
.Include(a => a.Author)
.Where(a => a.Status == ArticleStatus.Draft && a.Author.Id == userId)
.OrderByDescending(a => a.PublishDate)
.ToListAsync());
}
}

View file

@ -0,0 +1,31 @@
@page "/review"
@using Wave.Data
@using Microsoft.EntityFrameworkCore
@attribute [Authorize(Policy = "ArticleReviewPermissions")]
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
@inject IStringLocalizer<Review> Localizer
<div class="flex gap-x-8 gap-y-4">
@foreach (var article in Articles) {
<ArticleTile Article="article" />
}
@if(Articles.Count < 1) {
<p>@Localizer["NoArticles"]</p>
}
</div>
@code {
private List<Article> Articles { get; } = [];
protected override async Task OnInitializedAsync() {
await using var context = await ContextFactory.CreateDbContextAsync();
Articles.AddRange(await
context.Set<Article>()
.Include(a => a.Author)
.Where(a => a.Status == ArticleStatus.InReview)
.OrderByDescending(a => a.PublishDate)
.ToListAsync());
}
}

View file

@ -1,6 +1,7 @@
@using System.Net.Http @using System.Net.Http
@using System.Net.Http.Json @using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Authorization @using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing @using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web @using Microsoft.AspNetCore.Components.Web