Handle modification of external tasks
This commit is contained in:
@@ -44,7 +44,7 @@ class ExternalTaskCreationController extends BaseController
|
|||||||
|
|
||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
$values = $this->request->getValues();
|
$values = $this->request->getValues();
|
||||||
$externalTask = $taskProvider->retrieve($taskProvider->buildTaskUri($values));
|
$externalTask = $taskProvider->fetch($taskProvider->buildTaskUri($values));
|
||||||
|
|
||||||
$values = $externalTask->getFormValues() + array(
|
$values = $externalTask->getFormValues() + array(
|
||||||
'external_uri' => $externalTask->getUri(),
|
'external_uri' => $externalTask->getUri(),
|
||||||
@@ -56,7 +56,7 @@ class ExternalTaskCreationController extends BaseController
|
|||||||
'owner_id' => $this->userSession->getId(),
|
'owner_id' => $this->userSession->getId(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$externalTask = $taskProvider->retrieve($values['external_uri']);
|
$externalTask = $taskProvider->fetch($values['external_uri']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response->html($this->template->render('external_task_creation/step2', array(
|
$this->response->html($this->template->render('external_task_creation/step2', array(
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class ExternalTaskViewController extends BaseController
|
|||||||
try {
|
try {
|
||||||
$task = $this->getTask();
|
$task = $this->getTask();
|
||||||
$taskProvider = $this->externalTaskManager->getProvider($task['external_provider']);
|
$taskProvider = $this->externalTaskManager->getProvider($task['external_provider']);
|
||||||
$externalTask = $taskProvider->retrieve($task['external_uri']);
|
$externalTask = $taskProvider->fetch($task['external_uri']);
|
||||||
|
|
||||||
$this->response->html($this->template->render($taskProvider->getViewTemplate(), array(
|
$this->response->html($this->template->render($taskProvider->getViewTemplate(), array(
|
||||||
'task' => $task,
|
'task' => $task,
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
namespace Kanboard\Controller;
|
namespace Kanboard\Controller;
|
||||||
|
|
||||||
|
use Kanboard\Core\Controller\AccessForbiddenException;
|
||||||
|
use Kanboard\Core\ExternalTask\AccessForbiddenException as ExternalTaskAccessForbiddenException;
|
||||||
|
use Kanboard\Core\ExternalTask\ExternalTaskException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task Modification controller
|
* Task Modification controller
|
||||||
*
|
*
|
||||||
@@ -43,7 +47,7 @@ class TaskModificationController extends BaseController
|
|||||||
$values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values));
|
$values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values));
|
||||||
$values = $this->hook->merge('controller:task-modification:form:default', $values, array('default_values' => $values));
|
$values = $this->hook->merge('controller:task-modification:form:default', $values, array('default_values' => $values));
|
||||||
|
|
||||||
$this->response->html($this->template->render('task_modification/show', array(
|
$params = array(
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
'values' => $values,
|
'values' => $values,
|
||||||
'errors' => $errors,
|
'errors' => $errors,
|
||||||
@@ -51,7 +55,29 @@ class TaskModificationController extends BaseController
|
|||||||
'tags' => $this->taskTagModel->getList($task['id']),
|
'tags' => $this->taskTagModel->getList($task['id']),
|
||||||
'users_list' => $this->projectUserRoleModel->getAssignableUsersList($task['project_id']),
|
'users_list' => $this->projectUserRoleModel->getAssignableUsersList($task['project_id']),
|
||||||
'categories_list' => $this->categoryModel->getList($task['project_id']),
|
'categories_list' => $this->categoryModel->getList($task['project_id']),
|
||||||
)));
|
);
|
||||||
|
|
||||||
|
$this->renderTemplate($task, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderTemplate(array &$task, array &$params)
|
||||||
|
{
|
||||||
|
if (empty($task['external_uri'])) {
|
||||||
|
$this->response->html($this->template->render('task_modification/show', $params));
|
||||||
|
} else {
|
||||||
|
|
||||||
|
try {
|
||||||
|
$taskProvider = $this->externalTaskManager->getProvider($task['external_provider']);
|
||||||
|
$params['template'] = $taskProvider->getModificationFormTemplate();
|
||||||
|
$params['external_task'] = $taskProvider->fetch($task['external_uri']);
|
||||||
|
} catch (ExternalTaskAccessForbiddenException $e) {
|
||||||
|
throw new AccessForbiddenException($e->getMessage());
|
||||||
|
} catch (ExternalTaskException $e) {
|
||||||
|
$params['error_message'] = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->response->html($this->template->render('external_task_modification/show', $params));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,7 +92,7 @@ class TaskModificationController extends BaseController
|
|||||||
|
|
||||||
list($valid, $errors) = $this->taskValidator->validateModification($values);
|
list($valid, $errors) = $this->taskValidator->validateModification($values);
|
||||||
|
|
||||||
if ($valid && $this->taskModificationModel->update($values)) {
|
if ($valid && $this->updateTask($task, $values, $errors)) {
|
||||||
$this->flash->success(t('Task updated successfully.'));
|
$this->flash->success(t('Task updated successfully.'));
|
||||||
$this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true);
|
$this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true);
|
||||||
} else {
|
} else {
|
||||||
@@ -74,4 +100,23 @@ class TaskModificationController extends BaseController
|
|||||||
$this->edit($values, $errors);
|
$this->edit($values, $errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function updateTask(array &$task, array &$values, array &$errors)
|
||||||
|
{
|
||||||
|
$result = $this->taskModificationModel->update($values);
|
||||||
|
|
||||||
|
if ($result && ! empty($task['external_uri'])) {
|
||||||
|
try {
|
||||||
|
$taskProvider = $this->externalTaskManager->getProvider($task['external_provider']);
|
||||||
|
$result = $taskProvider->save($task['external_uri'], $values, $errors);
|
||||||
|
} catch (ExternalTaskAccessForbiddenException $e) {
|
||||||
|
throw new AccessForbiddenException($e->getMessage());
|
||||||
|
} catch (ExternalTaskException $e) {
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,22 @@ interface ExternalTaskProviderInterface
|
|||||||
* Retrieve task from external system or cache
|
* Retrieve task from external system or cache
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @throws \Kanboard\Core\ExternalTask\AccessForbiddenException
|
* @throws \Kanboard\Core\ExternalTask\ExternalTaskException
|
||||||
* @throws \Kanboard\Core\ExternalTask\NotFoundException
|
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
* @return ExternalTaskInterface
|
* @return ExternalTaskInterface
|
||||||
*/
|
*/
|
||||||
public function retrieve($uri);
|
public function fetch($uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save external task to another system
|
||||||
|
*
|
||||||
|
* @throws \Kanboard\Core\ExternalTask\ExternalTaskException
|
||||||
|
* @param string $uri
|
||||||
|
* @param array $formValues
|
||||||
|
* @param array $formErrors
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function save($uri, array $formValues, array &$formErrors);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get task import template name
|
* Get task import template name
|
||||||
@@ -43,6 +53,13 @@ interface ExternalTaskProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function getCreationFormTemplate();
|
public function getCreationFormTemplate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get modification form template
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getModificationFormTemplate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get task view template name
|
* Get task view template name
|
||||||
*
|
*
|
||||||
|
|||||||
26
app/Template/external_task_modification/show.php
Normal file
26
app/Template/external_task_modification/show.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<form class="popover-form" method="post" action="<?= $this->url->href('TaskModificationController', 'update', array('task_id' => $task['id'], 'project_id' => $project['id'])) ?>">
|
||||||
|
<?= $this->form->csrf() ?>
|
||||||
|
<?= $this->form->hidden('id', $values) ?>
|
||||||
|
<?= $this->form->hidden('project_id', $values) ?>
|
||||||
|
|
||||||
|
<?php if (! empty($error_message)): ?>
|
||||||
|
<p class="alert alert-error"><?= $this->text->e($error_message) ?></p>
|
||||||
|
<?php else: ?>
|
||||||
|
<?= $this->render($template, array(
|
||||||
|
'project' => $project,
|
||||||
|
'task' => $task,
|
||||||
|
'external_task' => $external_task,
|
||||||
|
'tags' => $tags,
|
||||||
|
'users_list' => $users_list,
|
||||||
|
'categories_list' => $categories_list,
|
||||||
|
'values' => $values,
|
||||||
|
'errors' => $errors,
|
||||||
|
)) ?>
|
||||||
|
<?php endif ?>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
|
||||||
|
<?= t('or') ?>
|
||||||
|
<?= $this->url->link(t('cancel'), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
Reference in New Issue
Block a user