#413 display search category in title

This commit is contained in:
Hamid Reza Mohammadi 2023-12-09 17:08:46 +03:30
parent efe36f155c
commit 151b1df2a1
2 changed files with 70 additions and 2 deletions

View File

@ -68,6 +68,8 @@ namespace GanjooRazor.Pages
public string Query { get; set; }
public int PoetId { get; set; }
public int CatId { get; set; }
public string CatFullTitle { get; set; }
public string CatFullUrl { get; set; }
public GanjoorPoetCompleteViewModel Poet { get; set; }
public List<GanjoorPoemCompleteViewModel> Poems { get; set; }
public PaginationMetadata PaginationMetadata { get; set; }
@ -192,6 +194,33 @@ namespace GanjooRazor.Pages
PoetId = string.IsNullOrEmpty(Request.Query["author"]) ? 0 : int.Parse(Request.Query["author"]);
CatId = string.IsNullOrEmpty(Request.Query["cat"]) ? 0 : int.Parse(Request.Query["cat"]);
if (CatId != 0)
{
var catResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/cat/{CatId}?poems=false&mainSections=false");
if (!catResponse.IsSuccessStatusCode)
{
LastError = JsonConvert.DeserializeObject<string>(await catResponse.Content.ReadAsStringAsync());
return Page();
}
else
{
var cat = JObject.Parse(await catResponse.Content.ReadAsStringAsync()).ToObject<GanjoorPoetCompleteViewModel>();
CatFullUrl = cat.Cat.FullUrl;
CatFullTitle = "";
foreach (var parentCat in cat.Cat.Ancestors)
{
CatFullTitle += parentCat.Title;
CatFullTitle += " »";
}
CatFullTitle += cat.Cat.Title;
}
}
else
{
CatFullUrl = "";
CatFullTitle = "";
}
ViewData["GoogleAnalyticsCode"] = Configuration["GoogleAnalyticsCode"];
//todo: use html master layout or make it partial
@ -202,7 +231,14 @@ namespace GanjooRazor.Pages
var poetName = Poets.SingleOrDefault(p => p.Id == PoetId);
if (poetName != null)
{
ViewData["Title"] = $"گنجور » نتایج جستجو برای {Query} در آثار {poetName?.Name}";
if(CatFullTitle != "")
{
ViewData["Title"] = $"گنجور » نتایج جستجو برای {Query} در بخش {CatFullTitle}";
}
else
{
ViewData["Title"] = $"گنجور » نتایج جستجو برای {Query} در آثار {poetName?.Name}";
}
}
else
{

View File

@ -7,6 +7,7 @@ using DNTPersianUtils.Core;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using NAudio.Gui;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RMuseum.Models.Ganjoor;
@ -65,9 +66,11 @@ namespace GanjooRazor.Pages
public List<GanjoorPoetViewModel> Poets { get; set; }
public int PoetId { get; set; }
public int CatId { get; set; }
public string CatFullTitle { get; set; }
public string CatFullUrl { get; set; }
public string Metre { get; set; }
public string Rhyme { get; set; }
public GanjoorLanguage[] Languages { get; set; }
public GanjoorPoetCompleteViewModel Poet { get; set; }
public List<GanjoorPoemCompleteViewModel> Poems { get; set; }
@ -185,6 +188,8 @@ namespace GanjooRazor.Pages
CanEdit = Request.Cookies["CanEdit"] == "True";
PoetId = string.IsNullOrEmpty(Request.Query["a"]) ? 0 : int.Parse(Request.Query["a"]);
CatId = string.IsNullOrEmpty(Request.Query["c"]) ? 0 : int.Parse(Request.Query["c"]);
anyParamsGiven |= PoetId != 0;
@ -318,6 +323,33 @@ namespace GanjooRazor.Pages
title += $" در قالب شعری «{GanjoorPoemFormatConvertor.GetString(Format)}»";
}
if(CatId != 0)
{
var catResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/cat/{CatId}?poems=false&mainSections=false");
if (!catResponse.IsSuccessStatusCode)
{
LastError = JsonConvert.DeserializeObject<string>(await catResponse.Content.ReadAsStringAsync());
return Page();
}
else
{
var cat = JObject.Parse(await catResponse.Content.ReadAsStringAsync()).ToObject<GanjoorPoetCompleteViewModel>();
CatFullUrl = cat.Cat.FullUrl;
CatFullTitle = "";
foreach (var parentCat in cat.Cat.Ancestors)
{
CatFullTitle += parentCat.Title;
CatFullTitle += " &raquo";
}
CatFullTitle += cat.Cat.Title;
}
}
else
{
CatFullUrl = "";
CatFullTitle = "";
}
string url = $"{APIRoot.Url}/api/ganjoor/poems/similar?PageNumber={pageNumber}&PageSize=20&metre={Metre}&rhyme={Rhyme}&poetId={PoetId}&language={Language}&format={(int)Format}";
var response = await _httpClient.GetAsync(url);