docs: #320 API fix + client implementation

This commit is contained in:
Hamid Reza Mohammadi 2022-05-19 17:46:06 +04:30
parent f78de5becc
commit f72e27ba75
3 changed files with 71 additions and 2 deletions

View File

@ -13,6 +13,34 @@
}
else
{
<script>
function rebuildRelatedSections(sectionId, meterId, rhyming) {
if (!confirm(String(meterId) + ' : ' + rhyming))
return;
$('#rebuild-related-' + String(sectionId)).hide();
var url = '?handler=RebuildRelatedSections';
$.ajax({
type: "POST",
url: url,
data: {
meterId: meterId,
rhyming: rhyming
},
success: function() {
alert('شروع شد.');
},
error: function(e) {
if (e.responseText == null)
alert(e);
else
alert(e.responseText);
$('#rebuild-related-' + String(sectionId)).show();
}
});
}
</script>
<table>
@foreach (var poemSection in Model.PoemSections)
{
@ -86,6 +114,15 @@ else
@poemSection.RhymeLetters
</td>
</tr>
@if (poemSection.GanjoorMetre != null && !string.IsNullOrEmpty(poemSection.RhymeLetters) && Model.CanEdit)
{
<tr>
<td colspan="2">
<a role="button" id="rebuild-related-@poemSection.Id" style="cursor:pointer;width:100%;color:white;background-color:red;display:block" onclick="rebuildRelatedSections(@poemSection.Id, @poemSection.GanjoorMetreId, '@poemSection.RhymeLetters')">شکستن از اینجا</a>
</td>
</tr>
}
}
</table>

View File

@ -1,4 +1,5 @@
using System.Net.Http;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using GanjooRazor.Utils;
using Microsoft.AspNetCore.Mvc;
@ -8,6 +9,7 @@ using RMuseum.Models.Ganjoor;
namespace GanjooRazor.Areas.User.Pages
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class AllPoemSectionsModel : PageModel
{
/// <summary>
@ -17,10 +19,16 @@ namespace GanjooRazor.Areas.User.Pages
public GanjoorPoemSection[] PoemSections { get; set; }
/// <summary>
/// can edit
/// </summary>
public bool CanEdit { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
CanEdit = Request.Cookies["CanEdit"] == "True";
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
@ -36,5 +44,29 @@ namespace GanjooRazor.Areas.User.Pages
}
return Page();
}
public async Task<IActionResult> OnPostRebuildRelatedSectionsAsync(int meterId, string rhyming)
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.PostAsync(
$"{APIRoot.Url}/api/ganjoor/sections/updaterelated?metreId={meterId}&rhyme={rhyming}",
null
);
if (!response.IsSuccessStatusCode)
{
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
}
return new OkObjectResult(JsonConvert.DeserializeObject<int>(await response.Content.ReadAsStringAsync()));
}
else
{
return new BadRequestObjectResult("لطفا از گنجور خارج و مجددا به آن وارد شوید.");
}
}
}
}
}

View File

@ -2804,7 +2804,7 @@ namespace RMuseum.Controllers
/// <returns></returns>
[HttpPost]
[Route("startfindingmissingrhythms")]
[Route("sections/updaterelated")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]