Projects (GanjooRazor -> DivanRazor, GanjoorService.sln -> DivanService.sln), files, folders, classes, namespaces, settings, API routes (/api/divan) and DB tables (Divan*). External addresses (ganjoor.net, github.com/ganjoor) unchanged. Migrations renamed consistently (no pending model changes); requires a fresh database. Upstream RUNNING_LOCALLY/SEMANTIC_SEARCH docs archived unmodified under docs/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
159 lines
6.9 KiB
C#
159 lines
6.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using DNTPersianUtils.Core;
|
|
using DivanRazor.Utils;
|
|
using GSpotifyProxy.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using RMuseum.Models.Divan.ViewModels;
|
|
using RSecurityBackend.Models.Generic;
|
|
|
|
|
|
namespace DivanRazor.Areas.User.Pages
|
|
{
|
|
public class SectionEditsModel : 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<DivanPoemSectionCorrectionViewModel> 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(new DivanReloginHandler(Request, Response)))
|
|
if (await DivanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
{
|
|
int pageNumber = 1;
|
|
if (!string.IsNullOrEmpty(Request.Query["page"]))
|
|
{
|
|
pageNumber = int.Parse(Request.Query["page"]);
|
|
}
|
|
string url = $"{APIRoot.Url}/api/divan/section/corrections/mine?PageNumber={pageNumber}&PageSize=20";
|
|
|
|
if (CanEdit)
|
|
{
|
|
AllUsersEdits = Request.Query["AllUsers"] == "1";
|
|
if (AllUsersEdits)
|
|
{
|
|
url = $"{APIRoot.Url}/api/divan/section/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<DivanPoemSectionCorrectionViewModel>>();
|
|
|
|
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/SectionEdits/?page=1&AllUsers=1" : "/User/SectionEdits/?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();
|
|
}
|
|
}
|
|
}
|