From b567d261cf15f9ed7ca17e9b18815fc0448dd8bc Mon Sep 17 00:00:00 2001 From: jakubenglicky Date: Mon, 20 Sep 2021 18:26:07 +0200 Subject: [PATCH] =?UTF-8?q?Spr=C3=A1va=20Slack=20integrac=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SlackIntegrationList/Control.latte | 1 + .../Controls/SlackIntegrationList/Control.php | 86 +++++++++++++++++++ .../SlackIntegrationList/IFactory.php | 10 +++ app/DashBoard/Presenters/SlackPresenter.php | 30 ++++--- app/DashBoard/Presenters/UserPresenter.php | 1 + .../Presenters/templates/@layout.latte | 2 +- .../Presenters/templates/Slack/default.latte | 7 ++ .../Presenters/templates/Slack/edit.latte | 7 ++ app/Router/RouterFactory.php | 24 +++++- app/Slack/IntegrationRepository.php | 3 + app/config/config.neon | 3 + 11 files changed, 160 insertions(+), 14 deletions(-) create mode 100644 app/DashBoard/Controls/SlackIntegrationList/Control.latte create mode 100644 app/DashBoard/Controls/SlackIntegrationList/Control.php create mode 100644 app/DashBoard/Controls/SlackIntegrationList/IFactory.php create mode 100644 app/DashBoard/Presenters/templates/Slack/default.latte create mode 100644 app/DashBoard/Presenters/templates/Slack/edit.latte diff --git a/app/DashBoard/Controls/SlackIntegrationList/Control.latte b/app/DashBoard/Controls/SlackIntegrationList/Control.latte new file mode 100644 index 00000000..6c68be2c --- /dev/null +++ b/app/DashBoard/Controls/SlackIntegrationList/Control.latte @@ -0,0 +1 @@ +{control listGrid} diff --git a/app/DashBoard/Controls/SlackIntegrationList/Control.php b/app/DashBoard/Controls/SlackIntegrationList/Control.php new file mode 100644 index 00000000..ac3f6f78 --- /dev/null +++ b/app/DashBoard/Controls/SlackIntegrationList/Control.php @@ -0,0 +1,86 @@ +slackIntegrationRepository = $slackIntegrationRepository; + $this->dataGridFactory = $dataGridFactory; + } + + + public function render(): void + { + $this->template->setFile(__DIR__ . '/Control.latte'); + $this->template->render(); + } + + + protected function createComponentListGrid(): \Nette\Application\UI\Control + { + $grid = $this->dataGridFactory->create(); + + $grid + ->addColumnText('name', 'Jméno') + ->setFilterText(['name']) + ; + + $grid + ->addColumnText('hookUrl', 'Hook URL') + ; + + $grid + ->addColumnText('channel', 'Kanál') + ->setFilterText(['channel']) + ; + + $grid + ->addAction('edit', 'Upravit') + ->setClass('btn btn-warning') + ; + + $grid + ->addAction('delete', 'Smazat') + ->setClass('btn btn-danger') + ->setDataAttribute('confirm', '') + ; + + $grid->setDataSource($this->slackIntegrationRepository->findAll()); + + return $grid; + } + + + public function handleEdit(int $id): void + { + $integration = $this->slackIntegrationRepository->getById($id); + $this->getPresenter()->redirect(':DashBoard:Slack:edit', $integration); + } + + + /** + * @Acl(user, delete) + * @throws \Nette\Application\AbortException + */ + public function handleDelete(int $id): void + { + $this->slackIntegrationRepository->removeAndFlush($this->slackIntegrationRepository->getById($id)); + $this->getPresenter()->flashMessage('Slack integrace byla smazána', \Pd\Monitoring\DashBoard\Presenters\BasePresenter::FLASH_MESSAGE_SUCCESS); + $this->redirect('this'); + } + +} diff --git a/app/DashBoard/Controls/SlackIntegrationList/IFactory.php b/app/DashBoard/Controls/SlackIntegrationList/IFactory.php new file mode 100644 index 00000000..8c2785f1 --- /dev/null +++ b/app/DashBoard/Controls/SlackIntegrationList/IFactory.php @@ -0,0 +1,10 @@ +checksRepository = $checksRepository; + $this->factory = $factory; } - public function actionPause(int $id): void + public function actionDefault() { - $check = $this->checksRepository->getById($id); + } - if ( ! $check) { - $this->error(); - } - $check->paused = TRUE; - $this->checksRepository->persistAndFlush($check); + public function actionEdit(\Pd\Monitoring\Slack\Integration $integration): void + { - $this->flashMessage('Kontrola byla zapauzována', self::FLASH_MESSAGE_SUCCESS); + } - $this->redirect(':DashBoard:Project:', [$check->project]); + + public function renderEdit(\Pd\Monitoring\Slack\Integration $integration): void + { + $this->template->name = $integration->getFullName(); + } + + + public function createComponentSlackIntegrationList(): \Pd\Monitoring\DashBoard\Controls\SlackIntegrationList\Control + { + return $this->factory->create(); } } diff --git a/app/DashBoard/Presenters/UserPresenter.php b/app/DashBoard/Presenters/UserPresenter.php index ac3a756a..0af8c901 100644 --- a/app/DashBoard/Presenters/UserPresenter.php +++ b/app/DashBoard/Presenters/UserPresenter.php @@ -33,6 +33,7 @@ public function actionDefault(): void public function actionEdit(\Pd\Monitoring\User\User $user): void { + \Tracy\Debugger::barDump($user); if ( ! $this->user->isAllowed($user, \Pd\Monitoring\User\AclFactory::PRIVILEGE_EDIT)) { throw new \Nette\Application\ForbiddenRequestException(); } diff --git a/app/DashBoard/Presenters/templates/@layout.latte b/app/DashBoard/Presenters/templates/@layout.latte index 2f67c3c0..e7d13523 100644 --- a/app/DashBoard/Presenters/templates/@layout.latte +++ b/app/DashBoard/Presenters/templates/@layout.latte @@ -50,7 +50,7 @@ .btn-group { margin-bottom:5px; } @media only screen and (min-width: 960px){ - .title { float:left; width:50%; } + .title { float:left; } .buttons { float:right; width:50%; text-align:right; margin:20px 0 10px; } .break { height:0; font-size:0; line-height:0; clear:both; overflow:hidden; visibility:hidden; display:block; width:100%; } } diff --git a/app/DashBoard/Presenters/templates/Slack/default.latte b/app/DashBoard/Presenters/templates/Slack/default.latte new file mode 100644 index 00000000..c0a186d3 --- /dev/null +++ b/app/DashBoard/Presenters/templates/Slack/default.latte @@ -0,0 +1,7 @@ +{block title} + Správa Slack integrací +{/block} + +{block content} + {control slackIntegrationList} +{/block} diff --git a/app/DashBoard/Presenters/templates/Slack/edit.latte b/app/DashBoard/Presenters/templates/Slack/edit.latte new file mode 100644 index 00000000..47fed26d --- /dev/null +++ b/app/DashBoard/Presenters/templates/Slack/edit.latte @@ -0,0 +1,7 @@ +{block title} + Úprava Slack integrace - {$name} +{/block} + +{block content} + +{/block} diff --git a/app/Router/RouterFactory.php b/app/Router/RouterFactory.php index 0e6039a8..a6a400cf 100644 --- a/app/Router/RouterFactory.php +++ b/app/Router/RouterFactory.php @@ -11,16 +11,20 @@ final class RouterFactory private \Pd\Monitoring\User\UsersRepository $usersRepository; + private \Pd\Monitoring\Slack\IntegrationRepository $integrationRepository; + public function __construct( \Pd\Monitoring\Project\ProjectsRepository $projectsRepository, \Pd\Monitoring\Check\ChecksRepository $checksRepository, - \Pd\Monitoring\User\UsersRepository $usersRepository + \Pd\Monitoring\User\UsersRepository $usersRepository, + \Pd\Monitoring\Slack\IntegrationRepository $integrationRepository ) { $this->projectsRepository = $projectsRepository; $this->checksRepository = $checksRepository; $this->usersRepository = $usersRepository; + $this->integrationRepository = $integrationRepository; } @@ -122,6 +126,24 @@ public function createRouter(): \Nette\Routing\Router ]; $router[] = new \Nette\Application\Routers\Route('dash-board/user/[/]', $metadata); + $metadata = [ + 'module' => 'DashBoard', + 'presenter' => 'Slack', + 'action' => 'edit', + 'integration' => [ + \Nette\Application\Routers\Route::FILTER_IN => function (string $integration): ?\Pd\Monitoring\Slack\Integration + { + return $this->integrationRepository->getById((int) $integration); + }, + \Nette\Application\Routers\Route::FILTER_OUT => static function (\Pd\Monitoring\Slack\Integration $integration): int + { + return $integration->id; + }, + ], + ]; + $router[] = new \Nette\Application\Routers\Route('dash-board/slack/[/]', $metadata); + + $metadata = [ 'module' => 'DashBoard', 'presenter' => 'HomePage', diff --git a/app/Slack/IntegrationRepository.php b/app/Slack/IntegrationRepository.php index 8d53c2a7..72192346 100644 --- a/app/Slack/IntegrationRepository.php +++ b/app/Slack/IntegrationRepository.php @@ -2,6 +2,9 @@ namespace Pd\Monitoring\Slack; +/** + * @method \Pd\Monitoring\Slack\Integration|null getById(int $id) + */ class IntegrationRepository extends \Nextras\Orm\Repository\Repository { diff --git a/app/config/config.neon b/app/config/config.neon index abbcde5d..529ea4d8 100644 --- a/app/config/config.neon +++ b/app/config/config.neon @@ -455,6 +455,9 @@ services: arguments: isAllowed: %github.allow% + - + implement: \Pd\Monitoring\DashBoard\Controls\SlackIntegrationList\IFactory + decorator: Nette\Application\UI\Control: