#467 cat editor
This commit is contained in:
parent
4539dd8870
commit
1ade0ff13c
157
GanjooRazor/Areas/User/Pages/CatEdits.cshtml
Normal file
157
GanjooRazor/Areas/User/Pages/CatEdits.cshtml
Normal file
@ -0,0 +1,157 @@
|
||||
@page
|
||||
@model GanjooRazor.Areas.User.Pages.CatEditsModel
|
||||
@using RMuseum.Models.Ganjoor
|
||||
@using RMuseum.Services.Implementation
|
||||
@{
|
||||
Layout = "_UserPanelLayout";
|
||||
ViewData["Title"] = "ویرایشهای بخشهای من";
|
||||
await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);
|
||||
string color = "gray";
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
@if (Model.LastError != "")
|
||||
{
|
||||
<h2>@Model.LastError</h2>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (@Model.CanEdit)
|
||||
{
|
||||
<div class="clear-both">
|
||||
<p>
|
||||
<a role="button" href="/User/CatEdits?AllUsers=1" class="pagebutton">ویرایشهای بخشهای همه</a>
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (Model.Corrections.Count == 0)
|
||||
{
|
||||
<p>
|
||||
شما هنوز هیچ ویرایشی در بخشهای انجام ندادهاید.
|
||||
</p>
|
||||
}
|
||||
|
||||
|
||||
<p style="text-align:center">
|
||||
@foreach (var paginationLink in Model.PaginationLinks)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(paginationLink.Url))
|
||||
{
|
||||
<a href="@paginationLink.Url">@paginationLink.Name</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
@paginationLink.Name
|
||||
}
|
||||
}
|
||||
</p>
|
||||
|
||||
@foreach (var correction in Model.Corrections)
|
||||
{
|
||||
if (color == "gray")
|
||||
color = "lightsteelblue";
|
||||
else
|
||||
color = "gray";
|
||||
|
||||
<div style="background-color:@color" id="correction-@correction.Id">
|
||||
<table>
|
||||
|
||||
@if (Model.AllUsersEdits)
|
||||
{
|
||||
<tr>
|
||||
<td colspan="3"><a href="/hashieha/?userid=@correction.UserId" target="_blank">@correction.UserNickname</a></td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
<tr>
|
||||
<td>متن اولیه</td>
|
||||
<td>تغییرات من</td>
|
||||
<td>نتیجهٔ بررسی</td>
|
||||
</tr>
|
||||
|
||||
@if (correction.Description != null)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<p style="color:red">متن اولیه: @correction.Description</p>
|
||||
</td>
|
||||
<td>
|
||||
<p style="color:green">@correction.Description</p>
|
||||
</td>
|
||||
<td>
|
||||
@if (correction.Result == CorrectionReviewResult.NotReviewed)
|
||||
{
|
||||
<p style="color:blue">@CorrectionReviewResultConvertor.GetString(correction.Result)</p>
|
||||
}
|
||||
else
|
||||
@if (correction.Result == CorrectionReviewResult.Approved)
|
||||
{
|
||||
<p style="color:green">@CorrectionReviewResultConvertor.GetString(correction.Result)</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p style="color:red">@CorrectionReviewResultConvertor.GetString(correction.Result)</p>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
@if (!string.IsNullOrEmpty(correction.ReviewNote))
|
||||
{
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<p>@correction.ReviewNote</p>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@if (!string.IsNullOrEmpty(correction.Note))
|
||||
{
|
||||
<tr>
|
||||
<td>یادداشت:</td>
|
||||
<td colspan="2">
|
||||
@correction.Note
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(correction.ReviewNote))
|
||||
{
|
||||
<tr>
|
||||
<td>یادداشت بررسی:</td>
|
||||
<td colspan="2">
|
||||
@correction.ReviewNote
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<hr />
|
||||
}
|
||||
|
||||
<p style="text-align:center">
|
||||
@foreach (var paginationLink in Model.PaginationLinks)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(paginationLink.Url))
|
||||
{
|
||||
<a href="@paginationLink.Url">@paginationLink.Name</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
@paginationLink.Name
|
||||
}
|
||||
}
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
159
GanjooRazor/Areas/User/Pages/CatEdits.cshtml.cs
Normal file
159
GanjooRazor/Areas/User/Pages/CatEdits.cshtml.cs
Normal file
@ -0,0 +1,159 @@
|
||||
using DNTPersianUtils.Core;
|
||||
using GanjooRazor.Utils;
|
||||
using GSpotifyProxy.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace GanjooRazor.Areas.User.Pages
|
||||
{
|
||||
[IgnoreAntiforgeryToken(Order = 1001)]
|
||||
public class CatEditsModel : PageModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Last Error
|
||||
/// </summary>
|
||||
public string LastError { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// pagination links
|
||||
/// </summary>
|
||||
public List<NameIdUrlImage> PaginationLinks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// can edit
|
||||
/// </summary>
|
||||
public bool CanEdit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// all users edits
|
||||
/// </summary>
|
||||
public bool AllUsersEdits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Corrections
|
||||
/// </summary>
|
||||
public List<GanjoorCatCorrectionViewModel> Corrections { get; set; }
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
|
||||
return Redirect("/");
|
||||
CanEdit = Request.Cookies["CanEdit"] == "True";
|
||||
AllUsersEdits = false;
|
||||
LastError = "";
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
{
|
||||
int pageNumber = 1;
|
||||
if (!string.IsNullOrEmpty(Request.Query["page"]))
|
||||
{
|
||||
pageNumber = int.Parse(Request.Query["page"]);
|
||||
}
|
||||
string url = $"{APIRoot.Url}/api/ganjoor/cat/corrections/mine?PageNumber={pageNumber}&PageSize=20";
|
||||
|
||||
if (CanEdit)
|
||||
{
|
||||
AllUsersEdits = Request.Query["AllUsers"] == "1";
|
||||
if (AllUsersEdits)
|
||||
{
|
||||
url = $"{APIRoot.Url}/api/ganjoor/cat/corrections/all?PageNumber={pageNumber}&PageSize=20";
|
||||
}
|
||||
}
|
||||
var response = await secureClient.GetAsync(url);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
||||
return Page();
|
||||
}
|
||||
|
||||
Corrections = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorCatCorrectionViewModel>>();
|
||||
|
||||
string paginnationMetadata = response.Headers.GetValues("paging-headers").FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(paginnationMetadata))
|
||||
{
|
||||
PaginationMetadata paginationMetadata = JsonConvert.DeserializeObject<PaginationMetadata>(paginnationMetadata);
|
||||
PaginationLinks = new List<NameIdUrlImage>();
|
||||
if (paginationMetadata.totalPages > 1)
|
||||
{
|
||||
if (paginationMetadata.currentPage > 3)
|
||||
{
|
||||
PaginationLinks.Add
|
||||
(
|
||||
new NameIdUrlImage()
|
||||
{
|
||||
Name = "صفحهٔ اول",
|
||||
Url = AllUsersEdits ? "/User/CatEdits/?page=1&AllUsers=1" : "/User/CatEdits/?page=1"
|
||||
}
|
||||
);
|
||||
}
|
||||
for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++)
|
||||
{
|
||||
if (i >= 1 && i <= paginationMetadata.totalPages)
|
||||
{
|
||||
if (i == paginationMetadata.currentPage)
|
||||
{
|
||||
|
||||
PaginationLinks.Add
|
||||
(
|
||||
new NameIdUrlImage()
|
||||
{
|
||||
Name = i.ToPersianNumbers(),
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
PaginationLinks.Add
|
||||
(
|
||||
new NameIdUrlImage()
|
||||
{
|
||||
Name = i.ToPersianNumbers(),
|
||||
Url = AllUsersEdits ? $"/User/SectionEdits/?page={i}&AllUsers=1" : $"/User/SectionEdits/?page={i}"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2))
|
||||
{
|
||||
|
||||
PaginationLinks.Add
|
||||
(
|
||||
new NameIdUrlImage()
|
||||
{
|
||||
Name = "... ",
|
||||
}
|
||||
);
|
||||
|
||||
PaginationLinks.Add
|
||||
(
|
||||
new NameIdUrlImage()
|
||||
{
|
||||
Name = "صفحهٔ آخر",
|
||||
Url = AllUsersEdits ? $"/User/SectionEdits/?page={paginationMetadata.totalPages}&AllUsers=1" : $"/User/SectionEdits/?page={paginationMetadata.totalPages}"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LastError = "لطفاً از گنجور خارج و مجددا به آن وارد شوید.";
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -17,9 +17,10 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
{
|
||||
[IgnoreAntiforgeryToken(Order = 1001)]
|
||||
public class SectionEditsModel : PageModel
|
||||
{ /// <summary>
|
||||
/// Last Error
|
||||
/// </summary>
|
||||
{
|
||||
/// <summary>
|
||||
/// Last Error
|
||||
/// </summary>
|
||||
public string LastError { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -58,7 +59,7 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
pageNumber = int.Parse(Request.Query["page"]);
|
||||
}
|
||||
string url = $"{APIRoot.Url}/api/ganjoor/section/corrections/mine?PageNumber={pageNumber}&PageSize=20";
|
||||
|
||||
|
||||
if (CanEdit)
|
||||
{
|
||||
AllUsersEdits = Request.Query["AllUsers"] == "1";
|
||||
|
||||
@ -117,6 +117,10 @@
|
||||
<a class="nav-link text-dark" asp-area="User" asp-page="/SectionEdits">ویرایشهای قطعات من</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="User" asp-page="/CatEdits">ویرایشهای بخشهای من</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="User" asp-page="/MySuggestedQuotes">مشقهای پیشنهادی من</a>
|
||||
</li>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user