docs: #349 regenerate poem sections from UI, done!

This commit is contained in:
Hamid Reza Mohammadi 2022-07-21 17:57:28 +04:30
parent ba3b2549ec
commit ad9d568184
2 changed files with 57 additions and 0 deletions

View File

@ -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('انجام شد.');
},
});
}
</script>
@if (!string.IsNullOrEmpty(Model.FatalError))
{
@ -918,6 +948,10 @@ else
@if (Model.ShowAdminOps)
{
<tr>
<td><a role="button" onclick="regenerateSections(@Model.PageInformation.Poem.Id)" class="pagebutton">قطعه‌بندی مجدد</a></td>
</tr>
<tr>
<td>برای حذف شعر از قسمت مدیریت بخش اقدام کنید.</td>
</tr>

View File

@ -363,5 +363,28 @@ namespace GanjooRazor.Areas.User.Pages
}
}
}
public async Task<IActionResult> 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<string>(await response.Content.ReadAsStringAsync()));
}
return new OkResult();
}
else
{
return new BadRequestObjectResult("لطفا از گنجور خارج و مجددا به آن وارد شوید.");
}
}
}
}
}