From 8477da26437cd927b47fbac8874e2a7e02b580ca Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 14 Feb 2016 15:49:59 -0500 Subject: Rename File controller to TaskFile --- app/Controller/BoardPopover.php | 2 +- app/Controller/File.php | 186 ------------------------- app/Controller/TaskFile.php | 186 +++++++++++++++++++++++++ app/ServiceProvider/AuthenticationProvider.php | 2 +- app/ServiceProvider/RouteProvider.php | 2 - app/Template/board/tooltip_files.php | 4 +- app/Template/file/new.php | 33 ----- app/Template/file/open.php | 6 - app/Template/file/remove.php | 15 -- app/Template/file/screenshot.php | 19 --- app/Template/file/show.php | 84 ----------- app/Template/task/menu.php | 4 +- app/Template/task/show.php | 2 +- app/Template/task_file/new.php | 33 +++++ app/Template/task_file/open.php | 6 + app/Template/task_file/remove.php | 15 ++ app/Template/task_file/screenshot.php | 19 +++ app/Template/task_file/show.php | 84 +++++++++++ 18 files changed, 350 insertions(+), 352 deletions(-) delete mode 100644 app/Controller/File.php create mode 100644 app/Controller/TaskFile.php delete mode 100644 app/Template/file/new.php delete mode 100644 app/Template/file/open.php delete mode 100644 app/Template/file/remove.php delete mode 100644 app/Template/file/screenshot.php delete mode 100644 app/Template/file/show.php create mode 100644 app/Template/task_file/new.php create mode 100644 app/Template/task_file/open.php create mode 100644 app/Template/task_file/remove.php create mode 100644 app/Template/task_file/screenshot.php create mode 100644 app/Template/task_file/show.php diff --git a/app/Controller/BoardPopover.php b/app/Controller/BoardPopover.php index f2b39d8d..965669ff 100644 --- a/app/Controller/BoardPopover.php +++ b/app/Controller/BoardPopover.php @@ -93,7 +93,7 @@ class BoardPopover extends Base { $task = $this->getTask(); - $this->response->html($this->template->render('file/screenshot', array( + $this->response->html($this->template->render('task_file/screenshot', array( 'task' => $task, ))); } diff --git a/app/Controller/File.php b/app/Controller/File.php deleted file mode 100644 index c5517df8..00000000 --- a/app/Controller/File.php +++ /dev/null @@ -1,186 +0,0 @@ -getTask(); - - if ($this->request->isPost() && $this->taskFile->uploadScreenshot($task['id'], $this->request->getValue('screenshot')) !== false) { - $this->flash->success(t('Screenshot uploaded successfully.')); - return $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); - } - - $this->response->html($this->helper->layout->task('file/screenshot', array( - 'task' => $task, - ))); - } - - /** - * File upload form - * - * @access public - */ - public function create() - { - $task = $this->getTask(); - - $this->response->html($this->helper->layout->task('file/new', array( - 'task' => $task, - 'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')), - ))); - } - - /** - * File upload (save files) - * - * @access public - */ - public function save() - { - $task = $this->getTask(); - - if (! $this->taskFile->uploadFiles($task['id'], $this->request->getFileInfo('files'))) { - $this->flash->failure(t('Unable to upload the file.')); - } - - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); - } - - /** - * File download - * - * @access public - */ - public function download() - { - try { - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - if ($file['task_id'] != $task['id']) { - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); - } - - $this->response->forceDownload($file['name']); - $this->objectStorage->output($file['path']); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - } - } - - /** - * Open a file (show the content in a popover) - * - * @access public - */ - public function open() - { - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - if ($file['task_id'] == $task['id']) { - $this->response->html($this->template->render('file/open', array( - 'file' => $file, - 'task' => $task, - ))); - } - } - - /** - * Display image - * - * @access public - */ - public function image() - { - try { - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - if ($file['task_id'] == $task['id']) { - $this->response->contentType($this->taskFile->getImageMimeType($file['name'])); - $this->objectStorage->output($file['path']); - } - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - } - } - - /** - * Display image thumbnails - * - * @access public - */ - public function thumbnail() - { - $this->response->contentType('image/jpeg'); - - try { - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - if ($file['task_id'] == $task['id']) { - $this->objectStorage->output($this->taskFile->getThumbnailPath($file['path'])); - } - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - - // Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19 - $data = $this->objectStorage->get($file['path']); - $this->taskFile->generateThumbnailFromData($file['path'], $data); - $this->objectStorage->output($this->taskFile->getThumbnailPath($file['path'])); - } - } - - /** - * Remove a file - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - if ($file['task_id'] == $task['id'] && $this->taskFile->remove($file['id'])) { - $this->flash->success(t('File removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this file.')); - } - - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); - } - - /** - * Confirmation dialog before removing a file - * - * @access public - */ - public function confirm() - { - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - $this->response->html($this->helper->layout->task('file/remove', array( - 'task' => $task, - 'file' => $file, - ))); - } -} diff --git a/app/Controller/TaskFile.php b/app/Controller/TaskFile.php new file mode 100644 index 00000000..102fdc5c --- /dev/null +++ b/app/Controller/TaskFile.php @@ -0,0 +1,186 @@ +getTask(); + + if ($this->request->isPost() && $this->taskFile->uploadScreenshot($task['id'], $this->request->getValue('screenshot')) !== false) { + $this->flash->success(t('Screenshot uploaded successfully.')); + return $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); + } + + $this->response->html($this->helper->layout->task('task_file/screenshot', array( + 'task' => $task, + ))); + } + + /** + * File upload form + * + * @access public + */ + public function create() + { + $task = $this->getTask(); + + $this->response->html($this->helper->layout->task('task_file/new', array( + 'task' => $task, + 'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')), + ))); + } + + /** + * File upload (save files) + * + * @access public + */ + public function save() + { + $task = $this->getTask(); + + if (! $this->taskFile->uploadFiles($task['id'], $this->request->getFileInfo('files'))) { + $this->flash->failure(t('Unable to upload the file.')); + } + + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); + } + + /** + * File download + * + * @access public + */ + public function download() + { + try { + $task = $this->getTask(); + $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); + + if ($file['task_id'] != $task['id']) { + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } + + $this->response->forceDownload($file['name']); + $this->objectStorage->output($file['path']); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + } + + /** + * Open a file (show the content in a popover) + * + * @access public + */ + public function open() + { + $task = $this->getTask(); + $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); + + if ($file['task_id'] == $task['id']) { + $this->response->html($this->template->render('task_file/open', array( + 'file' => $file, + 'task' => $task, + ))); + } + } + + /** + * Display image + * + * @access public + */ + public function image() + { + try { + $task = $this->getTask(); + $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); + + if ($file['task_id'] == $task['id']) { + $this->response->contentType($this->taskFile->getImageMimeType($file['name'])); + $this->objectStorage->output($file['path']); + } + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + } + + /** + * Display image thumbnails + * + * @access public + */ + public function thumbnail() + { + $this->response->contentType('image/jpeg'); + + try { + $task = $this->getTask(); + $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); + + if ($file['task_id'] == $task['id']) { + $this->objectStorage->output($this->taskFile->getThumbnailPath($file['path'])); + } + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + + // Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19 + $data = $this->objectStorage->get($file['path']); + $this->taskFile->generateThumbnailFromData($file['path'], $data); + $this->objectStorage->output($this->taskFile->getThumbnailPath($file['path'])); + } + } + + /** + * Remove a file + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $task = $this->getTask(); + $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); + + if ($file['task_id'] == $task['id'] && $this->taskFile->remove($file['id'])) { + $this->flash->success(t('File removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this file.')); + } + + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } + + /** + * Confirmation dialog before removing a file + * + * @access public + */ + public function confirm() + { + $task = $this->getTask(); + $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); + + $this->response->html($this->helper->layout->task('task_file/remove', array( + 'task' => $task, + 'file' => $file, + ))); + } +} diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php index c2f7a5c4..cc7b9302 100644 --- a/app/ServiceProvider/AuthenticationProvider.php +++ b/app/ServiceProvider/AuthenticationProvider.php @@ -76,7 +76,7 @@ class AuthenticationProvider implements ServiceProviderInterface $acl->add('Comment', '*', Role::PROJECT_MEMBER); $acl->add('Customfilter', '*', Role::PROJECT_MEMBER); $acl->add('Export', '*', Role::PROJECT_MANAGER); - $acl->add('File', array('screenshot', 'create', 'save', 'remove', 'confirm'), Role::PROJECT_MEMBER); + $acl->add('TaskFile', array('screenshot', 'create', 'save', 'remove', 'confirm'), Role::PROJECT_MEMBER); $acl->add('Gantt', '*', Role::PROJECT_MANAGER); $acl->add('Project', array('share', 'integrations', 'notifications', 'duplicate', 'disable', 'enable', 'remove'), Role::PROJECT_MANAGER); $acl->add('ProjectPermission', '*', Role::PROJECT_MANAGER); diff --git a/app/ServiceProvider/RouteProvider.php b/app/ServiceProvider/RouteProvider.php index 5003eb88..c723140e 100644 --- a/app/ServiceProvider/RouteProvider.php +++ b/app/ServiceProvider/RouteProvider.php @@ -94,8 +94,6 @@ class RouteProvider implements ServiceProviderInterface $container['route']->addRoute('public/task/:task_id/:token', 'task', 'readonly'); $container['route']->addRoute('project/:project_id/task/:task_id/activity', 'activity', 'task'); - $container['route']->addRoute('project/:project_id/task/:task_id/screenshot', 'file', 'screenshot'); - $container['route']->addRoute('project/:project_id/task/:task_id/upload', 'file', 'create'); $container['route']->addRoute('project/:project_id/task/:task_id/transitions', 'task', 'transitions'); $container['route']->addRoute('project/:project_id/task/:task_id/analytics', 'task', 'analytics'); $container['route']->addRoute('project/:project_id/task/:task_id/subtasks', 'subtask', 'show'); diff --git a/app/Template/board/tooltip_files.php b/app/Template/board/tooltip_files.php index 407309b3..4fa14b57 100644 --- a/app/Template/board/tooltip_files.php +++ b/app/Template/board/tooltip_files.php @@ -8,9 +8,9 @@ - url->link(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?> + url->link(t('download'), 'TaskFile', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?> -   url->link(t('open file'), 'file', 'open', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id']), false, 'popover') ?> +   url->link(t('open file'), 'TaskFile', 'open', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id']), false, 'popover') ?> diff --git a/app/Template/file/new.php b/app/Template/file/new.php deleted file mode 100644 index e84ef839..00000000 --- a/app/Template/file/new.php +++ /dev/null @@ -1,33 +0,0 @@ - - - - - -
-
- -
-
- - - -
- - - url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?> -
diff --git a/app/Template/file/open.php b/app/Template/file/open.php deleted file mode 100644 index 3df012b6..00000000 --- a/app/Template/file/open.php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/app/Template/file/remove.php b/app/Template/file/remove.php deleted file mode 100644 index 24844835..00000000 --- a/app/Template/file/remove.php +++ /dev/null @@ -1,15 +0,0 @@ - - -
-

- e($file['name'])) ?> -

- -
- url->link(t('Yes'), 'file', 'remove', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id']), true, 'btn btn-red') ?> - - url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?> -
-
\ No newline at end of file diff --git a/app/Template/file/screenshot.php b/app/Template/file/screenshot.php deleted file mode 100644 index 58b93ac3..00000000 --- a/app/Template/file/screenshot.php +++ /dev/null @@ -1,19 +0,0 @@ - - -
-

-
- -
- - form->csrf() ?> -
- - - url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?> -
-
- -

\ No newline at end of file diff --git a/app/Template/file/show.php b/app/Template/file/show.php deleted file mode 100644 index ed006299..00000000 --- a/app/Template/file/show.php +++ /dev/null @@ -1,84 +0,0 @@ - -
- - - -
- -
- <?= $this->e($file['name']) ?> -
-
- -
-
- dt->datetime($file['date'])).'
'.t('Size: %s', $this->text->bytes($file['size'])) ?>'> - -
- -
-
-
- -
- - - - - - - - - - - - - - - - - - -
- - - - e($file['user_name'] ?: $file['username']) ?> - - dt->date($file['date']) ?> - - text->bytes($file['size']) ?> -
- -
- \ No newline at end of file diff --git a/app/Template/task/menu.php b/app/Template/task/menu.php index e997a6ad..cddd930a 100644 --- a/app/Template/task/menu.php +++ b/app/Template/task/menu.php @@ -38,11 +38,11 @@
  • - url->link(t('Attach a document'), 'file', 'create', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'popover') ?> + url->link(t('Attach a document'), 'TaskFile', 'create', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'popover') ?>
  • - url->link(t('Add a screenshot'), 'file', 'screenshot', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'popover') ?> + url->link(t('Add a screenshot'), 'TaskFile', 'screenshot', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'popover') ?>
  • diff --git a/app/Template/task/show.php b/app/Template/task/show.php index 43906a81..a32232ae 100644 --- a/app/Template/task/show.php +++ b/app/Template/task/show.php @@ -25,7 +25,7 @@ render('task/time_tracking_summary', array('task' => $task)) ?> -render('file/show', array( +render('task_file/show', array( 'task' => $task, 'files' => $files, 'images' => $images diff --git a/app/Template/task_file/new.php b/app/Template/task_file/new.php new file mode 100644 index 00000000..f03ce8dc --- /dev/null +++ b/app/Template/task_file/new.php @@ -0,0 +1,33 @@ + + + + + +
    +
    + +
    +
    + + + +
    + + + url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?> +
    diff --git a/app/Template/task_file/open.php b/app/Template/task_file/open.php new file mode 100644 index 00000000..e3721b59 --- /dev/null +++ b/app/Template/task_file/open.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/app/Template/task_file/remove.php b/app/Template/task_file/remove.php new file mode 100644 index 00000000..5e6c83f2 --- /dev/null +++ b/app/Template/task_file/remove.php @@ -0,0 +1,15 @@ + + +
    +

    + e($file['name'])) ?> +

    + +
    + url->link(t('Yes'), 'TaskFile', 'remove', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id']), true, 'btn btn-red') ?> + + url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?> +
    +
    \ No newline at end of file diff --git a/app/Template/task_file/screenshot.php b/app/Template/task_file/screenshot.php new file mode 100644 index 00000000..72214362 --- /dev/null +++ b/app/Template/task_file/screenshot.php @@ -0,0 +1,19 @@ + + +
    +

    +
    + +
    + + form->csrf() ?> +
    + + + url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?> +
    +
    + +

    \ No newline at end of file diff --git a/app/Template/task_file/show.php b/app/Template/task_file/show.php new file mode 100644 index 00000000..98f26c33 --- /dev/null +++ b/app/Template/task_file/show.php @@ -0,0 +1,84 @@ + +
    + + + +
    + +
    + <?= $this->e($file['name']) ?> +
    +
    + +
    +
    + dt->datetime($file['date'])).'
    '.t('Size: %s', $this->text->bytes($file['size'])) ?>'> + +
    + +
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + +
    + + + + e($file['user_name'] ?: $file['username']) ?> + + dt->date($file['date']) ?> + + text->bytes($file['size']) ?> +
    + +
    + \ No newline at end of file -- cgit v1.2.3