From 3af5aea88eb6292b37d532e2e8121c1d4a8a1065 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Wed, 11 May 2022 09:22:38 +0430 Subject: [PATCH] docs: #319 section editor --- GanjooRazor/Areas/User/Pages/Editor.cshtml | 2 +- GanjooRazor/Areas/User/Pages/Section.cshtml | 110 ++++++++++++++++++ .../Areas/User/Pages/Section.cshtml.cs | 105 +++++++++++++++++ 3 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 GanjooRazor/Areas/User/Pages/Section.cshtml create mode 100644 GanjooRazor/Areas/User/Pages/Section.cshtml.cs diff --git a/GanjooRazor/Areas/User/Pages/Editor.cshtml b/GanjooRazor/Areas/User/Pages/Editor.cshtml index cc15cd98..da3135aa 100644 --- a/GanjooRazor/Areas/User/Pages/Editor.cshtml +++ b/GanjooRazor/Areas/User/Pages/Editor.cshtml @@ -624,7 +624,7 @@ else { - + قطعهٔ @(poemSetion.Number.ToPersianNumbers()): diff --git a/GanjooRazor/Areas/User/Pages/Section.cshtml b/GanjooRazor/Areas/User/Pages/Section.cshtml new file mode 100644 index 00000000..ca4afea5 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/Section.cshtml @@ -0,0 +1,110 @@ +@page +@model GanjooRazor.Areas.User.Pages.SectionModel +@using DNTPersianUtils.Core +@{ + Layout = "_UserPanelLayout"; + ViewData["Title"] = "ویرایشگر قطعه"; + await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData); +} +

@ViewData["Title"]

+ +@if (!string.IsNullOrEmpty(Model.FatalError)) +{ + @Html.Raw(Model.FatalError) +} +else +{ + + + + + + + + + + + + + + + + + + + +
+ @Html.Raw(Model.PoemSection.HtmlText) +
+ وزن فعلی: +
+

@(Model.PoemSection.GanjoorMetre == null ? "" : Model.PoemSection.GanjoorMetre.Rhythm)

+
+ وزن ویراستهٔ من: +
+
+ + + @if (Model.RhythmsByVerseCount != null) + @foreach (var rhythm in Model.RhythmsByVerseCount) + { + + } + + +
+ +
+ + پاک کردن وزن +
+ + پیشنهاد وزن جدید +
+} diff --git a/GanjooRazor/Areas/User/Pages/Section.cshtml.cs b/GanjooRazor/Areas/User/Pages/Section.cshtml.cs new file mode 100644 index 00000000..549a4da6 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/Section.cshtml.cs @@ -0,0 +1,105 @@ +using System.Collections.Generic; +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; + +namespace GanjooRazor.Areas.User.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class SectionModel : PageModel + { + /// + /// fatal error + /// + public string FatalError { get; set; } + + /// + /// page + /// + public GanjoorPageCompleteViewModel PageInformation { get; set; } + + /// + /// section + /// + public GanjoorPoemSection PoemSection { get; set; } + + /// + /// rhythms alphabetically + /// + public GanjoorMetre[] RhythmsAlphabetically { get; set; } + + /// + /// rhythms by frequency + /// + public GanjoorMetre[] RhythmsByVerseCount { get; set; } + + /// + /// my last edit + /// + public GanjoorPoemCorrectionViewModel MyLastEdit { get; set; } + + public async Task OnGetAsync() + { + if (string.IsNullOrEmpty(Request.Cookies["Token"])) + return Redirect("/"); + + FatalError = ""; + + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var pageUrlResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={Request.Query["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(); + + var rhythmResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/rhythms?sortOnVerseCount=true"); + if (!rhythmResponse.IsSuccessStatusCode) + { + FatalError = JsonConvert.DeserializeObject(await rhythmResponse.Content.ReadAsStringAsync()); + return Page(); + } + + RhythmsByVerseCount = JsonConvert.DeserializeObject(await rhythmResponse.Content.ReadAsStringAsync()); + + List rhythmsByVerseCount = new List(RhythmsByVerseCount); + rhythmsByVerseCount.Sort((a, b) => a.Rhythm.CompareTo(b.Rhythm)); + rhythmsByVerseCount.Insert(0, new GanjoorMetre() + { + Rhythm = "" + } + ); + + RhythmsAlphabetically = rhythmsByVerseCount.ToArray(); + + PoemSection = PageInformation.Poem.Sections.Where(s => s.Index == int.Parse(Request.Query["index"])).Single(); + } + else + { + FatalError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + } + return Page(); + } + } +}