Related Work Items: #428
This commit is contained in:
Hamid Reza Mohammadi 2025-02-27 17:20:07 +03:30
parent 60745c61f3
commit 278efe5a03
4 changed files with 94 additions and 40 deletions

View File

@ -44,7 +44,7 @@ else
</tr>
<tr>
<td>
<input asp-for="ModerationModel.Approved" />
</td>
</tr>
@ -67,7 +67,7 @@ else
</form>
<table>
<tr>
<td>
بیت مرجع از <a href="/?p=@Model.GanjoorQuotedPoem.PoemId">شعر</a>:
@ -130,7 +130,14 @@ else
<td>
@if (Model.GanjoorQuotedPoem.RelatedCoupletIndex != null && Model.GanjoorQuotedPoem.RelatedCoupletIndex != -1)
{
<p>@($"{(Model.RelatedCouplets[(int)Model.GanjoorQuotedPoem.RelatedCoupletIndex].Item1 + 1).ToPersianNumbers()} - {Model.RelatedCouplets[(int)Model.GanjoorQuotedPoem.RelatedCoupletIndex].Item2}")</p>
if (Model.GanjoorQuotedPoem.RelatedCoupletIndex < Model.RelatedCouplets.Length)
{
<p>@($"{(Model.RelatedCouplets[(int)Model.GanjoorQuotedPoem.RelatedCoupletIndex].Item1 + 1).ToPersianNumbers()} - {Model.RelatedCouplets[(int)Model.GanjoorQuotedPoem.RelatedCoupletIndex].Item2}")</p>
}
else{
<p class="red-color">خطا</p>
}
}
</td>

View File

