docs: #324 probable meters UI fixes (not tested)

This commit is contained in:
Hamid Reza Mohammadi 2022-05-23 13:12:04 +04:30
parent b42245a759
commit f9a83f03e9
2 changed files with 38 additions and 22 deletions

View File

@ -11,7 +11,7 @@
{
<p>@Model.LastMessage</p>
}
else if(Model.Rhythms != null && Model.Poem != null)
else if(Model.Rhythms != null && Model.PoemSection != null)
{
<form method="post">
<table>
@ -34,13 +34,13 @@ else if(Model.Rhythms != null && Model.Poem != null)
</tr>
<tr>
<td>
<select asp-for="Poem.GanjoorMetre.Rhythm" style="width: 500px">
<select asp-for="PoemSection.GanjoorMetre.Rhythm" style="width: 500px">
@foreach (var rhythm in Model.Rhythms)
{
<option value="@rhythm.Rhythm">@rhythm.Rhythm</option>
}
</select>
<input type="hidden" asp-for="Poem.GanjoorMetre.Id" />
<input type="hidden" asp-for="PoemSection.GanjoorMetre.Id" />
</td>
</tr>
<tr>
@ -60,7 +60,7 @@ else if(Model.Rhythms != null && Model.Poem != null)
<table>
<tr>
<td>
<input type="hidden" asp-for="Poem.GanjoorMetre.Id" />
<input type="hidden" asp-for="PoemSection.GanjoorMetre.Id" />
<button type="submit" style="width:100%;color:white;background-color:red">نادیده بگیر</button>
</td>
</tr>
@ -71,18 +71,10 @@ else if(Model.Rhythms != null && Model.Poem != null)
<table>
<tr>
<td>
<a href="@Model.Poem.FullUrl" target="_blank">@Model.Poem.FullTitle</a>
<a href="@Model.PageInformation.FullUrl" target="_blank">@Model.PageInformation.FullTitle</a>
</td>
</tr>
@foreach(var verse in Model.Poem.Verses)
{
<tr>
<td>
@verse.Text
</td>
</tr>
}
@Html.Raw(Model.PoemSection.HtmlText)
</table>
}

View File

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RMuseum.Models.Ganjoor;
using RMuseum.Models.Ganjoor.ViewModels;
using System.Collections.Generic;
@ -38,8 +39,14 @@ namespace GanjooRazor.Areas.Admin.Pages
_httpClient = httpClient;
}
public GanjoorPageCompleteViewModel PageInformation { get; set; }
/// <summary>
/// poem section
/// </summary>
[BindProperty]
public GanjoorPoemCompleteViewModel Poem { get; set; }
public GanjoorPoemSection PoemSection { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
@ -62,8 +69,8 @@ namespace GanjooRazor.Areas.Admin.Pages
}
else
{
Poem = JsonConvert.DeserializeObject<GanjoorPoemCompleteViewModel>(await response.Content.ReadAsStringAsync());
if(string.IsNullOrEmpty(Poem.GanjoorMetre.Rhythm))
PoemSection = JsonConvert.DeserializeObject<GanjoorPoemSection>(await response.Content.ReadAsStringAsync());
if(string.IsNullOrEmpty(PoemSection.GanjoorMetre.Rhythm))
{
Rhythms.Add
(
@ -74,21 +81,38 @@ namespace GanjooRazor.Areas.Admin.Pages
}
);
}
var pageUrlResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={PoemSection.PoemId}");
if (!pageUrlResponse.IsSuccessStatusCode)
{
LastMessage = JsonConvert.DeserializeObject<string>(await pageUrlResponse.Content.ReadAsStringAsync());
return Page();
}
var pageUrl = JsonConvert.DeserializeObject<string>(await pageUrlResponse.Content.ReadAsStringAsync());
var pageQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={pageUrl}");
if (!pageQuery.IsSuccessStatusCode)
{
LastMessage = JsonConvert.DeserializeObject<string>(await pageQuery.Content.ReadAsStringAsync());
return Page();
}
PageInformation = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject<GanjoorPageCompleteViewModel>();
}
return Page();
}
public async Task<IActionResult> OnPostAsync(GanjoorPoemCompleteViewModel Poem)
public async Task<IActionResult> OnPostAsync(GanjoorPoemSection PoemSection)
{
LastMessage = "";
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
int probableRecordId = Poem.GanjoorMetre.Id;
string metre = Poem.GanjoorMetre.Rhythm;
int probableRecordId = PoemSection.GanjoorMetre.Id;
string metre = PoemSection.GanjoorMetre.Rhythm;
if(string.IsNullOrEmpty(metre))
{
@ -117,14 +141,14 @@ namespace GanjooRazor.Areas.Admin.Pages
return Page();
}
public async Task<IActionResult> OnPostDismissAsync(GanjoorPoemCompleteViewModel Poem)
public async Task<IActionResult> OnPostDismissAsync(GanjoorPoemSection PoemSection)
{
LastMessage = "";
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
int probableRecordId = Poem.GanjoorMetre.Id;
int probableRecordId = PoemSection.GanjoorMetre.Id;
var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/ganjoor/probablemetre/dismiss/{probableRecordId}");
if (!response.IsSuccessStatusCode)