diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-02-04 22:19:32 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-02-04 22:19:32 -0500 |
commit | b24b1e7e4e5ee0551ee56aa0f21c4425b479db2e (patch) | |
tree | 5fffaeb461707dada9f2909101d51c9da3c77a50 | |
parent | 2d070627d751bf5728ec98a5efaf163532594cd9 (diff) |
Add subtasks restrictions and time tracking
38 files changed, 522 insertions, 51 deletions
diff --git a/app/Controller/Base.php b/app/Controller/Base.php index d0d5e848..d36e02c0 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -167,6 +167,8 @@ abstract class Base if (! $this->acl->isPublicAction($controller, $action)) { $this->handleAuthentication(); $this->handleAuthorization($controller, $action); + + $this->session['has_subtask_inprogress'] = $this->subTask->hasSubtaskInProgress($this->userSession->getId()); } } diff --git a/app/Controller/Board.php b/app/Controller/Board.php index f4d17f92..3671b5fc 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -416,22 +416,6 @@ class Board extends Base } /** - * Change the status of a subtask from the mouseover - * - * @access public - */ - public function toggleSubtask() - { - $task = $this->getTask(); - $this->subTask->toggleStatus($this->request->getIntegerParam('subtask_id')); - - $this->response->html($this->template->render('board/subtasks', array( - 'subtasks' => $this->subTask->getAll($task['id']), - 'task' => $task, - ))); - } - - /** * Display all attachments during the task mouseover * * @access public diff --git a/app/Controller/Subtask.php b/app/Controller/Subtask.php index 0521b893..a6cec435 100644 --- a/app/Controller/Subtask.php +++ b/app/Controller/Subtask.php @@ -2,6 +2,8 @@ namespace Controller; +use Model\SubTask as SubtaskModel; + /** * SubTask controller * @@ -175,12 +177,86 @@ class Subtask extends Base public function toggleStatus() { $task = $this->getTask(); - $subtask_id = $this->request->getIntegerParam('subtask_id'); + $subtask = $this->getSubtask(); + $redirect = $this->request->getStringParam('redirect', 'task'); + + $this->subTask->toggleStatus($subtask['id']); - if (! $this->subTask->toggleStatus($subtask_id)) { - $this->session->flashError(t('Unable to update your sub-task.')); + if ($redirect === 'board') { + + $this->session['has_subtask_inprogress'] = $this->subTask->hasSubtaskInProgress($this->userSession->getId()); + + $this->response->html($this->template->render('board/subtasks', array( + 'subtasks' => $this->subTask->getAll($task['id']), + 'task' => $task, + ))); } - $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'].'#subtasks'); + $this->toggleRedirect($task, $redirect); + } + + /** + * Handle subtask restriction (popover) + * + * @access public + */ + public function subtaskRestriction() + { + $task = $this->getTask(); + $subtask = $this->getSubtask(); + + $this->response->html($this->template->render('subtask/restriction_change_status', array( + 'status_list' => array( + SubtaskModel::STATUS_TODO => t('Todo'), + SubtaskModel::STATUS_DONE => t('Done'), + ), + 'subtask_inprogress' => $this->subTask->getSubtaskInProgress($this->userSession->getId()), + 'subtask' => $subtask, + 'task' => $task, + 'redirect' => $this->request->getStringParam('redirect'), + ))); + } + + /** + * Change status of the in progress subtask and the other subtask + * + * @access public + */ + public function changeRestrictionStatus() + { + $task = $this->getTask(); + $subtask = $this->getSubtask(); + $values = $this->request->getValues(); + + // Change status of the previous in progress subtask + $this->subTask->update(array( + 'id' => $values['id'], + 'status' => $values['status'], + )); + + // Set the current subtask to in pogress + $this->subTask->update(array( + 'id' => $subtask['id'], + 'status' => SubtaskModel::STATUS_INPROGRESS, + )); + + $this->toggleRedirect($task, $values['redirect']); + } + + /** + * Redirect to the right page + * + * @access private + */ + private function toggleRedirect(array $task, $redirect) + { + switch ($redirect) { + case 'board': + $this->response->redirect($this->helper->url('board', 'show', array('project_id' => $task['project_id']))); + case 'dashboard': + $this->response->redirect($this->helper->url('app', 'index')); + default: + $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } } } diff --git a/app/Controller/User.php b/app/Controller/User.php index a02da7a9..3d44f226 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -190,6 +190,29 @@ class User extends Base } /** + * Display timesheet + * + * @access public + */ + public function timesheet() + { + $user = $this->getUser(); + + $subtask_paginator = $this->paginator + ->setUrl('user', 'timesheet', array('user_id' => $user['id'], 'pagination' => 'subtasks')) + ->setMax(20) + ->setOrder('start') + ->setDirection('DESC') + ->setQuery($this->subtaskTimeTracking->getUserQuery($user['id'])) + ->calculateOnlyIf($this->request->getStringParam('pagination') === 'subtasks'); + + $this->response->html($this->layout('user/timesheet', array( + 'subtask_paginator' => $subtask_paginator, + 'user' => $user, + ))); + } + + /** * Display last connections * * @access public @@ -450,7 +473,7 @@ class User extends Base * * @access public */ - public function gitHub() + public function github() { $code = $this->request->getStringParam('code'); @@ -494,7 +517,7 @@ class User extends Base * * @access public */ - public function unlinkGitHub() + public function unlinkGithub() { $this->checkCSRFParam(); diff --git a/app/Core/Helper.php b/app/Core/Helper.php index 0b267797..42cfbc8a 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -244,7 +244,7 @@ class Helper */ public function formRadio($name, $label, $value, $selected = false, $class = '') { - return '<label><input type="radio" name="'.$name.'" class="'.$class.'" value="'.$this->e($value).'" '.($selected ? 'selected="selected"' : '').'>'.$this->e($label).'</label>'; + return '<label><input type="radio" name="'.$name.'" class="'.$class.'" value="'.$this->e($value).'" '.($selected ? 'selected="selected"' : '').'> '.$this->e($label).'</label>'; } /** @@ -648,4 +648,26 @@ class Helper 'Sat' => t('Sat'), )); } + + public function toggleSubtaskStatus(array $subtask, $redirect) + { + if ($subtask['status'] == 0 && isset($this->session['has_subtask_inprogress']) && $this->session['has_subtask_inprogress'] === true) { + + return $this->a( + trim($this->render('subtask/icons', array('subtask' => $subtask))) . $this->e($subtask['status_name']), + 'subtask', + 'subtaskRestriction', + array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'redirect' => $redirect), + false, + 'popover-subtask-restriction' + ); + } + + return $this->a( + trim($this->render('subtask/icons', array('subtask' => $subtask))) . $this->e($subtask['status_name']), + 'subtask', + 'toggleStatus', + array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'redirect' => $redirect) + ); + } } diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index b117a6e7..88f06fce 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -701,4 +701,12 @@ return array( // 'Moved to column %s' => '', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index 6d7ef520..43dc41a3 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -701,4 +701,12 @@ return array( // 'Moved to column %s' => '', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index bd17dbdb..aa324a84 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -701,4 +701,12 @@ return array( 'Moved to column %s' => 'Movido a columna %s', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index a7a422f4..4f85b9a9 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -701,4 +701,12 @@ return array( // 'Moved to column %s' => '', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index d520635a..12e023fa 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -701,4 +701,12 @@ return array( 'Moved to column %s' => 'Tâche déplacée à la colonne %s', 'Change description' => 'Changer la description', 'User dashboard' => 'Tableau de bord de l\'utilisateur', + 'Allow only one subtask in progress at the same time for a user' => 'Autoriser une seule sous-tâche en progrès en même temps pour un utilisateur', + 'Edit column "%s"' => 'Modifier la colonne « %s »', + 'Enable time tracking for subtasks' => 'Activer la feuille de temps pour les sous-tâches', + 'Select the new status of the subtask: "%s"' => 'Selectionnez le nouveau statut de la sous-tâche : « %s »', + 'Subtask timesheet' => 'Feuille de temps des sous-tâches', + 'There is nothing to show.' => 'Il n\'y a rien à montrer', + 'Time Tracking' => 'Feuille de temps', + 'You already have one subtask in progress' => 'Vous avez déjà une sous-tâche en progrès', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index 06cf6242..3fc11384 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -701,4 +701,12 @@ return array( // 'Moved to column %s' => '', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index 4dac7782..1e2aa5eb 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -701,4 +701,12 @@ return array( // 'Moved to column %s' => '', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index abeac938..01043a74 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -701,4 +701,12 @@ return array( // 'Moved to column %s' => '', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index 301afa34..b616b405 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -701,4 +701,12 @@ return array( 'Moved to column %s' => 'Przeniosiono do kolumny %s', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index d108e5f3..31e9f268 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -701,4 +701,12 @@ return array( 'Moved to column %s' => 'Mover para a coluna %s', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index eaf8ea7e..07916a49 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -701,4 +701,12 @@ return array( // 'Moved to column %s' => '', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index 14984dab..f2cd9199 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -701,4 +701,12 @@ return array( // 'Moved to column %s' => '', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index 5107950f..e4196571 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -701,4 +701,12 @@ return array( // 'Moved to column %s' => '', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index ab867a7a..d89d46ce 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -701,4 +701,12 @@ return array( // 'Moved to column %s' => '', // 'Change description' => '', // 'User dashboard' => '', + // 'Allow only one subtask in progress at the same time for a user' => '', + // 'Edit column "%s"' => '', + // 'Enable time tracking for subtasks' => '', + // 'Select the new status of the subtask: "%s"' => '', + // 'Subtask timesheet' => '', + // 'There is nothing to show.' => '', + // 'Time Tracking' => '', + // 'You already have one subtask in progress' => '', ); diff --git a/app/Model/SubTask.php b/app/Model/SubTask.php index 3fccad47..dd243b1f 100644 --- a/app/Model/SubTask.php +++ b/app/Model/SubTask.php @@ -223,13 +223,43 @@ class SubTask extends Base $values = array( 'id' => $subtask['id'], 'status' => ($subtask['status'] + 1) % 3, - 'task_id' => $subtask['task_id'], ); return $this->update($values); } /** + * Get the subtask in progress for this user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getSubtaskInProgress($user_id) + { + return $this->db->table(self::TABLE) + ->eq('status', self::STATUS_INPROGRESS) + ->eq('user_id', $user_id) + ->findOne(); + } + + /** + * Return true if the user have a subtask in progress + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function hasSubtaskInProgress($user_id) + { + return $this->config->get('subtask_restriction') == 1 && + $this->db->table(self::TABLE) + ->eq('status', self::STATUS_INPROGRESS) + ->eq('user_id', $user_id) + ->count() === 1; + } + + /** * Remove * * @access public diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php new file mode 100644 index 00000000..5c8a7c81 --- /dev/null +++ b/app/Model/SubtaskTimeTracking.php @@ -0,0 +1,80 @@ +<?php + +namespace Model; + +/** + * Subtask timesheet + * + * @package model + * @author Frederic Guillot + */ +class SubtaskTimeTracking extends Base +{ + /** + * SQL table name + * + * @var string + */ + const TABLE = 'subtask_time_tracking'; + + /** + * Get query for user timesheet (pagination) + * + * @access public + * @param integer $user_id User id + * @return \PicoDb\Table + */ + public function getUserQuery($user_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.subtask_id', + self::TABLE.'.end', + self::TABLE.'.start', + SubTask::TABLE.'.task_id', + SubTask::TABLE.'.title AS subtask_title', + Task::TABLE.'.title AS task_title', + Task::TABLE.'.project_id' + ) + ->join(SubTask::TABLE, 'id', 'subtask_id') + ->join(Task::TABLE, 'id', 'task_id', SubTask::TABLE) + ->eq(self::TABLE.'.user_id', $user_id); + } + + /** + * Log start time + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @return boolean + */ + public function logStartTime($subtask_id, $user_id) + { + return $this->db + ->table(self::TABLE) + ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time())); + } + + /** + * Log end time + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @return boolean + */ + public function logEndTime($subtask_id, $user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('subtask_id', $subtask_id) + ->eq('user_id', $user_id) + ->eq('end', 0) + ->update(array( + 'end' => time() + )); + } +} diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index 54aa748e..5a52288b 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -5,7 +5,27 @@ namespace Schema; use PDO; use Core\Security; -const VERSION = 42; +const VERSION = 43; + +function version_43($pdo) +{ + $rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)'); + $rq->execute(array('subtask_restriction', '0')); + $rq->execute(array('subtask_time_tracking', '0')); + + $pdo->exec(" + CREATE TABLE subtask_time_tracking ( + id INT NOT NULL AUTO_INCREMENT, + user_id INT NOT NULL, + subtask_id INT NOT NULL, + start INT DEFAULT 0, + end INT DEFAULT 0, + PRIMARY KEY(id), + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE, + FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE + ) ENGINE=InnoDB CHARSET=utf8 + "); +} function version_42($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index eb094f17..7aa1c457 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -5,7 +5,26 @@ namespace Schema; use PDO; use Core\Security; -const VERSION = 23; +const VERSION = 24; + +function version_24($pdo) +{ + $rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)'); + $rq->execute(array('subtask_restriction', '0')); + $rq->execute(array('subtask_time_tracking', '0')); + + $pdo->exec(" + CREATE TABLE subtask_time_tracking ( + id SERIAL PRIMARY KEY, + user_id INTEGER NOT NULL, + subtask_id INTEGER NOT NULL, + start INTEGER DEFAULT 0, + end INTEGER DEFAULT 0, + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE, + FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE + ) + "); +} function version_23($pdo) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index 16143646..17166e64 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -5,7 +5,26 @@ namespace Schema; use Core\Security; use PDO; -const VERSION = 41; +const VERSION = 42; + +function version_42($pdo) +{ + $rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)'); + $rq->execute(array('subtask_restriction', '0')); + $rq->execute(array('subtask_time_tracking', '0')); + + $pdo->exec(" + CREATE TABLE subtask_time_tracking ( + id INTEGER PRIMARY KEY, + user_id INTEGER NOT NULL, + subtask_id INTEGER NOT NULL, + start INTEGER DEFAULT 0, + end INTEGER DEFAULT 0, + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE, + FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE + ) + "); +} function version_41($pdo) { diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index 91a42fa9..e8b3386a 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -33,6 +33,7 @@ class ClassProvider implements ServiceProviderInterface 'ProjectPermission', 'SubTask', 'SubtaskExport', + 'SubtaskTimeTracking', 'Swimlane', 'Task', 'TaskCreation', diff --git a/app/ServiceProvider/EventDispatcherProvider.php b/app/ServiceProvider/EventDispatcherProvider.php index fd0f7a84..f65a9dca 100644 --- a/app/ServiceProvider/EventDispatcherProvider.php +++ b/app/ServiceProvider/EventDispatcherProvider.php @@ -12,6 +12,7 @@ use Subscriber\ProjectActivitySubscriber; use Subscriber\ProjectDailySummarySubscriber; use Subscriber\ProjectModificationDateSubscriber; use Subscriber\WebhookSubscriber; +use Subscriber\SubtaskTimesheetSubscriber; class EventDispatcherProvider implements ServiceProviderInterface { @@ -25,6 +26,7 @@ class EventDispatcherProvider implements ServiceProviderInterface $container['dispatcher']->addSubscriber(new ProjectModificationDateSubscriber($container)); $container['dispatcher']->addSubscriber(new WebhookSubscriber($container)); $container['dispatcher']->addSubscriber(new NotificationSubscriber($container)); + $container['dispatcher']->addSubscriber(new SubtaskTimesheetSubscriber($container)); // Automatic actions $container['action']->attachEvents(); diff --git a/app/Subscriber/SubtaskTimesheetSubscriber.php b/app/Subscriber/SubtaskTimesheetSubscriber.php new file mode 100644 index 00000000..687db80a --- /dev/null +++ b/app/Subscriber/SubtaskTimesheetSubscriber.php @@ -0,0 +1,32 @@ +<?php + +namespace Subscriber; + +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Model\SubTask; +use Event\SubtaskEvent; + +class SubtaskTimesheetSubscriber extends Base implements EventSubscriberInterface +{ + public static function getSubscribedEvents() + { + return array( + SubTask::EVENT_UPDATE => array('log', 0), + ); + } + + public function log(SubtaskEvent $event) + { + if (isset($event['status'])) { + + $subtask = $this->subTask->getById($event['id']); + + if ($subtask['status'] == SubTask::STATUS_INPROGRESS) { + $this->subtaskTimeTracking->logStartTime($subtask['id'], $subtask['user_id']); + } + else { + $this->subtaskTimeTracking->logEndTime($subtask['id'], $subtask['user_id']); + } + } + } +} diff --git a/app/Template/app/subtasks.php b/app/Template/app/subtasks.php index 75320027..0948e8f5 100644 --- a/app/Template/app/subtasks.php +++ b/app/Template/app/subtasks.php @@ -18,7 +18,7 @@ <?= $this->a($this->e($subtask['project_name']), 'board', 'show', array('project_id' => $subtask['project_id'])) ?> </td> <td> - <?= $this->e($subtask['status_name']) ?> + <?= $this->toggleSubtaskStatus($subtask, 'dashboard') ?> </td> <td> <?= $this->a($this->e($subtask['title']), 'task', 'show', array('task_id' => $subtask['task_id'], 'project_id' => $subtask['project_id'])) ?> diff --git a/app/Template/board/subtasks.php b/app/Template/board/subtasks.php index 1cb05498..18f7f9da 100644 --- a/app/Template/board/subtasks.php +++ b/app/Template/board/subtasks.php @@ -1,14 +1,7 @@ <section id="tooltip-subtasks"> <?php foreach ($subtasks as $subtask): ?> - <?= $this->a( - trim($this->render('subtask/icons', array('subtask' => $subtask))) . $this->e($subtask['title']), - 'board', - 'toggleSubtask', - array('task_id' => $subtask['task_id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id']) - ) ?> - + <?= $this->toggleSubtaskStatus($subtask, 'board') ?> <?= $this->e(empty($subtask['username']) ? '' : ' ['.$this->getFullname($subtask).']') ?> - <br/> <?php endforeach ?> </section> diff --git a/app/Template/config/board.php b/app/Template/config/board.php index d7f8ee44..57efcd08 100644 --- a/app/Template/config/board.php +++ b/app/Template/config/board.php @@ -26,6 +26,9 @@ <?= $this->formText('project_categories', $values, $errors) ?><br/> <p class="form-help"><?= t('Example: "Bug, Feature Request, Improvement"') ?></p> + <?= $this->formCheckbox('subtask_restriction', t('Allow only one subtask in progress at the same time for a user'), 1, $values['subtask_restriction'] == 1) ?> + <?= $this->formCheckbox('subtask_time_tracking', t('Enable time tracking for subtasks'), 1, $values['subtask_time_tracking'] == 1) ?> + <div class="form-actions"> <input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/> </div> diff --git a/app/Template/subtask/edit.php b/app/Template/subtask/edit.php index 8350dc09..f34d9532 100644 --- a/app/Template/subtask/edit.php +++ b/app/Template/subtask/edit.php @@ -12,9 +12,6 @@ <?= $this->formLabel(t('Title'), 'title') ?> <?= $this->formText('title', $values, $errors, array('required', 'autofocus', 'maxlength="50"')) ?><br/> - <?= $this->formLabel(t('Status'), 'status') ?> - <?= $this->formSelect('status', $status_list, $values, $errors) ?><br/> - <?= $this->formLabel(t('Assignee'), 'user_id') ?> <?= $this->formSelect('user_id', $users_list, $values, $errors) ?><br/> diff --git a/app/Template/subtask/restriction_change_status.php b/app/Template/subtask/restriction_change_status.php new file mode 100644 index 00000000..99e022f8 --- /dev/null +++ b/app/Template/subtask/restriction_change_status.php @@ -0,0 +1,19 @@ +<div class="page-header"> + <h2><?= t('You already have one subtask in progress') ?></h2> +</div> + + <form action="<?= $this->u('subtask', 'changeRestrictionStatus', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id'])) ?>" method="post"> + + <?= $this->formCsrf() ?> + <?= $this->formHidden('redirect', array('redirect' => $redirect)) ?> + + <p><?= t('Select the new status of the subtask: "%s"', $subtask_inprogress['title']) ?></p> + <?= $this->formRadios('status', $status_list) ?> + <?= $this->formHidden('id', $subtask_inprogress) ?> + + <div class="form-actions"> + <input type="submit" value="<?= t('Save') ?>" class="btn btn-red"/> + <?= t('or') ?> + <a href="#" class="close-popover"><?= t('cancel') ?></a> + </div> +</form>
\ No newline at end of file diff --git a/app/Template/subtask/show.php b/app/Template/subtask/show.php index 265883b7..6d4533d2 100644 --- a/app/Template/subtask/show.php +++ b/app/Template/subtask/show.php @@ -20,15 +20,14 @@ <td><?= $this->e($subtask['title']) ?></td> <td> <?php if (! isset($not_editable)): ?> - <?= $this->a(trim($this->render('subtask/icons', array('subtask' => $subtask))) . $this->e($subtask['status_name']), - 'subtask', 'toggleStatus', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id'])) ?> + <?= $this->toggleSubtaskStatus($subtask, 'task') ?> <?php else: ?> <?= $this->render('subtask/icons', array('subtask' => $subtask)) . $this->e($subtask['status_name']) ?> <?php endif ?> </td> <td> <?php if (! empty($subtask['username'])): ?> - <?= $this->e($subtask['name'] ?: $subtask['username']) ?> + <?= $this->a($this->e($subtask['name'] ?: $subtask['username']), 'user', 'show', array('user_id' => $subtask['user_id'])) ?> <?php endif ?> </td> <td> diff --git a/app/Template/user/sidebar.php b/app/Template/user/sidebar.php index 4376aa18..05be2e84 100644 --- a/app/Template/user/sidebar.php +++ b/app/Template/user/sidebar.php @@ -28,6 +28,9 @@ <li> <?= $this->a(t('Persistent connections'), 'user', 'sessions', array('user_id' => $user['id'])) ?> </li> + <li> + <?= $this->a(t('Time tracking'), 'user', 'timesheet', array('user_id' => $user['id'])) ?> + </li> <?php endif ?> <?php if ($this->userSession->isAdmin()): ?> diff --git a/app/Template/user/timesheet.php b/app/Template/user/timesheet.php new file mode 100644 index 00000000..fb7e51f0 --- /dev/null +++ b/app/Template/user/timesheet.php @@ -0,0 +1,27 @@ +<div class="page-header"> + <h2><?= t('Time Tracking') ?></h2> +</div> + +<h3><?= t('Subtask timesheet') ?></h3> +<?php if ($subtask_paginator->isEmpty()): ?> + <p class="alert"><?= t('There is nothing to show.') ?></p> +<?php else: ?> + <table class="table-fixed"> + <tr> + <th class="column-20"><?= $subtask_paginator->order('Task', 'task_title') ?></th> + <th class="column-20"><?= $subtask_paginator->order('Subtask', 'subtask_title') ?></th> + <th><?= $subtask_paginator->order(t('Start'), 'start') ?></th> + <th><?= $subtask_paginator->order(t('End'), 'end') ?></th> + </tr> + <?php foreach ($subtask_paginator->getCollection() as $record): ?> + <tr> + <td><?= $this->a($this->e($record['task_title']), 'task', 'show', array('project_id' => $record['project_id'], 'task_id' => $record['task_id'])) ?></td> + <td><?= $this->a($this->e($record['subtask_title']), 'task', 'show', array('project_id' => $record['project_id'], 'task_id' => $record['task_id'])) ?></td> + <td><?= dt('%B %e, %Y at %k:%M %p', $record['start']) ?></td> + <td><?= dt('%B %e, %Y at %k:%M %p', $record['end']) ?></td> + </tr> + <?php endforeach ?> + </table> + + <?= $subtask_paginator ?> +<?php endif ?>
\ No newline at end of file diff --git a/assets/js/app.js b/assets/js/app.js index 9e21e7c3..d040b3be 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -135,16 +135,16 @@ var Kanboard=function(){return{Exists:function(a){return document.getElementById $(".close-popover").click(function(a){a.preventDefault();$("#popover-container").remove()});Mousetrap.bind("esc",function(){$("#popover-container").remove()});d&&d()})},IsVisible:function(){var a="";"undefined"!==typeof document.hidden?a="visibilityState":"undefined"!==typeof document.mozHidden?a="mozVisibilityState":"undefined"!==typeof document.msHidden?a="msVisibilityState":"undefined"!==typeof document.webkitHidden&&(a="webkitVisibilityState");return""!=a?"visible"==document[a]:!0},SetStorageItem:function(a, d){"undefined"!==typeof Storage&&localStorage.setItem(a,d)},GetStorageItem:function(a){return"undefined"!==typeof Storage?localStorage.getItem(a):""},MarkdownPreview:function(a){a.preventDefault();var d=$(this),c=$(this).closest("ul"),f=$(".write-area"),e=$(".preview-area"),b=$("textarea");$.ajax({url:"?controller=app&action=preview",contentType:"application/json",type:"POST",processData:!1,dataType:"html",data:JSON.stringify({text:b.val()})}).done(function(a){c.find("li").removeClass("form-tab-selected"); d.parent().addClass("form-tab-selected");e.find(".markdown").html(a);e.css("height",b.css("height"));e.css("width",b.css("width"));f.hide();e.show()})},MarkdownWriter:function(a){a.preventDefault();$(this).closest("ul").find("li").removeClass("form-tab-selected");$(this).parent().addClass("form-tab-selected");$(".write-area").show();$(".preview-area").hide()},CheckSession:function(){$(".form-login").length||$.ajax({cache:!1,url:$("body").data("status-url"),statusCode:{401:function(a){window.location= -$("body").data("login-url")}}})},Init:function(){$("#board-selector").chosen({width:180});$("#board-selector").change(function(){window.location=$(this).attr("data-board-url").replace(/PROJECT_ID/g,$(this).val())});window.setInterval(Kanboard.CheckSession,6E4);Mousetrap.bind("ctrl+enter",function(){$("form").submit()});Kanboard.InitAfterAjax()},InitAfterAjax:function(){$(".form-date").datepicker({showOtherMonths:!0,selectOtherMonths:!0,dateFormat:"yy-mm-dd",constrainInput:!1});$("#markdown-preview").click(Kanboard.MarkdownPreview); -$("#markdown-write").click(Kanboard.MarkdownWriter);$(".auto-select").focus(function(){$(this).select()});$(".dropit-submenu").hide();$(".dropdown").not(".dropit").dropit()}}}(); +$("body").data("login-url")}}})},Init:function(){$("#board-selector").chosen({width:180});$("#board-selector").change(function(){window.location=$(this).attr("data-board-url").replace(/PROJECT_ID/g,$(this).val())});window.setInterval(Kanboard.CheckSession,6E4);Mousetrap.bind("ctrl+enter",function(){$("form").submit()});$(".popover-subtask-restriction").click(Kanboard.Popover);Kanboard.InitAfterAjax()},InitAfterAjax:function(){$(".form-date").datepicker({showOtherMonths:!0,selectOtherMonths:!0,dateFormat:"yy-mm-dd", +constrainInput:!1});$("#markdown-preview").click(Kanboard.MarkdownPreview);$("#markdown-write").click(Kanboard.MarkdownWriter);$(".auto-select").focus(function(){$(this).select()});$(".dropit-submenu").hide();$(".dropdown").not(".dropit").dropit()}}}(); Kanboard.Board=function(){function a(a){Kanboard.Popover(a,Kanboard.InitAfterAjax)}function d(){Mousetrap.bind("n",function(){Kanboard.OpenPopover($(".task-creation-popover").attr("href"),Kanboard.InitAfterAjax)})}function c(){$(".column").sortable({delay:300,distance:5,connectWith:".column",placeholder:"draggable-placeholder",stop:function(a,b){e(b.item.attr("data-task-id"),b.item.parent().attr("data-column-id"),b.item.index()+1,b.item.parent().attr("data-swimlane-id"))}});$(".assignee-popover").click(a); $(".category-popover").click(a);$(".task-edit-popover").click(a);$(".task-creation-popover").click(a);$(".task-description-popover").click(a);$(".column-tooltip").tooltip({content:function(a){return $(this).attr("title")}});$(".task-board-tooltip").tooltip({track:!1,position:{my:"left-20 top",at:"center bottom+9",using:function(a,b){$(this).css(a);var c=b.target.left+b.target.width/2-b.element.left-20;$("<div>").addClass("tooltip-arrow").addClass(b.vertical).addClass(0==c?"align-left":"align-right").appendTo(this)}}, -content:function(a){if(a=$(this).attr("data-href")){var b=this;$.get(a,function k(a){$(".ui-tooltip-content:visible").html(a);a=$(".ui-tooltip:visible");a.css({top:"",left:""});a.children(".tooltip-arrow").remove();var c=$(b).tooltip("option","position");c.of=$(b);a.position(c);$("#tooltip-subtasks a").click(function(a){a.preventDefault();a.stopPropagation();$.get($(this).attr("href"),k)})});return'<i class="fa fa-refresh fa-spin fa-2x"></i>'}}}).on("mouseenter",function(){var a=this;$(this).tooltip("open"); -$(".ui-tooltip").on("mouseleave",function(){$(a).tooltip("close")})}).on("mouseleave focusout",function(a){a.stopImmediatePropagation();var b=this;setTimeout(function(){$(".ui-tooltip:hover").length||$(b).tooltip("close")},100)});$("[data-task-url]").each(function(){$(this).click(function(){window.location=$(this).attr("data-task-url")})});var c=parseInt($("#board").attr("data-check-interval"));0<c&&(h=window.setInterval(b,1E3*c))}function f(){$("[data-task-url]").off();clearInterval(h)}function e(a, -b,e,d){f();$.ajax({cache:!1,url:$("#board").attr("data-save-url"),contentType:"application/json",type:"POST",processData:!1,data:JSON.stringify({task_id:a,column_id:b,swimlane_id:d,position:e}),success:function(a){$("#board").remove();$("#main").append(a);Kanboard.InitAfterAjax();c();g()}})}function b(){Kanboard.IsVisible()&&$.ajax({cache:!1,url:$("#board").attr("data-check-url"),statusCode:{200:function(a){$("#board").remove();$("#main").append(a);Kanboard.InitAfterAjax();f();c();g()}}})}function g(){var a= -$("#form-user_id").val(),b=$("#form-category_id").val(),c=$("#filter-due-date").hasClass("filter-on"),e=$("#board").data("project-id");$("[data-task-id]").each(function(e,d){var f=d.getAttribute("data-owner-id"),g=d.getAttribute("data-due-date"),h=d.getAttribute("data-category-id");d.style.opacity=f!=a&&-1!=a?"0.2":"1.0";!c||""!=g&&"0"!=g||(d.style.opacity="0.2");h!=b&&-1!=b&&(d.style.opacity="0.2")});Kanboard.SetStorageItem("board_filter_"+e+"_form-user_id",a);Kanboard.SetStorageItem("board_filter_"+ -e+"_form-category_id",b);Kanboard.SetStorageItem("board_filter_"+e+"_filter-due-date",~~c)}function l(){var a=$("#board").data("project-id");$("#form-user_id").change(g);$("#form-category_id").change(g);$("#filter-due-date").click(function(a){$(this).toggleClass("filter-on");g();a.preventDefault()});$("#form-user_id").val(Kanboard.GetStorageItem("board_filter_"+a+"_form-user_id")||-1);$("#form-category_id").val(Kanboard.GetStorageItem("board_filter_"+a+"_form-category_id")||-1);+Kanboard.GetStorageItem("board_filter_"+ -a+"_filter-due-date")?$("#filter-due-date").addClass("filter-on"):$("#filter-due-date").removeClass("filter-on");g()}var h=null;return{Init:function(){c();l();d()}}}(); +content:function(a){if(a=$(this).attr("data-href")){var b=this;$.get(a,function k(a){$(".ui-tooltip-content:visible").html(a);a=$(".ui-tooltip:visible");a.css({top:"",left:""});a.children(".tooltip-arrow").remove();var c=$(b).tooltip("option","position");c.of=$(b);a.position(c);$("#tooltip-subtasks a").click(function(a){a.preventDefault();a.stopPropagation();$(this).hasClass("popover-subtask-restriction")?(Kanboard.OpenPopover($(this).attr("href")),$(b).tooltip("close")):$.get($(this).attr("href"), +k)})});return'<i class="fa fa-refresh fa-spin fa-2x"></i>'}}}).on("mouseenter",function(){var a=this;$(this).tooltip("open");$(".ui-tooltip").on("mouseleave",function(){$(a).tooltip("close")})}).on("mouseleave focusout",function(a){a.stopImmediatePropagation();var b=this;setTimeout(function(){$(".ui-tooltip:hover").length||$(b).tooltip("close")},100)});$("[data-task-url]").each(function(){$(this).click(function(){window.location=$(this).attr("data-task-url")})});var c=parseInt($("#board").attr("data-check-interval")); +0<c&&(h=window.setInterval(b,1E3*c))}function f(){$("[data-task-url]").off();clearInterval(h)}function e(a,b,e,d){f();$.ajax({cache:!1,url:$("#board").attr("data-save-url"),contentType:"application/json",type:"POST",processData:!1,data:JSON.stringify({task_id:a,column_id:b,swimlane_id:d,position:e}),success:function(a){$("#board").remove();$("#main").append(a);Kanboard.InitAfterAjax();c();g()}})}function b(){Kanboard.IsVisible()&&$.ajax({cache:!1,url:$("#board").attr("data-check-url"),statusCode:{200:function(a){$("#board").remove(); +$("#main").append(a);Kanboard.InitAfterAjax();f();c();g()}}})}function g(){var a=$("#form-user_id").val(),b=$("#form-category_id").val(),c=$("#filter-due-date").hasClass("filter-on"),e=$("#board").data("project-id");$("[data-task-id]").each(function(e,d){var f=d.getAttribute("data-owner-id"),g=d.getAttribute("data-due-date"),h=d.getAttribute("data-category-id");d.style.opacity=f!=a&&-1!=a?"0.2":"1.0";!c||""!=g&&"0"!=g||(d.style.opacity="0.2");h!=b&&-1!=b&&(d.style.opacity="0.2")});Kanboard.SetStorageItem("board_filter_"+ +e+"_form-user_id",a);Kanboard.SetStorageItem("board_filter_"+e+"_form-category_id",b);Kanboard.SetStorageItem("board_filter_"+e+"_filter-due-date",~~c)}function l(){var a=$("#board").data("project-id");$("#form-user_id").change(g);$("#form-category_id").change(g);$("#filter-due-date").click(function(a){$(this).toggleClass("filter-on");g();a.preventDefault()});$("#form-user_id").val(Kanboard.GetStorageItem("board_filter_"+a+"_form-user_id")||-1);$("#form-category_id").val(Kanboard.GetStorageItem("board_filter_"+ +a+"_form-category_id")||-1);+Kanboard.GetStorageItem("board_filter_"+a+"_filter-due-date")?$("#filter-due-date").addClass("filter-on"):$("#filter-due-date").removeClass("filter-on");g()}var h=null;return{Init:function(){c();l();d()}}}(); Kanboard.Calendar=function(){function a(a){$.ajax({cache:!1,url:$("#calendar").data("save-url"),contentType:"application/json",type:"POST",processData:!1,data:JSON.stringify({task_id:a.id,date_due:a.start.format()})})}function d(a){var b=$("#calendar"),c=b.data("check-url"),d={start:b.fullCalendar("getView").start.format(),end:b.fullCalendar("getView").end.format()};jQuery.extend(d,a);for(var f in d)c+="&"+f+"="+d[f];$.getJSON(c,function(a){b.fullCalendar("removeEvents");b.fullCalendar("addEventSource", a);b.fullCalendar("rerenderEvents")})}function c(){var a={};$(".calendar-filter").each(function(b,c){a[$(this).attr("name")]=$(this).val()});Kanboard.SetStorageItem(f,JSON.stringify(a));d(a)}var f="";return{Init:function(){f="calendar_filters_"+$("#calendar").data("project-id");var e=$("#calendar"),b=e.data("translations");e.fullCalendar({editable:!0,eventLimit:!0,header:{left:"prev,next today",center:"title",right:""},eventDrop:a,monthNames:[b.January,b.February,b.March,b.April,b.May,b.June,b.July, b.August,b.September,b.October,b.November,b.December],monthNamesShort:[b.Jan,b.Feb,b.Mar,b.Apr,b.May,b.Jun,b.Jul,b.Aug,b.Sep,b.Oct,b.Nov,b.Dec],buttonText:{today:b.Today},dayNames:[b.Sunday,b.Monday,b.Tuesday,b.Wednesday,b.Thursday,b.Friday,b.Saturday],dayNamesShort:[b.Sun,b.Mon,b.Tue,b.Wed,b.Thu,b.Fri,b.Sat]});e=Kanboard.GetStorageItem(f);if("undefined"!==e&&""!==e){var e=JSON.parse(e),g;for(g in e)$("select[name="+g+"]").val(e[g])}d(e||{});$(".calendar-filter").change(c)}}}();Kanboard.Task=function(){return{Init:function(){$(".file-popover").click(Kanboard.Popover)}}}(); diff --git a/assets/js/src/base.js b/assets/js/src/base.js index 956064fb..a10f5cce 100644 --- a/assets/js/src/base.js +++ b/assets/js/src/base.js @@ -178,6 +178,8 @@ var Kanboard = (function() { $("form").submit(); }); + $(".popover-subtask-restriction").click(Kanboard.Popover); + Kanboard.InitAfterAjax(); }, diff --git a/assets/js/src/board.js b/assets/js/src/board.js index 6bc52326..e86d8018 100644 --- a/assets/js/src/board.js +++ b/assets/js/src/board.js @@ -107,7 +107,13 @@ Kanboard.Board = (function() { e.preventDefault(); e.stopPropagation(); - $.get($(this).attr('href'), setTooltipContent); + if ($(this).hasClass("popover-subtask-restriction")) { + Kanboard.OpenPopover($(this).attr('href')); + $(_this).tooltip('close'); + } + else { + $.get($(this).attr('href'), setTooltipContent); + } }); }); |