docs: #317 moving prosody information in poem summary model view to its sections field

This commit is contained in:
Hamid Reza Mohammadi 2022-05-05 15:40:22 +04:30
parent 86606185b0
commit 88f3e442fe
7 changed files with 104 additions and 51 deletions

View File

@ -188,10 +188,7 @@
ابتدا
</th>
<th>
حروف قافیه
</th>
<th>
وزن
بخش‌ها
</th>
<th>
<input type="checkbox" id="poems-select-switch" onclick="onSwitchPoemsSelections()" />
@ -207,10 +204,37 @@
@poem.Excerpt
</td>
<td>
@poem.RhymeLetters
</td>
<td>
@poem.Rhythm
<table>
<tr>
<th>
ابتدا
</th>
<th>
وزن اصلی
</th>
<th>
قافیه
</th>
</tr>
@foreach (var s in poem.MainSections)
{
<tr>
<td>
@s.Excerpt
</td>
<td>
@if(s.GanjoorMetre != null)
{
@s.GanjoorMetre.Rhythm
}
</td>
<td>
@s.RhymeLetters
</td>
</tr>
}
</table>
</td>
<td>
<input type="checkbox" id="select-@poem.Id" data-value="@poem.Id" class="poemSelect" />

View File

@ -398,6 +398,7 @@ namespace RMuseum.Controllers
/// </summary>
/// <param name="id"></param>
/// <param name="poems"></param>
/// <param name="mainSections"></param>
/// <returns></returns>
[HttpGet]
[Route("cat/{id}")]
@ -405,13 +406,13 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetCompleteViewModel))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> GetCatById(int id, bool poems = true)
public async Task<IActionResult> GetCatById(int id, bool poems = true, bool mainSections = false)
{
var cacheKey = $"cat/byid/{id}/{poems}";
if (!_memoryCache.TryGetValue(cacheKey, out GanjoorPoetCompleteViewModel cat))
{
RServiceResult<GanjoorPoetCompleteViewModel> res =
await _ganjoorService.GetCatById(id, poems);
await _ganjoorService.GetCatById(id, poems, mainSections);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
if (res.Result == null)
@ -430,6 +431,7 @@ namespace RMuseum.Controllers
/// </summary>
/// <param name="url"></param>
/// <param name="poems"></param>
/// <param name="mainSections"></param>
/// <returns></returns>
[HttpGet]
[Route("cat")]
@ -437,13 +439,13 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetCompleteViewModel))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> GetCatByUrl(string url, bool poems = true)
public async Task<IActionResult> GetCatByUrl(string url, bool poems = true, bool mainSections = false)
{
var cacheKey = $"cat/byurl/{url}/{poems}";
if (!_memoryCache.TryGetValue(cacheKey, out GanjoorPoetCompleteViewModel cat))
{
RServiceResult<GanjoorPoetCompleteViewModel> res =
await _ganjoorService.GetCatByUrl(url, poems);
await _ganjoorService.GetCatByUrl(url, poems, mainSections);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
if (res.Result == null)

View File

@ -118,5 +118,11 @@ namespace RMuseum.Models.Ganjoor
/// </summary>
[NotMapped]
public bool Modified { get; set; }
/// <summary>
/// excerpt
/// </summary>
[NotMapped]
public string Excerpt { get; set; }
}
}

View File

@ -26,16 +26,9 @@
public string Excerpt { get; set; }
/// <summary>
/// Rythm
/// whole poem sections
/// </summary>
/// <example>مفاعیلن مفاعیلن فعولن</example>
public string Rhythm { get; set; }
/// <summary>
/// rhyme letters
/// </summary>
public string RhymeLetters { get; set; }
public GanjoorPoemSection[] MainSections { get; set; }
}
}

View File

