Skip to content

Commit

Permalink
Исправление множества ошибок.
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Feb 16, 2016
1 parent 659cb0b commit 2c7cdb6
Show file tree
Hide file tree
Showing 33 changed files with 111 additions and 158 deletions.
4 changes: 0 additions & 4 deletions src/ColumnFilters/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ class Date extends Text
*/
public function getFormat()
{
if (is_null($this->format)) {
$this->setFormat(config('sleeping_owl.datetimeFormat'));
}

return $this->format;
}

Expand Down
26 changes: 13 additions & 13 deletions src/Columns/Column/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Control extends BaseColumn
protected $view = 'control';

/**
* @var
* @var string
*/
protected $width = '50px';

Expand Down Expand Up @@ -46,7 +46,7 @@ protected function isTrashed()
* Check if instance editable.
* @return bool
*/
protected function editable()
protected function isEditable()
{
return ! $this->isTrashed() && ! is_null($this->getModelConfiguration()->fireEdit($this->getModelKey()));
}
Expand All @@ -55,7 +55,7 @@ protected function editable()
* Get instance edit url.
* @return string
*/
protected function editUrl()
protected function getEditUrl()
{
return $this->getModelConfiguration()->getEditUrl($this->getModelKey());
}
Expand All @@ -64,7 +64,7 @@ protected function editUrl()
* Check if instance is deletable.
* @return bool
*/
protected function deletable()
protected function isDeletable()
{
return ! $this->isTrashed() && ! is_null($this->getModelConfiguration()->fireDelete($this->getModelKey()));
}
Expand All @@ -73,7 +73,7 @@ protected function deletable()
* Get instance delete url.
* @return string
*/
protected function deleteUrl()
protected function getDeleteUrl()
{
return $this->getModelConfiguration()->getDeleteUrl($this->getModelKey());
}
Expand All @@ -82,7 +82,7 @@ protected function deleteUrl()
* Check if instance is restorable.
* @return bool
*/
protected function restorable()
protected function isRestorable()
{
return $this->isTrashed() && ! is_null($this->getModelConfiguration()->fireRestore($this->getModelKey()));
}
Expand All @@ -91,7 +91,7 @@ protected function restorable()
* Get instance restore url.
* @return string
*/
protected function restoreUrl()
protected function getRestoreUrl()
{
return $this->getModelConfiguration()->getRestoreUrl($this->getModelKey());
}
Expand All @@ -102,12 +102,12 @@ protected function restoreUrl()
public function render()
{
return app('sleeping_owl.template')->view('column.'.$this->view, [
'editable' => $this->editable(),
'editUrl' => $this->editUrl(),
'deletable' => $this->deletable(),
'deleteUrl' => $this->deleteUrl(),
'restorable' => $this->restorable(),
'restoreUrl' => $this->restoreUrl(),
'editable' => $this->isEditable(),
'editUrl' => $this->getEditUrl(),
'deletable' => $this->isDeletable(),
'deleteUrl' => $this->getDeleteUrl(),
'restorable' => $this->isRestorable(),
'restoreUrl' => $this->getRestoreUrl(),
]);
}
}
4 changes: 0 additions & 4 deletions src/Columns/Column/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class DateTime extends NamedColumn
*/
public function getFormat()
{
if (is_null($this->format)) {
$this->setFormat(config('sleeping_owl.datetimeFormat'));
}

return $this->format;
}

Expand Down
11 changes: 1 addition & 10 deletions src/FormItems/BaseDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BaseDateTime extends NamedFormItem
/**
* @var string
*/
protected $format;
protected $format = 'Y-m-d H:i:s';

/**
* @var bool
Expand All @@ -22,20 +22,11 @@ class BaseDateTime extends NamedFormItem
*/
protected $pickerFormat;

/**
* @var string
*/
protected $defaultConfigFormat = 'datetimeFormat';

/**
* @return string
*/
public function getFormat()
{
if (is_null($this->format)) {
$this->setFormat(config('sleeping_owl.'.$this->defaultConfigFormat));
}

return $this->format;
}

