Skip to content
Draft
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 app/DashBoard/Controls/SlackIntegrationList/Control.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{control listGrid}
86 changes: 86 additions & 0 deletions app/DashBoard/Controls/SlackIntegrationList/Control.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php declare(strict_types = 1);

namespace Pd\Monitoring\DashBoard\Controls\SlackIntegrationList;

class Control extends \Nette\Application\UI\Control
{

use \Pd\Monitoring\DashBoard\TSecuredComponent;


private \Pd\Monitoring\Slack\IntegrationRepository $slackIntegrationRepository;

private \Pd\Monitoring\DashBoard\Controls\DataGridFactory $dataGridFactory;


public function __construct(
\Pd\Monitoring\Slack\IntegrationRepository $slackIntegrationRepository,
\Pd\Monitoring\DashBoard\Controls\DataGridFactory $dataGridFactory
)
{
$this->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');
}

}
10 changes: 10 additions & 0 deletions app/DashBoard/Controls/SlackIntegrationList/IFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);

namespace Pd\Monitoring\DashBoard\Controls\SlackIntegrationList;

interface IFactory
{

public function create(): Control;

}
30 changes: 18 additions & 12 deletions app/DashBoard/Presenters/SlackPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,38 @@
final class SlackPresenter extends BasePresenter
{

private \Pd\Monitoring\Check\ChecksRepository $checksRepository;
private \Pd\Monitoring\DashBoard\Controls\SlackIntegrationList\IFactory $factory;


public function __construct(
\Pd\Monitoring\Check\ChecksRepository $checksRepository
\Pd\Monitoring\DashBoard\Controls\SlackIntegrationList\IFactory $factory
)
{
parent::__construct();
$this->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();
}

}
1 change: 1 addition & 0 deletions app/DashBoard/Presenters/UserPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion app/DashBoard/Presenters/templates/@layout.latte
Original file line number Diff line number Diff line change
Expand Up @@ -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%; }
}
Expand Down
7 changes: 7 additions & 0 deletions app/DashBoard/Presenters/templates/Slack/default.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{block title}
Správa Slack integrací
{/block}

{block content}
{control slackIntegrationList}
{/block}
7 changes: 7 additions & 0 deletions app/DashBoard/Presenters/templates/Slack/edit.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{block title}
Úprava Slack integrace - {$name}
{/block}

{block content}

{/block}
24 changes: 23 additions & 1 deletion app/Router/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down Expand Up @@ -122,6 +126,24 @@ public function createRouter(): \Nette\Routing\Router
];
$router[] = new \Nette\Application\Routers\Route('dash-board/user/<action>[/<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/<action>[/<integration>]', $metadata);


$metadata = [
'module' => 'DashBoard',
'presenter' => 'HomePage',
Expand Down
3 changes: 3 additions & 0 deletions app/Slack/IntegrationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Pd\Monitoring\Slack;

/**
* @method \Pd\Monitoring\Slack\Integration|null getById(int $id)
*/
class IntegrationRepository extends \Nextras\Orm\Repository\Repository
{

Expand Down
3 changes: 3 additions & 0 deletions app/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ services:
arguments:
isAllowed: %github.allow%

-
implement: \Pd\Monitoring\DashBoard\Controls\SlackIntegrationList\IFactory


decorator:
Nette\Application\UI\Control:
Expand Down