Skip to content

Commit

Permalink
Merge pull request #238 from skaut/dokumentace
Browse files Browse the repository at this point in the history
Dokumentace
  • Loading branch information
Jan Staněk authored Mar 20, 2017
2 parents 4f80db6 + 763e41e commit 7f42bba
Show file tree
Hide file tree
Showing 211 changed files with 2,803 additions and 950 deletions.
17 changes: 7 additions & 10 deletions app/AdminModule/CMSModule/components/DocumentTagsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@

namespace App\AdminModule\CMSModule\Components;


use App\Model\CMS\Document\Tag;
use App\Model\CMS\Document\TagRepository;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
use Nette\Application\UI\Form;
use Ublaboo\DataGrid\DataGrid;


class DocumentTagsGridControl extends Control
{
/**
* @var Translator
*/
/** @var Translator */
private $translator;

/**
* @var TagRepository
*/
/** @var TagRepository */
private $tagRepository;


public function __construct(Translator $translator, TagRepository $tagRepository)
{
parent::__construct();
Expand All @@ -47,18 +44,18 @@ public function createComponentDocumentTagsGrid($name)
$grid->addColumnText('name', 'admin.cms.tags_name');


$grid->addInlineAdd()->onControlAdd[] = function($container) {
$grid->addInlineAdd()->onControlAdd[] = function ($container) {
$container->addText('name', '')
->addRule(Form::FILLED, 'admin.cms.tags_name_empty')
->addRule(Form::IS_NOT_IN, 'admin.cms.tags_name_exists', $this->tagRepository->findAllNames());
};
$grid->getInlineAdd()->onSubmit[] = [$this, 'add'];

$grid->addInlineEdit()->onControlAdd[] = function($container) {
$grid->addInlineEdit()->onControlAdd[] = function ($container) {
$container->addText('name', '')
->addRule(Form::FILLED, 'admin.cms.tags_name_empty');
};
$grid->getInlineEdit()->onSetDefaults[] = function($container, $item) {
$grid->getInlineEdit()->onSetDefaults[] = function ($container, $item) {
$container['name']
->addRule(Form::IS_NOT_IN, 'admin.cms.tags_name_exists', $this->tagRepository->findOthersNames($item->getId()));

Expand Down
34 changes: 15 additions & 19 deletions app/AdminModule/CMSModule/components/DocumentsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\AdminModule\CMSModule\Components;


use App\Model\CMS\Document\Document;
use App\Model\CMS\Document\DocumentRepository;
use App\Model\CMS\Document\TagRepository;
Expand All @@ -15,29 +14,24 @@
use Nette\Utils\Strings;
use Ublaboo\DataGrid\DataGrid;


class DocumentsGridControl extends Control
{
/**
* @var Translator
*/
/** @var Translator */
private $translator;

/**
* @var DocumentRepository
*/
/** @var DocumentRepository */
private $documentRepository;

/**
* @var FilesService
*/
/** @var FilesService */
private $filesService;

/**
* @var TagRepository
*/
/** @var TagRepository */
private $tagRepository;

public function __construct(Translator $translator, DocumentRepository $documentRepository, TagRepository $tagRepository, FilesService $filesService)

public function __construct(Translator $translator, DocumentRepository $documentRepository,
TagRepository $tagRepository, FilesService $filesService)
{
parent::__construct();

Expand Down Expand Up @@ -93,7 +87,7 @@ public function createComponentDocumentsGrid($name)

$tagsOptions = $this->tagRepository->getTagsOptions();

$grid->addInlineAdd()->onControlAdd[] = function($container) use($tagsOptions) {
$grid->addInlineAdd()->onControlAdd[] = function ($container) use ($tagsOptions) {
$container->addText('name', '')
->addRule(Form::FILLED, 'admin.cms.documents_name_empty');

Expand All @@ -107,7 +101,7 @@ public function createComponentDocumentsGrid($name)
};
$grid->getInlineAdd()->onSubmit[] = [$this, 'add'];

$grid->addInlineEdit()->onControlAdd[] = function($container) use($tagsOptions) {
$grid->addInlineEdit()->onControlAdd[] = function ($container) use ($tagsOptions) {
$container->addText('name', '')
->addRule(Form::FILLED, 'admin.cms.documents_name_empty');

Expand All @@ -118,7 +112,7 @@ public function createComponentDocumentsGrid($name)

$container->addText('description', '');
};
$grid->getInlineEdit()->onSetDefaults[] = function($container, $item) {
$grid->getInlineEdit()->onSetDefaults[] = function ($container, $item) {
$container->setDefaults([
'name' => $item->getName(),
'tags' => $this->tagRepository->findTagsIds($item->getTags()),
Expand All @@ -137,7 +131,8 @@ public function createComponentDocumentsGrid($name)
]);
}

public function add($values) {
public function add($values)
{
$file = $values['file'];
$path = $this->generatePath($file);
$this->filesService->save($file, $path);
Expand Down Expand Up @@ -193,7 +188,8 @@ public function handleDelete($id)
$this->redirect('this');
}

private function generatePath($file) {
private function generatePath($file)
{
return Document::PATH . '/' . Random::generate(5) . '/' . Strings::webalize($file->name, '.');
}
}
25 changes: 11 additions & 14 deletions app/AdminModule/CMSModule/components/FaqGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@

namespace App\AdminModule\CMSModule\Components;


use App\Model\CMS\FaqRepository;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
use Ublaboo\DataGrid\DataGrid;


class FaqGridControl extends Control
{
/**
* @var Translator
*/
/** @var Translator */
private $translator;

/**
* @var FaqRepository
*/
/** @var FaqRepository */
private $faqRepository;


public function __construct(Translator $translator, FaqRepository $faqRepository)
{
parent::__construct();
Expand Down Expand Up @@ -49,11 +46,11 @@ public function createComponentFaqGrid($name)

$grid->addColumnStatus('public', 'admin.cms.faq_public')
->addOption(false, 'admin.cms.faq_public_private')
->setClass('btn-danger')
->endOption()
->setClass('btn-danger')
->endOption()
->addOption(true, 'admin.cms.faq_public_public')
->setClass('btn-success')
->endOption()
->setClass('btn-success')
->endOption()
->onChange[] = [$this, 'changeStatus'];

$grid->addColumnText('answered', 'admin.cms.faq_answered')
Expand Down Expand Up @@ -104,7 +101,8 @@ public function handleSort($item_id, $prev_id, $next_id)
}
}

public function changeStatus($id, $public) {
public function changeStatus($id, $public)
{
$faq = $this->faqRepository->findById($id);
$faq->setPublic($public);
$this->faqRepository->save($faq);
Expand All @@ -115,8 +113,7 @@ public function changeStatus($id, $public) {
if ($p->isAjax()) {
$p->redrawControl('flashes');
$this['faqGrid']->redrawItem($id);
}
else {
} else {
$this->redirect('this');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\AdminModule\CMSModule\Components;


interface IDocumentTagsGridControlFactory
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\AdminModule\CMSModule\Components;


interface IDocumentsGridControlFactory
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\AdminModule\CMSModule\Components;


interface IFaqGridControlFactory
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\AdminModule\CMSModule\Components;


interface INewsGridControlFactory
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\AdminModule\CMSModule\Components;


interface IPagesGridControlFactory
{
/**
Expand Down
11 changes: 4 additions & 7 deletions app/AdminModule/CMSModule/components/NewsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@

namespace App\AdminModule\CMSModule\Components;


use App\Model\CMS\NewsRepository;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
use Ublaboo\DataGrid\DataGrid;


class NewsGridControl extends Control
{
/**
* @var Translator
*/
/** @var Translator */
private $translator;

/**
* @var NewsRepository
*/
/** @var NewsRepository */
private $newsRepository;


public function __construct(Translator $translator, NewsRepository $newsRepository)
{
parent::__construct();
Expand Down
41 changes: 17 additions & 24 deletions app/AdminModule/CMSModule/components/PagesGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,27 @@

namespace App\AdminModule\CMSModule\Components;


use App\Model\ACL\RoleRepository;

use App\Model\CMS\Page;
use App\Model\CMS\PageRepository;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
use Nette\Application\UI\Form;
use Ublaboo\DataGrid\DataGrid;


class PagesGridControl extends Control
{
/**
* @var Translator
*/
/** @var Translator */
private $translator;

/**
* @var PageRepository
*/
/** @var PageRepository */
private $pageRepository;

/**
* @var RoleRepository
*/
/** @var RoleRepository */
private $roleRepository;


public function __construct(Translator $translator, PageRepository $pageRepository, RoleRepository $roleRepository)
{
parent::__construct();
Expand Down Expand Up @@ -59,11 +53,11 @@ public function createComponentPagesGrid($name)

$grid->addColumnStatus('public', 'admin.cms.pages_public')
->addOption(false, 'admin.cms.pages_public_private')
->setClass('btn-danger')
->endOption()
->setClass('btn-danger')
->endOption()
->addOption(true, 'admin.cms.pages_public_public')
->setClass('btn-success')
->endOption()
->setClass('btn-success')
->endOption()
->onChange[] = [$this, 'changeStatus'];

$grid->addColumnText('roles', 'admin.cms.pages_roles')
Expand All @@ -86,7 +80,7 @@ public function createComponentPagesGrid($name)
true => 'admin.cms.pages_public_public'
];

$grid->addInlineAdd()->onControlAdd[] = function($container) use($rolesOptions, $publicOptions) {
$grid->addInlineAdd()->onControlAdd[] = function ($container) use ($rolesOptions, $publicOptions) {
$container->addText('name', '')
->addRule(Form::FILLED, 'admin.cms.pages_name_empty');

Expand All @@ -103,7 +97,7 @@ public function createComponentPagesGrid($name)
};
$grid->getInlineAdd()->onSubmit[] = [$this, 'add'];

$grid->addInlineEdit()->onControlAdd[] = function($container) use($rolesOptions, $publicOptions) {
$grid->addInlineEdit()->onControlAdd[] = function ($container) use ($rolesOptions, $publicOptions) {
$container->addText('name', '')
->addRule(Form::FILLED, 'admin.cms.pages_name_empty');

Expand All @@ -116,7 +110,7 @@ public function createComponentPagesGrid($name)

$container->addSelect('public', '', $publicOptions);
};
$grid->getInlineEdit()->onSetDefaults[] = function($container, $item) {
$grid->getInlineEdit()->onSetDefaults[] = function ($container, $item) {
$container['slug']
->addRule(Form::IS_NOT_IN, 'admin.cms.pages_slug_exists', $this->pageRepository->findOthersSlugs($item->getId()));

Expand All @@ -142,7 +136,7 @@ public function createComponentPagesGrid($name)
'data-toggle' => 'confirmation',
'data-content' => $this->translator->translate('admin.cms.pages_delete_confirm')
]);
$grid->allowRowsAction('delete', function($item) {
$grid->allowRowsAction('delete', function ($item) {
return $item->getSlug() != '/';
});
}
Expand Down Expand Up @@ -204,13 +198,13 @@ public function handleSort($item_id, $prev_id, $next_id)
}
}

public function changeStatus($id, $public) {
public function changeStatus($id, $public)
{
$p = $this->getPresenter();

if ($this->pageRepository->findById($id)->getSlug() == '/' && !$public) {
$p->flashMessage('admin.cms.pages_change_public_denied', 'danger');
}
else {
} else {
$page = $this->pageRepository->findById($id);
$page->setPublic($public);
$this->pageRepository->save($page);
Expand All @@ -221,8 +215,7 @@ public function changeStatus($id, $public) {
if ($p->isAjax()) {
$p->redrawControl('flashes');
$this['pagesGrid']->redrawItem($id);
}
else {
} else {
$this->redirect('this');
}
}
Expand Down
Loading

0 comments on commit 7f42bba

Please sign in to comment.