mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-22 12:11:51 +08:00
Added comments controller, model, repo, and the database schema. Modified existing Page model to associate with comments.
This commit is contained in:
parent
cd6572b61a
commit
397db04428
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -8,9 +8,11 @@ Homestead.yaml
|
||||||
/public/css
|
/public/css
|
||||||
/public/js
|
/public/js
|
||||||
/public/bower
|
/public/bower
|
||||||
|
/public/build/
|
||||||
/storage/images
|
/storage/images
|
||||||
_ide_helper.php
|
_ide_helper.php
|
||||||
/storage/debugbar
|
/storage/debugbar
|
||||||
.phpstorm.meta.php
|
.phpstorm.meta.php
|
||||||
yarn.lock
|
yarn.lock
|
||||||
/bin
|
/bin
|
||||||
|
nbproject
|
35
app/Comment.php
Normal file
35
app/Comment.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack;
|
||||||
|
|
||||||
|
class Comment extends Ownable
|
||||||
|
{
|
||||||
|
protected $fillable = ['text', 'html'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the entity that this comment belongs to
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
||||||
|
*/
|
||||||
|
public function entity()
|
||||||
|
{
|
||||||
|
return $this->morphTo('entity');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the page that this comment is in.
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function page()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Page::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the owner of this comment.
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
}
|
33
app/Http/Controllers/CommentController.php
Normal file
33
app/Http/Controllers/CommentController.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
use BookStack\Http\Requests;
|
||||||
|
|
||||||
|
class CommentController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
public function add(Request $request, $pageId) {
|
||||||
|
// $this->checkOwnablePermission('page-view', $page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, $id) {
|
||||||
|
// Check whether its an admin or the comment owner.
|
||||||
|
// $this->checkOwnablePermission('page-view', $page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($id) {
|
||||||
|
// Check whether its an admin or the comment owner.
|
||||||
|
// $this->checkOwnablePermission('page-view', $page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLastXComments($pageId) {
|
||||||
|
// $this->checkOwnablePermission('page-view', $page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getChildComments($pageId, $id) {
|
||||||
|
// $this->checkOwnablePermission('page-view', $page);
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,15 @@ class Page extends Entity
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Chapter::class);
|
return $this->belongsTo(Chapter::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the comments in the page.
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
*/
|
||||||
|
public function comment()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Comment::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this page has a chapter.
|
* Check if this page has a chapter.
|
||||||
|
|
17
app/Repos/CommentRepo.php
Normal file
17
app/Repos/CommentRepo.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php namespace BookStack\Repos;
|
||||||
|
|
||||||
|
use BookStack\Comment;
|
||||||
|
use BookStack\Entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TagRepo
|
||||||
|
* @package BookStack\Repos
|
||||||
|
*/
|
||||||
|
class CommentRepo {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var Comment $comment
|
||||||
|
*/
|
||||||
|
protected $comment;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateCommentsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('comments', function (Blueprint $table) {
|
||||||
|
$table->increments('id')->unsigned();
|
||||||
|
$table->integer('page_id')->unsigned();
|
||||||
|
$table->longText('text')->nullable();
|
||||||
|
$table->longText('html')->nullable();
|
||||||
|
$table->integer('parent_id')->unsigned()->nullable();
|
||||||
|
$table->integer('created_by')->unsigned();
|
||||||
|
$table->integer('updated_by')->unsigned()->nullable();
|
||||||
|
$table->index(['page_id', 'parent_id']);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('comments');
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,7 +51,7 @@
|
||||||
@include('partials/entity-list', [
|
@include('partials/entity-list', [
|
||||||
'entities' => $recentlyUpdatedPages,
|
'entities' => $recentlyUpdatedPages,
|
||||||
'style' => 'compact',
|
'style' => 'compact',
|
||||||
'emptyText' => trans('entites.no_pages_recently_updated')
|
'emptyText' => trans('entities.no_pages_recently_updated')
|
||||||
])
|
])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -113,6 +113,13 @@ Route::group(['middleware' => 'auth'], function () {
|
||||||
|
|
||||||
Route::get('/ajax/search/entities', 'SearchController@searchEntitiesAjax');
|
Route::get('/ajax/search/entities', 'SearchController@searchEntitiesAjax');
|
||||||
|
|
||||||
|
// Comments
|
||||||
|
Route::post('/ajax/page/{pageId}/comment/', 'CommentController@add');
|
||||||
|
Route::put('/ajax/page/comment/{id}', 'CommentController@update');
|
||||||
|
Route::delete('/ajax/comment/{id}', 'CommentController@destroy');
|
||||||
|
Route::get('/ajax/page/{pageId}/comment/', 'CommentController@getLastXComments');
|
||||||
|
Route::get('/ajax/page/{pageId}/comment/{id}/sub-comments', 'CommentController@getChildComments');
|
||||||
|
|
||||||
// Links
|
// Links
|
||||||
Route::get('/link/{id}', 'PageController@redirectFromLink');
|
Route::get('/link/{id}', 'PageController@redirectFromLink');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user