Files
ZelWiki/TightWiki/Views/Page/Comments.cshtml
2025-01-22 23:31:03 +08:00

81 lines
3.4 KiB
Plaintext

@using TightWiki.Models
@model TightWiki.Models.ViewModels.Page.PageCommentsViewModel
@{
Layout = "/Views/Shared/_Layout.cshtml";
var sessionState = ViewData["SessionState"] as TightWiki.SessionState ?? throw new Exception("Wiki State Context cannot be null.");
}
<h3>
Comments for <a href="@GlobalConfiguration.BasePath/@sessionState.PageNavigation">@sessionState.Page.Name</a>.
</h3>
<p>
All comment made on the given page.
</p>
@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
<div class="alert alert-danger">@Html.Raw(Model.ErrorMessage)</div>
}
@if (!string.IsNullOrEmpty(Model.SuccessMessage))
{
<div class="alert alert-success">@Html.Raw(Model.SuccessMessage)</div>
}
@using (Html.BeginForm(null, null, FormMethod.Post, new { action = $"{GlobalConfiguration.BasePath}{Context.Request.Path}" }))
{
if (sessionState.IsAuthenticated == true)
{
<div class="container">
<div class="d-flex justify-content-end mb-4">
<div class="flex-grow-1 me-2">
<input type="text" name="Comment" id="Comment" class="form-control" placeholder="Type comment..." />
</div>
<button type="submit" value="Find" class="btn btn-primary">Post</button>
</div>
</div>
}
else
{
@:<a href="@GlobalConfiguration.BasePath/Identity/Account/Login?returnUrl=@Context.Request.Path.Value">Login to leave a comment</a>.
}
if (Model.Comments.Count > 0)
{
<div class="container mt-4">
@foreach (var h in Model.Comments)
{
<div class="border rounded mb-2 p-2">
<p class="mb-1">@Html.Raw(h.Body)</p>
<div class="d-flex justify-content-between align-items-center">
<div class="d-flex align-items-center small text-muted mb-0">
<img src="/Profile/@h.UserNavigation/Avatar?Exact=16" class="rounded-circle me-2" alt="Avatar" />
@if (TightWiki.Models.GlobalConfiguration.EnablePublicProfiles)
{
<a href="@GlobalConfiguration.BasePath/Profile/@h.UserNavigation/Public" class="small text-decoration-none mb-0">@Html.DisplayTextFor(x => h.UserName)</a>
}
else
{
<span class="small text-decoration-none mb-0">@Html.DisplayTextFor(x => h.UserName)</span>
}
&nbsp;&nbsp;<p class="small text-decoration-none text-muted mb-0">@Html.DisplayTextFor(x => h.CreatedDate)</p>
</div>
@if (sessionState.CanModerate == true || h.UserId == sessionState.Profile?.UserId)
{
<a href="?Delete=@h.Id" class="small text-danger text-decoration-none" onclick="return confirm('Are you sure you want to delete this comment?')">Delete</a>
}
</div>
</div>
}
</div>
}
else
{
<div class="d-flex small text-muted mb-0">
<strong>The page does not have any comments, why don't you add one?</strong>
</div>
}
@Html.Raw(TightWiki.Library.PageSelectorGenerator.Generate(Context.Request.QueryString, Model.PaginationPageCount))
}