#204 phase 1 + fix for regenerating verses when the verse is related with comments
This commit is contained in:
parent
4d665ccfa6
commit
cf10eef184
@ -817,6 +817,13 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
}
|
||||
|
||||
while (poemtext.IndexOf("id=\"bn") != -1)
|
||||
{
|
||||
int idxbn1 = poemtext.IndexOf(" id=\"bn");
|
||||
int idxbn2 = poemtext.IndexOf("\"", idxbn1 + " id=\"bn".Length);
|
||||
poemtext = poemtext.Substring(0, idxbn1) + poemtext.Substring(idxbn2+1);
|
||||
}
|
||||
|
||||
|
||||
poemtext = poemtext.Replace("Adaptation du milieu", "یییییییییییییییییییی");
|
||||
poemtext = poemtext.Replace("Empirique", "ببببببببب");
|
||||
|
||||
@ -748,18 +748,20 @@ namespace RMuseum.Services.Implementation
|
||||
private static string PrepareHtmlText(List<GanjoorVerse> verses)
|
||||
{
|
||||
string htmlText = "";
|
||||
int coupletIndex = 0;
|
||||
for (int vIndex = 0; vIndex < verses.Count; vIndex++)
|
||||
{
|
||||
GanjoorVerse v = verses[vIndex];
|
||||
if (v.VersePosition == VersePosition.CenteredVerse1)
|
||||
{
|
||||
coupletIndex++;
|
||||
if (((vIndex + 1) < verses.Count) && (verses[vIndex + 1].VersePosition == VersePosition.CenteredVerse2))
|
||||
{
|
||||
htmlText += $"<div class=\"b2\"><p>{v.Text}</p>{Environment.NewLine}";
|
||||
htmlText += $"<div class=\"b2\" id=\"bn{coupletIndex}\" ><p>{v.Text}</p>{Environment.NewLine}";
|
||||
}
|
||||
else
|
||||
{
|
||||
htmlText += $"<div class=\"b2\"><p>{v.Text}</p></div>{Environment.NewLine}";
|
||||
htmlText += $"<div class=\"b2\" id=\"bn{coupletIndex}\"><p>{v.Text}</p></div>{Environment.NewLine}";
|
||||
|
||||
}
|
||||
}
|
||||
@ -772,7 +774,8 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
if (v.VersePosition == VersePosition.Right)
|
||||
{
|
||||
htmlText += $"<div class=\"b\"><div class=\"m1\"><p>{v.Text}</p></div>{Environment.NewLine}";
|
||||
coupletIndex++;
|
||||
htmlText += $"<div class=\"b\" id=\"bn{coupletIndex}\"><div class=\"m1\"><p>{v.Text}</p></div>{Environment.NewLine}";
|
||||
}
|
||||
else
|
||||
if (v.VersePosition == VersePosition.Left)
|
||||
@ -782,7 +785,7 @@ namespace RMuseum.Services.Implementation
|
||||
else
|
||||
if (v.VersePosition == VersePosition.Paragraph || v.VersePosition == VersePosition.Single)
|
||||
{
|
||||
|
||||
coupletIndex++;
|
||||
string[] lines = v.Text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
string cssClass = v.VersePosition == VersePosition.Paragraph ? "n" : "l";
|
||||
@ -791,23 +794,23 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
if (v.Text.Length / lines.Length < 150)
|
||||
{
|
||||
htmlText += $"<div class=\"{cssClass}\"><p>{v.Text.Replace("\r\n", " ")}</p></div>{Environment.NewLine}";
|
||||
htmlText += $"<div class=\"{cssClass}\" id=\"bn{coupletIndex}\"><p>{v.Text.Replace("\r\n", " ")}</p></div>{Environment.NewLine}";
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (string line in lines)
|
||||
htmlText += $"<div class=\"{cssClass}\"><p>{line}</p></div>{Environment.NewLine}";
|
||||
htmlText += $"<div class=\"{cssClass}\" id=\"bn{coupletIndex}\"><p>{line}</p></div>{Environment.NewLine}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(string.IsNullOrEmpty(v.Text))
|
||||
{
|
||||
htmlText += $"<div class=\"{cssClass}\"><p> </p></div>{Environment.NewLine}";//empty line!
|
||||
htmlText += $"<div class=\"{cssClass}\" id=\"bn{coupletIndex}\"><p> </p></div>{Environment.NewLine}";//empty line!
|
||||
}
|
||||
else
|
||||
{
|
||||
htmlText += $"<div class=\"{cssClass}\"><p>{v.Text}</p></div>{Environment.NewLine}";//not brave enough to ignore it!
|
||||
htmlText += $"<div class=\"{cssClass}\" id=\"bn{coupletIndex}\"><p>{v.Text}</p></div>{Environment.NewLine}";//not brave enough to ignore it!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2722,20 +2722,52 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
List<GanjoorVerse> verses = _extractVersesFromPoemHtmlText(id, pageData.HtmlText);
|
||||
|
||||
|
||||
dbPoem.PlainText = PreparePlainText(verses);
|
||||
|
||||
_context.GanjoorPoems.Update(dbPoem);
|
||||
|
||||
|
||||
var oldVerses = await _context.GanjoorVerses.Where(v => v.PoemId == id).ToListAsync();
|
||||
_context.GanjoorVerses.RemoveRange(oldVerses);
|
||||
|
||||
_context.GanjoorVerses.AddRange(verses);
|
||||
if (oldVerses.Count <= verses.Count)
|
||||
{
|
||||
for (int v = 0; v < oldVerses.Count; v++)
|
||||
{
|
||||
oldVerses[v].Text = verses[v].Text;
|
||||
oldVerses[v].VersePosition = verses[v].VersePosition;
|
||||
oldVerses[v].VOrder= verses[v].VOrder;
|
||||
_context.GanjoorVerses.Update(oldVerses[v]);
|
||||
}
|
||||
|
||||
for(int v = oldVerses.Count; v < verses.Count; v++)
|
||||
{
|
||||
_context.GanjoorVerses.Add(verses[v]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int v = 0; v < verses.Count; v++)
|
||||
{
|
||||
oldVerses[v].Text = verses[v].Text;
|
||||
oldVerses[v].VersePosition = verses[v].VersePosition;
|
||||
oldVerses[v].VOrder = verses[v].VOrder;
|
||||
_context.GanjoorVerses.Update(oldVerses[v]);
|
||||
}
|
||||
|
||||
for (int v = verses.Count; v < oldVerses.Count; v++)
|
||||
{
|
||||
_context.GanjoorVerses.Remove(oldVerses[v]);
|
||||
}
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<GanjoorPageCompleteViewModel>(null, exp.ToString());
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
CacheCleanForPageByUrl(dbPage.FullUrl);
|
||||
@ -3708,7 +3740,10 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
var poem = poems[i];
|
||||
|
||||
poem.PlainText = PreparePlainText(await context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == poem.Id).OrderBy(v => v.Id).ToListAsync());
|
||||
var verses = await context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == poem.Id).OrderBy(v => v.Id).ToListAsync();
|
||||
|
||||
poem.PlainText = PreparePlainText(verses);
|
||||
poem.HtmlText = PrepareHtmlText(verses);
|
||||
}
|
||||
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, $"Finalizing PlainText");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user