#186 api for delete corrections and other utilities
This commit is contained in:
parent
61f41547e2
commit
f363fd4f4e
@ -3,31 +3,47 @@
|
||||
@using DNTPersianUtils.Core
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
ViewData["Title"] = "ویرایشگر شعر";
|
||||
ViewData["Title"] = "ویرایشگر";
|
||||
await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.FatalError))
|
||||
{
|
||||
<p>@Model.FatalError</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p><a role="button" target="_blank" href="@Model.PageInformation.FullUrl" class="actionlink">@Model.PageInformation.FullTitle</a></p>
|
||||
|
||||
@if (Model.PageInformation.Poem.Previous != null)
|
||||
{
|
||||
<p><a href="/User/Editor?id=@Model.PageInformation.Poem.Previous.Id">ویرایش شعر قبل</a></p>
|
||||
}
|
||||
@if (Model.PageInformation.Poem.Next != null)
|
||||
{
|
||||
<p><a href="/User/Editor?id=@Model.PageInformation.Poem.Next.Id">ویرایش شعر بعد</a></p>
|
||||
}
|
||||
|
||||
if (Model.MyLastEdit != null)
|
||||
{
|
||||
<table>
|
||||
<tr>
|
||||
<td colspan="2">ویرایشهای من</td>
|
||||
<td colspan="2">ویرایشهای بررسی نشدهٔ من</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>متن اولیه</td>
|
||||
<td>تغییرات من</td>
|
||||
</tr>
|
||||
|
||||
@if (Model.MyLastEdit.Title != null)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<p style="color:red">@Model.MyLastEdit.Title</p>
|
||||
<p style="color:red">@Model.MyLastEdit.OriginalTitle</p>
|
||||
</td>
|
||||
<td>
|
||||
<p style="color:green">@Model.MyLastEdit.OriginalTitle</p>
|
||||
<p style="color:green">@Model.MyLastEdit.Title</p>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@ -35,10 +51,10 @@ else
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<p style="color:red">@Model.MyLastEdit.Rhythm</p>
|
||||
<p style="color:red">@Model.MyLastEdit.OriginalRhythm</p>
|
||||
</td>
|
||||
<td>
|
||||
<p style="color:green">@Model.MyLastEdit.OriginalRhythm</p>
|
||||
<p style="color:green">@Model.MyLastEdit.Rhythm</p>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@ -64,6 +80,12 @@ else
|
||||
</tr>
|
||||
}
|
||||
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<a role="button" id="deletecorrections" style="cursor:pointer;width:100%;color:white;background-color:red;display:block" onclick="deletePoemCorrections(@Model.PageInformation.Poem.Id)">انصراف و حذف این ویرایش</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
}
|
||||
|
||||
@ -90,7 +112,19 @@ else
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="id-0" name="id-0" value="@Model.PageInformation.Poem.Title" size="100" oninput="editorcompare(0)" />
|
||||
@if (Model.MyLastEdit != null && Model.MyLastEdit.Title != null)
|
||||
{
|
||||
<input type="text" id="id-0" name="id-0" value="@Model.MyLastEdit.Title" size="50" oninput="editorcompare(0)" />
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
editorcompare(0);
|
||||
});
|
||||
</script>
|
||||
}
|
||||
else
|
||||
{
|
||||
<input type="text" id="id-0" name="id-0" value="@Model.PageInformation.Poem.Title" size="50" oninput="editorcompare(0)" />
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -137,7 +171,19 @@ else
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="id-@($"{verse.VOrder}")" name="name-@($"{verse.VOrder}")" value="@verse.Text" size="100" oninput="editorcompare(@verse.VOrder)" />
|
||||
@if (Model.MyLastEdit != null && Model.MyLastEdit.VerseOrderText != null && Model.MyLastEdit.VerseOrderText.Where(v => v.VORder == verse.VOrder).Any())
|
||||
{
|
||||
<input type="text" id="id-@($"{verse.VOrder}")" name="name-@($"{verse.VOrder}")" value="@Model.MyLastEdit.VerseOrderText.Where(v => v.VORder == verse.VOrder).First().Text" size="50" oninput="editorcompare(@verse.VOrder)" />
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
editorcompare(@verse.VOrder);
|
||||
});
|
||||
</script>
|
||||
}
|
||||
else
|
||||
{
|
||||
<input type="text" id="id-@($"{verse.VOrder}")" name="name-@($"{verse.VOrder}")" value="@verse.Text" size="50" oninput="editorcompare(@verse.VOrder)" />
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -170,7 +216,15 @@ else
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="rhythm-new" name="rhythm-new" value="@(Model.PageInformation.Poem.GanjoorMetre == null ? "" : Model.PageInformation.Poem.GanjoorMetre.Rhythm)" size="100" list="rythms" />
|
||||
@if (Model.MyLastEdit != null && Model.MyLastEdit.Rhythm != null)
|
||||
{
|
||||
<input type="text" id="rhythm-new" name="rhythm-new" value="@Model.MyLastEdit.Rhythm" size="50" list="rythms" />
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
<input type="text" id="rhythm-new" name="rhythm-new" value="@(Model.PageInformation.Poem.GanjoorMetre == null ? "" : Model.PageInformation.Poem.GanjoorMetre.Rhythm)" size="50" list="rythms" />
|
||||
}
|
||||
<datalist id="rythms">
|
||||
@if (Model.Rhythms != null)
|
||||
@foreach (var rhythm in Model.Rhythms)
|
||||
@ -188,16 +242,39 @@ else
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="note" name="note" value="" size="100" />
|
||||
@if (Model.MyLastEdit != null && !string.IsNullOrEmpty(Model.MyLastEdit.Note))
|
||||
{
|
||||
<input type="text" id="note" name="note" value="@Model.MyLastEdit.Note" size="50" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<input type="text" id="note" name="note" value="" size="50" />
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<a role="button" style="cursor:pointer;width:100%;color:white;background-color:green;display:block" onclick="savePoemCorrections(@Model.PageInformation.Poem.Id, @Model.PageInformation.Poem.Verses.Length)">ذخیره</a>
|
||||
<a role="button" id="savecorrections" style="cursor:pointer;width:100%;color:white;background-color:green;display:block" onclick="savePoemCorrections(@Model.PageInformation.Poem.Id, @Model.PageInformation.Poem.Verses.Length)">ذخیره</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><p id="saving"> </p></td>
|
||||
</tr>
|
||||
|
||||
@if (Model.PageInformation.Poem.Previous != null)
|
||||
{
|
||||
<tr>
|
||||
<td><a href="/User/Editor?id=@Model.PageInformation.Poem.Previous.Id">ویرایش شعر قبل</a></td>
|
||||
</tr>
|
||||
}
|
||||
@if (Model.PageInformation.Poem.Next != null)
|
||||
{
|
||||
<tr>
|
||||
<td><a href="/User/Editor?id=@Model.PageInformation.Poem.Next.Id">ویرایش شعر بعد</a></td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
||||
}
|
||||
@ -114,6 +114,21 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeletePoemCorrectionsAsync(int poemid)
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
HttpResponseMessage response = await secureClient.DeleteAsync(
|
||||
$"{APIRoot.Url}/api/ganjoor/poem/correction/{poemid}");
|
||||
response.EnsureSuccessStatusCode();
|
||||
return new OkObjectResult(true);
|
||||
}
|
||||
}
|
||||
return new BadRequestObjectResult("لطفا از گنجور خارج و مجددا به آن وارد شوید.");
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostSendPoemCorrectionsAsync(int poemid, string[] verseOrderText, string rhythm, string note)
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
<link href="/css/fab.css" rel="stylesheet" type="text/css" />
|
||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
|
||||
<link rel="search" type="application/opensearchdescription+xml" title="گنجور" href="https://ganjoor.net/search.xml" />
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="/lib/tinymce/tinymce.min.js"></script>
|
||||
<script>tinymce.init({ selector: 'textarea.editor', language: 'fa_IR' });</script>
|
||||
<script src="/lib/diff.js"></script>
|
||||
@ -201,7 +202,33 @@
|
||||
result.appendChild(fragment);
|
||||
}
|
||||
|
||||
function deletePoemCorrections(id) {
|
||||
if (!confirm('آیا از حذف تغییرات پیشنهادی اطمینان دارید؟'))
|
||||
return;
|
||||
|
||||
$('#deletecorrections').hide();
|
||||
$('#saving').text('در حال ذخیره ...');
|
||||
|
||||
var url = '?handler=DeletePoemCorrections';
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
data: {
|
||||
poemid: id,
|
||||
},
|
||||
error: function () {
|
||||
alert('خطا رخ داد.')
|
||||
},
|
||||
success: function () {
|
||||
location.reload(true);
|
||||
},
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function savePoemCorrections(id, verseCount) {
|
||||
|
||||
var verseOrderText = [];
|
||||
for (var i = 0; i <= verseCount; i++) {
|
||||
var oldElementName = '#original-' + i.toString();
|
||||
@ -218,6 +245,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
$('#savecorrections').hide();
|
||||
$('#saving').text('در حال ذخیره ...');
|
||||
|
||||
var rhythm_new = $('#rhythm-new').val();
|
||||
if (rhythm_new == $('#rhythm-old').text()) {
|
||||
rhythm_new = null;
|
||||
@ -239,7 +269,9 @@
|
||||
location.reload(true);
|
||||
},
|
||||
error: function (e) {
|
||||
alert(e)
|
||||
alert(e);
|
||||
$('#savecorrections').show();
|
||||
$('#saving').text('');
|
||||
}
|
||||
|
||||
});
|
||||
@ -309,8 +341,8 @@
|
||||
</main>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
|
||||
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
|
||||
|
||||
@ -808,6 +808,29 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete unreviewed user corrections for a poem
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
[Route("poem/correction/{id}")]
|
||||
[Authorize]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemCorrectionViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> DeletePoemCorrections(int id)
|
||||
{
|
||||
var userId =
|
||||
new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
|
||||
var res =
|
||||
await _ganjoorService.DeletePoemCorrections(userId, id);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns last unreviewed correction from the user for a poem
|
||||
/// </summary>
|
||||
|
||||
@ -921,6 +921,13 @@
|
||||
<param name="correction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.DeletePoemCorrections(System.Int32)">
|
||||
<summary>
|
||||
delete unreviewed user corrections for a poem
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetLastUnreviewedUserCorrectionForPoem(System.Int32)">
|
||||
<summary>
|
||||
returns last unreviewed correction from the user for a poem
|
||||
@ -7643,6 +7650,14 @@
|
||||
<param name="poemId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.DeletePoemCorrections(System.Guid,System.Int32)">
|
||||
<summary>
|
||||
delete unreviewed user corrections for a poem
|
||||
</summary>
|
||||
<param name="userId"></param>
|
||||
<param name="poemId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetNextUnreviewedSong(System.Int32,System.Guid)">
|
||||
<summary>
|
||||
next unreviewed track
|
||||
@ -9213,6 +9228,14 @@
|
||||
<param name="trackType"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeletePoemCorrections(System.Guid,System.Int32)">
|
||||
<summary>
|
||||
delete unreviewed user corrections for a poem
|
||||
</summary>
|
||||
<param name="userId"></param>
|
||||
<param name="poemId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.SuggestPoemCorrection(RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemCorrectionViewModel)">
|
||||
<summary>
|
||||
send poem correction
|
||||
|
||||
@ -152,6 +152,14 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPoemCorrectionViewModel>> GetLastUnreviewedUserCorrectionForPoem(Guid userId, int poemId);
|
||||
|
||||
/// <summary>
|
||||
/// delete unreviewed user corrections for a poem
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="poemId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> DeletePoemCorrections(Guid userId, int poemId);
|
||||
|
||||
/// <summary>
|
||||
/// next unreviewed track
|
||||
/// </summary>
|
||||
|
||||
@ -1298,6 +1298,29 @@ namespace RMuseum.Services.Implementation
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete unreviewed user corrections for a poem
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="poemId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> DeletePoemCorrections(Guid userId, int poemId)
|
||||
{
|
||||
var preCorrections = await _context.GanjoorPoemCorrections.Include(c => c.VerseOrderText)
|
||||
.Where(c => c.UserId == userId && c.PoemId == poemId && c.Result == CorrectionReviewResult.NotReviewed)
|
||||
.ToListAsync();
|
||||
if (preCorrections.Count > 0)
|
||||
{
|
||||
foreach (var preCorrection in preCorrections)
|
||||
{
|
||||
preCorrection.VerseOrderText.Clear();
|
||||
}
|
||||
_context.GanjoorPoemCorrections.RemoveRange(preCorrections);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// send poem correction
|
||||
/// </summary>
|
||||
@ -1305,6 +1328,10 @@ namespace RMuseum.Services.Implementation
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorPoemCorrectionViewModel>> SuggestPoemCorrection(GanjoorPoemCorrectionViewModel correction)
|
||||
{
|
||||
var preCorrections = await _context.GanjoorPoemCorrections.Include(c => c.VerseOrderText)
|
||||
.Where(c => c.UserId == correction.UserId && c.PoemId == correction.PoemId && c.Result == CorrectionReviewResult.NotReviewed)
|
||||
.ToListAsync();
|
||||
|
||||
var poem = (await GetPoemById(correction.PoemId, false, false, true, false, false, false, false, true, false)).Result;
|
||||
foreach (var verse in correction.VerseOrderText)
|
||||
{
|
||||
@ -1328,6 +1355,16 @@ namespace RMuseum.Services.Implementation
|
||||
await _context.SaveChangesAsync();
|
||||
correction.Id = dbCorrection.Id;
|
||||
|
||||
if(preCorrections.Count > 0)
|
||||
{
|
||||
foreach (var preCorrection in preCorrections)
|
||||
{
|
||||
preCorrection.VerseOrderText.Clear();
|
||||
}
|
||||
_context.GanjoorPoemCorrections.RemoveRange(preCorrections);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return new RServiceResult<GanjoorPoemCorrectionViewModel>(correction);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user