docs: #319 addg ReviewSections page

This commit is contained in:
Hamid Reza Mohammadi 2022-05-13 15:42:04 +04:30
parent 2406ec0e3e
commit d1bb2c4f5f
4 changed files with 321 additions and 0 deletions

View File

@ -0,0 +1,170 @@
@page
@model GanjooRazor.Areas.Admin.Pages.ReviewSectionsModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@using DNTPersianUtils.Core
@{
Layout = "_AdminLayout";
ViewData["Title"] = "بازبینی ویرایش‌های قطعات";
}
<h1>@ViewData["Title"]</h1>
@if (!string.IsNullOrEmpty(Model.FatalError))
{
<p>@Model.FatalError</p>
}
else if (@Model.Correction == null)
{
<p>ویرایشی وجود ندارد.</p>
}
else
{
<p><a role="button" target="_blank" href="@Model.PageInformation.FullUrl" class="actionlink">@Model.PageInformation.FullTitle</a></p>
<table>
<tr>
<td>
پیشنهاد دهنده:
</td>
<td>
<a href="/hashieha/?userid=@Model.Correction.UserId" target="_blank">@Model.Correction.UserNickname</a>
</td>
</tr>
<tr>
<td>
<a role="button" id="moderatecorrections" style="cursor:pointer;width:100%;color:white;background-color:green;display:block" onclick="moderatePoemCorrections(@Model.PageInformation.Poem.Verses.Length, @Model.Correction.Id)">بررسی</a>
</td>
<td>
<form method="post">
<button type="submit" name="next" id="next" style="width:100%;color:white;background-color:orange">بعدی</button>
</form>
</td>
</tr>
<tr>
<td>
زمان:
</td>
<td>
@Model.Correction.Date.ToFriendlyPersianDateTextify()
</td>
</tr>
<tr>
<td>
تعداد کل:
</td>
<td>
@Model.TotalCount
</td>
</tr>
<tr>
<td colspan=2>
<a role="button" onclick="checkAllNotCorrect()" class="pagebutton">درست نیست</a>
</td>
</tr>
<tr>
<td colspan="2"><p id="saving">&nbsp;</p></td>
</tr>
@if (Model.TextSourceImage != null)
{
<tr>
<td colspan="2">
<div class="related-images">
<div class="related-image-container">
<a target="_blank" href="@Html.Raw(Model.TextSourceImage.TargetPageUrl)">
<img src="@Html.Raw(Model.TextSourceImage.ThumbnailImageUrl)" alt="@Model.TextSourceImage.AltText" loading="lazy" width="200" class="related-image">
</a>
</div>
</div>
</td>
</tr>
}
@if (Model.Correction.Rhythm != null)
{
<tr>
<td colspan="2">
وزن
</td>
</tr>
<tr>
<td>
@if (Model.PageInformation.Poem.Verses.Length > 0)
{
@Model.PageInformation.Poem.Verses[0].Text
}
</td>
<td>
@if (Model.PageInformation.Poem.Verses.Length > 1)
{
@Model.PageInformation.Poem.Verses[1].Text
}
</td>
</tr>
<tr>
<td>متن اولیه</td>
<td>پیشنهاد</td>
</tr>
<tr>
<td>
<p style="color:red">@Model.Correction.OriginalRhythm</p>
</td>
<td>
<p style="color:green">@Model.Correction.Rhythm</p>
</td>
</tr>
<tr>
<td colspan="2">
@if (Model.Correction.RhythmResult == RMuseum.Models.Ganjoor.CorrectionReviewResult.NotChanged)
{
<input type="radio" id="rhythm_review_result_Approved" name="rhythm_review_result" class="radio-approved" value="@RMuseum.Models.Ganjoor.CorrectionReviewResult.Approved">
<label for="rhythm_review_result_Approved">تأیید می‌شود</label>
<br>
<input type="radio" id="rhythm_review_result_NotChanged" name="rhythm_review_result" class="radio-notchanged" value="@RMuseum.Models.Ganjoor.CorrectionReviewResult.NotChanged" checked="checked">
}
else
{
<input type="radio" id="rhythm_review_result_Approved" name="rhythm_review_result" class="radio-approved" value="@RMuseum.Models.Ganjoor.CorrectionReviewResult.Approved" checked="checked">
<label for="rhythm_review_result_Approved">تأیید می‌شود</label>
<br>
<input type="radio" id="rhythm_review_result_NotChanged" name="rhythm_review_result" class="radio-notchanged" value="@RMuseum.Models.Ganjoor.CorrectionReviewResult.NotChanged">
}
<label for="rhythm_review_result_NotChanged">تغییری نکرده</label><br>
<input type="radio" id="rhythm_review_result_RejectedBecauseWrong" name="rhythm_review_result" class="radio-notcorrect" value="@RMuseum.Models.Ganjoor.CorrectionReviewResult.RejectedBecauseWrong">
<label for="rhythm_review_result_RejectedBecauseWrong">درست نیست</label><br>
<input type="radio" id="rhythm_review_result_RejectedBecauseVariant" name="rhythm_review_result" class="radio-variant" value="@RMuseum.Models.Ganjoor.CorrectionReviewResult.RejectedBecauseVariant">
<label for="rhythm_review_result_RejectedBecauseVariant">مربوط به نسخهٔ دیگری است</label><br>
<input type="radio" id="rhythm_review_result_RejectedBecauseUnnecessaryChange" name="rhythm_review_result" class="radio-unnecessary" value="@RMuseum.Models.Ganjoor.CorrectionReviewResult.RejectedBecauseUnnecessaryChange">
<label for="rhythm_review_result_RejectedBecauseUnnecessaryChange">تغییر سلیقه‌ای یا بی دلیل است</label><br>
<input type="radio" id="rhythm_review_result_Rejected" name="rhythm_review_result" class="radio-rejected" value="@RMuseum.Models.Ganjoor.CorrectionReviewResult.Rejected">
<label for="rhythm_review_result_Rejected">به دلیل دیگری رد می‌شود</label><br>
<input type="text" id="title_review_note" name="title_review_note" value="" size="50" />
</td>
</tr>
}
@if (!string.IsNullOrEmpty(Model.Correction.Note))
{
<tr>
<td>یادداشت:</td>
<td>
@Model.Correction.Note
</td>
</tr>
}
</table>
}

