mirror of
https://github.com/WerySkok/nativegallery.git
synced 2024-11-15 03:31:19 +03:00
load news after creating
This commit is contained in:
parent
f887b1f0a9
commit
f5d26107b8
4 changed files with 78 additions and 43 deletions
20
app/Controllers/Api/Admin/LoadNews.php
Normal file
20
app/Controllers/Api/Admin/LoadNews.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Api\Admin;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF, Date};
|
||||||
|
use App\Models\{User, Vote, Photo};
|
||||||
|
|
||||||
|
|
||||||
|
class LoadNews
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$news = DB::query('SELECT * FROM news ORDER BY id');
|
||||||
|
foreach ($news as $n) {
|
||||||
|
echo '<div class="card mb-3"><div class="card-body">' . Date::zmdate($n['time']) . '<br>' . $n['body'] . '</div></div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ use \App\Controllers\Api\Images\Comments\Rate as PhotoCommentVote;
|
||||||
use \App\Controllers\Api\Profile\Update as ProfileUpdate;
|
use \App\Controllers\Api\Profile\Update as ProfileUpdate;
|
||||||
use \App\Controllers\Api\Admin\Images\SetVisibility as AdminPhotoSetVisibility;
|
use \App\Controllers\Api\Admin\Images\SetVisibility as AdminPhotoSetVisibility;
|
||||||
use \App\Controllers\Api\Admin\CreateNews as AdminCreateNews;
|
use \App\Controllers\Api\Admin\CreateNews as AdminCreateNews;
|
||||||
|
use \App\Controllers\Api\Admin\LoadNews as AdminLoadNews;
|
||||||
class ApiController
|
class ApiController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -63,6 +64,9 @@ class ApiController
|
||||||
public static function admincreatenews() {
|
public static function admincreatenews() {
|
||||||
return new AdminCreateNews();
|
return new AdminCreateNews();
|
||||||
}
|
}
|
||||||
|
public static function adminloadnews() {
|
||||||
|
return new AdminLoadNews();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -56,6 +56,7 @@ class Routes
|
||||||
Router::any('/admin', 'AdminController@index');
|
Router::any('/admin', 'AdminController@index');
|
||||||
Router::any('/api/admin/images/setvisibility', 'ApiController@adminsetvis');
|
Router::any('/api/admin/images/setvisibility', 'ApiController@adminsetvis');
|
||||||
Router::any('/api/admin/createnews', 'ApiController@admincreatenews');
|
Router::any('/api/admin/createnews', 'ApiController@admincreatenews');
|
||||||
|
Router::any('/api/admin/loadnews', 'ApiController@adminloadnews');
|
||||||
}
|
}
|
||||||
Router::get('/logout', 'MainController@logout');
|
Router::get('/logout', 'MainController@logout');
|
||||||
Router::get('/404', 'ExceptionRegister@notfound');
|
Router::get('/404', 'ExceptionRegister@notfound');
|
||||||
|
|
|
@ -11,51 +11,61 @@ use \App\Models\User;
|
||||||
<a data-bs-toggle="modal" data-bs-target="#createNewsModal" href="#" class="btn btn-primary">Создать</a>
|
<a data-bs-toggle="modal" data-bs-target="#createNewsModal" href="#" class="btn btn-primary">Создать</a>
|
||||||
|
|
||||||
<div class="modal fade" id="createNewsModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
<div class="modal fade" id="createNewsModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h1 class="modal-title fs-5" id="exampleModalLabel"><b>Создать новость</b></h1>
|
<h1 class="modal-title fs-5" id="exampleModalLabel"><b>Создать новость</b></h1>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="body" class="form-label">Содержание</label>
|
<label for="body" class="form-label">Содержание</label>
|
||||||
<textarea class="form-control" id="body" name="body" rows="3"></textarea>
|
<textarea class="form-control" id="body" name="body" rows="3"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<a type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</a>
|
<a type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</a>
|
||||||
<a href="#" onclick="createNews(); return false;" data-bs-dismiss="modal" class="btn btn-primary">Создать</a>
|
<a href="#" onclick="createNews(); return false;" data-bs-dismiss="modal" class="btn btn-primary">Создать</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<div id="news">
|
||||||
$news = DB::query('SELECT * FROM news ORDER BY id');
|
<?php
|
||||||
foreach ($news as $n) {
|
$news = DB::query('SELECT * FROM news ORDER BY id');
|
||||||
echo '<div class="card"><div class="card-body">'.Date::zmdate($n['time']).'<br>'.$n['body'].'</div></div>';
|
foreach ($news as $n) {
|
||||||
}
|
echo '<div class="card mb-3"><div class="card-body">' . Date::zmdate($n['time']) . '<br>' . $n['body'] . '</div></div>';
|
||||||
?>
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function photoAction(photo_id, decline_reason, mod) {
|
function createNews() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "POST",
|
||||||
url: '/api/admin/createnews',
|
url: '/api/admin/createnews',
|
||||||
data: {
|
data: {
|
||||||
body: $('#body').val()
|
body: $('#body').val()
|
||||||
},
|
},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
$('#pht'+photo_id).remove();
|
Notify.noty('success', 'OK!');
|
||||||
Notify.noty('success', 'OK!');
|
$.ajax({
|
||||||
//$("#result").html("<div class='alert alert-successnew container mt-5' role='alert'>Успешный вход!</div>");
|
type: "GET",
|
||||||
|
url: '/api/admin/loadnews',
|
||||||
|
|
||||||
|
success: function(response) {
|
||||||
|
$('#news').html(response);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
Loading…
Reference in a new issue