- translate remaining public views and page-model strings (titles, messages, relation names) - Urdu stopword list for word-frequency stats (replaces Persian list) - error pages: drop list of alternative Ganjoor services Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
4.1 KiB
C#
116 lines
4.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using RMuseum.Models.Divan.ViewModels;
|
|
|
|
namespace DivanRazor.Pages
|
|
{
|
|
public class MapModel : PageModel
|
|
{
|
|
|
|
public string LastError { get; set; }
|
|
|
|
private async Task<List<DivanPoetViewModel>> _PreparePoets()
|
|
{
|
|
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/divan/poets");
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
|
return new List<DivanPoetViewModel>();
|
|
}
|
|
var poets = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<DivanPoetViewModel>>();
|
|
|
|
var poetsWithBirthPlaces = poets.Where(p => !string.IsNullOrEmpty(p.BirthPlace)).ToList();
|
|
|
|
foreach (var poet in poetsWithBirthPlaces)
|
|
{
|
|
poet.ImageUrl = $"{APIRoot.InternetUrl}{poet.ImageUrl}";
|
|
}
|
|
|
|
return poetsWithBirthPlaces;
|
|
}
|
|
|
|
|
|
public List<DivanCenturyViewModel> PoetGroupsWithBirthPlaces { get; set; }
|
|
|
|
private async Task _PreparePoetGroups()
|
|
{
|
|
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/divan/centuries");
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
|
return;
|
|
}
|
|
var poetGroups = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<DivanCenturyViewModel>>();
|
|
PoetGroupsWithBirthPlaces = new List<DivanCenturyViewModel>();
|
|
PoetGroupsWithBirthPlaces.Add
|
|
(
|
|
new DivanCenturyViewModel()
|
|
{
|
|
Id = 0,
|
|
Name = "تمام ادوار",
|
|
ShowInTimeLine = true,
|
|
Poets = await _PreparePoets()
|
|
}
|
|
);
|
|
DivanCenturyViewModel prePoetGroup = null;
|
|
foreach (var poetGroup in poetGroups)
|
|
{
|
|
if (poetGroup.Id == 0)
|
|
continue;
|
|
poetGroup.Poets = poetGroup.Poets.Where(p => !string.IsNullOrEmpty(p.BirthPlace)).ToList();
|
|
if (poetGroup.Poets.Count > 0)
|
|
{
|
|
foreach (var poet in poetGroup.Poets)
|
|
{
|
|
poet.ImageUrl = $"{APIRoot.InternetUrl}{poet.ImageUrl}";
|
|
}
|
|
if (!poetGroup.ShowInTimeLine && prePoetGroup != null)
|
|
{
|
|
prePoetGroup.Poets.AddRange(poetGroup.Poets);
|
|
}
|
|
else
|
|
{
|
|
PoetGroupsWithBirthPlaces.Add(poetGroup);
|
|
prePoetGroup = poetGroup;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public async Task<IActionResult> OnGetAsync()
|
|
{
|
|
if (bool.Parse(Configuration["MaintenanceMode"]))
|
|
{
|
|
return StatusCode(503);
|
|
}
|
|
|
|
ViewData["TrackingScript"] = Configuration["TrackingScript"] != null && string.IsNullOrEmpty(Request.Cookies["Token"]) ? Configuration["TrackingScript"].Replace("loggedon", "") : Configuration["TrackingScript"];
|
|
await _PreparePoetGroups();
|
|
return Page();
|
|
}
|
|
|
|
/// <summary>
|
|
/// HttpClient instance
|
|
/// </summary>
|
|
private readonly HttpClient _httpClient;
|
|
|
|
/// <summary>
|
|
/// configration file reader (appsettings.json)
|
|
/// </summary>
|
|
private readonly IConfiguration Configuration;
|
|
|
|
public MapModel(HttpClient httpClient, IConfiguration configuration)
|
|
{
|
|
_httpClient = httpClient;
|
|
Configuration = configuration;
|
|
}
|
|
}
|
|
}
|