#478 contribs page
This commit is contained in:
parent
863b486e24
commit
22fb47c3a7
@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using RMuseum.Models.Generic.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System.Linq;
|
||||
using static Betalgo.Ranul.OpenAI.ObjectModels.RealtimeModels.RealtimeEventTypes;
|
||||
|
||||
namespace GanjooRazor.Pages
|
||||
{
|
||||
@ -187,6 +188,32 @@ namespace GanjooRazor.Pages
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<ActionResult> OnGetGroupedByDayAsync(string dataType, int pageNumber)
|
||||
{
|
||||
var responseDays = await _httpClient.GetAsync($"{APIRoot.Url}/api/contributions/{dataType}/daily?PageNumber={pageNumber}&PageSize=30");
|
||||
|
||||
if (!responseDays.IsSuccessStatusCode)
|
||||
{
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await responseDays.Content.ReadAsStringAsync()));
|
||||
}
|
||||
var days = JArray.Parse(await responseDays.Content.ReadAsStringAsync()).ToObject<List<GroupedByDateViewModel>>();
|
||||
|
||||
return new PartialViewResult()
|
||||
{
|
||||
ViewName = "_GroupedByDateViewTablePartial",
|
||||
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
|
||||
{
|
||||
Model = new _GroupedByDateViewTablePartialModel()
|
||||
{
|
||||
DataType = dataType,
|
||||
Days = days.ToArray(),
|
||||
DaysPagination = JsonConvert.DeserializeObject<PaginationMetadata>(responseDays.Headers.GetValues("paging-headers").Single()),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// memory cache
|
||||
/// </summary>
|
||||
|
||||
@ -19,6 +19,7 @@ namespace GanjooRazor.Pages
|
||||
{
|
||||
return new _GroupedByDateViewTablePartialModel()
|
||||
{
|
||||
DataType = DataType,
|
||||
Days = Days,
|
||||
DaysPagination = DaysPagination,
|
||||
Users = Users,
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
<div class="pagination-controls">
|
||||
@if (Model.DaysPagination.hasPreviousPage)
|
||||
{
|
||||
<button id="dailyPrevPage" class="btn btn-primary" onclick="loadDailyPage('prev')">صفحهٔ قبل</button>
|
||||
<button id="dailyPrevPage" class="btn btn-primary" onclick="loadContributionsDays('@Model.DataType', @(Model.DaysPagination.currentPage - 1))">صفحهٔ قبل</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -18,7 +18,7 @@
|
||||
<span id="dailyCurrentPage">صفحهٔ @Model.DaysPagination.currentPage.ToPersianNumbers() از @Model.DaysPagination.totalPages.ToPersianNumbers()</span>
|
||||
@if (Model.DaysPagination.hasNextPage)
|
||||
{
|
||||
<button id="dailyNextPage" class="btn btn-primary" onclick="loadDailyPage('next')">صفحهٔ بعد</button>
|
||||
<button id="dailyNextPage" class="btn btn-primary" onclick="loadContributionsDays('@Model.DataType', @(Model.DaysPagination.currentPage + 1))">صفحهٔ بعد</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -1,14 +1,28 @@
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using RMuseum.Models.Generic.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace GanjooRazor.Pages
|
||||
{
|
||||
public class _GroupedByDateViewTablePartialModel : PageModel
|
||||
{
|
||||
public string DataType { get; set; }
|
||||
public GroupedByDateViewModel[] Days { get; set; }
|
||||
public PaginationMetadata DaysPagination { get; set; }
|
||||
public GroupedByUserViewModel[] Users { get; set; }
|
||||
public PaginationMetadata UsersPagination { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1906,4 +1906,28 @@ function loadContributions(dataType) {
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
function loadContributionsDays(dataType, pageNumber) {
|
||||
var divParent = document.getElementById('days');
|
||||
divParent.innerHTML = '<div class="bnumdiv" id="remove-days-placeholder"><img src="/image/loading.gif" alt="بارگذاری"/></div>';
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: '?Handler=GroupedByDay&dataType=' + dataType + '&pageNumber=' + pageNumber.toString(),
|
||||
error: function (e) {
|
||||
if (document.getElementById("remove-days-placeholder") != null) {
|
||||
document.getElementById("remove-days-placeholder").remove();
|
||||
}
|
||||
if (e.responseText == null)
|
||||
alert(e);
|
||||
else
|
||||
alert(e.responseText);
|
||||
},
|
||||
success: function (data) {
|
||||
if (document.getElementById("remove-days-placeholder") != null) {
|
||||
document.getElementById("remove-days-placeholder").remove();
|
||||
$(data).appendTo(divParent);
|
||||
plotChart('grouped-by-date', 100);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user