docs: #275 suggesting new spec line for poets work
This commit is contained in:
parent
e7c79d08f5
commit
e9642dbd95
@ -3,22 +3,16 @@ using GanjooRazor.Utils;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RMuseum.Models.Auth.Memory;
|
||||
using RMuseum.Models.Auth.ViewModel;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using RSecurityBackend.Models.Auth.Memory;
|
||||
using RSecurityBackend.Models.Auth.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
|
||||
@ -41,9 +41,7 @@
|
||||
|
||||
function suggestNote(buttonSelector) {
|
||||
var commentformSelector = '#commentform';
|
||||
if (coupletIndex != '') {
|
||||
commentformSelector += ('-' + coupletIndex);
|
||||
}
|
||||
|
||||
$(commentformSelector).unbind('submit').bind('submit', function (e) {
|
||||
|
||||
e.preventDefault(); // avoid to execute the actual submit of the form.
|
||||
@ -53,11 +51,7 @@
|
||||
|
||||
$('#comment-error').remove();
|
||||
|
||||
var parent1 = $('#comments-block');
|
||||
var parent2 = null;
|
||||
if (coupletIndex != '') {
|
||||
parent2 = $('#comments-block-' + coupletIndex);
|
||||
}
|
||||
var parent1 = $('#lines');
|
||||
|
||||
var form = $(this);
|
||||
var url = form.attr('action');
|
||||
@ -66,14 +60,13 @@
|
||||
type: "POST",
|
||||
url: url,
|
||||
data: form.serialize(), // serializes the form's elements.
|
||||
error: function () {
|
||||
error: function (data) {
|
||||
$(data).appendTo(parent1);
|
||||
$(buttonSelector).text('پیشنهاد');
|
||||
$(buttonSelector).prop("disabled", false);
|
||||
},
|
||||
success: function (data) {
|
||||
$(data).appendTo(parent1);
|
||||
if (parent2 != null)
|
||||
$(data).appendTo(parent2);
|
||||
$(buttonSelector).text('پیشنهاد');
|
||||
$(buttonSelector).prop("disabled", false);
|
||||
form[0].reset();
|
||||
@ -158,12 +151,12 @@
|
||||
نکات مهم دربارهٔ @Model.Poet.Nickname
|
||||
</div>
|
||||
|
||||
@foreach (var line in Model.SpecLines)
|
||||
{
|
||||
<div class="clear-both">
|
||||
@line.Contents
|
||||
</div>
|
||||
}
|
||||
<div id="lines">
|
||||
@foreach (var line in Model.SpecLines)
|
||||
{
|
||||
<partial name="_PoetSpecLinePartial" model=line />
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="clear-both">
|
||||
@if (Model.LoggedIn)
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
using GanjooRazor.Utils;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
@ -43,8 +44,8 @@ namespace GanjooRazor.Pages
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"]);
|
||||
|
||||
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(Request.Query["p"]))
|
||||
{
|
||||
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poet?url=/{Request.Query["p"]}");
|
||||
@ -76,6 +77,7 @@ namespace GanjooRazor.Pages
|
||||
|
||||
public async Task<ActionResult> OnPostSuggestAsync(int poetId, string contents)
|
||||
{
|
||||
string error = "";
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
@ -92,22 +94,51 @@ namespace GanjooRazor.Pages
|
||||
),
|
||||
Encoding.UTF8, "application/json")
|
||||
);
|
||||
if(response.StatusCode == HttpStatusCode.OK)
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
|
||||
var line = JsonConvert.DeserializeObject<GanjoorPoetSuggestedSpecLineViewModel>(await response.Content.ReadAsStringAsync());
|
||||
return new PartialViewResult()
|
||||
{
|
||||
ViewName = "_PoetSpecLinePartial",
|
||||
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
|
||||
{
|
||||
Model = new _PoetSpecLinePartialModel()
|
||||
{
|
||||
Line = line
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
error = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
|
||||
}
|
||||
}
|
||||
return Page();
|
||||
return new PartialViewResult()
|
||||
{
|
||||
ViewName = "_PoetSpecLinePartial",
|
||||
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
|
||||
{
|
||||
Model = new _PoetSpecLinePartialModel()
|
||||
{
|
||||
Line = new GanjoorPoetSuggestedSpecLineViewModel()
|
||||
{
|
||||
Id = 0,
|
||||
Contents = error
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public PhotosModel(HttpClient httpClient) : base(httpClient)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
GanjooRazor/Pages/_PoetSpecLinePartial.cshtml
Normal file
15
GanjooRazor/Pages/_PoetSpecLinePartial.cshtml
Normal file
@ -0,0 +1,15 @@
|
||||
@model GanjooRazor.Pages._PoetSpecLinePartialModel
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<div class="clear-both" id="@(Model.Line.Id == 0 ? "comment-error" : $"line-{Model.Line.Id}")">
|
||||
@Html.Raw(Model.Line.Contents)
|
||||
</div>
|
||||
|
||||
@if (Model.Line.Id != 0 && !Model.Line.Published)
|
||||
{
|
||||
<div class="clear-both">
|
||||
در انتظار بررسی
|
||||
</div>
|
||||
}
|
||||
10
GanjooRazor/Pages/_PoetSpecLinePartial.cshtml.cs
Normal file
10
GanjooRazor/Pages/_PoetSpecLinePartial.cshtml.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
|
||||
namespace GanjooRazor.Pages
|
||||
{
|
||||
public class _PoetSpecLinePartialModel : PageModel
|
||||
{
|
||||
public GanjoorPoetSuggestedSpecLineViewModel Line { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user