From 42c515b1259db517401b9c62cca92169e6635a3c Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sat, 14 Aug 2021 19:14:12 +0430 Subject: [PATCH] #186 showing user suggested corrections and result in their panel --- GanjooRazor/Areas/User/Pages/Edits.cshtml | 176 ++++++++++++++++++ GanjooRazor/Areas/User/Pages/Edits.cshtml.cs | 135 ++++++++++++++ GanjooRazor/Pages/Shared/_Layout.cshtml | 4 + RMuseum/RMuseum.xml | 12 ++ .../CorrectionReviewResultConvertor.cs | 35 ++++ .../Services/Implementation/GanjoorService.cs | 50 +++-- 6 files changed, 392 insertions(+), 20 deletions(-) create mode 100644 GanjooRazor/Areas/User/Pages/Edits.cshtml create mode 100644 GanjooRazor/Areas/User/Pages/Edits.cshtml.cs create mode 100644 RMuseum/Services/Implementation/CorrectionReviewResultConvertor.cs diff --git a/GanjooRazor/Areas/User/Pages/Edits.cshtml b/GanjooRazor/Areas/User/Pages/Edits.cshtml new file mode 100644 index 00000000..a444c378 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/Edits.cshtml @@ -0,0 +1,176 @@ +@page +@model GanjooRazor.Areas.User.Pages.EditsModel +@using RMuseum.Models.Ganjoor +@using RMuseum.Services.Implementation +@{ + Layout = "_Layout"; + ViewData["Title"] = "ویرایش‌های من"; + await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData); + string color = "gray"; +} +

@ViewData["Title"]

+@if (Model.LastError != "") +{ +

@Model.LastError

+} +else +{ +

+ @foreach (var paginationLink in Model.PaginationLinks) + { + if (!string.IsNullOrEmpty(paginationLink.Url)) + { + @paginationLink.Name + } + else + { + @paginationLink.Name + } + } +

+ + @foreach (var correction in Model.Corrections) + { + if (color == "gray") + color = "white"; + else + color = "gray"; + +
+ + + + + + + + + + + + @if (correction.Title != null) + { + + + + + + } + @if (correction.Rhythm != null) + { + + + + + + } + @if (correction.VerseOrderText != null) + @foreach (var verse in correction.VerseOrderText) + { + + + + + + } + @if (!string.IsNullOrEmpty(correction.Note)) + { + + + + + } + + + + + +
مشاهدهٔ متن شعر یا بخش
متن اولیهتغییرات مننتیجهٔ بررسی
+

@correction.OriginalTitle

+
+

@correction.Title

+
+ @if (correction.Result == CorrectionReviewResult.Approved) + { +

@CorrectionReviewResultConvertor.GetString(correction.Result)

+ } + else + @if (correction.Result == CorrectionReviewResult.Approved) + { +

@CorrectionReviewResultConvertor.GetString(correction.Result)

+ } + else + { +

@CorrectionReviewResultConvertor.GetString(correction.Result)

+ } +
+

@correction.OriginalRhythm

+
+

@correction.Rhythm

+
+ @if (correction.RhythmResult == CorrectionReviewResult.Approved) + { +

@CorrectionReviewResultConvertor.GetString(correction.RhythmResult)

+ } + else + @if (correction.RhythmResult == CorrectionReviewResult.Approved) + { +

@CorrectionReviewResultConvertor.GetString(correction.RhythmResult)

+ } + else + { +

@CorrectionReviewResultConvertor.GetString(correction.RhythmResult)

+ } +
+

@verse.OriginalText

+
+

@verse.Text

+
+ @if (verse.Result == CorrectionReviewResult.Approved) + { +

@CorrectionReviewResultConvertor.GetString(verse.Result)

+ } + else + @if (verse.Result == CorrectionReviewResult.Approved) + { +

@CorrectionReviewResultConvertor.GetString(verse.Result)

+ } + else + { +

@CorrectionReviewResultConvertor.GetString(verse.Result)

+ } +
یادداشت: + @correction.Note +
+ @if (correction.Reviewed) + { + ویرایش مجدد + } + else + { + مشاهده + } +
+ +
+ + +
+ } + +

+ @foreach (var paginationLink in Model.PaginationLinks) + { + if (!string.IsNullOrEmpty(paginationLink.Url)) + { + @paginationLink.Name + } + else + { + @paginationLink.Name + } + } +

+ + +} \ No newline at end of file diff --git a/GanjooRazor/Areas/User/Pages/Edits.cshtml.cs b/GanjooRazor/Areas/User/Pages/Edits.cshtml.cs new file mode 100644 index 00000000..55de5007 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/Edits.cshtml.cs @@ -0,0 +1,135 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using DNTPersianUtils.Core; +using GanjooRazor.Utils; +using GSpotifyProxy.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using RMuseum.Models.Ganjoor.ViewModels; +using RSecurityBackend.Models.Generic; + +namespace GanjooRazor.Areas.User.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class EditsModel : PageModel + { + // + /// Last Error + /// + public string LastError { get; set; } + + /// + /// pagination links + /// + public List PaginationLinks { get; set; } + + /// + /// Corrections + /// + public List Corrections { get; set; } + public async Task OnGetAsync() + { + LastError = ""; + using (HttpClient secureClient = new HttpClient()) + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + { + int pageNumber = 1; + if (!string.IsNullOrEmpty(Request.Query["page"])) + { + pageNumber = int.Parse(Request.Query["page"]); + } + var response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/corrections/mine?PageNumber={pageNumber}&PageSize=20"); + if (!response.IsSuccessStatusCode) + { + LastError = await response.Content.ReadAsStringAsync(); + return Page(); + } + response.EnsureSuccessStatusCode(); + + Corrections = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject>(); + + string paginnationMetadata = response.Headers.GetValues("paging-headers").FirstOrDefault(); + if (!string.IsNullOrEmpty(paginnationMetadata)) + { + PaginationMetadata paginationMetadata = JsonConvert.DeserializeObject(paginnationMetadata); + PaginationLinks = new List(); + if (paginationMetadata.totalPages > 1) + { + if (paginationMetadata.currentPage > 3) + { + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "صفحهٔ اول", + Url = "/User/Edits/?page=1" + } + ); + } + for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++) + { + if (i >= 1 && i <= paginationMetadata.totalPages) + { + if (i == paginationMetadata.currentPage) + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = i.ToPersianNumbers(), + } + ); + } + else + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = i.ToPersianNumbers(), + Url = $"/User/Edits/?page={i}" + } + ); + } + } + } + if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2)) + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "... ", + } + ); + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "صفحهٔ آخر", + Url = $"/User/Edits/?page={paginationMetadata.totalPages}" + } + ); + } + } + } + + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + return Page(); + } + } +} diff --git a/GanjooRazor/Pages/Shared/_Layout.cshtml b/GanjooRazor/Pages/Shared/_Layout.cshtml index 255d659c..2423cbf6 100644 --- a/GanjooRazor/Pages/Shared/_Layout.cshtml +++ b/GanjooRazor/Pages/Shared/_Layout.cshtml @@ -306,6 +306,10 @@ اعلان‌‌های من + + @if (ViewData.ContainsKey("ganjoor-songrevu")) {