#273 making the corresponding option switchable through UI

This commit is contained in:
Hamid Reza Mohammadi 2022-01-22 09:32:25 +03:30
parent 4176e97297
commit c99de47391
5 changed files with 222 additions and 78 deletions

View File

@ -74,8 +74,86 @@ else
},
});
}
function switchOption(start) {
if(start == false){
document.getElementById('switch-tracking-button').style.visibility = 'hidden';
document.getElementById('processing').innerHTML = 'در حال پردازش ...';
$.ajax({
type: "POST",
url: '?handler=StopKeeping',
error: function() {
alert('خطا رخ داد.');
location.reload();
},
success: function () {
location.reload();
},
});
return;
}
document.getElementById('switch-tracking-button').style.visibility = 'hidden';
document.getElementById('processing').innerHTML = 'در حال پردازش ...';
$.ajax({
type: "POST",
url: '?handler=StartKeeping',
error: function() {
alert('خطا رخ داد.');
location.reload();
},
success: function () {
location.reload();
},
});
}
</script>
<div class="related-images-frame">
@if (Model.KeepFirstTimeUsersComments)
{
<p style="text-align:center; color: green">
نگه داشتن حاشیه‌های حاشیه‌گذاران بدون سابقه فعال است.
</p>
<p>
<a role="button" onclick="switchOption(false)" id="switch-tracking-button" class="pagebutton">غیرفعال کردن</a>
</p>
<p id="processing">
</p>
}
else
{
<p>
نگه داشتن حاشیه‌های حاشیه‌گذاران بدون سابقه غیرفعال است.
</p>
<p>
<a role="button" onclick="switchOption(true)" id="switch-tracking-button" class="pagebutton">فعال کردن</a>
</p>
<p id="processing">
</p>
}
</div>
@if (Model.Comments.Count == 0)
{
<p>
موردی وجود ندارد.
</p>
}
@foreach (var comment in Model.Comments)
{
if (color == "gray")
@ -96,8 +174,8 @@ else
</p>
</blockquote>
<p>
<a role="button" onclick="deleteAwaitingComment(@comment.Id)" class="actionlink" title="حذف حاشیه">🗑</a>
<a role="button" onclick="publishAwaitingComment(@comment.Id)" class="actionlink" title="انتشار حاشیه">انتشار</a>
<a role="button" onclick="deleteAwaitingComment(@comment.Id)" class="actionlink" title="حذف حاشیه"><i class="noindent-info-button delete-icon"></i></a>
<a role="button" onclick="publishAwaitingComment(@comment.Id)" class="actionlink" title="انتشار حاشیه"><i class="noindent-info-button done-icon"></i></a>
</p>
</div>

View File

@ -33,99 +33,111 @@ namespace GanjooRazor.Areas.User.Pages
/// pagination links
/// </summary>
public List<NameIdUrlImage> PaginationLinks { get; set; }
/// <summary>
/// keep comments
/// </summary>
public bool KeepFirstTimeUsersComments { get; set; }
public async Task<IActionResult> OnGetAsync()
{
LastError = "";
using (HttpClient secureClient = new HttpClient())
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
var responseKeepFirstTimeUsersComments = await secureClient.GetAsync($"{APIRoot.Url}/api/options/global/KeepFirstTimeUsersComments");
if (!responseKeepFirstTimeUsersComments.IsSuccessStatusCode)
{
LastError = JsonConvert.DeserializeObject<string>(await responseKeepFirstTimeUsersComments.Content.ReadAsStringAsync());
return Page();
}
int pageNumber = 1;
if (!string.IsNullOrEmpty(Request.Query["page"]))
{
pageNumber = int.Parse(Request.Query["page"]);
}
var response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/comments/awaiting?PageNumber={pageNumber}&PageSize=20");
if (!response.IsSuccessStatusCode)
{
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
return Page();
}
KeepFirstTimeUsersComments = JsonConvert.DeserializeObject<string>(await responseKeepFirstTimeUsersComments.Content.ReadAsStringAsync()) == true.ToString();
Comments = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorCommentFullViewModel>>();
int pageNumber = 1;
if (!string.IsNullOrEmpty(Request.Query["page"]))
{
pageNumber = int.Parse(Request.Query["page"]);
}
var response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/comments/awaiting?PageNumber={pageNumber}&PageSize=20");
if (!response.IsSuccessStatusCode)
{
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
return Page();
}
string paginnationMetadata = response.Headers.GetValues("paging-headers").FirstOrDefault();
if (!string.IsNullOrEmpty(paginnationMetadata))
Comments = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorCommentFullViewModel>>();
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)
{
PaginationMetadata paginationMetadata = JsonConvert.DeserializeObject<PaginationMetadata>(paginnationMetadata);
PaginationLinks = new List<NameIdUrlImage>();
if (paginationMetadata.totalPages > 1)
if (paginationMetadata.currentPage > 3)
{
if (paginationMetadata.currentPage > 3)
{
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = "صفحهٔ اول",
Url = "/User/AwaitingComments/?page=1"
}
);
}
for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++)
{
if (i >= 1 && i <= paginationMetadata.totalPages)
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = "صفحهٔ اول",
Url = "/User/AwaitingComments/?page=1"
}
);
}
for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++)
{
if (i >= 1 && i <= paginationMetadata.totalPages)
{
if (i == paginationMetadata.currentPage)
{
if (i == paginationMetadata.currentPage)
{
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = i.ToPersianNumbers(),
}
);
}
else
{
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = i.ToPersianNumbers(),
}
);
}
else
{
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = i.ToPersianNumbers(),
Url = $"/User/AwaitingComments/?page={i}"
}
);
}
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = i.ToPersianNumbers(),
Url = $"/User/AwaitingComments/?page={i}"
}
);
}
}
if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2))
{
}
if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2))
{
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = "... ",
}
);
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = "... ",
}
);
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = "صفحهٔ آخر",
Url = $"/User/AwaitingComments/?page={paginationMetadata.totalPages}"
}
);
}
PaginationLinks.Add
(
new NameIdUrlImage()
{
Name = "صفحهٔ آخر",
Url = $"/User/AwaitingComments/?page={paginationMetadata.totalPages}"
}
);
}
}
}
}
else
{
@ -175,5 +187,45 @@ namespace GanjooRazor.Areas.User.Pages
}
return new JsonResult(true);
}
public async Task<IActionResult> OnPostStopKeepingAsync()
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
var response = await secureClient.PutAsync($"{APIRoot.Url}/api/options/global/KeepFirstTimeUsersComments", new StringContent(JsonConvert.SerializeObject(false.ToString()), Encoding.UTF8, "application/json"));
if (response.StatusCode != HttpStatusCode.OK)
{
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
}
}
else
{
return new BadRequestObjectResult("لطفا از گنجور خارج و مجددا به آن وارد شوید.");
}
}
return new JsonResult(true);
}
public async Task<IActionResult> OnPostStartKeepingAsync()
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
var response = await secureClient.PutAsync($"{APIRoot.Url}/api/options/global/KeepFirstTimeUsersComments", new StringContent(JsonConvert.SerializeObject(true.ToString()), Encoding.UTF8, "application/json"));
if (response.StatusCode != HttpStatusCode.OK)
{
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
}
}
else
{
return new BadRequestObjectResult("لطفا از گنجور خارج و مجددا به آن وارد شوید.");
}
}
return new JsonResult(true);
}
}
}

