From 3b403a1a4b33443ee853556e40d4fe89d3399387 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 12 Apr 2015 18:44:42 -0400 Subject: Add screenshot support for tasks (copy/paste images directly) --- app/Controller/Board.php | 15 ++++++++++++++ app/Controller/File.php | 38 +++++++++++++++++++++++++++------- app/Locale/da_DK/translations.php | 6 ++++++ app/Locale/de_DE/translations.php | 6 ++++++ app/Locale/es_ES/translations.php | 6 ++++++ app/Locale/fi_FI/translations.php | 6 ++++++ app/Locale/fr_FR/translations.php | 10 +++++++-- app/Locale/hu_HU/translations.php | 6 ++++++ app/Locale/it_IT/translations.php | 6 ++++++ app/Locale/ja_JP/translations.php | 6 ++++++ app/Locale/nl_NL/translations.php | 6 ++++++ app/Locale/pl_PL/translations.php | 6 ++++++ app/Locale/pt_BR/translations.php | 6 ++++++ app/Locale/ru_RU/translations.php | 6 ++++++ app/Locale/sr_Latn_RS/translations.php | 6 ++++++ app/Locale/sv_SE/translations.php | 7 ++++++- app/Locale/th_TH/translations.php | 6 ++++++ app/Locale/tr_TR/translations.php | 6 ++++++ app/Locale/zh_CN/translations.php | 6 ++++++ app/Model/Config.php | 1 + app/Model/File.php | 38 +++++++++++++++++++++++++++++++--- app/Template/board/task_menu.php | 1 + app/Template/file/screenshot.php | 19 +++++++++++++++++ app/Template/task/sidebar.php | 3 +++ 24 files changed, 209 insertions(+), 13 deletions(-) create mode 100644 app/Template/file/screenshot.php (limited to 'app') diff --git a/app/Controller/Board.php b/app/Controller/Board.php index 89272393..d9243633 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -335,4 +335,19 @@ class Board extends Base $this->response->redirect($this->helper->url('board', 'show', array('project_id' => $values['project_id']))); } + + /** + * Screenshot popover + * + * @access public + */ + public function screenshot() + { + $task = $this->getTask(); + + $this->response->html($this->template->render('file/screenshot', array( + 'task' => $task, + 'redirect' => 'board', + ))); + } } diff --git a/app/Controller/File.php b/app/Controller/File.php index cc326dcd..39032abc 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -10,6 +10,32 @@ namespace Controller; */ class File extends Base { + /** + * Screenshot + * + * @access public + */ + public function screenshot() + { + $task = $this->getTask(); + + if ($this->request->isPost() && $this->file->uploadScreenshot($task['project_id'], $task['id'], $this->request->getValue('screenshot'))) { + + $this->session->flash(t('Screenshot uploaded successfully.')); + + if ($this->request->getStringParam('redirect') === 'board') { + $this->response->redirect($this->helper->url('board', 'show', array('project_id' => $task['project_id']))); + } + + $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } + + $this->response->html($this->taskLayout('file/screenshot', array( + 'task' => $task, + 'redirect' => 'task', + ))); + } + /** * File upload form * @@ -34,13 +60,11 @@ class File extends Base { $task = $this->getTask(); - if ($this->file->upload($task['project_id'], $task['id'], 'files') === true) { - $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'].'#attachments'); - } - else { + if (! $this->file->upload($task['project_id'], $task['id'], 'files')) { $this->session->flashError(t('Unable to upload the file.')); - $this->response->redirect('?controller=file&action=create&task_id='.$task['id'].'&project_id='.$task['project_id']); } + + $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } /** @@ -59,7 +83,7 @@ class File extends Base $this->response->binary(file_get_contents($filename)); } - $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']); + $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } /** @@ -140,7 +164,7 @@ class File extends Base $this->session->flashError(t('Unable to remove this file.')); } - $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']); + $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } /** diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index e9725a00..564a4e89 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index cd0b4b7f..32880fce 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index efbf589e..fa4dd4be 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index e8df52d0..8699f74c 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index 63270415..a4aacd80 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -849,10 +849,16 @@ return array( 'Test your device' => 'Testez votre appareil', 'Assign a color when the task is moved to a specific column' => 'Assigner une couleur lorsque la tâche est déplacée dans une colonne spécifique', '%s via Kanboard' => '%s via Kanboard', - 'uploaded by: %s' => 'Télécharger par : %s', - 'uploaded on: %s' => 'Télécharger le : %s', + 'uploaded by: %s' => 'Téléchargé par %s', + 'uploaded on: %s' => 'Téléchargé le %s', 'size: %s' => 'Taille : %s', 'Burndown chart for "%s"' => 'Graphique d\'avancement pour « %s »', 'Burndown chart' => 'Graphique d\'avancement', 'This chart show the task complexity over the time (Work Remaining).' => 'Ce graphique représente la complexité des tâches en fonction du temps (travail restant).', + 'Screenshot taken %s' => 'Capture d\'écran prise le %s', + 'Add a screenshot' => 'Ajouter une capture d\'écran', + 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => 'Copier/coller des images est uniquement supporté par Mozilla Firefox et Google Chrome.', + 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => 'Prenez une capture d\'écran et appuyez sur CTRL+V ou ⌘+V pour coller ici.', + 'Screenshot uploaded successfully.' => 'Capture d\'écran téléchargée avec succès.', + 'SEK - Swedish Krona' => 'SEK - Couronne suédoise', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index ca6e540f..b0caa154 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index 7c932d02..8a117d0a 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index 4b56298a..206d4650 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php index 374bfe20..3321f1b6 100644 --- a/app/Locale/nl_NL/translations.php +++ b/app/Locale/nl_NL/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index 99de9460..047e32dc 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index e02489a6..2684724e 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index 8f2ed825..baedde36 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/sr_Latn_RS/translations.php b/app/Locale/sr_Latn_RS/translations.php index 8245d177..281afb26 100644 --- a/app/Locale/sr_Latn_RS/translations.php +++ b/app/Locale/sr_Latn_RS/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index 93e0cb55..19437c71 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -802,7 +802,6 @@ return array( 'The budget line have been created successfully.' => 'Budgetlinjen har skapats.', 'Unable to create the budget line.' => 'Kunde inte skapa budgetlinjen.', 'Unable to remove this budget line.' => 'Kunde inte ta bort budgetlinjen.', - 'SEK - Swedish Krona' => 'SEK - Svensk Krona', 'USD - US Dollar' => 'USD - Amerikanska Dollar', 'Remaining' => 'Återstående', 'Destination column' => 'Målkolumn', @@ -854,4 +853,10 @@ return array( 'Burndown chart for "%s"' => 'Burndown diagram för "%s"', 'Burndown chart' => 'Burndown diagram', 'This chart show the task complexity over the time (Work Remaining).' => 'Diagrammet visar uppgiftens svårighet över tid (återstående arbete).', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + 'SEK - Swedish Krona' => 'SEK - Svensk Krona', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index 72edd63b..9d055a5f 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/tr_TR/translations.php b/app/Locale/tr_TR/translations.php index fad993d1..f1050cb5 100644 --- a/app/Locale/tr_TR/translations.php +++ b/app/Locale/tr_TR/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index 8c454807..15f0ab30 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -853,4 +853,10 @@ return array( // 'Burndown chart for "%s"' => '', // 'Burndown chart' => '', // 'This chart show the task complexity over the time (Work Remaining).' => '', + // 'Screenshot taken %s' => '', + // 'Add a screenshot' => '', + // 'Copy and paste images are only supported with Mozilla Firefox and Google Chrome.' => '', + // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', + // 'Screenshot uploaded successfully.' => '', + // 'SEK - Swedish Krona' => '', ); diff --git a/app/Model/Config.php b/app/Model/Config.php index 736ae08d..bbcff50c 100644 --- a/app/Model/Config.php +++ b/app/Model/Config.php @@ -40,6 +40,7 @@ class Config extends Base 'INR' => t('INR - Indian Rupee'), 'JPY' => t('JPY - Japanese Yen'), 'RSD' => t('RSD - Serbian dinar'), + 'SEK' => t('SEK - Swedish Krona'), ); } diff --git a/app/Model/File.php b/app/Model/File.php index 5da5c014..fe417d48 100644 --- a/app/Model/File.php +++ b/app/Model/File.php @@ -248,9 +248,9 @@ class File extends Base * Handle file upload * * @access public - * @param integer $project_id Project id - * @param integer $task_id Task id - * @param string $form_name File form name + * @param integer $project_id Project id + * @param integer $task_id Task id + * @param string $form_name File form name * @return bool */ public function upload($project_id, $task_id, $form_name) @@ -287,6 +287,38 @@ class File extends Base return count(array_unique($result)) === 1; } + /** + * Handle screenshot upload + * + * @access public + * @param integer $project_id Project id + * @param integer $task_id Task id + * @param string $blob Base64 encoded image + * @return bool + */ + public function uploadScreenshot($project_id, $task_id, $blob) + { + $data = base64_decode($blob); + + if (empty($data)) { + return false; + } + + $original_filename = e('Screenshot taken %s', dt('%B %e, %Y at %k:%M %p', time())); + $destination_filename = $this->generatePath($project_id, $task_id, $original_filename); + + @mkdir(FILES_DIR.dirname($destination_filename), 0755, true); + @file_put_contents(FILES_DIR.$destination_filename, $data); + + return $this->create( + $task_id, + $original_filename, + $destination_filename, + true, + strlen($data) + ); + } + /** * Generate a jpeg thumbnail from an image (output directly the image) * diff --git a/app/Template/board/task_menu.php b/app/Template/board/task_menu.php index 35104b66..f3ec3019 100644 --- a/app/Template/board/task_menu.php +++ b/app/Template/board/task_menu.php @@ -8,6 +8,7 @@
  • a(t('Add a comment'), 'comment', 'create', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'task-board-popover') ?>
  • a(t('Add a link'), 'tasklink', 'create', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'task-board-popover') ?>
  • a(t('Edit this task'), 'task', 'edit', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'task-board-popover') ?>
  • +
  • a(t('Add a screenshot'), 'board', 'screenshot', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'task-board-popover') ?>
  • a(t('Close this task'), 'task', 'close', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'redirect' => 'board'), false, 'task-board-popover') ?>
  • diff --git a/app/Template/file/screenshot.php b/app/Template/file/screenshot.php new file mode 100644 index 00000000..386b83b6 --- /dev/null +++ b/app/Template/file/screenshot.php @@ -0,0 +1,19 @@ + + +
    +

    +
    + +
    + + formCsrf() ?> +
    + + + a(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/sidebar.php b/app/Template/task/sidebar.php index 2ab034e0..a740e939 100644 --- a/app/Template/task/sidebar.php +++ b/app/Template/task/sidebar.php @@ -36,6 +36,9 @@
  • a(t('Attach a document'), 'file', 'create', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
  • +
  • + a(t('Add a screenshot'), 'file', 'screenshot', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?> +
  • a(t('Duplicate'), 'task', 'duplicate', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
  • -- cgit v1.2.3