docs: #319 sending moderated breakpoints in sections from client

This commit is contained in:
Hamid Reza Mohammadi 2022-05-16 17:24:51 +04:30
parent 0b5ae1e36a
commit f186b4650d
2 changed files with 74 additions and 3 deletions

View File

@ -20,13 +20,24 @@ else if (@Model.Correction == null)
else
{
<script>
function moderateSectionCorrections(correctionId) {
function moderateSectionCorrections(correctionId, verseCount) {
$('#moderatecorrections').hide();
$('#saving').text('در حال بررسی ...');
var breakFromVIndices = [];
for (var i = 0; i <= verseCount; i++) {
var checkVIndex = '#break-from-' + i.toString();
if ($(checkVIndex).is(":checked")) {
breakFromVIndices.push(i);
}
}
if(breakFromVIndices.length > 4){
alert('حداکثر از ۴ محل می‌توانید قطعه را بشکنید.');
return;
}
var rhythmReviewResult = 'DontCare';
if ($('#rhythm_review_result_Approved').length > 0) {
@ -44,6 +55,7 @@ else
data: {
correctionId: correctionId,
rhythmReviewResult: rhythmReviewResult,
breakFromVIndices: breakFromVIndices,
titleReviewNote: $('#title_review_note') == null? null : $('#title_review_note').val(),
},
success: function () {
@ -77,7 +89,7 @@ else
</tr>
<tr>
<td>
<a role="button" id="moderatecorrections" style="cursor:pointer;width:100%;color:white;background-color:green;display:block" onclick="moderateSectionCorrections(@Model.Correction.Id)">بررسی</a>
<a role="button" id="moderatecorrections" style="cursor:pointer;width:100%;color:white;background-color:green;display:block" onclick="moderateSectionCorrections(@Model.Correction.Id, @Model.Verses.Count)">بررسی</a>
</td>
<td>
<form method="post">

View File

@ -170,6 +170,7 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnPostSendCorrectionsModerationAsync(int correctionId,
string rhythmReviewResult,
int[] breakFromVIndices,
string titleReviewNote)
{
using (HttpClient secureClient = new HttpClient())
@ -184,6 +185,59 @@ namespace GanjooRazor.Areas.Admin.Pages
Correction = JsonConvert.DeserializeObject<GanjoorPoemSectionCorrectionViewModel>(await correctionResponse.Content.ReadAsStringAsync());
int? breakFromVerse1VOrder = null;
int? breakFromVerse2VOrder = null;
int? breakFromVerse3VOrder = null;
int? breakFromVerse4VOrder = null;
if (breakFromVIndices.Length > 0)
{
var sectionResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/section/{Correction.SectionId}");
if (!sectionResponse.IsSuccessStatusCode)
{
FatalError = JsonConvert.DeserializeObject<string>(await sectionResponse.Content.ReadAsStringAsync());
return Page();
}
PoemSection = JsonConvert.DeserializeObject<GanjoorPoemSection>(await sectionResponse.Content.ReadAsStringAsync());
var pageUrlResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={PoemSection.PoemId}");
if (!pageUrlResponse.IsSuccessStatusCode)
{
FatalError = JsonConvert.DeserializeObject<string>(await pageUrlResponse.Content.ReadAsStringAsync());
return Page();
}
var pageUrl = JsonConvert.DeserializeObject<string>(await pageUrlResponse.Content.ReadAsStringAsync());
var pageQuery = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={pageUrl}");
if (!pageQuery.IsSuccessStatusCode)
{
FatalError = JsonConvert.DeserializeObject<string>(await pageQuery.Content.ReadAsStringAsync());
return Page();
}
PageInformation = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject<GanjoorPageCompleteViewModel>();
Verses = _FilterSectionVerses(PoemSection, PageInformation.Poem.Verses);
breakFromVerse1VOrder = Verses[breakFromVIndices[0]].VOrder;
if (breakFromVIndices.Length > 1)
{
breakFromVerse2VOrder = Verses[breakFromVIndices[1]].VOrder;
}
if (breakFromVIndices.Length > 2)
{
breakFromVerse3VOrder = Verses[breakFromVIndices[2]].VOrder;
}
if (breakFromVIndices.Length > 3)
{
breakFromVerse4VOrder = Verses[breakFromVIndices[3]].VOrder;
}
}
if (Correction.Rhythm != null)
{
@ -198,6 +252,11 @@ namespace GanjooRazor.Areas.Admin.Pages
}
}
Correction.BreakFromVerse1VOrder = breakFromVerse1VOrder;
Correction.BreakFromVerse2VOrder = breakFromVerse2VOrder;
Correction.BreakFromVerse3VOrder = breakFromVerse3VOrder;
Correction.BreakFromVerse4VOrder = breakFromVerse4VOrder;
var moderationResponse = await secureClient.PostAsync($"{APIRoot.Url}/api/ganjoor/section/moderate",
new StringContent(JsonConvert.SerializeObject(Correction), Encoding.UTF8, "application/json"