From ad9d568184faadddd436a3efb74a5212c4ada6d6 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Thu, 21 Jul 2022 17:57:28 +0430 Subject: [PATCH] docs: #349 regenerate poem sections from UI, done! --- GanjooRazor/Areas/User/Pages/Editor.cshtml | 34 +++++++++++++++++++ GanjooRazor/Areas/User/Pages/Editor.cshtml.cs | 23 +++++++++++++ 2 files changed, 57 insertions(+) diff --git a/GanjooRazor/Areas/User/Pages/Editor.cshtml b/GanjooRazor/Areas/User/Pages/Editor.cshtml index 839c3e80..2c98c171 100644 --- a/GanjooRazor/Areas/User/Pages/Editor.cshtml +++ b/GanjooRazor/Areas/User/Pages/Editor.cshtml @@ -209,6 +209,36 @@ document.getElementById('secondr-btn').style.display = 'none'; } + + function regenerateSections(id) { + if (!confirm('آیا از قطعه‌بندی مجدد اطمینان دارید؟')) + return; + + if (!confirm('قطعه‌بندی مجدد باعث حذف اطلاعات وزن‌ها می‌شود. آیا اطمینان دارید؟')) + return; + + + + var url = '?handler=RegeneratePoemSections'; + + $.ajax({ + type: "POST", + url: url, + data: { + id: id, + }, + error: function(e) { + if (e.responseText == null) + alert(e); + else + alert(e.responseText); + }, + success: function() { + alert('انجام شد.'); + }, + + }); + } @if (!string.IsNullOrEmpty(Model.FatalError)) { @@ -918,6 +948,10 @@ else @if (Model.ShowAdminOps) { + + قطعه‌بندی مجدد + + برای حذف شعر از قسمت مدیریت بخش اقدام کنید. diff --git a/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs b/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs index 9d6f50bf..7ab9c461 100644 --- a/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs @@ -363,5 +363,28 @@ namespace GanjooRazor.Areas.User.Pages } } } + + public async Task OnPostRegeneratePoemSectionsAsync(int id) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + HttpResponseMessage response = await secureClient.PostAsync( + $"{APIRoot.Url}/api/ganjoor/poem/{id}/sections/regenerate", + null + ); + if (!response.IsSuccessStatusCode) + { + return new BadRequestObjectResult(JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync())); + } + return new OkResult(); + } + else + { + return new BadRequestObjectResult("لطفا از گنجور خارج و مجددا به آن وارد شوید."); + } + } + } } }