From fc001ee0cf19ad30e901bf8c4e6510bab9af3e79 Mon Sep 17 00:00:00 2001 From: ro4 Date: Wed, 18 Apr 2018 17:16:36 +0800 Subject: [PATCH 1/2] read mode --- app/Http/Controllers/DocumentController.php | 28 +++++++++++++++++++ resources/lang/en/document.php | 1 + resources/lang/zh/document.php | 1 + .../views/components/page-menus.blade.php | 4 +++ routes/web.php | 3 ++ 5 files changed, 37 insertions(+) diff --git a/app/Http/Controllers/DocumentController.php b/app/Http/Controllers/DocumentController.php index cdccb83e..80a0e8d8 100644 --- a/app/Http/Controllers/DocumentController.php +++ b/app/Http/Controllers/DocumentController.php @@ -343,4 +343,32 @@ public function getPageJSON(Request $request, $id, $page_id) 'updated_at' => $pageItem->updated_at->format('Y-m-d H:i:s'), ]; } + + /** + * read mode + * + * @param $id + * @param $page_id + * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function readMode($id, $page_id) + { + /** @var Project $project */ + $project = Project::with([ + 'pages' => function (Relation $query) { + $query->select('id', 'pid', 'title', 'description', 'project_id', 'type', 'status'); + } + ])->findOrFail($id); + + $page = Document::where('project_id', $id)->where('id', $page_id)->firstOrFail(); + $type = $page->type == Document::TYPE_DOC ? 'markdown' : 'swagger'; + + return view('share-show', [ + 'project' => $project, + 'pageItem' => $page, + 'type' => $type, + 'noheader' => true, + ]); + } } \ No newline at end of file diff --git a/resources/lang/en/document.php b/resources/lang/en/document.php index b4b72a47..1463579b 100644 --- a/resources/lang/en/document.php +++ b/resources/lang/en/document.php @@ -27,6 +27,7 @@ 'document_differ' => 'Document Differ', 'latest_document' => 'Latest', 'history_document' => 'History Archive', + 'read_mode' => 'Read Mode', 'after_modified' => 'After', 'select_template' => 'Choose Template', diff --git a/resources/lang/zh/document.php b/resources/lang/zh/document.php index 60fa1936..49ca1412 100644 --- a/resources/lang/zh/document.php +++ b/resources/lang/zh/document.php @@ -29,6 +29,7 @@ 'document_differ' => '文档差异对比', 'latest_document' => '最新文档', 'history_document' => '历史版本', + 'read_mode' => '阅读模式', 'after_modified' => '修改后', 'select_template' => '选择模板', diff --git a/resources/views/components/page-menus.blade.php b/resources/views/components/page-menus.blade.php index e8405c5c..b4fdc1fb 100644 --- a/resources/views/components/page-menus.blade.php +++ b/resources/views/components/page-menus.blade.php @@ -9,6 +9,10 @@ @lang('common.btn_share') + + + @lang('document.read_mode') + @if($pageItem->type == \App\Repositories\Document::TYPE_DOC) diff --git a/routes/web.php b/routes/web.php index 194cb17f..02fc5650 100644 --- a/routes/web.php +++ b/routes/web.php @@ -131,6 +131,9 @@ // 文档分享 Route::post('/{id}/doc/{page_id}/share', 'ShareController@create')->name('doc:share'); + // 阅读模式 + Route::get('/{id}/doc/{page_id}/read', 'DocumentController@readMode')->name('doc:read'); + // 文档评论 Route::post('/{id}/doc/{page_id}/comments', 'CommentController@publish')->name('doc:comment'); From 15a57beb970f7eb3376cd9450e1d461b6dc102a6 Mon Sep 17 00:00:00 2001 From: ro4 Date: Thu, 19 Apr 2018 10:53:41 +0800 Subject: [PATCH 2/2] read mode --- app/Http/Controllers/DocumentController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/DocumentController.php b/app/Http/Controllers/DocumentController.php index 80a0e8d8..1e6a8e2f 100644 --- a/app/Http/Controllers/DocumentController.php +++ b/app/Http/Controllers/DocumentController.php @@ -355,11 +355,11 @@ public function getPageJSON(Request $request, $id, $page_id) public function readMode($id, $page_id) { /** @var Project $project */ - $project = Project::with([ - 'pages' => function (Relation $query) { - $query->select('id', 'pid', 'title', 'description', 'project_id', 'type', 'status'); - } - ])->findOrFail($id); + $project = Project::query()->findOrFail($id); + $policy = new ProjectPolicy(); + if (!$policy->view(\Auth::user(), $project)) { + abort(403, '您没有访问该项目的权限'); + } $page = Document::where('project_id', $id)->where('id', $page_id)->firstOrFail(); $type = $page->type == Document::TYPE_DOC ? 'markdown' : 'swagger';