From a0a25986111e1e9886f388bf5fade17d6ff5fb29 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sun, 1 Aug 2021 18:23:28 +0430 Subject: [PATCH] #186 display corrections for review --- .../Areas/Admin/Pages/ReviewEdits.cshtml | 89 ++++++++++++++++++- .../Areas/Admin/Pages/ReviewEdits.cshtml.cs | 51 ++++++++++- RMuseum/Controllers/GanjoorController.cs | 19 ++++ RMuseum/RMuseum.xml | 12 +++ RMuseum/Services/IGanjoorService.cs | 6 ++ .../Services/Implementation/GanjoorService.cs | 13 ++- 6 files changed, 186 insertions(+), 4 deletions(-) diff --git a/GanjooRazor/Areas/Admin/Pages/ReviewEdits.cshtml b/GanjooRazor/Areas/Admin/Pages/ReviewEdits.cshtml index 28496d87..baaee103 100644 --- a/GanjooRazor/Areas/Admin/Pages/ReviewEdits.cshtml +++ b/GanjooRazor/Areas/Admin/Pages/ReviewEdits.cshtml @@ -6,4 +6,91 @@ ViewData["Title"] = "بازبینی ویرایش‌ها"; } -

@ViewData["Title"]

\ No newline at end of file +

@ViewData["Title"]

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

@Model.FatalError

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

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

+} +else +{ + + + + @if (Model.Correction.Title != null) + { + + + + + + + + + + + + } + @if (Model.Correction.Rhythm != null) + { + + + + + + + + + + + + } + @if (Model.Correction.VerseOrderText != null) + @foreach (var verse in Model.Correction.VerseOrderText) + { + + + + + + + + + + + + } + @if (!string.IsNullOrEmpty(Model.Correction.Note)) + { + + + + + } + + +
+ عنوان +
متن اولیهتغییرات
+

@Model.Correction.OriginalTitle

+
+

@Model.Correction.Title

+
+ وزن +
متن اولیهتغییرات
+

@Model.Correction.OriginalRhythm

+
+

@Model.Correction.Rhythm

+
+ @verse.VORder +
متن اولیهتغییرات
+

@verse.OriginalText

+
+

@verse.Text

+
یادداشت: + @Model.Correction.Note +
+} diff --git a/GanjooRazor/Areas/Admin/Pages/ReviewEdits.cshtml.cs b/GanjooRazor/Areas/Admin/Pages/ReviewEdits.cshtml.cs index 70745888..b5065ac2 100644 --- a/GanjooRazor/Areas/Admin/Pages/ReviewEdits.cshtml.cs +++ b/GanjooRazor/Areas/Admin/Pages/ReviewEdits.cshtml.cs @@ -1,16 +1,63 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Threading.Tasks; +using GanjooRazor.Utils; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using RMuseum.Models.Ganjoor.ViewModels; +using RSecurityBackend.Models.Generic; namespace GanjooRazor.Areas.Admin.Pages { public class ReviewEditsModel : PageModel { - public void OnGet() + /// + /// correction + /// + public GanjoorPoemCorrectionViewModel Correction { get; set; } + /// + /// fatal error + /// + public string FatalError { get; set; } + + /// + /// skip + /// + public int Skip { get; set; } + + /// + /// total count + /// + public int TotalCount { get; set; } + + public async Task OnGetAsync() { + 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}"); + nextResponse.EnsureSuccessStatusCode(); + + string paginnationMetadata = nextResponse.Headers.GetValues("paging-headers").FirstOrDefault(); + if (!string.IsNullOrEmpty(paginnationMetadata)) + { + TotalCount = JsonConvert.DeserializeObject(paginnationMetadata).totalCount; + } + Correction = JsonConvert.DeserializeObject(await nextResponse.Content.ReadAsStringAsync()); + } + else + { + FatalError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + } + return Page(); } } } diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 51093c00..95455f20 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -871,6 +871,25 @@ namespace RMuseum.Controllers await _ganjoorService.GetNextUnreviewedCorrection(skip); if (!string.IsNullOrEmpty(res.ExceptionString)) return BadRequest(res.ExceptionString); + + var resCount = await _ganjoorService.GetUnreviewedCorrectionCount(); + if (!string.IsNullOrEmpty(resCount.ExceptionString)) + return BadRequest(resCount.ExceptionString); + + // Paging Header + HttpContext.Response.Headers.Add("paging-headers", + JsonConvert.SerializeObject( + new PaginationMetadata() + { + totalCount = resCount.Result, + pageSize = -1, + currentPage = -1, + hasNextPage = false, + hasPreviousPage = false, + totalPages = -1 + }) + ); + return Ok(res.Result);//might be null } diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 8af99c7f..70e14257 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -7672,6 +7672,12 @@ + + + unreview correction count + + + next unreviewed track @@ -9272,6 +9278,12 @@ + + + unreview correction count + + + suggest song diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 69bcd876..7cb388d5 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -167,6 +167,12 @@ namespace RMuseum.Services /// Task> GetNextUnreviewedCorrection(int skip); + /// + /// unreview correction count + /// + /// + Task> GetUnreviewedCorrectionCount(); + /// /// next unreviewed track /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 32ae0a8b..c33368c9 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -1411,7 +1411,7 @@ namespace RMuseum.Services.Implementation /// public async Task> GetNextUnreviewedCorrection(int skip) { - var dbCorrection = await _context.GanjoorPoemCorrections.AsNoTracking().Include(c => c.VerseOrderText) + var dbCorrection = await _context.GanjoorPoemCorrections.AsNoTracking().Include(c => c.VerseOrderText).Include(c => c.User) .Where(c => c.Result == CorrectionReviewResult.NotReviewed) .OrderBy(c => c.Id) .Skip(skip) @@ -1440,6 +1440,17 @@ namespace RMuseum.Services.Implementation ); } + /// + /// unreview correction count + /// + /// + public async Task> GetUnreviewedCorrectionCount() + { + return new RServiceResult(await _context.GanjoorPoemCorrections.AsNoTracking().Include(c => c.VerseOrderText) + .Where(c => c.Result == CorrectionReviewResult.NotReviewed) + .CountAsync()); + } + /// /// suggest song ///