@ -964,20 +964,22 @@
<param name="id">poet image</param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetCatById(System.Int32,System.Boolean)">
<member name="M:RMuseum.Controllers.GanjoorController.GetCatById(System.Int32,System.Boolean,System.Boolean)">
<summary>
cat by id
</summary>
<param name="id"></param>
<param name="poems"></param>
<param name="mainSections"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetCatByUrl(System.String,System.Boolean)">
<member name="M:RMuseum.Controllers.GanjoorController.GetCatByUrl(System.String,System.Boolean,System.Boolean)">
<summary>
cat by full url
</summary>
<param name="url"></param>
<param name="poems"></param>
<param name="mainSections"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.BatchRenameCatPoemTitles(System.Int32,RMuseum.Models.Ganjoor.ViewModels.GanjoorBatchNamingModel)">
@ -7107,6 +7109,11 @@
modified
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorPoemSection.Excerpt">
<summary>
excerpt
</summary>
</member>
<member name="T:RMuseum.Models.Ganjoor.GanjoorPoemTranslation">
<summary>
poem translation
@ -8844,15 +8851,9 @@
excerpt text
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemSummaryViewModel.Rhythm">
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemSummaryViewModel.MainSections">
<summary>
Rythm
</summary>
<example>مفاعیلن مفاعیلن فعولن</example>
</member>
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemSummaryViewModel.RhymeLetters">
<summary>
rhyme letters
whole poem sections
</summary>
</member>
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemTranslationViewModel">
@ -11139,20 +11140,22 @@
<param name="url"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.GetCatById(System.Int32,System.Boolean)">
<member name="M:RMuseum.Services.IGanjoorService.GetCatById(System.Int32,System.Boolean,System.Boolean)">
<summary>
get cat by id
</summary>
<param name="id"></param>
<param name="poems"></param>
<param name="mainSections"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.GetCatByUrl(System.String,System.Boolean)">
<member name="M:RMuseum.Services.IGanjoorService.GetCatByUrl(System.String,System.Boolean,System.Boolean)">
<summary>
get cat by url
</summary>
<param name="url"></param>
<param name="poems"></param>
<param name="mainSections"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.GetPageByUrl(System.String,System.Boolean)">
@ -13892,20 +13895,22 @@
<param name="url"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetCatByUrl(System.String,System.Boolean)">
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetCatByUrl(System.String,System.Boolean,System.Boolean)">
<summary>
get cat by url
</summary>
<param name="url"></param>
<param name="poems"></param>
<param name="mainSections"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetCatById(System.Int32,System.Boolean)">
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetCatById(System.Int32,System.Boolean,System.Boolean)">
<summary>
get cat by id
</summary>
<param name="id"></param>
<param name="poems"></param>
<param name="mainSections"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPageUrlById(System.Int32)">

View File

@ -49,16 +49,18 @@ namespace RMuseum.Services
/// </summary>
/// <param name="id"></param>
/// <param name="poems"></param>
/// <param name="mainSections"></param>
/// <returns></returns>
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatById(int id, bool poems = false);
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatById(int id, bool poems = false, bool mainSections = false);
/// <summary>
/// get cat by url
/// </summary>
/// <param name="url"></param>
/// <param name="poems"></param>
/// <param name="mainSections"></param>
/// <returns></returns>
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatByUrl(string url, bool poems = false);
Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatByUrl(string url, bool poems = false, bool mainSections = false);
/// <summary>
/// get page by url

View File