@ -67,11 +67,6 @@ namespace GanjooRazor.Areas.Admin.Pages
{
case VersePosition.Comment:
incompleteCouplet = false;
if (!string.IsNullOrEmpty(coupletText))
{
couplets.Add(new Tuple<int, string>(coupetIndex, coupletText));
coupletText = "";
}
break;
case VersePosition.Paragraph:
case VersePosition.Single:

View File

@ -23,13 +23,67 @@
document.getElementById('finalize-select2').style.display = 'block';
}
function getCouplets(verses) {
let coupetIndex = -1;
let coupletText = "";
let coupletIndices = [];
let coupletTexts = [];
let verseIndex = 0;
let incompleteCouplet = false;
while (verseIndex < verses.length) {
switch (verses[verseIndex].versePosition) {
case 5: // Comment
incompleteCouplet = false;
break;
case -1: // Paragraph
case 4: // Single
incompleteCouplet = false;
if (coupletText) {
coupletIndices.push(coupetIndex);
coupletTexts.push(coupletText);
coupletText = "";
}
coupetIndex++;
coupletIndices.push(coupetIndex);
coupletTexts.push(verses[verseIndex].text);
break;
case 0: // Right
case 2: // CenteredVerse1
incompleteCouplet = false;
if (coupletText) {
coupletIndices.push(coupetIndex);
coupletTexts.push(coupletText);
}
coupetIndex++;
coupletText = verses[verseIndex].text;
break;
case 1: // Left
case 3: // CenteredVerse2
incompleteCouplet = true;
coupletText += ` - ${verses[verseIndex].text}`;
break;
}
verseIndex++;
}
if (incompleteCouplet && coupletText) {
coupletIndices.push(coupetIndex);
coupletTexts.push(coupletText);
}
return { coupletIndices, coupletTexts };
}
function finalizeSelectPage() {
document.getElementById('loading-selection').style.display = 'block';
document.getElementById('finalize-select2').style.display = 'none';
document.getElementById('display-frame').style.display = 'block';
document.getElementById('select-poem').style.display = 'none';
document.getElementById('finalize-select').style.display = 'none';
const currentUrl = document.getElementById('select-poem').contentWindow.location.href;
@ -55,20 +109,9 @@
document.getElementById('GanjoorQuotedPoem_CachedRelatedPoemFullTitle').value = json.poem.fullTitle;
document.getElementById('GanjoorQuotedPoem_CachedRelatedPoemFullUrl').value = json.poem.fullUrl;
var coupletIndices = [];
var coupletTexts = [];
for (var i = 0; i < json.poem.verses.length; i++) {
var verse = json.poem.verses[i];
if (coupletIndices.indexOf(verse.coupletIndex) != -1) {
coupletTexts[coupletIndices.indexOf(verse.coupletIndex)] += ' - ';
coupletTexts[coupletIndices.indexOf(verse.coupletIndex)] += verse.text;
}
else {
coupletIndices.push(verse.coupletIndex);
coupletTexts.push(verse.text);
}
}
const result = getCouplets(json.poem.verses);
var coupletIndices = result.coupletIndices;
var coupletTexts = result.coupletTexts;
var x = document.getElementById("GanjoorQuotedPoem_RelatedCoupletIndex");
x.length = 0;
@ -84,7 +127,7 @@
}).catch((error) => {
document.getElementById('loading-selection').style.display = 'none';
alert('صفحه‌ای که انتخاب کرده‌اید حاوی یک شعر نیست. جزئیات بیشتر: ' + error);
alert('در انتخاب صفحه خطایی رخ داد. جزئیات بیشتر: ' + error);
selectGanjoorPage();
});
@ -105,7 +148,7 @@
از فهرست زیر بیتی را که نقل قول در آن رخ داده مشخص کنید.
</p>
</div>
</td>
</tr>
<tr>
@ -114,7 +157,7 @@
<input type="hidden" asp-for="GanjoorQuotedPoem.Id" />
<input type="hidden" asp-for="GanjoorQuotedPoem.PoemId" />
<input type="hidden" asp-for="GanjoorQuotedPoem.PoetId" />
</td>
</tr>
<tr>
@ -179,7 +222,7 @@
</td>
</tr>
@if (Model.GanjoorQuotedPoem.RelatedPoemId != null)
{
<tr>
@ -219,11 +262,11 @@
</tr>
<tr>
<td>
<div class="notice">
<p>
اگر شعر را از طریق دکمهٔ «گزینش شعر مرتبط» انتخاب کرده‌اید کادر زیر را خالی بگذارید.
</p>
</div>
<div class="notice">
<p>
اگر شعر را از طریق دکمهٔ «گزینش شعر مرتبط» انتخاب کرده‌اید کادر زیر را خالی بگذارید.
</p>
</div>
</td>
</tr>
<tr>
@ -299,7 +342,7 @@
شاعر:
</td>
</tr>
<tr>
<td>
<input asp-for="GanjoorQuotedPoem.RelatedPoetId" hidden />
@ -329,7 +372,6 @@
</tr>
<tr>
<td>
</td>
</tr>
<tr>
@ -382,7 +424,7 @@
</tr>
<tr><td><hr /></td></tr>
</table>
</form>

View File

@ -60,11 +60,6 @@ namespace GanjooRazor.Areas.User.Pages
{
case VersePosition.Comment:
incompleteCouplet = false;
if (!string.IsNullOrEmpty(coupletText))
{
couplets.Add(new Tuple<int, string>(coupetIndex, coupletText));
coupletText = "";
}
break;
case VersePosition.Paragraph:
case VersePosition.Single:
@ -249,6 +244,21 @@ namespace GanjooRazor.Areas.User.Pages
RelatedCouplets = GetCouplets(RelatedPoem.Verses);
}
int cIndex = -1;
foreach (var verse in RelatedPoem.Verses)
{
if (verse.VersePosition != VersePosition.Left && verse.VersePosition != VersePosition.CenteredVerse2 && verse.VersePosition != VersePosition.Comment)
cIndex++;
if (verse.VersePosition != VersePosition.Comment)
{
verse.CoupletIndex = cIndex;
}
else
{
verse.CoupletIndex = null;
}
}
if (GanjoorQuotedPoem.RelatedCoupletIndex != null)
{
GanjoorQuotedPoem.RelatedCoupletVerse1 = RelatedPoem.Verses.Where(v => v.CoupletIndex == GanjoorQuotedPoem.RelatedCoupletIndex).Count() < 1 ? "" : RelatedPoem.Verses.Where(v => v.CoupletIndex == GanjoorQuotedPoem.RelatedCoupletIndex).ToArray()[0].Text;