#444 loadWordCounts

This commit is contained in:
Hamid Reza Mohammadi 2024-06-26 09:55:17 +03:30
parent 4881990047
commit 89e1baf1bb
5 changed files with 83 additions and 28 deletions

View File

@ -308,6 +308,13 @@
</script>
}
@if(Model.IsCatPage || Model.IsPoetPage)
{
<script>
loadWordCounts(@Model.GanjoorPage.PoetOrCat.Cat.Id, @Model.GanjoorPage.PoetOrCat.Poet.Id)
</script>
}
</body>

View File

@ -954,32 +954,6 @@ namespace GanjooRazor.Pages
};
}
public async Task<ActionResult> OnGetCategoryRecitationsAsync(int catId)
{
var catTop1RecitationsQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/audio/cattop1/{catId}?includePoemText=false");
if (!catTop1RecitationsQuery.IsSuccessStatusCode)
{
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await catTop1RecitationsQuery.Content.ReadAsStringAsync()));
}
var categoryTop1Recitations = JsonConvert.DeserializeObject<PublicRecitationViewModel[]>(await catTop1RecitationsQuery.Content.ReadAsStringAsync());
return new PartialViewResult()
{
ViewName = "_AudioPlayerPartial",
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
{
Model = new _AudioPlayerPartialModel()
{
LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"]),
Recitations = categoryTop1Recitations,
ShowAllRecitaions = true,
CategoryMode = true,
}
}
};
}
public async Task<IActionResult> OnPostSwitchBookmarkAsync(int poemId, int coupletIndex)
{
using (HttpClient secureClient = new HttpClient())
@ -1281,5 +1255,58 @@ namespace GanjooRazor.Pages
}
}
}
public async Task<ActionResult> OnGetCategoryRecitationsAsync(int catId)
{
var catTop1RecitationsQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/audio/cattop1/{catId}?includePoemText=false");
if (!catTop1RecitationsQuery.IsSuccessStatusCode)
{
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await catTop1RecitationsQuery.Content.ReadAsStringAsync()));
}
var categoryTop1Recitations = JsonConvert.DeserializeObject<PublicRecitationViewModel[]>(await catTop1RecitationsQuery.Content.ReadAsStringAsync());
return new PartialViewResult()
{
ViewName = "_AudioPlayerPartial",
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
{
Model = new _AudioPlayerPartialModel()
{
LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"]),
Recitations = categoryTop1Recitations,
ShowAllRecitaions = true,
CategoryMode = true,
}
}
};
}
public async Task<ActionResult> OnGetCategoryWordCountsAsync(int catId, int poetId)
{
var wordCountsResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/wordcounts/{catId}?PageNumber=1&PageSize=100");
if (!wordCountsResponse.IsSuccessStatusCode)
{
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await wordCountsResponse.Content.ReadAsStringAsync()));
}
var wordCounts = JsonConvert.DeserializeObject<CategoryWordCount[]>(await wordCountsResponse.Content.ReadAsStringAsync());
return new PartialViewResult()
{
ViewName = "_CategoryWordsCountPartial",
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
{
Model = new _CategoryWordsCountPartialModel()
{
CatId = catId,
PoetId = poetId,
WordCounts = wordCounts
}
}
};
}
}
}

View File

@ -39,6 +39,4 @@
</table>
</div>
</div>
}

View File

@ -398,6 +398,11 @@
}
@if(Model.IsCatPage || Model.IsPoetPage)
{
<div id="wordcounts-placeholder"></div>
}
@if ((Model.IsCatPage || Model.IsPoetPage) && Model.CategoryHasRecitations)
{
<div class="spacer">&nbsp;</div>

View File

@ -1516,3 +1516,21 @@ function markAsTextOriginal(bookId, categoryId, bookName, catName) {
},
});
}
function loadWordCounts(catId, poetId) {
var divParent = document.getElementById('wordcounts-placeholder');
var imgElementId = 'loadingwordcountsimg';
divParent.innerHTML = divParent.innerHTML + '<div class="bnumdiv" id="remove-this-wordcounts"><img id="' + imgElementId + '" src="/image/loading.gif" alt="بارگذاری"/></div>';
$.ajax({
type: "GET",
url: '?Handler=CategoryWordCounts&catId=' + String(catId) + '&poetId=' + String(poetId),
error: function () {
document.getElementById("remove-this-wordcounts").remove();
},
success: function (data) {
document.getElementById("remove-this-wordcounts").remove();
$(data).appendTo(divParent);
},
});
}