feat: added Board adding, editing and removing

This commit is contained in:
limited_dev 2023-03-11 02:50:07 +01:00
parent 9bdad9e48d
commit b595ce2909
15 changed files with 222 additions and 11 deletions

View file

@ -21,4 +21,7 @@ public class BoardData
[Required] [Required]
public bool isLocked { get; set; } public bool isLocked { get; set; }
[Required]
public int NumberOfGETs { get; set; }
} }

View file

@ -41,4 +41,6 @@ public class CommentData
public ReportData? Report { get; set; } public ReportData? Report { get; set; }
public int GET { get; set; }
} }

View file

@ -46,4 +46,6 @@ public class PostData
public bool IsSticky { get; set; } public bool IsSticky { get; set; }
public bool IsLocked { get; set; } public bool IsLocked { get; set; }
public int GET { get; set; }
} }

View file

@ -0,0 +1,45 @@
@page "/sys/modmenu/boards"
@using ImageBoardServerApp.Data.Repository
<AuthorizeView Roles="Admin">
<Authorized>
<h3>Boards</h3>
<span>Tag / Topic / Max Threads / GETs / Locked?</span>
<br/>
<hr/>
@foreach (var b in brds)
{
<a href="/@b.Tag">@b.Tag</a>
<span> / @b.Topic / @b.maxThreads / @b.NumberOfGETs / @b.isLocked / </span>
<a href="/sys/modmenu/boards/edit/@b.Tag">Edit Board</a>
<span> / </span>
<a @onclick="() => removeBoard(b)" href="javascript:void(0)">Delete Board</a>
<br/>
<hr/>
}
<BoardForm/>
</Authorized>
<NotAuthorized>
<DeadLink/>
</NotAuthorized>
</AuthorizeView>
@code {
public List<BoardData> brds { get; set; }
protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();
brds = await BoardsRepository.getBoardsAsync();
}
private async Task removeBoard(BoardData b)
{
List<PostData> postsOnB = await PostsRepository.getPostsByBoardAsync(b.Tag);
foreach (var p in postsOnB)
{
await TheManager.deleteThread(p);
}
await BoardsRepository.deleteBoardAsync(b.BoardID);
}
}

View file

@ -0,0 +1,29 @@
@page "/sys/modmenu/boards/edit/{Tag}"
@using ImageBoardServerApp.Data.Repository
<AuthorizeView Roles="Admin">
<Authorized>
<BoardForm Tag="@b.Tag" Topic="@b.Topic" maxThread="@mxThr" lockBoard="@b.isLocked"/>
</Authorized>
<NotAuthorized>
<DeadLink/>
</NotAuthorized>
</AuthorizeView>
@code {
[Parameter]
public string Tag { get; set; }
public string mxThr { get; set; }
public BoardData b { get; set; }
protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();
b = await BoardsRepository.getBoardByTagAsync(Tag);
if (b == null)
return;
mxThr = b.maxThreads + "";
}
}

View file

@ -8,8 +8,9 @@
<h3>ModMenu</h3> <h3>ModMenu</h3>
<span>Welcome @mail to the mod menu</span> <span>Welcome @mail to the mod menu</span>
<div> <div>
<a href="/sys/reports">[Reports]</a> <a href="/sys/modmenu/reports">[Reports]</a>
<a href="/sys/users">[Users]</a> <a href="/sys/modmenu/users">[Users]</a>
<a href="/sys/modmenu/boards">[Boards]</a>
</div> </div>
</Authorized> </Authorized>
<NotAuthorized> <NotAuthorized>

View file

@ -1,4 +1,4 @@
@page "/sys/reports" @page "/sys/modmenu/reports"
@using ImageBoardServerApp.Data.Repository @using ImageBoardServerApp.Data.Repository
<AuthorizeView Roles="Admin,Mod"> <AuthorizeView Roles="Admin,Mod">
<Authorized> <Authorized>

View file

@ -1,4 +1,4 @@
@page "/sys/users" @page "/sys/modmenu/users"
@using ImageBoardServerApp.Data.Repository @using ImageBoardServerApp.Data.Repository
<AuthorizeView Roles="Admin"> <AuthorizeView Roles="Admin">
<Authorized> <Authorized>

View file