@ -154,8 +154,9 @@ namespace RMuseum.Services.Implementation
/// </summary>
/// <param name="url"></param>
/// <param name="poems"></param>
/// <param name="mainSections"></param>
/// <returns></returns>
public async Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatByUrl(string url, bool poems = false)
public async Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatByUrl(string url, bool poems = false, bool mainSections = false)
{
// /hafez/ => /hafez :
if (url.LastIndexOf('/') == url.Length - 1)
@ -165,7 +166,7 @@ namespace RMuseum.Services.Implementation
var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url).AsNoTracking().SingleOrDefaultAsync();
if (cat == null)
return new RServiceResult<GanjoorPoetCompleteViewModel>(null);
return await GetCatById(cat.Id, poems);
return await GetCatById(cat.Id, poems, mainSections);
}
/// <summary>
@ -173,8 +174,9 @@ namespace RMuseum.Services.Implementation
/// </summary>
/// <param name="id"></param>
/// <param name="poems"></param>
/// <param name="mainSections"></param>
/// <returns></returns>
public async Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatById(int id, bool poems = false)
public async Task<RServiceResult<GanjoorPoetCompleteViewModel>> GetCatById(int id, bool poems = false, bool mainSections = false)
{
var cat = await _context.GanjoorCategories.Include(c => c.Poet).Include(c => c.Parent).Where(c => c.Id == id).AsNoTracking().FirstOrDefaultAsync();
if (cat == null)
@ -293,14 +295,34 @@ namespace RMuseum.Services.Implementation
Title = p.Title,
UrlSlug = p.UrlSlug,
Excerpt = _context.GanjoorVerses.Where(v => v.PoemId == p.Id && v.VOrder == 1).FirstOrDefault().Text,
Rhythm = p.GanjoorMetre.Rhythm,
RhymeLetters = p.RhymeLetters
}
).AsNoTracking().ToListAsync()
:
null
};
if(poems && mainSections)
{
foreach (var poem in catViewModel.Poems)
{
poem.MainSections = await _context.GanjoorPoemSections.AsNoTracking().Include(s => s.GanjoorMetre).Where(s => s.PoemId == poem.Id && s.SectionType == PoemSectionType.WholePoem && s.VerseType == VersePoemSectionType.First).OrderBy(s => s.Index).ToArrayAsync();
foreach (var section in poem.MainSections)
{
section.Excerpt = (await _context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == section.PoemId &&
(
(section.VerseType == VersePoemSectionType.First && v.SectionIndex1 == section.Index)
||
(section.VerseType == VersePoemSectionType.Second && v.SectionIndex2 == section.Index)
||
(section.VerseType == VersePoemSectionType.Third && v.SectionIndex3 == section.Index)
||
(section.VerseType == VersePoemSectionType.Forth && v.SectionIndex4 == section.Index)
)
).OrderBy(v => v.VOrder).FirstOrDefaultAsync()).Text;
}
}
}
return new RServiceResult<GanjoorPoetCompleteViewModel>
(
new GanjoorPoetCompleteViewModel()
@ -1197,15 +1219,14 @@ namespace RMuseum.Services.Implementation
string searchConditions = null;
if (!string.IsNullOrEmpty(term))
{
/// You need to run this scripts manually on the database before using this method:
///
/// CREATE FULLTEXT CATALOG [GanjoorHtmlCommentTextCatalog] WITH ACCENT_SENSITIVITY = OFF AS DEFAULT
///
/// CREATE FULLTEXT INDEX ON [dbo].[GanjoorComments](
/// [HtmlComment] LANGUAGE 'English')
/// KEY INDEX [PK_GanjoorComments]ON ([GanjoorHtmlCommentTextCatalog], FILEGROUP [PRIMARY])
/// WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
///
/* You need to run this scripts manually on the database before using this method:
CREATE FULLTEXT CATALOG [GanjoorHtmlCommentTextCatalog] WITH ACCENT_SENSITIVITY = OFF AS DEFAULT
CREATE FULLTEXT INDEX ON [dbo].[GanjoorComments](
[HtmlComment] LANGUAGE 'English')
KEY INDEX [PK_GanjoorComments]ON ([GanjoorHtmlCommentTextCatalog], FILEGROUP [PRIMARY])
WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
*/
term = term.Replace("‌", " ");//replace zwnj with space
if (term.IndexOf('"') == 0 && term.LastIndexOf('"') == (term.Length - 1))