View File

@ -0,0 +1,128 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using GanjooRazor.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RMuseum.Models.Ganjoor;
using RMuseum.Models.Ganjoor.ViewModels;
using RSecurityBackend.Models.Generic;
namespace GanjooRazor.Areas.Admin.Pages
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class ReviewSectionsModel : PageModel
{
/// <summary>
/// correction
/// </summary>
public GanjoorPoemSectionCorrectionViewModel Correction { get; set; }
/// <summary>
/// fatal error
/// </summary>
public string FatalError { get; set; }
/// <summary>
/// skip
/// </summary>
public int Skip { get; set; }
/// <summary>
/// total count
/// </summary>
public int TotalCount { get; set; }
public PoemRelatedImage TextSourceImage { get; set; }
/// <summary>
/// page
/// </summary>
public GanjoorPageCompleteViewModel PageInformation { get; set; }
/// <summary>
/// poem section
/// </summary>
public GanjoorPoemSection PoemSection { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
FatalError = "";
TotalCount = 0;
Skip = string.IsNullOrEmpty(Request.Query["skip"]) ? 0 : int.Parse(Request.Query["skip"]);
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
var nextResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/correction/next?skip={Skip}");
if (!nextResponse.IsSuccessStatusCode)
{
FatalError = JsonConvert.DeserializeObject<string>(await nextResponse.Content.ReadAsStringAsync());
return Page();
}
string paginnationMetadata = nextResponse.Headers.GetValues("paging-headers").FirstOrDefault();
if (!string.IsNullOrEmpty(paginnationMetadata))
{
TotalCount = JsonConvert.DeserializeObject<PaginationMetadata>(paginnationMetadata).totalCount;
}
Correction = JsonConvert.DeserializeObject<GanjoorPoemSectionCorrectionViewModel>(await nextResponse.Content.ReadAsStringAsync());
if (Correction != null)
{
var sectionResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/section/{Correction.SectionId}");
if (!sectionResponse.IsSuccessStatusCode)
{
FatalError = JsonConvert.DeserializeObject<string>(await sectionResponse.Content.ReadAsStringAsync());
return Page();
}
PoemSection = JsonConvert.DeserializeObject<GanjoorPoemSection>(await sectionResponse.Content.ReadAsStringAsync());
var pageUrlResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={PoemSection.PoemId}");
if (!pageUrlResponse.IsSuccessStatusCode)
{
FatalError = JsonConvert.DeserializeObject<string>(await pageUrlResponse.Content.ReadAsStringAsync());
return Page();
}
var pageUrl = JsonConvert.DeserializeObject<string>(await pageUrlResponse.Content.ReadAsStringAsync());
var pageQuery = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={pageUrl}");
if (!pageQuery.IsSuccessStatusCode)
{
FatalError = JsonConvert.DeserializeObject<string>(await pageQuery.Content.ReadAsStringAsync());
return Page();
}
PageInformation = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject<GanjoorPageCompleteViewModel>();
if (PageInformation.Poem.Images.Where(i => i.IsTextOriginalSource).Any())
{
TextSourceImage = PageInformation.Poem.Images.Where(i => i.IsTextOriginalSource).First();
}
if (Correction.Rhythm != null)
{
GanjoorMetre originalMetre = null;
if (PageInformation.Poem.Sections.Where(s => s.SectionType == PoemSectionType.WholePoem && s.GanjoorMetre != null && s.VerseType == VersePoemSectionType.First).Any())
{
originalMetre = PageInformation.Poem.Sections.Where(s => s.SectionType == PoemSectionType.WholePoem && s.VerseType == VersePoemSectionType.First && s.GanjoorMetre != null).OrderBy(s => s.VerseType).First().GanjoorMetre;
}
Correction.OriginalRhythm = originalMetre == null ? null : originalMetre.Rhythm;
if (Correction.OriginalRhythm == Correction.Rhythm)
Correction.RhythmResult = CorrectionReviewResult.NotChanged;
}
}
}
else
{
FatalError = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
}
}
return Page();
}
}
}

View File

@ -6,6 +6,10 @@
<StartupObject>GanjooRazor.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Content Remove="Areas\Admin\Pages\ReviewSections.cshtml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RMuseum\RMuseum.csproj" />
</ItemGroup>
@ -22,4 +26,16 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="Areas\Admin\Pages\ReviewSections.cshtml" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="Areas\Admin\Pages\ReviewSections.cshtml" />
</ItemGroup>
<ItemGroup>
<None Include="Areas\Admin\Pages\ReviewSections.cshtml" />
</ItemGroup>
</Project>

View File

@ -340,6 +340,13 @@
<a class="nav-link text-dark" asp-area="Admin" asp-page="ReviewEdits">ویرایش‌ها</a>
</li>
</ul>
</div>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="Admin" asp-page="ReviewSections">ویرایش‌های قطعات</a>
</li>
</ul>
</div>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">