@ -15,7 +15,7 @@
<span class="@role" >##@role</span> <span class="@role" >##@role</span>
} }
<span class="date">@getTimeFromUnix(comment.CreatedAt)</span> <span class="date">@getTimeFromUnix(comment.CreatedAt)</span>
<span class="post-id">No.@comment.CommentID</span> <span class="post-id">No.@comment.GET</span>
</div> </div>
@if (opened) @if (opened)
{ {

View file

@ -0,0 +1,72 @@
@using ImageBoardServerApp.Data.Repository
@inject NavigationManager navigationManager
<div class="pd centered">
<div class="centered formContent">
<div>
<div class="pd centered marg">
<RadzenTextBox Placeholder="Tag" MaxLength="3" @bind-Value="@Tag" Class="w-100"/>
</div>
<div class="pd centered marg">
<RadzenTextBox Placeholder="Topic" MaxLength="15" @bind-Value="@Topic" Class="w-100"/>
</div>
<div class="pd centered marg">
<RadzenTextBox Placeholder="MaxThreads (Number)" MaxLength="3" @bind-Value="@maxThread" Class="w-100"/>
</div>
<div class="pd centered marg">
<RadzenCheckBox @bind-Value=@lockBoard />
<span>Lock Board</span>
</div>
</div>
</div>
<div class="pd centered marg">
<RadzenButton class="pd" Click="@onPostClick" Text="Set!"></RadzenButton>
</div>
</div>
@code {
[Parameter]
public string Tag { get; set; }
[Parameter]
public string Topic { get; set; }
[Parameter]
public string maxThread { get; set; }
[Parameter]
public bool lockBoard { get; set; }
private async Task onPostClick()
{
if (!int.TryParse(maxThread, out _))
return;
var newB = new BoardData()
{
Tag = Tag.ToLower(),
Topic = Topic,
maxThreads = int.Parse(maxThread),
isLocked = lockBoard,
NumberOfGETs = 0
};
var bCheck = await BoardsRepository.getBoardByTagAsync(newB.Tag);
if (bCheck == null)
{
await BoardsRepository.createBoardAsync(newB);
return;
}
bCheck.Tag = newB.Tag;
bCheck.Topic = newB.Topic;
bCheck.maxThreads = newB.maxThreads;
bCheck.isLocked = newB.isLocked;
await BoardsRepository.updateBoardAsync(bCheck);
navigationManager.NavigateTo("/sys/modmenu/boards", true, true);
}
}

View file

@ -0,0 +1,44 @@
.toggleOpened{
color: #0a58ca;
text-decoration: none;
}
.toggleOpened:hover{
color: #0a58ca; !important;
cursor: pointer;
}
.centered {
text-align: center;
justify-content: center;
align-items: center;
}
.pd {
padding: 5px;
}
.marg{
margin: 2px
}
.formImage{
margin: 6px;
max-width: 200px;
max-height: 200px;
padding: 5px;
}
.formImage img{
max-width:150px;
width: 100%;
}
.formContent{
text-align: left;
display: flex;
}
.postError{
color: #ff191c;
}

View file

@ -119,7 +119,9 @@
{ {
postUsername = "Anonymous"; postUsername = "Anonymous";
} }
int thisGET = b.NumberOfGETs + 1;
b.NumberOfGETs++;
await BoardsRepository.updateBoardAsync(b);
CommentData commentToCreate; CommentData commentToCreate;
if (hasImage) if (hasImage)
{ {
@ -146,7 +148,8 @@
Content = postContent, Content = postContent,
Username = postUsername, Username = postUsername,
Board = post.Board, Board = post.Board,
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
GET = thisGET
}; };
} }
else else
@ -158,7 +161,8 @@
Content = postContent, Content = postContent,
Username = postUsername, Username = postUsername,
Board = post.Board, Board = post.Board,
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
GET = thisGET
}; };
} }

View file

@ -149,6 +149,11 @@
{ {
postUsername = "Anonymous"; postUsername = "Anonymous";
} }
int thisGET = b.NumberOfGETs + 1;
b.NumberOfGETs++;
await BoardsRepository.updateBoardAsync(b);
var postToPost = new PostData var postToPost = new PostData
{ {
UserID = userID, UserID = userID,
@ -160,7 +165,8 @@
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(), CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
Board = board.Tag, Board = board.Tag,
IsLocked = false, IsLocked = false,
IsSticky = false IsSticky = false,
GET = thisGET
}; };
int postId = await PostsRepository.createPostAsync(postToPost); int postId = await PostsRepository.createPostAsync(postToPost);
if (postId != -1) if (postId != -1)

View file

@ -23,7 +23,7 @@
} }
<span> </span> <span> </span>
<span class="date"> @getTimeFromUnix(post.CreatedAt)</span> <span class="date"> @getTimeFromUnix(post.CreatedAt)</span>
<span class="post-id">No.@post.PostID</span> <span class="post-id">No.@post.GET</span>
<AuthorizeView Roles="Admin,Mod"> <AuthorizeView Roles="Admin,Mod">
<Authorized> <Authorized>
<span> </span> <span> </span>

View file

@ -3,3 +3,6 @@
- Search - Search
- Notify on Topic / Tag - Notify on Topic / Tag
- Send thread to user before deletion - Send thread to user before deletion
-
# FIXES IN NEED:
- Finish the GET mentioning