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

@ViewData["Title"]

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

@Model.FatalError

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

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

+} +else +{ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @if (Model.GanjoorQuotedPoem.RelatedPoemId != null) + { + + + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ بیت مرجع از شعر: + + + +
+ +
+ مصرع اول مهم است: +
+ +
+ مصرع دوم مهم است: +
+ +
+ شاعر مرجع: +
+ +
+ +
+ +
+ گزینش شعر مرتبط +
+ +
+ مشاهدهٔ شعر مرتبط +
+ بیت مرتبط: +
+ +
+ مصرع اول مرتبط (خارج از گنجور): +
+ +
+ مصرع اول مهم است: +
+ +
+ مصرع دوم مرتبط (خارج از گنجور): +
+ +
+ مصرع دوم مهم است: +
+ +
+ ترتیب: +
+ +
+ این شعر قدیمی‌تر از شعر مرتبط است: +
+ +
+ نمایش در فهرست اصلی: +
+ +
+ مستقیماً ارتباط ندارد: +
+ +
+ منتسب به هر دو شاعر: +
+ +
+ شاعر: +
+ +
+ +
+ سالمرگ شاعر: +
+ +
+ نشانی صفحهٔ شاعر: +
+ +
+ تصویر شاعر: +
+ +
+ عنوان شعر: +
+ +
+ نشانی شعر: +
+ +
+ یادداشت: +
+ +
+ منتشر شده: +
+ +
+ تعداد همسان‌ها: +
+ +
+ +

+ حذف +
+
+ + +} diff --git a/GanjooRazor/Areas/Admin/Pages/ReviewQuoteds.cshtml.cs b/GanjooRazor/Areas/Admin/Pages/ReviewQuoteds.cshtml.cs new file mode 100644 index 00000000..fee1c511 --- /dev/null +++ b/GanjooRazor/Areas/Admin/Pages/ReviewQuoteds.cshtml.cs @@ -0,0 +1,168 @@ +using GanjooRazor.Utils; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using RMuseum.Models.Ganjoor.ViewModels; +using RSecurityBackend.Models.Generic; +using System.Net.Http; +using System.Threading.Tasks; +using System.Linq; +using System; +using RMuseum.Models.Ganjoor; +using System.Collections.Generic; +using Newtonsoft.Json.Linq; + +namespace GanjooRazor.Areas.Admin.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class ReviewQuotedsModel : PageModel + { + /// + /// suggestion + /// + [BindProperty] + public GanjoorQuotedPoemViewModel GanjoorQuotedPoem { get; set; } + /// + /// fatal error + /// + public string FatalError { get; set; } + + /// + /// skip + /// + public int Skip { get; set; } + + /// + /// total count + /// + public int TotalCount { get; set; } + + public Tuple[] Couplets { get; set; } + + public Tuple[] RelatedCouplets { get; set; } + + public GanjoorPoemCompleteViewModel Poem { get; set; } + + public GanjoorPoemCompleteViewModel RelatedPoem { get; set; } + + private Tuple[] GetCouplets(GanjoorVerseViewModel[] verses) + { + int coupetIndex = -1; + string coupletText = ""; + List> couplets = new List>(); + int verseIndex = 0; + bool incompleteCouplet = false; + while (verseIndex < verses.Length) + { + switch (verses[verseIndex].VersePosition) + { + case VersePosition.Comment: + incompleteCouplet = false; + if (!string.IsNullOrEmpty(coupletText)) + { + couplets.Add(new Tuple(coupetIndex, coupletText)); + coupletText = ""; + } + break; + case VersePosition.Paragraph: + case VersePosition.Single: + incompleteCouplet = false; + if (!string.IsNullOrEmpty(coupletText)) + { + couplets.Add(new Tuple(coupetIndex, coupletText)); + coupletText = ""; + } + coupetIndex++; + couplets.Add(new Tuple(coupetIndex, verses[verseIndex].Text)); + break; + case VersePosition.Right: + case VersePosition.CenteredVerse1: + incompleteCouplet = false; + if (!string.IsNullOrEmpty(coupletText)) + { + couplets.Add(new Tuple(coupetIndex, coupletText)); + } + coupetIndex++; + coupletText = verses[verseIndex].Text; + break; + case VersePosition.Left: + case VersePosition.CenteredVerse2: + incompleteCouplet = true; + coupletText += $" - {verses[verseIndex].Text}"; + break; + } + verseIndex++; + } + + + if (incompleteCouplet && !string.IsNullOrEmpty(coupletText)) + couplets.Add(new Tuple(coupetIndex, coupletText)); + + return couplets.ToArray(); + } + 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"]); + RelatedCouplets = []; + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var nextResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/quoted/suggestion/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; + } + GanjoorQuotedPoem = JsonConvert.DeserializeObject(await nextResponse.Content.ReadAsStringAsync()); + + if(GanjoorQuotedPoem != null) + { + var poemQuery = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{GanjoorQuotedPoem.PoemId}"); + if (!poemQuery.IsSuccessStatusCode) + { + FatalError = JsonConvert.DeserializeObject(await poemQuery.Content.ReadAsStringAsync()); + return Page(); + } + Poem = JObject.Parse(await poemQuery.Content.ReadAsStringAsync()).ToObject(); + + Couplets = GetCouplets(Poem.Verses); + + if (GanjoorQuotedPoem.RelatedPoemId != null) + { + var relPoemQuery = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{GanjoorQuotedPoem.RelatedPoemId}"); + if (!relPoemQuery.IsSuccessStatusCode) + { + FatalError = JsonConvert.DeserializeObject(await relPoemQuery.Content.ReadAsStringAsync()); + return Page(); + } + RelatedPoem = JObject.Parse(await relPoemQuery.Content.ReadAsStringAsync()).ToObject(); + + RelatedCouplets = GetCouplets(RelatedPoem.Verses); + + + + } + } + + } + else + { + FatalError = "لطفاً از گنجور خارج و مجددا به آن وارد شوید."; + } + } + return Page(); + } + } +} diff --git a/GanjooRazor/Pages/Shared/_AdminLayout.cshtml b/GanjooRazor/Pages/Shared/_AdminLayout.cshtml index cda53fbc..f5dc41b0 100644 --- a/GanjooRazor/Pages/Shared/_AdminLayout.cshtml +++ b/GanjooRazor/Pages/Shared/_AdminLayout.cshtml @@ -272,6 +272,13 @@ +