#125 displaying older versions of a page

This commit is contained in:
Hamid Reza Mohammadi 2021-05-31 19:01:33 +04:30
parent 8052ba5dec
commit 6fc5f955ec
2 changed files with 62 additions and 2 deletions

View File

@ -1,6 +1,7 @@
@page
@model GanjooRazor.Areas.Admin.Pages.PageHistoryModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@using DNTPersianUtils.Core
@{
Layout = "_AdminLayout";
ViewData["Title"] = "سابقهٔ ویرایش";
@ -8,4 +9,30 @@
<h1>@ViewData["Title"]</h1>
<p>@Model.LastMessage</p>
<p>@Model.LastMessage</p>
@if (Model.OlderVersions != null)
{
<table>
<tr>
<th>شناسه</th>
<th>تاریخ</th>
<th>یاداشت</th>
</tr>
@foreach (var olderVersion in Model.OlderVersions)
{
<tr id="tr-@olderVersion.Id">
<td>
<a href="/Admin/ViewPageHistory?id=@olderVersion.Id">@olderVersion.Id</a>
</td>
<td>
@olderVersion.RecordDate.ToFriendlyPersianDateTextify()
</td>
<td>
@olderVersion.Note
</td>
</tr>
}
</table>
}

View File

@ -1,4 +1,10 @@
using GanjooRazor.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using RMuseum.Models.Ganjoor.ViewModels;
using System.Net.Http;
using System.Threading.Tasks;
namespace GanjooRazor.Areas.Admin.Pages
{
@ -8,8 +14,35 @@ namespace GanjooRazor.Areas.Admin.Pages
/// last message
/// </summary>
public string LastMessage { get; set; }
public void OnGet()
public GanjoorPageSnapshotSummaryViewModel[] OlderVersions { get; set; }
public async Task<IActionResult> OnGetAsync()
{
LastMessage = "";
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
var response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page/oldversions/{Request.Query["id"]}");
if (!response.IsSuccessStatusCode)
{
LastMessage = await response.Content.ReadAsStringAsync();
}
response.EnsureSuccessStatusCode();
OlderVersions = JsonConvert.DeserializeObject<GanjoorPageSnapshotSummaryViewModel[]>(await response.Content.ReadAsStringAsync());
}
else
{
LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
}
}
return Page();
}
}
}