#445 tajik ganjoor
This commit is contained in:
parent
3e02c3e5ae
commit
6c52dad883
@ -1,8 +1,6 @@
|
||||
@page
|
||||
@model IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Ганҷур";
|
||||
}
|
||||
|
||||
|
||||
@if(!string.IsNullOrEmpty(Model.LastError))
|
||||
{
|
||||
|
||||
@ -4,13 +4,28 @@ using Microsoft.Extensions.Caching.Memory;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using NAudio.Gui;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace TajikGanjoor.Pages
|
||||
{
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
public bool IsHomePage { get; set; }
|
||||
public List<GanjoorPoetViewModel>? Poets { get; set; }
|
||||
public bool IsPoetPage { get; set; }
|
||||
public bool IsCatPage { get; set; }
|
||||
public bool IsPoemPage { get; set; }
|
||||
public GanjoorPageCompleteViewModel? GanjoorPage { get; set; }
|
||||
public string NextUrl { get; set; }
|
||||
public string NextTitle { get; set; }
|
||||
public string PreviousUrl { get; set; }
|
||||
public string PreviousTitle { get; set; }
|
||||
|
||||
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
@ -24,6 +39,84 @@ namespace TajikGanjoor.Pages
|
||||
return Page();
|
||||
}
|
||||
|
||||
IsHomePage = Request.Path == "/";
|
||||
if (!IsHomePage)
|
||||
{
|
||||
var pageQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={Request.Path}");
|
||||
if (!pageQuery.IsSuccessStatusCode)
|
||||
{
|
||||
if (pageQuery.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
var redirectQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/redirecturl?url={Request.Path}");
|
||||
if (redirectQuery.IsSuccessStatusCode)
|
||||
{
|
||||
var redirectUrl = JsonConvert.DeserializeObject<string>(await redirectQuery.Content.ReadAsStringAsync());
|
||||
return Redirect(redirectUrl ?? "/");
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
if (!pageQuery.IsSuccessStatusCode)
|
||||
{
|
||||
LastError = JsonConvert.DeserializeObject<string>(await pageQuery.Content.ReadAsStringAsync());
|
||||
return Page();
|
||||
}
|
||||
GanjoorPage = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject<GanjoorPageCompleteViewModel>();
|
||||
if(GanjoorPage == null)
|
||||
{
|
||||
LastError = "GanjoorPage == null";
|
||||
return Page();
|
||||
}
|
||||
switch (GanjoorPage.GanjoorPageType)
|
||||
{
|
||||
case GanjoorPageType.PoemPage:
|
||||
GanjoorPage.PoetOrCat = GanjoorPage.Poem.Category;
|
||||
_prepareNextPre();
|
||||
IsPoemPage = true;
|
||||
break;
|
||||
case GanjoorPageType.PoetPage:
|
||||
IsPoetPage = true;
|
||||
break;
|
||||
case GanjoorPageType.CatPage:
|
||||
_prepareNextPre();
|
||||
IsCatPage = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (IsHomePage)
|
||||
{
|
||||
ViewData["Title"] = "Ганҷур";
|
||||
}
|
||||
else
|
||||
if (IsPoetPage)
|
||||
{
|
||||
ViewData["Title"] = $"Ганҷур - {GanjoorPage?.PoetOrCat.Poet.TajikNickName}";
|
||||
}
|
||||
else
|
||||
if (IsCatPage)
|
||||
{
|
||||
string title = $"Ганҷур - ";
|
||||
foreach (var gran in GanjoorPage.PoetOrCat.Cat.Ancestors)
|
||||
{
|
||||
title += $"{gran.TajikTitle} - ";
|
||||
}
|
||||
title += GanjoorPage.PoetOrCat.Cat.TajikTitle;
|
||||
ViewData["Title"] = title;
|
||||
}
|
||||
else
|
||||
if (IsPoemPage)
|
||||
{
|
||||
string title = $"Ганҷур - ";
|
||||
foreach (var gran in GanjoorPage.PoetOrCat.Cat.Ancestors)
|
||||
{
|
||||
title += $"{gran.TajikTitle} - ";
|
||||
}
|
||||
title += GanjoorPage.Poem.TajikTitle;
|
||||
ViewData["Title"] = title;
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
@ -50,7 +143,7 @@ namespace TajikGanjoor.Pages
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LastError = $"خطا در دسترسی به وب سرویس گنجور - {e}";
|
||||
LastError = e.ToString();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -60,6 +153,72 @@ namespace TajikGanjoor.Pages
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void _prepareNextPre()
|
||||
{
|
||||
if (GanjoorPage == null) return;
|
||||
switch (GanjoorPage.GanjoorPageType)
|
||||
{
|
||||
case GanjoorPageType.PoemPage:
|
||||
{
|
||||
if (GanjoorPage.Poem.Next != null)
|
||||
{
|
||||
NextUrl = GanjoorPage.PoetOrCat.Cat.FullUrl + "/" + GanjoorPage.Poem.Next.UrlSlug;
|
||||
NextTitle = GanjoorPage.Poem.Next.Title + ": " + GanjoorPage.Poem.Next.Excerpt;
|
||||
}
|
||||
else
|
||||
if (GanjoorPage.Poem.MixedModeOrder > 0
|
||||
&& GanjoorPage.Poem.Category.Cat.Children.Where(c => c.MixedModeOrder == 0 || c.MixedModeOrder > GanjoorPage.Poem.MixedModeOrder).Any())
|
||||
{
|
||||
var nextCat = GanjoorPage.Poem.Category.Cat.Children.Where(c => c.MixedModeOrder == 0 || c.MixedModeOrder > GanjoorPage.Poem.MixedModeOrder).OrderBy(c => c.MixedModeOrder).First();
|
||||
NextUrl = nextCat.FullUrl;
|
||||
NextTitle = nextCat.Title;
|
||||
}
|
||||
else
|
||||
if (GanjoorPage.Poem.Category.Cat.Next != null)
|
||||
{
|
||||
NextUrl = GanjoorPage.Poem.Category.Cat.Next.FullUrl;
|
||||
NextTitle = GanjoorPage.Poem.Category.Cat.Next.Title;
|
||||
}
|
||||
|
||||
if (GanjoorPage.Poem.Previous != null)
|
||||
{
|
||||
PreviousUrl = GanjoorPage.PoetOrCat.Cat.FullUrl + "/" + GanjoorPage.Poem.Previous.UrlSlug;
|
||||
PreviousTitle = GanjoorPage.Poem.Previous.Title + ": " + GanjoorPage.Poem.Previous.Excerpt;
|
||||
}
|
||||
else
|
||||
if (GanjoorPage.Poem.MixedModeOrder > 0
|
||||
&& GanjoorPage.Poem.Category.Cat.Children.Where(c => c.MixedModeOrder != 0 && c.MixedModeOrder < GanjoorPage.Poem.MixedModeOrder).Any())
|
||||
{
|
||||
var prevCat = GanjoorPage.Poem.Category.Cat.Children.Where(c => c.MixedModeOrder != 0 && c.MixedModeOrder < GanjoorPage.Poem.MixedModeOrder).OrderByDescending(c => c.MixedModeOrder).First();
|
||||
PreviousUrl = prevCat.FullUrl;
|
||||
PreviousTitle = prevCat.Title;
|
||||
}
|
||||
else
|
||||
if (GanjoorPage.Poem.Category.Cat.Previous != null)
|
||||
{
|
||||
PreviousUrl = GanjoorPage.Poem.Category.Cat.Previous.FullUrl;
|
||||
PreviousTitle = GanjoorPage.Poem.Category.Cat.Previous.Title;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GanjoorPageType.CatPage:
|
||||
{
|
||||
if (GanjoorPage.PoetOrCat.Cat.Next != null)
|
||||
{
|
||||
NextUrl = GanjoorPage.PoetOrCat.Cat.Next.FullUrl;
|
||||
NextTitle = GanjoorPage.PoetOrCat.Cat.Next.Title;
|
||||
}
|
||||
if (GanjoorPage.PoetOrCat.Cat.Previous != null)
|
||||
{
|
||||
PreviousUrl = GanjoorPage.PoetOrCat.Cat.Previous.FullUrl;
|
||||
PreviousTitle = GanjoorPage.PoetOrCat.Cat.Previous.Title;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public string? LastError { get; set; }
|
||||
|
||||
public bool AggressiveCacheEnabled
|
||||
|
||||
@ -6,6 +6,14 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<NoWarn>1701;1702;8602;8618</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<NoWarn>1701;1702;8602;8618</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RMuseum\RMuseum.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user