docs: #352 addng geo/date tags to poems

This commit is contained in:
Hamid Reza Mohammadi 2022-08-02 20:24:53 +04:30
parent 28da2349ad
commit ee20641f5b
2 changed files with 86 additions and 4 deletions

View File

@ -266,6 +266,38 @@
});
}
function newGeoDateTag(poemId) {
var url = '?handler=NewGeoDateTag';
var locationId = $('#location').val();
var year = $('#year').val();
var month = $('#month').val()
var day = $('#day').val()
$.ajax({
type: "POST",
url: url,
data: {
poemId: poemId,
locationId: locationId,
year: year,
month: month,
day: day
},
success: function() {
alert('انجام شد.');
location.reload();
},
error: function(e) {
if (e.responseText == null)
alert(e);
else
alert(e.responseText);
}
});
}
</script>
@if (!string.IsNullOrEmpty(Model.FatalError))
{
@ -1072,7 +1104,7 @@ else
@{
foreach (var location in Model.Locations)
{
<option value="@location.Name">@location.Name</option>
<option value="@location.Id">@location.Name</option>
}
}
</select>
@ -1081,7 +1113,21 @@ else
<input type="text" id="year" />
</td>
<td>
<input type="text" id="month" />
<select id="month">
<option value="0">هیچکدام</option>
<option value="1">محرم</option>
<option value="2">صفر</option>
<option value="3">ربیع‌الاول</option>
<option value="4">ربیع‌الثانی</option>
<option value="5">جمادی‌الاول</option>
<option value="6">جمادی‌الثانی</option>
<option value="7">رجب</option>
<option value="8">شعبان</option>
<option value="9">رمضان</option>
<option value="10">شوال</option>
<option value="11">ذیقعده</option>
<option value="12">ذیحجه</option>
</select>
</td>
<td>
<input type="text" id="day" />
@ -1089,7 +1135,7 @@ else
</tr>
<tr>
<td colspan="4">
<a role="button" class="pagebutton" onclick="newLocation()">برچسب جدید</a>
<a role="button" class="pagebutton" onclick="newGeoDateTag(@Model.PageInformation.Id)">برچسب جدید</a>
</td>
</tr>
</table>
@ -1097,7 +1143,7 @@ else
</tr>
<tr>
<td>
<a href="/Admin/Locations" role="button" class="pagebutton">مکان‌ها</a>
<a href="/Admin/Locations" role="button" class="pagebutton">مکان‌ها</a>
</td>
</tr>
}

View File

@ -433,6 +433,8 @@ namespace GanjooRazor.Areas.User.Pages
}
}
public async Task<IActionResult> OnGetComputeRhymeAsync(int id)
{
@ -455,5 +457,39 @@ namespace GanjooRazor.Areas.User.Pages
}
}
public async Task<IActionResult> OnPostNewGeoDateTagAsync(int poemId, int locationId, string year, int month, string day)
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.PostAsync(
$"{APIRoot.Url}/api/ganjoor/poem/geotag",
new StringContent(JsonConvert.SerializeObject(
new PoemGeoDateTag()
{
PoemId = poemId,
LocationId = locationId == 0 ? null : locationId,
LunarYear = string.IsNullOrEmpty(year) ? null : int.Parse(year),
LunarMonth = month == 0 ? null : month,
LunarDay = string.IsNullOrEmpty(day) ? null : int.Parse(day)
}
),
Encoding.UTF8,
"application/json")
);
if (!response.IsSuccessStatusCode)
{
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
}
return new OkResult();
}
else
{
return new BadRequestObjectResult("لطفا از گنجور خارج و مجددا به آن وارد شوید.");
}
}
}
}
}