diff --git a/GanjooRazor/Areas/User/Pages/Editor.cshtml b/GanjooRazor/Areas/User/Pages/Editor.cshtml index 5edcf7fb..99c8132d 100644 --- a/GanjooRazor/Areas/User/Pages/Editor.cshtml +++ b/GanjooRazor/Areas/User/Pages/Editor.cshtml @@ -324,6 +324,32 @@ document.getElementById('secondr-btn').style.display = 'none'; } + function updateCoupletIndices(id){ + if (!confirm('آیا از بازسازی اندیس‌های ابیات اطمینان دارید؟')) + return; + + + var url = '?handler=RefillCoupletIndices'; + + $.ajax({ + type: "POST", + url: url, + data: { + id: id, + }, + error: function (e) { + if (e.responseText == null) + alert(e); + else + alert(e.responseText); + }, + success: function () { + alert('انجام شد.'); + }, + + }); + } + function regenerateSections(id) { if (!confirm('آیا از قطعه‌بندی مجدد اطمینان دارید؟')) return; @@ -1646,6 +1672,13 @@ else } + @if (Model.ShowAdminOps) + { + + تصحیح اندیس‌های ابیات + + } + @if (Model.ShowAdminOps) { diff --git a/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs b/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs index fd003b10..6b4e0bf3 100644 --- a/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs @@ -548,6 +548,29 @@ namespace GanjooRazor.Areas.User.Pages } } + public async Task OnPostRefillCoupletIndicesAsync(int id) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + HttpResponseMessage response = await secureClient.PostAsync( + $"{APIRoot.Url}/api/ganjoor/refillcoupletindices/{id}", + null + ); + if (!response.IsSuccessStatusCode) + { + return new BadRequestObjectResult(JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync())); + } + return new OkResult(); + } + else + { + return new BadRequestObjectResult("لطفاً از گنجور خارج و مجددا به آن وارد شوید."); + } + } + } + public async Task OnPostRegeneratePoemSectionsAsync(int id) { using (HttpClient secureClient = new HttpClient()) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index b398273d..a3eeada4 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -2616,6 +2616,27 @@ namespace RMuseum.Controllers return BadRequest(res.ExceptionString); } + /// + /// refill couplet indices for poem + /// + /// + /// + [HttpPost] + [Route("refillcoupletindices/{poemId}")] + [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.ImportOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task RefillCoupletIndicesAsync(int poemId) + { + RServiceResult res = + await _ganjoorService.RefillCoupletIndicesAsync(poemId); + if (!string.IsNullOrEmpty(res.ExceptionString)) + { + return BadRequest(res.ExceptionString); + } + return Ok(); + } + /// /// fill section couplet counts /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 97e96e0e..0e525420 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1747,6 +1747,13 @@ + + + refill couplet indices for poem + + + + fill section couplet counts @@ -16586,6 +16593,13 @@ + + + refill couplet indices + + + + fill section couplets count @@ -19393,6 +19407,13 @@ + + + refill couplet indices + + + + fill section couplets count diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index b054f92c..f280798e 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -628,6 +628,13 @@ namespace RMuseum.Services /// RServiceResult StartFillingPoemsCoupletIndices(); + /// + /// refill couplet indices + /// + /// + /// + Task> RefillCoupletIndicesAsync(int poemId); + /// /// fill section couplets count /// diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs index 4f947e23..e03398cb 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs @@ -692,6 +692,25 @@ namespace RMuseum.Services.Implementation return new RServiceResult(true); } + /// + /// refill couplet indices + /// + /// + /// + public async Task> RefillCoupletIndicesAsync(int poemId) + { + try + { + await _FillPoemCoupletIndices(_context, poemId); + await _context.SaveChangesAsync(); + return new RServiceResult(false); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString() ); + } + } + /// /// fill section couplets count /// diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs index c890bc40..ee4c840b 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs @@ -120,6 +120,7 @@ namespace RMuseum.Services.Implementation if (moderation.VerseOrderText.Length != dbCorrection.VerseOrderText.Count) return new RServiceResult(null, "moderation.VerseOrderText.Length != dbCorrection.VerseOrderText.Count"); + bool versePosistionsChanged = false; var modifiedVerses = new List(); foreach (var moderatedVerse in moderation.VerseOrderText) @@ -135,6 +136,7 @@ namespace RMuseum.Services.Implementation { if (moderatedVerse.VersePositionResult == CorrectionReviewResult.NotReviewed) return new RServiceResult(null, $"تغییرات نوع مصرع {moderatedVerse.VORder} بررسی نشده است."); + versePosistionsChanged = true; dbVerse.VersePositionResult = moderatedVerse.VersePositionResult; } if(dbVerse.CoupletSummary != null) @@ -284,7 +286,7 @@ namespace RMuseum.Services.Implementation await _context.SaveChangesAsync();//temporary ids should be saved } - if (versesDeleted || verseAdded) + if (versesDeleted || verseAdded || versePosistionsChanged) { var undeletedPoemVerss = poemVerses.OrderBy(v => v.VOrder).Where(v => !moderation.VerseOrderText.Any(mv => mv.VORder == v.VOrder && mv.MarkForDelete == true)).ToList(); for (int vOrder = 1; vOrder <= undeletedPoemVerss.Count; vOrder++)