#478 user contributions page
This commit is contained in:
parent
cea47c58a0
commit
7e2a263992
144
GanjooRazor/Pages/Contribs.cshtml
Normal file
144
GanjooRazor/Pages/Contribs.cshtml
Normal file
@ -0,0 +1,144 @@
|
||||
@page
|
||||
@model GanjooRazor.Pages.ContribsModel
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa-IR" dir="rtl">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>
|
||||
گنجور » مشارکتهای کاربران
|
||||
</title>
|
||||
|
||||
<link href="/css/p8.css?version=79" rel="stylesheet" type="text/css" />
|
||||
<link rel="shortcut icon" href="/favicon.ico?version=1" type="image/x-icon" />
|
||||
<link rel="search" type="application/opensearchdescription+xml" title="گنجور" href="https://ganjoor.net/search.xml" />
|
||||
<script src="/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="/js/bk.js?version=72"></script>
|
||||
<script>
|
||||
var cookieValue = getCookie("playerScrollLock");
|
||||
var playerScrollLock = cookieValue === "true";
|
||||
|
||||
cookieValue = getCookie("stickyEnabled");
|
||||
var stickyEnabled = cookieValue != "false";
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.LastError))
|
||||
{
|
||||
@Html.Raw(Model.LastError)
|
||||
}
|
||||
else
|
||||
{
|
||||
<div id="hdr2" class="clearfix">
|
||||
<h1><a href="/" title="گنجور"><img src="/image/gdapk.png" alt="گنجور" /></a></h1>
|
||||
<div class="actionbox">
|
||||
<form action="/search" method="get" id="searchform">
|
||||
<input type="text" name="s" id="s" class="inputText" value="" placeholder="جستجو" />
|
||||
<input type="hidden" name="es" id="es" value="1" />
|
||||
<select name="author" id="author" onchange="onSelectedPoetChanged()">
|
||||
|
||||
@{
|
||||
if (Model.PoetId != 0)
|
||||
{
|
||||
<option value="0">در آثار همهٔ سخنوران</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
<option value="0" selected>در آثار همهٔ سخنوران</option>
|
||||
}
|
||||
|
||||
if (Model.Poets != null)
|
||||
{
|
||||
foreach (RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetViewModel poet in Model.Poets)
|
||||
{
|
||||
if (poet.Id == Model.PoetId)
|
||||
{
|
||||
<option value="@poet.Id" selected>@poet.Nickname</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
<option value="@poet.Id">@poet.Nickname</option>
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</select>
|
||||
@{
|
||||
if (Model.Poet != null)
|
||||
{
|
||||
<select name="cat" id="cat" style="width:150px">
|
||||
<option value="0" selected>در همهٔ بخشها</option>
|
||||
@{
|
||||
foreach (var gran in Model.Poet.Cat.Ancestors)
|
||||
{
|
||||
<option value="@gran.Id">@gran.Title</option>
|
||||
}
|
||||
<option value="@Model.Poet.Cat.Id">@Model.Poet.Cat.Title</option>
|
||||
foreach (var child in Model.Poet.Cat.Children)
|
||||
{
|
||||
<option value="@child.Id">@child.Title</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
}
|
||||
}
|
||||
|
||||
<input type="submit" value="بیاب" />
|
||||
</form>
|
||||
</div><!-- .actionbox -->
|
||||
</div>
|
||||
|
||||
<!-- #hdr2 -->
|
||||
|
||||
<div id="fa">
|
||||
|
||||
<partial name="_InlineLoginPartial" model="Model" />
|
||||
|
||||
<div id="maincnt">
|
||||
<div class="poem">
|
||||
<h2>
|
||||
گنجور » مشارکتهای کاربران
|
||||
</h2>
|
||||
|
||||
<p>محتوا</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@Html.Raw(Model.PagingToolsHtml)
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<partial name="_FooterPartial" model=@(new _FooterPartialModel(){StickyEnabled = true}) />
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<script src="/js/vaabd.js?version=10"></script>
|
||||
|
||||
@if (!string.IsNullOrEmpty(ViewData["GoogleAnalyticsCode"].ToString()))
|
||||
{
|
||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=@(ViewData["GoogleAnalyticsCode"])"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag() { dataLayer.push(arguments); }
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', '@ViewData["GoogleAnalyticsCode"]');
|
||||
</script>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
171
GanjooRazor/Pages/Contribs.cshtml.cs
Normal file
171
GanjooRazor/Pages/Contribs.cshtml.cs
Normal file
@ -0,0 +1,171 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using DNTPersianUtils.Core;
|
||||
using RMuseum.Models.Auth.ViewModel;
|
||||
using RMuseum.Services.Implementation;
|
||||
using RSecurityBackend.Models.Auth.Memory;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net;
|
||||
using System.Xml.Linq;
|
||||
using System;
|
||||
|
||||
namespace GanjooRazor.Pages
|
||||
{
|
||||
[IgnoreAntiforgeryToken(Order = 1001)]
|
||||
public class ContribsModel : LoginPartialEnabledPageModel
|
||||
{
|
||||
public List<GanjoorPoetViewModel> Poets { get; set; }
|
||||
public int PoetId { get; set; }
|
||||
public GanjoorPoetCompleteViewModel Poet { get; set; }
|
||||
public string PagingToolsHtml { get; set; }
|
||||
public string LastError { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// aggressive cache
|
||||
/// </summary>
|
||||
public bool AggressiveCacheEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return bool.Parse(Configuration["AggressiveCacheEnabled"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async Task<bool> preparePoets()
|
||||
{
|
||||
var cacheKey = $"/api/ganjoor/poets";
|
||||
if (!_memoryCache.TryGetValue(cacheKey, out List<GanjoorPoetViewModel> poets))
|
||||
{
|
||||
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poets");
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
||||
return false;
|
||||
}
|
||||
poets = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorPoetViewModel>>();
|
||||
if (AggressiveCacheEnabled)
|
||||
{
|
||||
_memoryCache.Set(cacheKey, poets);
|
||||
}
|
||||
}
|
||||
|
||||
Poets = poets;
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<bool> preparePoet()
|
||||
{
|
||||
var cacheKey = $"/api/ganjoor/poet/{PoetId}";
|
||||
if (!_memoryCache.TryGetValue(cacheKey, out GanjoorPoetCompleteViewModel poet))
|
||||
{
|
||||
var poetResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poet/{PoetId}");
|
||||
if (!poetResponse.IsSuccessStatusCode)
|
||||
{
|
||||
LastError = JsonConvert.DeserializeObject<string>(await poetResponse.Content.ReadAsStringAsync());
|
||||
return false;
|
||||
}
|
||||
poet = JObject.Parse(await poetResponse.Content.ReadAsStringAsync()).ToObject<GanjoorPoetCompleteViewModel>();
|
||||
if (AggressiveCacheEnabled)
|
||||
{
|
||||
_memoryCache.Set(cacheKey, poet);
|
||||
}
|
||||
}
|
||||
|
||||
Poet = poet;
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetPoetInformationAsync(int id)
|
||||
{
|
||||
if (id == 0)
|
||||
return new OkObjectResult(null);
|
||||
var cacheKey = $"/api/ganjoor/poet/{id}";
|
||||
if (!_memoryCache.TryGetValue(cacheKey, out GanjoorPoetCompleteViewModel poet))
|
||||
{
|
||||
var poetResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poet/{id}");
|
||||
if (!poetResponse.IsSuccessStatusCode)
|
||||
{
|
||||
return BadRequest(JsonConvert.DeserializeObject<string>(await poetResponse.Content.ReadAsStringAsync()));
|
||||
}
|
||||
poet = JObject.Parse(await poetResponse.Content.ReadAsStringAsync()).ToObject<GanjoorPoetCompleteViewModel>();
|
||||
if (AggressiveCacheEnabled)
|
||||
{
|
||||
_memoryCache.Set(cacheKey, poet);
|
||||
}
|
||||
}
|
||||
return new OkObjectResult(poet);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
if (bool.Parse(Configuration["MaintenanceMode"]))
|
||||
{
|
||||
return StatusCode(503);
|
||||
}
|
||||
|
||||
LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"]);
|
||||
|
||||
PoetId = string.IsNullOrEmpty(Request.Query["a"]) ? 0 : int.Parse(Request.Query["a"]);
|
||||
|
||||
ViewData["GoogleAnalyticsCode"] = Configuration["GoogleAnalyticsCode"];
|
||||
|
||||
//todo: use html master layout or make it partial
|
||||
// 1. poets
|
||||
if (false == (await preparePoets()))
|
||||
return Page();
|
||||
|
||||
if (PoetId != 0)
|
||||
{
|
||||
if (false == (await preparePoet()))
|
||||
return Page();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// memory cache
|
||||
/// </summary>
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
/// <summary>
|
||||
/// configration file reader (appsettings.json)
|
||||
/// </summary>
|
||||
private readonly IConfiguration Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="httpClient"></param>
|
||||
/// <param name="memoryCache"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public ContribsModel(HttpClient httpClient, IMemoryCache memoryCache, IConfiguration configuration) : base(httpClient)
|
||||
{
|
||||
_memoryCache = memoryCache;
|
||||
Configuration
|
||||
= configuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,6 +122,11 @@
|
||||
<svg class="footer-icon" height="14px" viewBox="0 -960 960 960" width="14px"><path d="M560-360q17 0 29.5-12.5T602-402q0-17-12.5-29.5T560-444q-17 0-29.5 12.5T518-402q0 17 12.5 29.5T560-360Zm-30-128h60q0-29 6-42.5t28-35.5q30-30 40-48.5t10-43.5q0-45-31.5-73.5T560-760q-41 0-71.5 23T446-676l54 22q9-25 24.5-37.5T560-704q24 0 39 13.5t15 36.5q0 14-8 26.5T578-596q-33 29-40.5 45.5T530-488ZM320-240q-33 0-56.5-23.5T240-320v-480q0-33 23.5-56.5T320-880h480q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H320Zm0-80h480v-480H320v480ZM160-80q-33 0-56.5-23.5T80-160v-560h80v560h560v80H160Zm160-720v480-480Z" /></svg> پرسشهای متداول
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/contribs">
|
||||
<svg class="footer-icon" height="14px" viewBox="0 0 24 24" width="14px"><g><rect fill="none" height="24" width="24" /></g><g><g><path d="M6.32,13.01c0.96,0.02,1.85,0.5,2.45,1.34C9.5,15.38,10.71,16,12,16c1.29,0,2.5-0.62,3.23-1.66 c0.6-0.84,1.49-1.32,2.45-1.34C16.96,11.78,14.08,11,12,11C9.93,11,7.04,11.78,6.32,13.01z" /><path d="M4,13L4,13c1.66,0,3-1.34,3-3c0-1.66-1.34-3-3-3s-3,1.34-3,3C1,11.66,2.34,13,4,13z" /><path d="M20,13L20,13c1.66,0,3-1.34,3-3c0-1.66-1.34-3-3-3s-3,1.34-3,3C17,11.66,18.34,13,20,13z" /><path d="M12,10c1.66,0,3-1.34,3-3c0-1.66-1.34-3-3-3S9,5.34,9,7C9,8.66,10.34,10,12,10z" /><path d="M21,14h-3.27c-0.77,0-1.35,0.45-1.68,0.92C16.01,14.98,14.69,17,12,17c-1.43,0-3.03-0.64-4.05-2.08 C7.56,14.37,6.95,14,6.27,14H3c-1.1,0-2,0.9-2,2v4h7v-2.26c1.15,0.8,2.54,1.26,4,1.26s2.85-0.46,4-1.26V20h7v-4 C23,14.9,22.1,14,21,14z" /></g></g></svg> مشارکتها
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/donate">
|
||||
<svg class="footer-icon" height="14px" viewBox="0 -960 960 960" width="14px"><path d="M640-440 474-602q-31-30-52.5-66.5T400-748q0-55 38.5-93.5T532-880q32 0 60 13.5t48 36.5q20-23 48-36.5t60-13.5q55 0 93.5 38.5T880-748q0 43-21 79.5T807-602L640-440Zm0-112 109-107q19-19 35-40.5t16-48.5q0-22-15-37t-37-15q-14 0-26.5 5.5T700-778l-60 72-60-72q-9-11-21.5-16.5T532-800q-22 0-37 15t-15 37q0 27 16 48.5t35 40.5l109 107ZM280-220l278 76 238-74q-5-9-14.5-15.5T760-240H558q-27 0-43-2t-33-8l-93-31 22-78 81 27q17 5 40 8t68 4q0-11-6.5-21T578-354l-234-86h-64v220ZM40-80v-440h304q7 0 14 1.5t13 3.5l235 87q33 12 53.5 42t20.5 66h80q50 0 85 33t35 87v40L560-60l-280-78v58H40Zm80-80h80v-280h-80v280Zm520-546Z" /></svg> حمایت مالی
|
||||
|
||||
Loading…
Reference in New Issue
Block a user