From ece7e076ade097b172971029a105a05ff618de41 Mon Sep 17 00:00:00 2001 From: Mike Protasov Date: Tue, 19 May 2020 15:04:49 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20View=20=D0=B4=D0=BB=D1=8F=20=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D0=BC=D0=B0=20=D0=B2=20=D1=81=D0=B5=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/lang/en/lang.php | 1 + src/Contracts/ModelConfigurationInterface.php | 21 +++++++ src/Factories/DisplayColumnFactory.php | 1 + src/Http/Controllers/AdminController.php | 22 ++++++++ src/Http/routes.php | 6 ++ src/Model/ModelConfigurationManager.php | 56 +++++++++++++++++++ 6 files changed, 107 insertions(+) diff --git a/resources/lang/en/lang.php b/resources/lang/en/lang.php index b39214df9..dc14dcaad 100755 --- a/resources/lang/en/lang.php +++ b/resources/lang/en/lang.php @@ -18,6 +18,7 @@ 'model' => [ 'create' => 'Create record in section :title', 'edit' => 'Update record in section :title', + 'view' => 'View item in section :title', ], 'links' => [ diff --git a/src/Contracts/ModelConfigurationInterface.php b/src/Contracts/ModelConfigurationInterface.php index 16a5929e1..4ec852275 100755 --- a/src/Contracts/ModelConfigurationInterface.php +++ b/src/Contracts/ModelConfigurationInterface.php @@ -271,4 +271,25 @@ public function getControllerClass(); * @return \SleepingOwl\Admin\Navigation\Page */ public function addToNavigation(); + + /** + * @return string + */ + public function getViewPath(); + + /** + * @param string + * @return string + */ + public function setViewPath($path); + + /** + * @return bool + */ + public function isViewable(); + + /** + * @return string + */ + public function getViewTitle(); } diff --git a/src/Factories/DisplayColumnFactory.php b/src/Factories/DisplayColumnFactory.php index e3c28e2b3..d2cbad08c 100755 --- a/src/Factories/DisplayColumnFactory.php +++ b/src/Factories/DisplayColumnFactory.php @@ -55,6 +55,7 @@ public function __construct(Application $application) 'email' => Column\Email::class, 'treeControl' => Column\TreeControl::class, 'url' => Column\Url::class, + 'view' => Column\View::class, ]); } } diff --git a/src/Http/Controllers/AdminController.php b/src/Http/Controllers/AdminController.php index c2edf233e..8de910e06 100644 --- a/src/Http/Controllers/AdminController.php +++ b/src/Http/Controllers/AdminController.php @@ -815,4 +815,26 @@ public function deletedAll(ModelConfigurationInterface $model, Request $request) return $response ->with('success_message', $model->getMessageOnDelete()); } + + /** + * @param ModelConfigurationInterface $model + * @param $id + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @throws \DaveJamesMiller\Breadcrumbs\Exceptions\DuplicateBreadcrumbException + */ + public function getView(ModelConfigurationInterface $model, $id) + { + $item = $model->getRepository()->find($id); + + if (is_null($item) || ! $model->isViewable()) { + abort(404); + } + + $content = view($model->getViewPath(), ['model' => $item]); + + $this->registerBreadcrumbs($model); + $this->registerBreadcrumb($model->getViewTitle(), $this->parentBreadcrumb); + + return $this->renderContent($content, $model->getViewTitle()); + } } diff --git a/src/Http/routes.php b/src/Http/routes.php index 7e5533daa..4f70818e0 100755 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -16,6 +16,12 @@ 'uses' => 'AdminController@inlineEdit', ]); + $router->get('{adminModel}/{adminModelId?}', [ + 'as' => 'model.view', + 'uses' => 'AdminController@getView', + ]); + + $router->get('{adminModel}/create', [ 'as' => 'model.create', 'uses' => 'AdminController@getCreate', diff --git a/src/Model/ModelConfigurationManager.php b/src/Model/ModelConfigurationManager.php index 83a5ae05b..1e7e7c188 100755 --- a/src/Model/ModelConfigurationManager.php +++ b/src/Model/ModelConfigurationManager.php @@ -108,6 +108,11 @@ public static function setEventDispatcher(Dispatcher $dispatcher) */ protected $model_value = null; + /** + * @var string|null + */ + protected $view; + /** * ModelConfigurationManager constructor. * @@ -698,4 +703,55 @@ protected function getDefaultClassTitle() { return Str::snake(Str::plural(class_basename($this->getClass()))); } + + /** + * @return bool + */ + public function isViewable() + { + return ( $this->can('view', $this->getModel() ) and $this->view ) ? true : false; + } + + /** + * @return bool + */ + public function getViewPath() + { + return $this->view; + } + + /** + * @param string + * @return $this + */ + public function setViewPath($path) + { + $this->view = $path; + return $this; + } + + /** + * @param string|int $id + * @param array $parameters + * + * @return string + */ + public function getViewUrl($id, array $parameters = []) + { + if (! $id) { + return '#'; + } + + array_unshift($parameters, $this->getAlias(), $id); + + return route('admin.model.view', $parameters); + } + + /** + * @return string + */ + public function getViewTitle() + { + return trans('sleeping_owl::lang.model.view', ['title' => $this->getTitle()]); + } } From b95ad663b8446045560e9c9f2dda5df0b65c3ccc Mon Sep 17 00:00:00 2001 From: ProtasovM Date: Tue, 19 May 2020 15:27:25 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/routes.php | 1 - src/Model/ModelConfigurationManager.php | 3 ++- src/Model/SectionModelConfiguration.php | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Http/routes.php b/src/Http/routes.php index 4f70818e0..05fc8810b 100755 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -21,7 +21,6 @@ 'uses' => 'AdminController@getView', ]); - $router->get('{adminModel}/create', [ 'as' => 'model.create', 'uses' => 'AdminController@getCreate', diff --git a/src/Model/ModelConfigurationManager.php b/src/Model/ModelConfigurationManager.php index 1e7e7c188..1cd712e04 100755 --- a/src/Model/ModelConfigurationManager.php +++ b/src/Model/ModelConfigurationManager.php @@ -709,7 +709,7 @@ protected function getDefaultClassTitle() */ public function isViewable() { - return ( $this->can('view', $this->getModel() ) and $this->view ) ? true : false; + return ($this->can('view', $this->getModel() ) and $this->view) ? true : false; } /** @@ -727,6 +727,7 @@ public function getViewPath() public function setViewPath($path) { $this->view = $path; + return $this; } diff --git a/src/Model/SectionModelConfiguration.php b/src/Model/SectionModelConfiguration.php index 261c2f5ac..e79ec497a 100755 --- a/src/Model/SectionModelConfiguration.php +++ b/src/Model/SectionModelConfiguration.php @@ -221,7 +221,6 @@ public function getPayload() public function setPayload($payload = []) { $this->payload = $payload; - return $this; } } From 6c541f4bfeb49a792e5388af83a449b7f8185be1 Mon Sep 17 00:00:00 2001 From: ProtasovM Date: Tue, 19 May 2020 15:30:31 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=B5=D1=89=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model/ModelConfigurationManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/ModelConfigurationManager.php b/src/Model/ModelConfigurationManager.php index 1cd712e04..801891663 100755 --- a/src/Model/ModelConfigurationManager.php +++ b/src/Model/ModelConfigurationManager.php @@ -709,7 +709,7 @@ protected function getDefaultClassTitle() */ public function isViewable() { - return ($this->can('view', $this->getModel() ) and $this->view) ? true : false; + return ($this->can('view', $this->getModel()) and $this->view) ? true : false; } /**