Expand Down
12 changes: 6 additions & 6 deletions src/FormItems/CKEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,29 @@ protected static function postUpload()
$height = 0;
try {
if (is_null($file)) {
$errors[] = trans('sleepingowladmin::core.ckeditor.upload.error.common');
$errors[] = trans('sleepingowl::core.ckeditor.upload.error.common');
throw new Exception;
}
$extension = $file->guessClientExtension();
if (! in_array($extension, $allowedExtensions)) {
$errors[] = trans('sleepingowladmin::core.ckeditor.upload.error.wrong_extension',
$errors[] = trans('sleepingowl::core.ckeditor.upload.error.wrong_extension',
['file' => $file->getClientOriginalName()]);
throw new Exception;
}
if ($file->getSize() > $maxsize * 1000) {
$errors[] = trans('sleepingowladmin::core.ckeditor.upload.error.filesize_limit', ['size' => $maxsize]);
$errors[] = trans('sleepingowl::core.ckeditor.upload.error.filesize_limit', ['size' => $maxsize]);
}
list($width, $height) = getimagesize($file);
if ($width > $maxwidth || $height > $maxheight) {
$errors[] = trans('sleepingowladmin::core.ckeditor.upload.error.imagesize_max_limit', [
$errors[] = trans('sleepingowl::core.ckeditor.upload.error.imagesize_max_limit', [
'width' => $width,
'height' => $height,
'maxwidth' => $maxwidth,
'maxheight' => $maxheight,
]);
}
if ($width < $minwidth || $height < $minheight) {
$errors[] = trans('sleepingowladmin::core.ckeditor.upload.error.imagesize_min_limit', [
$errors[] = trans('sleepingowl::core.ckeditor.upload.error.imagesize_min_limit', [
'width' => $width,
'height' => $height,
'minwidth' => $minwidth,
Expand All @@ -132,7 +132,7 @@ protected static function postUpload()
$file = $file->move($upload_dir, $finalFilename);
$CKEditorFuncNum = Input::get('CKEditorFuncNum');
$url = asset($path.$finalFilename);
$message = trans('sleepingowladmin::core.ckeditor.upload.success', [
$message = trans('sleepingowl::core.ckeditor.upload.success', [
'size' => number_format($file->getSize() / 1024, 3, '.', ''),
'width' => $width,
'height' => $height,
Expand Down
22 changes: 1 addition & 21 deletions src/FormItems/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,5 @@ class Date extends BaseDateTime
/**
* @var string
*/
protected $defaultConfigFormat = 'dateFormat';

/**
* @return string
*/
public function getDefaultConfigFormat()
{
return $this->defaultConfigFormat;
}

/**
* @param string $defaultConfigFormat
*
* @return Date
*/
public function setDefaultConfigFormat($defaultConfigFormat)
{
$this->defaultConfigFormat = $defaultConfigFormat;

return $this;
}
protected $format = 'Y-m-d';
}
41 changes: 31 additions & 10 deletions src/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use KodiCMS\SleepingOwlAdmin\Model\ModelConfiguration;
use KodiCMS\CMS\Http\Controllers\System\BackendController;

// TODO: добавить заголовки для различных действий
class AdminController extends BackendController
{
/**
Expand Down Expand Up @@ -46,19 +45,30 @@ public function getCreate(ModelConfiguration $model)
public function postStore(ModelConfiguration $model)
{
$create = $model->fireCreate();

if (is_null($create)) {
abort(404);
}

$nextAction = $this->request->get('next_action');

if ($nextAction == 'cancel') {
return redirect()->to($model->getDisplayUrl());
}

if ($create instanceof FormInterface) {
if ($validator = $create->validate($model)) {
return redirect()->back()->withErrors($validator)->withInput()->with([
'_redirectBack' => Input::get('_redirectBack'),
]);
return redirect()->back()->withErrors($validator)->withInput();
}

$create->save($model);
}

return redirect()->to(Input::get('_redirectBack', $model->getDisplayUrl()));
if ($nextAction == 'continue') {
return redirect()->to($model->getEditUrl($create->getModelObject()->id));
}

return redirect()->to($model->getDisplayUrl());
}

/**
Expand Down Expand Up @@ -89,16 +99,25 @@ public function postUpdate(ModelConfiguration $model, $id)
if (is_null($edit)) {
abort(404);
}

$nextAction = $this->request->get('next_action');

if ($nextAction == 'cancel') {
return redirect()->to($model->getDisplayUrl());
}

if ($edit instanceof FormInterface) {
if ($validator = $edit->validate($model)) {
return redirect()->back()->withErrors($validator)->withInput()->with([
'_redirectBack' => Input::get('_redirectBack'),
]);
return redirect()->back()->withErrors($validator)->withInput();
}
$edit->save($model);
}

return redirect()->to(Input::get('_redirectBack', $model->getDisplayUrl()));
if ($nextAction == 'continue') {
return redirect()->back();
}

return redirect()->to($model->getDisplayUrl());
}

/**
Expand Down Expand Up @@ -150,7 +169,9 @@ public function render(ModelConfiguration $model, $content)
$this->breadcrumbs->add(config('sleeping_owl.title'), null, true);
$this->setTitle($model->getTitle(), $model->getDisplayUrl());

$this->template->with('content', $content);
$this->template
->with('content', $content)
->with('model', $model);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Http/routes.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

Route::group([
'middleware' => config('sleeping_owl.middleware'),
'prefix' => backend_url_segment().'/sleepingowl',
'as' => 'admin.',
'middleware' => ['web'],
'prefix' => backend_url_segment().'/sleepingowl',
'as' => 'admin.',
], function () {
Route::get('{adminModel}', [
'as' => 'model',
Expand All @@ -15,7 +15,7 @@
'uses' => 'AdminController@getCreate',
]);

Route::post('{adminModel}', [
Route::post('{adminModel}/create', [
'as' => 'model.store',
'uses' => 'AdminController@postStore',
]);
Expand All @@ -25,12 +25,12 @@
'uses' => 'AdminController@getEdit',
]);

Route::post('{adminModel}/{adminModelId}', [
Route::post('{adminModel}/{adminModelId}/edit', [
'as' => 'model.update',
'uses' => 'AdminController@postUpdate',
]);

Route::delete('{adminModel}/{adminModelId}', [
Route::delete('{adminModel}/{adminModelId}/delete', [
'as' => 'model.destroy',
'uses' => 'AdminController@postDestroy',
]);
Expand Down
2 changes: 2 additions & 0 deletions src/Model/ModelConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public function fireDisplay()
if (! is_callable($this->display)) {
return;
}

$display = app()->call($this->display);
if ($display instanceof DisplayInterface) {
$display->setClass($this->getClass());
Expand All @@ -255,6 +256,7 @@ public function fireCreate()
if (! is_callable($this->create)) {
return;
}

$create = app()->call($this->create);
if ($create instanceof DisplayInterface) {
$create->setClass($this->getClass());
Expand Down
2 changes: 1 addition & 1 deletion src/NavigationPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace KodiCMS\SleepingOwlAdmin;

use KodiCMS\CMS\Navigation\Page;
use KodiCMS\Navigation\Page;
use KodiCMS\Support\Traits\Accessor;
use KodiCMS\SleepingOwlAdmin\Model\ModelConfiguration;

Expand Down
6 changes: 3 additions & 3 deletions src/Providers/ModuleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Route;
use Event;
use ModulesFileSystem;
use KodiCMS\Navigation\Navigation;
use KodiCMS\Support\ServiceProvider;
use KodiCMS\SleepingOwlAdmin\Filter\Filter;
use KodiCMS\SleepingOwlAdmin\Columns\Column;
Expand All @@ -14,7 +15,6 @@
use KodiCMS\SleepingOwlAdmin\FormItems\FormItem;
use KodiCMS\SleepingOwlAdmin\Facades\SleepingOwlModule;
use KodiCMS\SleepingOwlAdmin\Display\SleepingOwlDisplay;
use KodiCMS\CMS\Navigation\Section as NavigationSection;
use KodiCMS\SleepingOwlAdmin\ColumnFilters\ColumnFilter;
use Illuminate\Database\Eloquent\ModelNotFoundException;

Expand Down Expand Up @@ -58,7 +58,7 @@ public function register()

public function boot()
{
Event::listen('navigation.inited', function (NavigationSection $navigation) {
Event::listen('navigation.inited', function (Navigation $navigation) {
$this->app['sleeping_owl']->buildMenu($navigation);
});
}
Expand All @@ -73,10 +73,10 @@ protected function registerRoutePatterns()
Route::pattern('adminModel', implode('|', $aliases));
Route::bind('adminModel', function ($model) use ($aliases) {
$class = array_search($model, $aliases);

if ($class === false) {
throw new ModelNotFoundException;
}

return $this->app['sleeping_owl']->getModel($class);
});
}
Expand Down
Loading

0 comments on commit 2c7cdb6

Please sign in to comment.