docs: #272 user page added

This commit is contained in:
Hamid Reza Mohammadi 2022-01-10 19:32:02 +03:30
parent c2dfcf7f3c
commit ada147f12e
6 changed files with 272 additions and 3 deletions

View File

@ -0,0 +1,105 @@
@page
@model GanjooRazor.Areas.User.Pages.HistoryModel
@using DNTPersianUtils.Core
@{
Layout = "_Layout";
ViewData["Title"] = "ادامهٔ مطالعه";
await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);
string color = "gray";
}
<h1>@ViewData["Title"]</h1>
@if (Model.LastError != "")
{
<h2>@Model.LastError</h2>
}
else
{
<script>
function deleteHistoryItem(historyItemId) {
if (!confirm('آیا از حذف این مورد اطمینان دارید؟'))
return;
var url = '?handler=HistoryItem';
$.ajax({
type: "DELETE",
url: url,
data: {
id: historyItemId
},
success: function () {
var notificationBlockId = '#history-item-' + historyItemId;
$(notificationBlockId).remove();
},
});
}
</script>
<p style="text-align:center">
@foreach (var paginationLink in Model.PaginationLinks)
{
if (!string.IsNullOrEmpty(paginationLink.Url))
{
<a href="@paginationLink.Url">@paginationLink.Name</a>
}
else
{
@paginationLink.Name
}
}
</p>
@foreach (var historyItem in Model.HistoryItems)
{
if (color == "gray")
color = "white";
else
color = "gray";
<div style="background-color:@color" id="history-item-@historyItem.Id">
<blockquote>
<p>
از <a href="@($"{historyItem.PoemFullUrl}#bn{historyItem.CoupletIndex + 1}")">@historyItem.PoemFullTitle</a> <small>در @historyItem.DateTime.ToFriendlyPersianDateTextify()</small>
</p>
<a href="@($"{historyItem.PoemFullUrl}#bn{historyItem.CoupletIndex + 1}")">
<img src="@historyItem.PoetImageUrl" style="width:unset;display:unset;border:unset" alt="@historyItem.PoetName" />
</a>
<div id="historyItem-text-@historyItem.Id">
<p>
@historyItem.VerseText
</p>
@if (!string.IsNullOrEmpty(historyItem.Verse2Text))
{
<p>
@historyItem.Verse2Text
</p>
}
</div>
</blockquote>
<p>
<a role="button" onclick="deleteHistoryItem('@historyItem.Id')" class="actionlink" title="حذف">🗑</a>
</p>
</div>
<hr />
}
<p style="text-align:center">
@foreach (var paginationLink in Model.PaginationLinks)
{
if (!string.IsNullOrEmpty(paginationLink.Url))
{
<a href="@paginationLink.Url">@paginationLink.Name</a>
}
else
{
@paginationLink.Name
}
}
</p>
}

View File

@ -0,0 +1,152 @@
using DNTPersianUtils.Core;
using GanjooRazor.Utils;
using GSpotifyProxy.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RMuseum.Models.Ganjoor.ViewModels;
using RSecurityBackend.Models.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace GanjooRazor.Areas.User.Pages
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class HistoryModel : PageModel
{
/// <summary>
/// Last Error
/// </summary>
public string LastError { get; set; }
/// <summary>
/// pagination links
/// </summary>
public List<NameIdUrlImage> PaginationLinks { get; set; }
public List<GanjoorUserBookmarkViewModel> HistoryItems { get; set; }
public async Task<IActionResult> OnGetAsync()
{
LastError = "";
using (HttpClient secureClient = new HttpClient())
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
{
int pageNumber = 1;
if (!string.IsNullOrEmpty(Request.Query["page"]))
{
pageNumber = int.Parse(Request.Query["page"]);
}
var response = await secureClient.GetAsync($"{APIRoot.Url}/api/tracking/?PageNumber={pageNumber}&PageSize=20");
if (!response.IsSuccessStatusCode)
{
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
return Page();
}
HistoryItems = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorUserBookmarkViewModel>>();
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 = "/User/History/?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 = $"/User/History/?page={i}"
}
);
}
}
}
if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2))
{
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = "... ",
}
);
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = "صفحهٔ آخر",
Url = $"/User/History/?page={paginationMetadata.totalPages}"
}
);
}
}
}
}
}
else
{
LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
}
return Page();
}
public async Task<IActionResult> OnDeleteHistoryItem(Guid id)
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/tracking/{id}");
if (response.StatusCode != HttpStatusCode.OK)
{
return Redirect($"/login?redirect={Request.Path}&error={JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync())}");
}
}
}
return new JsonResult(true);
}
}
}

View File

@ -360,6 +360,10 @@
<a class="nav-link text-dark" asp-area="User" asp-page="/UpVotedRecitations">خوانش‌های نشان شده</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="User" asp-page="/History">ادامهٔ مطالعه</a>
</li>
@if (ViewData.ContainsKey("ganjoor-songrevu"))
{
<li class="nav-item">

View File

@ -8,8 +8,8 @@
},
"AllowedHosts": "*",
"GoogleAnalyticsCode": "",
"APIRoot": "https://api.ganjoor.net",
"GlobalAPIRoot": "https://api.ganjoor.net",
"APIRoot": "http://localhost:3439",
"GlobalAPIRoot": "http://localhost:3439",
"SiteUrl": "http://localhost:33081",
"AggressiveCacheEnabled": "False",
"ReadOnlyMode": "False",

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using RMuseum.Models.Ganjoor.ViewModels;
using RMuseum.Services;
using RSecurityBackend.Models.Generic;
@ -32,7 +33,10 @@ namespace RMuseum.Controllers
var res = await _userVisitsTrackingService.GetUserHistoryAsync(paging, loggedOnUserId);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok(res.Result);
// Paging Header
HttpContext.Response.Headers.Add("paging-headers", JsonConvert.SerializeObject(res.Result.PagingMeta));
return Ok(res.Result.HistoryItems);
}
/// <summary>

View File

@ -293,6 +293,9 @@ namespace RMuseum
//geo location service
services.AddTransient<IGeoLocationService, GeoLocationService>();
//tracking service
services.AddTransient<IUserVisitsTrackingService, UserVisitsTrackingService>();
//upload limit for IIS
services.Configure<IISServerOptions>(options =>
{
@ -300,6 +303,7 @@ namespace RMuseum
});
services.AddHostedService<QueuedHostedService>();
services.AddSingleton<IBackgroundTaskQueue, BackgroundTaskQueue>();