diff --git a/GanjooRazor/Areas/User/Pages/FinalizeImages.cshtml b/GanjooRazor/Areas/User/Pages/FinalizeImages.cshtml new file mode 100644 index 00000000..b750eb3e --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/FinalizeImages.cshtml @@ -0,0 +1,24 @@ +@page +@model GanjooRazor.Areas.User.Pages.FinalizeImagesModel +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@{ + Layout = "_Layout"; + ViewData["Title"] = "نهایی‌سازی تصاویر پیشنهادی"; + await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData); +} +

@ViewData["Title"]

+ +@if (Model.LastError != "") +{ +

@Model.LastError

+} + +@if (Model.MainImage != null) +{ + +} + +@if (Model.PreviouslyLinkedImage != null) +{ + +} diff --git a/GanjooRazor/Areas/User/Pages/FinalizeImages.cshtml.cs b/GanjooRazor/Areas/User/Pages/FinalizeImages.cshtml.cs new file mode 100644 index 00000000..1fcd04c2 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/FinalizeImages.cshtml.cs @@ -0,0 +1,83 @@ +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using GanjooRazor.Utils; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using RMuseum.Models.GanjoorIntegration.ViewModels; +using RSecurityBackend.Models.Generic; + +namespace GanjooRazor.Areas.User.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class FinalizeImagesModel : PageModel + { + /// + /// Last Error + /// + public string LastError { get; set; } + + /// + /// skip + /// + public int Skip { get; set; } + + /// + /// total count + /// + public int TotalCount { get; set; } + + public GanjoorLinkViewModel MainImage { get; set; } + + public GanjoorLinkViewModel PreviouslyLinkedImage { get; set; } + + public async Task OnGetAsync() + { + LastError = ""; + Skip = string.IsNullOrEmpty(Request.Query["skip"]) ? 0 : int.Parse(Request.Query["skip"]); + MainImage = null; + PreviouslyLinkedImage = null; + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var imageResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/artifacts/ganjoor/nextunsychedimage?skip={Skip}"); + if (!imageResponse.IsSuccessStatusCode) + { + LastError = await imageResponse.Content.ReadAsStringAsync(); + } + else + { + string paginnationMetadata = imageResponse.Headers.GetValues("paging-headers").FirstOrDefault(); + if (!string.IsNullOrEmpty(paginnationMetadata)) + { + TotalCount = JsonConvert.DeserializeObject(paginnationMetadata).totalCount; + } + + var images = JsonConvert.DeserializeObject(await imageResponse.Content.ReadAsStringAsync()); + + if(images != null) + { + if(images.Length >= 1) + { + MainImage = images[0]; + } + + if (images.Length >= 2) + { + PreviouslyLinkedImage = images[1]; + } + } + + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + + } + } + } +} diff --git a/GanjooRazor/Areas/User/Pages/ReviewSongs.cshtml.cs b/GanjooRazor/Areas/User/Pages/ReviewSongs.cshtml.cs index 773f65e8..b0403d05 100644 --- a/GanjooRazor/Areas/User/Pages/ReviewSongs.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/ReviewSongs.cshtml.cs @@ -84,9 +84,6 @@ namespace GanjooRazor.Areas.User.Pages if (poemResponse.IsSuccessStatusCode) { Poem = JsonConvert.DeserializeObject(await poemResponse.Content.ReadAsStringAsync()); - - - } else { diff --git a/GanjooRazor/Pages/Shared/_Layout.cshtml b/GanjooRazor/Pages/Shared/_Layout.cshtml index 36b0a8f6..b26e5f4f 100644 --- a/GanjooRazor/Pages/Shared/_Layout.cshtml +++ b/GanjooRazor/Pages/Shared/_Layout.cshtml @@ -169,6 +169,13 @@ حاشیه‌های گزارش شده } + + @if (ViewData.ContainsKey($"{RMuseum.Models.Auth.Memory.RMuseumSecurableItem.ArtifactEntityShortName}-{RMuseum.Models.Auth.Memory.RMuseumSecurableItem.ReviewGanjoorLinksOperationShortName}")) + { + + } diff --git a/GanjooRazor/appsettings.json b/GanjooRazor/appsettings.json index 24839963..5c1b23d5 100644 --- a/GanjooRazor/appsettings.json +++ b/GanjooRazor/appsettings.json @@ -8,6 +8,6 @@ }, "AllowedHosts": "*", "GoogleAnalyticsCode": "", - "APIRoot": "http://localhost:3439", - "GlobalAPIRoot": "http://localhost:3439" + "APIRoot": "https://ganjgah.ir", + "GlobalAPIRoot": "https://ganjgah.ir" } diff --git a/RMuseum/Controllers/ArtifactController.cs b/RMuseum/Controllers/ArtifactController.cs index 01a21f8b..bc09faa3 100644 --- a/RMuseum/Controllers/ArtifactController.cs +++ b/RMuseum/Controllers/ArtifactController.cs @@ -1667,7 +1667,25 @@ namespace RMuseum.Controllers return Ok(res.Result); } - + /// + /// finds next unsynchronized suggested link with an aleady synched one from the artificat if exists, + /// return value might be null or an array with length 1 or 2 + /// + /// + /// return value might be null or an array with length 1 or 2 + [HttpGet] + [Route("ganjoor/nextunsychedimage")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorLinkViewModel[]))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetNextUnsynchronizedSuggestedLinkWithAlreadySynchedOneForPoem(int skip) + { + RServiceResult res = await _artifactService.GetNextUnsynchronizedSuggestedLinkWithAlreadySynchedOneForPoem(skip); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result); + } + /// /// review suggested ganjoor link /// @@ -1692,15 +1710,16 @@ namespace RMuseum.Controllers /// mark suggested ganjoor link as synchronized /// /// + /// display ogn page /// [HttpPut] - [Route("ganjoor/sync/{linkId}")] + [Route("ganjoor/sync/{linkId}/{displayOnPage}")] [Authorize(Policy = RMuseumSecurableItem.ArtifactEntityShortName + ":" + RMuseumSecurableItem.ReviewGanjoorLinksOperationShortName)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] - public async Task SynchronizeGanjoorLink(Guid linkId) + public async Task SynchronizeGanjoorLink(Guid linkId, bool displayOnPage) { - RServiceResult suggestion = await _artifactService.SynchronizeSuggestedLink(linkId); + RServiceResult suggestion = await _artifactService.SynchronizeSuggestedLink(linkId, displayOnPage); if (!string.IsNullOrEmpty(suggestion.ExceptionString)) return BadRequest(suggestion.ExceptionString); return Ok(); diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index a26d882c..26908ffa 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -478,6 +478,14 @@ + + + finds next unsynchronized suggested link with an aleady synched one from the artificat if exists, + return value might be null or an array with length 1 or 2 + + + return value might be null or an array with length 1 or 2 + review suggested ganjoor link @@ -486,11 +494,12 @@ - + mark suggested ganjoor link as synchronized + display ogn page @@ -6485,11 +6494,12 @@ - + Synchronize suggested link + @@ -7449,11 +7459,12 @@ - + Synchronize suggested link + diff --git a/RMuseum/Services/IArtifactService.cs b/RMuseum/Services/IArtifactService.cs index 5ef03908..23e85b23 100644 --- a/RMuseum/Services/IArtifactService.cs +++ b/RMuseum/Services/IArtifactService.cs @@ -467,8 +467,9 @@ namespace RMuseum.Services /// Synchronize suggested link /// /// + /// /// - Task> SynchronizeSuggestedLink(Guid linkId); + Task> SynchronizeSuggestedLink(Guid linkId, bool displayOnPage); /// /// get suggested pinterest links diff --git a/RMuseum/Services/Implementation/ArtifactService.cs b/RMuseum/Services/Implementation/ArtifactService.cs index cae6ff90..5c01f908 100644 --- a/RMuseum/Services/Implementation/ArtifactService.cs +++ b/RMuseum/Services/Implementation/ArtifactService.cs @@ -3007,8 +3007,9 @@ namespace RMuseum.Services.Implementation /// Synchronize suggested link /// /// + /// /// - public async Task> SynchronizeSuggestedLink(Guid linkId) + public async Task> SynchronizeSuggestedLink(Guid linkId, bool displayOnPage) { try { @@ -3018,6 +3019,7 @@ namespace RMuseum.Services.Implementation .SingleOrDefaultAsync(); link.Synchronized = true; + link.DisplayOnPage = displayOnPage; _context.GanjoorLinks.Update(link); await _context.SaveChangesAsync();