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 /app | |
parent | 2d070627d751bf5728ec98a5efaf163532594cd9 (diff) |
Add subtasks restrictions and time tracking
Diffstat (limited to 'app')
35 files changed, 505 insertions, 42 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 |