comment lists WIP
This commit is contained in:
parent
05d748c7f6
commit
6fff584f59
|
@ -4,20 +4,23 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Models\Comment;
|
||||
use App\Models\Post;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
public function index() {
|
||||
public function index(Request $request) {
|
||||
$pages = Comment::orderBy('posted_at', 'DESC')->simplePaginate(15);
|
||||
return view('comment.index', [
|
||||
'items' => $pages
|
||||
'items' => $pages,
|
||||
'is_ajax' => $request->isXmlHttpRequest(),
|
||||
]);
|
||||
}
|
||||
public function load($id) {
|
||||
public function load($id, Request $request) {
|
||||
$post = Post::findOrFail($id);
|
||||
$comments= $post->comments()->published()->get();
|
||||
return view('comment.index', [
|
||||
'items' => $comments
|
||||
'items' => $comments,
|
||||
'is_ajax' => $request->isXmlHttpRequest(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,22 @@
|
|||
<?php
|
||||
namespace App\Http\View;
|
||||
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CommentIndexComposer extends ReadComposer
|
||||
{
|
||||
|
||||
/** Bind data to the view.
|
||||
* @param View $view
|
||||
* @return void
|
||||
*/
|
||||
public function compose(View $view) {
|
||||
parent::compose($view);
|
||||
$is_ajax = false;
|
||||
$is_ajax = $view->getData()['is_ajax'] ?? false;
|
||||
$view->with('is_ajax', $is_ajax);
|
||||
}
|
||||
|
||||
/**
|
||||
* An internal function to prepare item data.
|
||||
**/
|
||||
|
|
37
resources/js/app.js
vendored
37
resources/js/app.js
vendored
|
@ -1,7 +1,7 @@
|
|||
import 'bootstrap';
|
||||
import 'moment';
|
||||
import jQuery from 'jquery';
|
||||
import 'autosize';
|
||||
import autosize from 'autosize';
|
||||
|
||||
/*import Alpine from 'alpinejs';
|
||||
|
||||
|
@ -9,24 +9,21 @@ window.Alpine = Alpine;
|
|||
|
||||
Alpine.start();
|
||||
*/
|
||||
|
||||
jQuery(document).on('ready', function($){
|
||||
$('.date').each(function(){
|
||||
if ($(this).text() != '')
|
||||
{
|
||||
var day = moment($(this).text());
|
||||
$(this).text(day.fromNow()+", "+day.format('LL'));
|
||||
}
|
||||
});
|
||||
|
||||
if ($('#new_comment').length > 0) {
|
||||
$('#new_comment').load($('#new_comment').data('url'), function(){
|
||||
$('#new_comment').html($('#new_comment').html().replace(/-ID-/g, $('#new_comment').data('id')));
|
||||
autosize($('textarea'));
|
||||
});
|
||||
}
|
||||
|
||||
if ($('#comments').length > 0) {
|
||||
$('#comments').load($('#comments').data('url'));
|
||||
jQuery('.date').each(function(){
|
||||
if (jQuery(this).text() != '')
|
||||
{
|
||||
var day = moment(jQuery(this).text());
|
||||
jQuery(this).text(day.fromNow()+", "+day.format('LL'));
|
||||
}
|
||||
});
|
||||
|
||||
if (jQuery('#new_comment').length > 0) {
|
||||
jQuery('#new_comment').load(jQuery('#new_comment').data('url'), function(){
|
||||
jQuery('#new_comment').html(jQuery('#new_comment').html().replace(/-ID-/g, jQuery('#new_comment').data('id')));
|
||||
autosize(jQuery('textarea'));
|
||||
});
|
||||
}
|
||||
|
||||
if (jQuery('#comments').length > 0) {
|
||||
jQuery('#comments').load(jQuery('#comments').data('url'));
|
||||
}
|
||||
|
|
36
resources/views/_layouts/empty.blade.php
Normal file
36
resources/views/_layouts/empty.blade.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<!doctype html>
|
||||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" class="@stack('html_classes')">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{ $title ?? '' }}</title>
|
||||
<meta content="width=device-width, initial-scale=1" name="viewport">
|
||||
<link href='favicon.ico' rel='shortcut icon' type='image/x-icon'/>
|
||||
@vite('resources/sass/main.scss')
|
||||
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.8.1/css/lightbox.css">
|
||||
{!! $head_scripts ?? ''!!}
|
||||
</head>
|
||||
<body vocab="http://schema.org">
|
||||
<div class = "main_content">
|
||||
{!! $breadcrumbs ?? ''!!}
|
||||
@if(!empty($title))
|
||||
<h1>{{ $title }}</h1>
|
||||
@endif
|
||||
@if (!empty($get_paging))
|
||||
<div class="row">
|
||||
<nav class="paging">
|
||||
{!! $get_paging !!}
|
||||
</nav>
|
||||
</div>
|
||||
@endif
|
||||
@yield('content')
|
||||
@if (!empty($get_paging))
|
||||
<div class="row">
|
||||
<nav class="paging">
|
||||
{!! $get_paging !!}
|
||||
</nav>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,8 +1,12 @@
|
|||
@extends('_layouts.app')
|
||||
@if (!$is_ajax)
|
||||
@extends('_layouts.app')
|
||||
@else
|
||||
@extends('_layouts.empty')
|
||||
@endif
|
||||
|
||||
@section('content')
|
||||
<table class="table table-striped table-hover">
|
||||
@if ($is_admin)
|
||||
@if (!$is_ajax && $is_admin)
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="col-md-9">Текст</th>
|
||||
|
@ -30,7 +34,7 @@
|
|||
@endif
|
||||
</div>
|
||||
</td>
|
||||
@if ($is_admin)
|
||||
@if (!$is_ajax && $is_admin)
|
||||
<td>
|
||||
@if ($item['is_approved'] === \App\Models\Comment::STATUS_APPROVED)
|
||||
<span class="fa fa-check-square-o"></span> одобрен
|
||||
|
|
|
@ -39,5 +39,5 @@ Route::controller(CommentController::class)->group(function() {
|
|||
Route::any('/comment/post/{id}', 'load')->name('comments.load');
|
||||
Route::any('/comment/edit/{id}', 'edit')->name('comments.edit');
|
||||
Route::any('/comment/delete/{id}', 'delete')->name('comments.delete');
|
||||
Route::post('/comment/post', 'post')->name('comments.post');
|
||||
Route::get('/comment/post', 'post')->name('comments.post');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue