diff --git a/GanjooRazor/Pages/Index.cshtml.cs b/GanjooRazor/Pages/Index.cshtml.cs index b823bd86..077153d7 100644 --- a/GanjooRazor/Pages/Index.cshtml.cs +++ b/GanjooRazor/Pages/Index.cshtml.cs @@ -1285,6 +1285,17 @@ namespace GanjooRazor.Pages public async Task OnGetCategoryWordCountsAsync(int catId, int poetId) { + var wordSumsResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/audio/wordsums/{catId}"); + + if (!wordSumsResponse.IsSuccessStatusCode) + { + return new BadRequestObjectResult(JsonConvert.DeserializeObject(await wordSumsResponse.Content.ReadAsStringAsync())); + } + var wordSums = JsonConvert.DeserializeObject(await wordSumsResponse.Content.ReadAsStringAsync()); + if(wordSums.TotalWordCount == 0) + { + return new BadRequestObjectResult(JsonConvert.DeserializeObject("شمارش واژگان انجام نشده.")); + } var wordCountsResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/wordcounts/{catId}?PageNumber=1&PageSize=100"); if (!wordCountsResponse.IsSuccessStatusCode) @@ -1302,13 +1313,15 @@ namespace GanjooRazor.Pages { CatId = catId, PoetId = poetId, - WordCounts = wordCounts + WordCounts = wordCounts, + UniqueWordCount = wordSums.UniqueWordCount, + TotalWordCount = wordSums.TotalWordCount, } } }; } - public async Task OnGetSearchCategoryWordCountsAsync(int catId, int poetId, string term) + public async Task OnGetSearchCategoryWordCountsAsync(int catId, int poetId, string term, int totalWordCount) { var wordCountsResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/wordcounts/{catId}?PageNumber=1&PageSize=100&term={term}"); @@ -1327,7 +1340,8 @@ namespace GanjooRazor.Pages { CatId = catId, PoetId = poetId, - WordCounts = wordCounts + WordCounts = wordCounts, + TotalWordCount = totalWordCount, } } }; diff --git a/GanjooRazor/Pages/_CategoryWordsCountPartial.cshtml b/GanjooRazor/Pages/_CategoryWordsCountPartial.cshtml index 61d17000..571e4a63 100644 --- a/GanjooRazor/Pages/_CategoryWordsCountPartial.cshtml +++ b/GanjooRazor/Pages/_CategoryWordsCountPartial.cshtml @@ -9,8 +9,11 @@
بسامد واژگان جمع شود / باز شود
+

+ @RMuseum.Services.Implementation.LanguageUtils.FormatMoney(Model.TotalWordCount) واژهٔ این بخش از @RMuseum.Services.Implementation.LanguageUtils.FormatMoney(Model.UniqueWordCount) تشکیل شده است. +

- +
diff --git a/GanjooRazor/Pages/_CategoryWordsCountPartial.cshtml.cs b/GanjooRazor/Pages/_CategoryWordsCountPartial.cshtml.cs index 3030cc63..290e1a91 100644 --- a/GanjooRazor/Pages/_CategoryWordsCountPartial.cshtml.cs +++ b/GanjooRazor/Pages/_CategoryWordsCountPartial.cshtml.cs @@ -15,6 +15,16 @@ namespace GanjooRazor.Pages /// public int PoetId { get; set; } + /// + /// unique word count + /// + public int UniqueWordCount { get; set; } + + /// + /// total word count + /// + public int TotalWordCount { get; set; } + /// /// words counts /// diff --git a/GanjooRazor/Pages/_CategoryWordsCountTablePartial.cshtml b/GanjooRazor/Pages/_CategoryWordsCountTablePartial.cshtml index 067f1fc6..61c4b87e 100644 --- a/GanjooRazor/Pages/_CategoryWordsCountTablePartial.cshtml +++ b/GanjooRazor/Pages/_CategoryWordsCountTablePartial.cshtml @@ -3,11 +3,14 @@ @{ } +@if (Model.TotalWordCount == 0) return; + + @for (int i = 0; i < Model.WordCounts.Length; i++) { @@ -17,6 +20,7 @@ + } @@ -26,6 +30,7 @@ + } } diff --git a/GanjooRazor/Pages/_CategoryWordsCountTablePartial.cshtml.cs b/GanjooRazor/Pages/_CategoryWordsCountTablePartial.cshtml.cs index ffb8563e..1e35c63e 100644 --- a/GanjooRazor/Pages/_CategoryWordsCountTablePartial.cshtml.cs +++ b/GanjooRazor/Pages/_CategoryWordsCountTablePartial.cshtml.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using RMuseum.Models.Ganjoor; @@ -16,6 +15,11 @@ namespace GanjooRazor.Pages /// public int PoetId { get; set; } + /// + /// total word count + /// + public int TotalWordCount { get; set; } + /// /// words counts /// diff --git a/GanjooRazor/wwwroot/js/bk.js b/GanjooRazor/wwwroot/js/bk.js index ad1beb3c..834b24e1 100644 --- a/GanjooRazor/wwwroot/js/bk.js +++ b/GanjooRazor/wwwroot/js/bk.js @@ -1534,7 +1534,7 @@ function loadWordCounts(catId, poetId) { }); } -function onSearchWordCounts(catId, poetId) { +function onSearchWordCounts(catId, poetId, totalWordCount) { setTimeout(function () { var value = document.getElementById('wordcountterm').value; var divParent = document.getElementById('wordcounts-section'); @@ -1542,7 +1542,7 @@ function onSearchWordCounts(catId, poetId) { divParent.innerHTML = '
بارگذاری
'; $.ajax({ type: "GET", - url: '?Handler=SearchCategoryWordCounts&catId=' + String(catId) + '&poetId=' + String(poetId) + '&term=' + value, + url: '?Handler=SearchCategoryWordCounts&catId=' + String(catId) + '&poetId=' + String(poetId) + '&totalWordCount' + String(totalWordCount) + '&term=' + value, error: function () { document.getElementById("remove-this-wordcounts").remove(); },
ردیف واژه شماردرصد از کل
@Model.WordCounts[i].RowNmbrInCat.ToPersianNumbers() @Model.WordCounts[i].Word @RMuseum.Services.Implementation.LanguageUtils.FormatMoney(Model.WordCounts[i].Count)@(Model.WordCounts[i].Count * 100.0 / Model.TotalWordCount).ToString("N4", new CultureInfo("fa-IR")).ToPersianNumbers())
@Model.WordCounts[i].RowNmbrInCat.ToPersianNumbers() @Model.WordCounts[i].Word @RMuseum.Services.Implementation.LanguageUtils.FormatMoney(Model.WordCounts[i].Count)@(Model.WordCounts[i].Count * 100.0 / Model.TotalWordCount).ToString("N4", new CultureInfo("fa-IR")).ToPersianNumbers())