View File

@ -12443,7 +12443,12 @@
http client
</summary>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.#ctor(RMuseum.DbContext.RMuseumDbContext,Microsoft.Extensions.Configuration.IConfiguration,RSecurityBackend.Services.IBackgroundTaskQueue,RSecurityBackend.Services.IAppUserService,RSecurityBackend.Services.IRNotificationService,RSecurityBackend.Services.IImageFileService,Microsoft.Extensions.Caching.Memory.IMemoryCache,System.Net.Http.HttpClient)">
<member name="F:RMuseum.Services.Implementation.GanjoorService._optionsService">
<summary>
options service
</summary>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.#ctor(RMuseum.DbContext.RMuseumDbContext,Microsoft.Extensions.Configuration.IConfiguration,RSecurityBackend.Services.IBackgroundTaskQueue,RSecurityBackend.Services.IAppUserService,RSecurityBackend.Services.IRNotificationService,RSecurityBackend.Services.IImageFileService,Microsoft.Extensions.Caching.Memory.IMemoryCache,System.Net.Http.HttpClient,RSecurityBackend.Services.IRGenericOptionsService)">
<summary>
constructor
</summary>
@ -12455,6 +12460,7 @@
<param name="imageFileService"></param>
<param name="memoryCache"></param>
<param name="httpClient"></param>
<param name="optionsService"></param>
</member>
<member name="T:RMuseum.Services.Implementation.GanjoorTranslationService">
<summary>

View File

@ -745,7 +745,8 @@ namespace RMuseum.Services.Implementation
}
PublishStatus status = PublishStatus.Published;
if (bool.Parse(Configuration.GetSection("Ganjoor")["KeepFirstTimeUsersComments"]))
var keepFirstTimeUsersComments = await _optionsService.GetValueAsync("KeepFirstTimeUsersComments", null);
if (keepFirstTimeUsersComments.Result == true.ToString())
{
if((await _context.GanjoorComments.AsNoTracking().Where(c => c.UserId == userId && c.Status == PublishStatus.Published).AnyAsync()) == false)//First time commenter
{
@ -3871,6 +3872,12 @@ namespace RMuseum.Services.Implementation
/// </summary>
protected readonly HttpClient _httpClient;
/// <summary>
/// options service
/// </summary>
protected readonly IRGenericOptionsService _optionsService;
/// <summary>
/// constructor
/// </summary>
@ -3882,7 +3889,8 @@ namespace RMuseum.Services.Implementation
/// <param name="imageFileService"></param>
/// <param name="memoryCache"></param>
/// <param name="httpClient"></param>
public GanjoorService(RMuseumDbContext context, IConfiguration configuration, IBackgroundTaskQueue backgroundTaskQueue, IAppUserService appUserService, IRNotificationService notificationService, IImageFileService imageFileService, IMemoryCache memoryCache, HttpClient httpClient)
/// <param name="optionsService"></param>
public GanjoorService(RMuseumDbContext context, IConfiguration configuration, IBackgroundTaskQueue backgroundTaskQueue, IAppUserService appUserService, IRNotificationService notificationService, IImageFileService imageFileService, IMemoryCache memoryCache, HttpClient httpClient, IRGenericOptionsService optionsService)
{
_context = context;
_backgroundTaskQueue = backgroundTaskQueue;
@ -3892,6 +3900,7 @@ namespace RMuseum.Services.Implementation
_memoryCache = memoryCache;
Configuration = configuration;
_httpClient = httpClient;
_optionsService = optionsService;
}
}
}

View File

@ -84,8 +84,7 @@
"GDBStorage": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i\\android\\sgdb",
"GDBStorageImageSource": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i\\android\\img",
"GDBListXMLFile": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i\\android\\sitepoets.xml",
"GDBPreExisitingListXMLFile": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i\\android\\programpoets.xml",
"KeepFirstTimeUsersComments": "True"
"GDBPreExisitingListXMLFile": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i\\android\\programpoets.xml"
},
"WebServiceUrl": "http://localhost:3439",
"ReadOnlyMode": "False",