#154 toc geneeration in UI
This commit is contained in:
parent
7ed761ebcb
commit
894569e86c
@ -8,7 +8,7 @@
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<p>@Model.LastMessage</p>
|
||||
<p>@Html.Raw(Model.LastMessage)</p>
|
||||
|
||||
<form method="post">
|
||||
<table style="width:100%" class="noborder">
|
||||
@ -129,3 +129,21 @@
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<form action="?Handler=GenerateCatPage&id=@Model.PageInformation.Id" method="post">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="radio" asp-for="GanjoorTOC" value="0" />بر اساس تحلیل بخش<br />
|
||||
<input type="radio" asp-for="GanjoorTOC" value="1" />فقط عناوین<br />
|
||||
<input type="radio" asp-for="GanjoorTOC" value="2" />عنوان و مصرع اول<br />
|
||||
<input type="radio" asp-for="GanjoorTOC" value="3" />الفبایی با مصرع اول<br />
|
||||
<input type="radio" asp-for="GanjoorTOC" value="4" />الفبایی با مصرع دوم<br />
|
||||
<input type="radio" asp-for="GanjoorTOC" value="5" />الفبایی با بیت اول<br />
|
||||
</td>
|
||||
<td>
|
||||
<button type="submit" style="width:100%;color:white;background-color:blue">تولید</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
@ -49,18 +49,19 @@ namespace GanjooRazor.Areas.Admin.Pages
|
||||
/// </summary>
|
||||
public GanjoorPageCompleteViewModel PageInformation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ganjoor toc
|
||||
/// </summary>
|
||||
[BindProperty]
|
||||
public GanjoorTOC GanjoorTOC { get; set; }
|
||||
/// <summary>
|
||||
/// last message
|
||||
/// </summary>
|
||||
public string LastMessage { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
private async Task PreparePage()
|
||||
{
|
||||
LastMessage = Request.Query["edit"] == "true" ? "ویرایش انجام شد." : "";
|
||||
if (string.IsNullOrEmpty(Request.Query["id"]))
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "شناسهٔ صفحه مشخص نیست.");
|
||||
}
|
||||
|
||||
var rhythmResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/rhythms");
|
||||
|
||||
rhythmResponse.EnsureSuccessStatusCode();
|
||||
@ -70,20 +71,13 @@ namespace GanjooRazor.Areas.Admin.Pages
|
||||
|
||||
var pageUrlResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={Request.Query["id"]}");
|
||||
|
||||
if (!pageUrlResponse.IsSuccessStatusCode)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, await pageUrlResponse.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
pageUrlResponse.EnsureSuccessStatusCode();
|
||||
|
||||
var pageUrl = JsonConvert.DeserializeObject<string>(await pageUrlResponse.Content.ReadAsStringAsync());
|
||||
|
||||
var pageQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={pageUrl}");
|
||||
if (!pageQuery.IsSuccessStatusCode)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, await pageQuery.Content.ReadAsStringAsync());
|
||||
}
|
||||
pageQuery.EnsureSuccessStatusCode();
|
||||
|
||||
PageInformation = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject<GanjoorPageCompleteViewModel>();
|
||||
|
||||
ModifyModel = new GanjoorModifyPageViewModel()
|
||||
@ -99,11 +93,21 @@ namespace GanjooRazor.Areas.Admin.Pages
|
||||
RhymeLetters = PageInformation.Poem == null ? null : PageInformation.Poem.RhymeLetters,
|
||||
Rhythm = PageInformation.Poem == null ? null : PageInformation.Poem.GanjoorMetre == null ? null : PageInformation.Poem.GanjoorMetre.Rhythm
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
LastMessage = Request.Query["edit"] == "true" ? "ویرایش انجام شد." : "";
|
||||
if (string.IsNullOrEmpty(Request.Query["id"]))
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "شناسهٔ صفحه مشخص نیست.");
|
||||
}
|
||||
GanjoorTOC = GanjoorTOC.Analyse;
|
||||
await PreparePage();
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
public async Task<IActionResult> OnPostAsync(GanjoorModifyPageViewModel ModifyModel)
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
@ -117,12 +121,39 @@ namespace GanjooRazor.Areas.Admin.Pages
|
||||
{
|
||||
LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostGenerateCatPageAsync(GanjoorTOC GanjoorTOC)
|
||||
{
|
||||
await PreparePage();
|
||||
|
||||
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/cat?url={PageInformation.FullUrl}&poems=true");
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var Cat = JsonConvert.DeserializeObject<GanjoorPoetCompleteViewModel>(await response.Content.ReadAsStringAsync());
|
||||
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
var htmlRes = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/cat/toc/{Cat.Cat.Id}/{(int)GanjoorTOC}");
|
||||
htmlRes.EnsureSuccessStatusCode();
|
||||
|
||||
ModifyModel.HtmlText = await htmlRes.Content.ReadAsStringAsync();
|
||||
|
||||
LastMessage = $"متن تولیدی دریافت شد. لطفا آن را کپی کنید و سپس <a href=\"/Admin/ModifyPage?id={Request.Query["id"]}\">اینجا</a> کلیک کنید و آن را درج نمایید.";
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
|
||||
}
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -476,6 +476,7 @@ namespace RMuseum.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("cat/toc/{id}/{options}")]
|
||||
[Produces("text/plain")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user