diff --git a/GanjooRazor/Areas/Admin/Pages/ReviewSections.cshtml b/GanjooRazor/Areas/Admin/Pages/ReviewSections.cshtml new file mode 100644 index 00000000..e7b47707 --- /dev/null +++ b/GanjooRazor/Areas/Admin/Pages/ReviewSections.cshtml @@ -0,0 +1,170 @@ +@page +@model GanjooRazor.Areas.Admin.Pages.ReviewSectionsModel +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@using DNTPersianUtils.Core +@{ + Layout = "_AdminLayout"; + ViewData["Title"] = "بازبینی ویرایش‌های قطعات"; +} + +

@ViewData["Title"]

+ +@if (!string.IsNullOrEmpty(Model.FatalError)) +{ +

@Model.FatalError

+} +else if (@Model.Correction == null) +{ +

ویرایشی وجود ندارد.

+} +else +{ +

@Model.PageInformation.FullTitle

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @if (Model.TextSourceImage != null) + { + + + + } + + @if (Model.Correction.Rhythm != null) + { + + + + + + + + + + + + + + + + + + + } + + + @if (!string.IsNullOrEmpty(Model.Correction.Note)) + { + + + + + } + + + + + + +
+ پیشنهاد دهنده: + + @Model.Correction.UserNickname +
+ بررسی + +
+ +
+
+ زمان: + + @Model.Correction.Date.ToFriendlyPersianDateTextify() +
+ تعداد کل: + + @Model.TotalCount +
+ درست نیست +

 

+ +
+ وزن +
+ @if (Model.PageInformation.Poem.Verses.Length > 0) + { + @Model.PageInformation.Poem.Verses[0].Text + } + + @if (Model.PageInformation.Poem.Verses.Length > 1) + { + @Model.PageInformation.Poem.Verses[1].Text + } +
متن اولیهپیشنهاد
+

@Model.Correction.OriginalRhythm

+
+

@Model.Correction.Rhythm

+
+ + @if (Model.Correction.RhythmResult == RMuseum.Models.Ganjoor.CorrectionReviewResult.NotChanged) + { + + + +
+ + } + else + { + + + +
+ + } +
+ +
+ +
+ +
+ +
+ +
یادداشت: + @Model.Correction.Note +
+} diff --git a/GanjooRazor/Areas/Admin/Pages/ReviewSections.cshtml.cs b/GanjooRazor/Areas/Admin/Pages/ReviewSections.cshtml.cs new file mode 100644 index 00000000..55194d17 --- /dev/null +++ b/GanjooRazor/Areas/Admin/Pages/ReviewSections.cshtml.cs @@ -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 + { + /// + /// correction + /// + public GanjoorPoemSectionCorrectionViewModel Correction { get; set; } + /// + /// fatal error + /// + public string FatalError { get; set; } + + /// + /// skip + /// + public int Skip { get; set; } + + /// + /// total count + /// + public int TotalCount { get; set; } + + public PoemRelatedImage TextSourceImage { get; set; } + + /// + /// page + /// + public GanjoorPageCompleteViewModel PageInformation { get; set; } + + /// + /// poem section + /// + public GanjoorPoemSection PoemSection { get; set; } + public async Task 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(await nextResponse.Content.ReadAsStringAsync()); + return Page(); + } + + string paginnationMetadata = nextResponse.Headers.GetValues("paging-headers").FirstOrDefault(); + if (!string.IsNullOrEmpty(paginnationMetadata)) + { + TotalCount = JsonConvert.DeserializeObject(paginnationMetadata).totalCount; + } + Correction = JsonConvert.DeserializeObject(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(await sectionResponse.Content.ReadAsStringAsync()); + return Page(); + } + PoemSection = JsonConvert.DeserializeObject(await sectionResponse.Content.ReadAsStringAsync()); + + var pageUrlResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={PoemSection.PoemId}"); + if (!pageUrlResponse.IsSuccessStatusCode) + { + FatalError = JsonConvert.DeserializeObject(await pageUrlResponse.Content.ReadAsStringAsync()); + return Page(); + } + var pageUrl = JsonConvert.DeserializeObject(await pageUrlResponse.Content.ReadAsStringAsync()); + + var pageQuery = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={pageUrl}"); + if (!pageQuery.IsSuccessStatusCode) + { + FatalError = JsonConvert.DeserializeObject(await pageQuery.Content.ReadAsStringAsync()); + return Page(); + } + PageInformation = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject(); + + 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(); + } + } +} diff --git a/GanjooRazor/GanjooRazor.csproj b/GanjooRazor/GanjooRazor.csproj index 1a32371a..49af5644 100644 --- a/GanjooRazor/GanjooRazor.csproj +++ b/GanjooRazor/GanjooRazor.csproj @@ -6,6 +6,10 @@ GanjooRazor.Program + + + + @@ -22,4 +26,16 @@ + + + + + + <_ContentIncludedByDefault Remove="Areas\Admin\Pages\ReviewSections.cshtml" /> + + + + + + diff --git a/GanjooRazor/Pages/Shared/_AdminLayout.cshtml b/GanjooRazor/Pages/Shared/_AdminLayout.cshtml index e0f78e03..edca6e23 100644 --- a/GanjooRazor/Pages/Shared/_AdminLayout.cshtml +++ b/GanjooRazor/Pages/Shared/_AdminLayout.cshtml @@ -340,6 +340,13 @@ ویرایش‌ها + +