chg: [requestProcessor] Recover local tool from request

pull/59/head
mokaddem 2021-06-12 14:04:17 +02:00
parent 5e0a4b155e
commit a03b433f2b
3 changed files with 34 additions and 2 deletions

View File

@ -16,11 +16,13 @@ class LocalToolRequestProcessor extends GenericRequestProcessor
]; ];
protected $processingTemplate = 'LocalTool/GenericRequest'; protected $processingTemplate = 'LocalTool/GenericRequest';
protected $Broods; protected $Broods;
protected $LocalTools;
public function __construct($loadFromAction=false) public function __construct($loadFromAction=false)
{ {
parent::__construct($loadFromAction); parent::__construct($loadFromAction);
$this->Broods = TableRegistry::getTableLocator()->get('Broods'); $this->Broods = TableRegistry::getTableLocator()->get('Broods');
$this->LocalTools = TableRegistry::getTableLocator()->get('LocalTools');
} }
public function create($requestData) public function create($requestData)
@ -53,6 +55,19 @@ class LocalToolRequestProcessor extends GenericRequestProcessor
return $brood; return $brood;
} }
protected function getConnector($request)
{
try {
$connectorClasses = $this->LocalTools->getConnectorByToolName($request->local_tool_name);
if (!empty($connectorClasses)) {
$connector = $this->LocalTools->extractMeta($connectorClasses)[0];
}
} catch (Cake\Http\Exception\NotFoundException $e) {
$connector = null;
}
return $connector;
}
protected function addBaseValidatorRules($validator) protected function addBaseValidatorRules($validator)
{ {
return $validator return $validator
@ -91,6 +106,7 @@ class IncomingConnectionRequestProcessor extends LocalToolRequestProcessor imple
public function getViewVariables($request) public function getViewVariables($request)
{ {
$request->brood = $this->getIssuerBrood($request); $request->brood = $this->getIssuerBrood($request);
$request->connector = $this->getConnector($request);
return [ return [
'request' => $request, 'request' => $request,
'progressStep' => 0, 'progressStep' => 0,
@ -144,6 +160,7 @@ class AcceptedRequestProcessor extends LocalToolRequestProcessor implements Gene
public function getViewVariables($request) public function getViewVariables($request)
{ {
$request->brood = $this->getIssuerBrood($request); $request->brood = $this->getIssuerBrood($request);
$request->connector = $this->getConnector($request);
return [ return [
'request' => $request, 'request' => $request,
'progressStep' => 1, 'progressStep' => 1,
@ -195,6 +212,7 @@ class DeclinedRequestProcessor extends LocalToolRequestProcessor implements Gene
public function getViewVariables($request) public function getViewVariables($request)
{ {
$request->brood = $this->getIssuerBrood($request); $request->brood = $this->getIssuerBrood($request);
$request->connector = $this->getConnector($request);
return [ return [
'request' => $request, 'request' => $request,
'progressStep' => 1, 'progressStep' => 1,

View File

@ -30,13 +30,21 @@ $progress = $this->Bootstrap->progressTimeline([
$table = $this->Bootstrap->table(['small' => true, 'bordered' => false, 'striped' => false, 'hover' => false], [ $table = $this->Bootstrap->table(['small' => true, 'bordered' => false, 'striped' => false, 'hover' => false], [
'fields' => [ 'fields' => [
['key' => 'data.toolName', 'label' => __('Tool Name')], ['key' => 'connector', 'label' => __('Tool Name'), 'formatter' => function($connector, $row) {
return sprintf('<a href="%s" target="_blank">%s</a>',
$this->Url->build(['controller' => 'localTools', 'action' => 'viewConnector', $connector['name']]),
sprintf('%s (v%s)', h($connector['name']), h($connector['connector_version']))
);
}],
['key' => 'created', 'label' => __('Date'), 'formatter' => function($value, $row) { ['key' => 'created', 'label' => __('Date'), 'formatter' => function($value, $row) {
return $value->i18nFormat('yyyy-MM-dd HH:mm:ss'); return $value->i18nFormat('yyyy-MM-dd HH:mm:ss');
}], }],
['key' => 'origin', 'label' => __('Origin')], ['key' => 'origin', 'label' => __('Origin')],
['key' => 'brood', 'label' => __('Brood'), 'formatter' => function($brood, $row) { ['key' => 'brood', 'label' => __('Brood'), 'formatter' => function($brood, $row) {
return sprintf('<a href="%s" target="_blank">%s</a>', $this->Url->build(['controller' => 'broods', 'action' => 'view', $brood['id']]), h($brood['name'])); return sprintf('<a href="%s" target="_blank">%s</a>',
$this->Url->build(['controller' => 'broods', 'action' => 'view', $brood['id']]),
h($brood['name'])
);
}] }]
], ],
'items' => [$request->toArray()], 'items' => [$request->toArray()],

View File

@ -73,6 +73,12 @@ class LocalToolsTable extends AppTable
throw new NotFoundException(__('Invalid connector module action requested.')); throw new NotFoundException(__('Invalid connector module action requested.'));
} }
public function getConnectorByToolName($toolName): array
{
$toolName = sprintf('%sConnector', ucfirst(strtolower($toolName)));
return $this->getConnectors($toolName);
}
public function getConnectors(string $name = null): array public function getConnectors(string $name = null): array
{ {
$connectors = []; $connectors = [];