Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Реализован нативный механизм View для итема в секции. #1197

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'model' => [
'create' => 'Create record in section :title',
'edit' => 'Update record in section :title',
'view' => 'View item in section :title',
],

'links' => [
Expand Down
21 changes: 21 additions & 0 deletions src/Contracts/ModelConfigurationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions src/Factories/DisplayColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}
22 changes: 22 additions & 0 deletions src/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
5 changes: 5 additions & 0 deletions src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
'uses' => 'AdminController@inlineEdit',
]);

$router->get('{adminModel}/{adminModelId?}', [
'as' => 'model.view',
'uses' => 'AdminController@getView',
]);

$router->get('{adminModel}/create', [
'as' => 'model.create',
'uses' => 'AdminController@getCreate',
Expand Down
57 changes: 57 additions & 0 deletions src/Model/ModelConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public static function setEventDispatcher(Dispatcher $dispatcher)
*/
protected $model_value = null;

/**
* @var string|null
*/
protected $view;

/**
* ModelConfigurationManager constructor.
*
Expand Down Expand Up @@ -698,4 +703,56 @@ 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()]);
}
}
1 change: 0 additions & 1 deletion src/Model/SectionModelConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ public function getPayload()
public function setPayload($payload = [])
{
$this->payload = $payload;

return $this;
}
}