diff options
Diffstat (limited to 'app/Helper')
| -rw-r--r-- | app/Helper/AppHelper.php | 23 | ||||
| -rw-r--r-- | app/Helper/CalendarHelper.php | 26 | ||||
| -rw-r--r-- | app/Helper/DateHelper.php | 2 | ||||
| -rw-r--r-- | app/Helper/FileHelper.php | 29 | ||||
| -rw-r--r-- | app/Helper/FormHelper.php | 71 | ||||
| -rw-r--r-- | app/Helper/ICalHelper.php | 11 | ||||
| -rw-r--r-- | app/Helper/LayoutHelper.php | 18 | ||||
| -rw-r--r-- | app/Helper/MailHelper.php | 23 | ||||
| -rw-r--r-- | app/Helper/ModalHelper.php | 83 | ||||
| -rw-r--r-- | app/Helper/ProjectActivityHelper.php | 9 | ||||
| -rw-r--r-- | app/Helper/ProjectRoleHelper.php | 2 | ||||
| -rw-r--r-- | app/Helper/SubtaskHelper.php | 8 | ||||
| -rw-r--r-- | app/Helper/TaskHelper.php | 98 | ||||
| -rw-r--r-- | app/Helper/TextHelper.php | 4 | ||||
| -rw-r--r-- | app/Helper/UrlHelper.php | 33 |
15 files changed, 342 insertions, 98 deletions
diff --git a/app/Helper/AppHelper.php b/app/Helper/AppHelper.php index 09f280cb..3cefd1c5 100644 --- a/app/Helper/AppHelper.php +++ b/app/Helper/AppHelper.php @@ -12,17 +12,34 @@ use Kanboard\Core\Base; */ class AppHelper extends Base { + public function isAjax() + { + return $this->request->isAjax(); + } + + /** + * Render Javascript component + * + * @param string $name + * @param array $params + * @return string + */ + public function component($name, array $params = array()) + { + return '<div class="js-'.$name.'" data-params=\''.json_encode($params, JSON_HEX_APOS).'\'></div>'; + } + /** * Get config variable * * @access public * @param string $param - * @param mixed $default_value + * @param mixed $default * @return mixed */ - public function config($param, $default_value = '') + public function config($param, $default = '') { - return $this->configModel->get($param, $default_value); + return $this->configModel->get($param, $default); } /** diff --git a/app/Helper/CalendarHelper.php b/app/Helper/CalendarHelper.php index b35c40f7..0942177d 100644 --- a/app/Helper/CalendarHelper.php +++ b/app/Helper/CalendarHelper.php @@ -5,8 +5,6 @@ namespace Kanboard\Helper; use Kanboard\Core\Base; use Kanboard\Core\Filter\QueryBuilder; use Kanboard\Filter\TaskDueDateRangeFilter; -use Kanboard\Formatter\SubtaskTimeTrackingCalendarFormatter; -use Kanboard\Formatter\TaskCalendarFormatter; /** * Calendar Helper @@ -17,6 +15,23 @@ use Kanboard\Formatter\TaskCalendarFormatter; class CalendarHelper extends Base { /** + * Render calendar component + * + * @param string $checkUrl + * @param string $saveUrl + * @return string + */ + public function render($checkUrl, $saveUrl) + { + $params = array( + 'checkUrl' => $checkUrl, + 'saveUrl' => $saveUrl, + ); + + return '<div class="js-calendar" data-params=\''.json_encode($params, JSON_HEX_APOS).'\'></div>'; + } + + /** * Get formatted calendar task due events * * @access public @@ -27,7 +42,7 @@ class CalendarHelper extends Base */ public function getTaskDateDueEvents(QueryBuilder $queryBuilder, $start, $end) { - $formatter = new TaskCalendarFormatter($this->container); + $formatter = $this->taskCalendarFormatter; $formatter->setFullDay(); $formatter->setColumns('date_due'); @@ -56,7 +71,7 @@ class CalendarHelper extends Base 'date_due' )); - $formatter = new TaskCalendarFormatter($this->container); + $formatter = $this->taskCalendarFormatter; $formatter->setColumns($startColumn, 'date_due'); return $queryBuilder->format($formatter); @@ -73,8 +88,7 @@ class CalendarHelper extends Base */ public function getSubtaskTimeTrackingEvents($user_id, $start, $end) { - $formatter = new SubtaskTimeTrackingCalendarFormatter($this->container); - return $formatter + return $this->subtaskTimeTrackingCalendarFormatter ->withQuery($this->subtaskTimeTrackingModel->getUserQuery($user_id) ->addCondition($this->getCalendarCondition( $this->dateParser->getTimestampFromIsoFormat($start), diff --git a/app/Helper/DateHelper.php b/app/Helper/DateHelper.php index 7e2ec79c..3bc85b76 100644 --- a/app/Helper/DateHelper.php +++ b/app/Helper/DateHelper.php @@ -54,7 +54,7 @@ class DateHelper extends Base */ public function datetime($value) { - return date($this->configModel->get('application_datetime_format', 'm/d/Y H:i'), $value); + return date($this->dateParser->getUserDateTimeFormat(), $value); } /** diff --git a/app/Helper/FileHelper.php b/app/Helper/FileHelper.php index cabf371c..06589124 100644 --- a/app/Helper/FileHelper.php +++ b/app/Helper/FileHelper.php @@ -21,9 +21,7 @@ class FileHelper extends Base */ public function icon($filename) { - $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); - - switch ($extension) { + switch (get_file_extension($filename)) { case 'jpeg': case 'jpg': case 'png': @@ -70,9 +68,7 @@ class FileHelper extends Base */ public function getImageMimeType($filename) { - $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); - - switch ($extension) { + switch (get_file_extension($filename)) { case 'jpeg': case 'jpg': return 'image/jpeg'; @@ -94,9 +90,7 @@ class FileHelper extends Base */ public function getPreviewType($filename) { - $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); - - switch ($extension) { + switch (get_file_extension($filename)) { case 'md': case 'markdown': return 'markdown'; @@ -106,4 +100,21 @@ class FileHelper extends Base return null; } + + /** + * Return the browser view mime-type based on the file extension. + * + * @access public + * @param $filename + * @return string + */ + public function getBrowserViewType($filename) + { + switch (get_file_extension($filename)) { + case 'pdf': + return 'application/pdf'; + } + + return null; + } } diff --git a/app/Helper/FormHelper.php b/app/Helper/FormHelper.php index eca1f317..9eabd724 100644 --- a/app/Helper/FormHelper.php +++ b/app/Helper/FormHelper.php @@ -131,16 +131,34 @@ class FormHelper extends Base * Display a checkbox field * * @access public - * @param string $name Field name - * @param string $label Form label - * @param string $value Form value - * @param boolean $checked Field selected or not - * @param string $class CSS class + * @param string $name Field name + * @param string $label Form label + * @param string $value Form value + * @param boolean $checked Field selected or not + * @param string $class CSS class + * @param array $attributes * @return string */ - public function checkbox($name, $label, $value, $checked = false, $class = '') + public function checkbox($name, $label, $value, $checked = false, $class = '', array $attributes = array()) { - return '<label><input type="checkbox" name="'.$name.'" class="'.$class.'" value="'.$this->helper->text->e($value).'" '.($checked ? 'checked="checked"' : '').'> '.$this->helper->text->e($label).'</label>'; + $htmlAttributes = ''; + + if ($checked) { + $attributes['checked'] = 'checked'; + } + + foreach ($attributes as $attribute => $attributeValue) { + $htmlAttributes .= sprintf('%s="%s"', $attribute, $this->helper->text->e($attributeValue)); + } + + return sprintf( + '<label><input type="checkbox" name="%s" class="%s" value="%s" %s> %s</label>', + $name, + $class, + $this->helper->text->e($value), + $htmlAttributes, + $this->helper->text->e($label) + ); } /** @@ -182,6 +200,45 @@ class FormHelper extends Base } /** + * Display a markdown editor + * + * @access public + * @param string $name Field name + * @param array $values Form values + * @param array $errors Form errors + * @param array $attributes + * @return string + */ + public function textEditor($name, $values = array(), array $errors = array(), array $attributes = array()) + { + $params = array( + 'name' => $name, + 'text' => isset($values[$name]) ? $values[$name] : '', + 'css' => $this->errorClass($errors, $name), + 'required' => isset($attributes['required']) && $attributes['required'], + 'tabindex' => isset($attributes['tabindex']) ? $attributes['tabindex'] : '-1', + 'labelPreview' => t('Preview'), + 'labelWrite' => t('Write'), + 'placeholder' => t('Write your text in Markdown'), + 'autofocus' => isset($attributes['autofocus']) && $attributes['autofocus'], + 'suggestOptions' => array( + 'triggers' => array( + '#' => $this->helper->url->to('TaskAjaxController', 'suggest', array('search' => 'SEARCH_TERM')), + ) + ), + ); + + if (isset($values['project_id'])) { + $params['suggestOptions']['triggers']['@'] = $this->helper->url->to('UserAjaxController', 'mention', array('project_id' => $values['project_id'], 'search' => 'SEARCH_TERM')); + } + + $html = '<div class="js-text-editor" data-params=\''.json_encode($params, JSON_HEX_APOS).'\'></div>'; + $html .= $this->errorList($errors, $name); + + return $html; + } + + /** * Display file field * * @access public diff --git a/app/Helper/ICalHelper.php b/app/Helper/ICalHelper.php index dc399bf8..95723417 100644 --- a/app/Helper/ICalHelper.php +++ b/app/Helper/ICalHelper.php @@ -5,7 +5,6 @@ namespace Kanboard\Helper; use Kanboard\Core\Base; use Kanboard\Core\Filter\QueryBuilder; use Kanboard\Filter\TaskDueDateRangeFilter; -use Kanboard\Formatter\TaskICalFormatter; use Eluceo\iCal\Component\Calendar as iCalendar; /** @@ -29,10 +28,10 @@ class ICalHelper extends Base { $queryBuilder->withFilter(new TaskDueDateRangeFilter(array($start, $end))); - $formatter = new TaskICalFormatter($this->container); - $formatter->setColumns('date_due'); - $formatter->setCalendar($calendar); - $formatter->withQuery($queryBuilder->getQuery()); - $formatter->addFullDayEvents(); + $this->taskICalFormatter + ->setColumns('date_due') + ->setCalendar($calendar) + ->withQuery($queryBuilder->getQuery()) + ->addFullDayEvents(); } } diff --git a/app/Helper/LayoutHelper.php b/app/Helper/LayoutHelper.php index 8d2e7e00..91745f58 100644 --- a/app/Helper/LayoutHelper.php +++ b/app/Helper/LayoutHelper.php @@ -22,12 +22,19 @@ class LayoutHelper extends Base */ public function app($template, array $params = array()) { - if ($this->request->isAjax()) { + $isAjax = $this->request->isAjax(); + $params['is_ajax'] = $isAjax; + + if ($isAjax) { return $this->template->render($template, $params); } if (! isset($params['no_layout']) && ! isset($params['board_selector'])) { $params['board_selector'] = $this->projectUserRoleModel->getActiveProjectsByUser($this->userSession->getId()); + + if (isset($params['project']['id'])) { + unset($params['board_selector'][$params['project']['id']]); + } } return $this->pageLayout($template, $params); @@ -160,7 +167,7 @@ class LayoutHelper extends Base $params['title'] = $params['project']['name'].' > '.$params['title']; } - return $this->subLayout('analytic/layout', 'analytic/sidebar', $template, $params); + return $this->subLayout('analytic/layout', 'analytic/sidebar', $template, $params, true); } /** @@ -188,13 +195,16 @@ class LayoutHelper extends Base * @param string $sidebar * @param string $template * @param array $params + * @param bool $ignoreAjax * @return string */ - public function subLayout($sublayout, $sidebar, $template, array $params = array()) + public function subLayout($sublayout, $sidebar, $template, array $params = array(), $ignoreAjax = false) { + $isAjax = $this->request->isAjax(); + $params['is_ajax'] = $isAjax; $content = $this->template->render($template, $params); - if ($this->request->isAjax()) { + if (!$ignoreAjax && $isAjax) { return $content; } diff --git a/app/Helper/MailHelper.php b/app/Helper/MailHelper.php index 3b1c9e41..cb16d6f8 100644 --- a/app/Helper/MailHelper.php +++ b/app/Helper/MailHelper.php @@ -40,8 +40,9 @@ class MailHelper extends Base */ public function filterSubject($subject) { - $subject = str_replace('RE: ', '', $subject); - $subject = str_replace('FW: ', '', $subject); + $subject = str_ireplace('RE: ', '', $subject); + $subject = str_ireplace('FW: ', '', $subject); + $subject = str_ireplace('Fwd: ', '', $subject); return $subject; } @@ -54,27 +55,31 @@ class MailHelper extends Base */ public function getMailSenderAddress() { - $email = $this->configModel->get('mail_sender_address'); + if (MAIL_CONFIGURATION) { + $email = $this->configModel->get('mail_sender_address'); - if (!empty($email)) { - return $email; + if (! empty($email)) { + return $email; + } } return MAIL_FROM; } /** - * Get mail sender address + * Get mail transport * * @access public * @return string */ public function getMailTransport() { - $transport = $this->configModel->get('mail_transport'); + if (MAIL_CONFIGURATION) { + $transport = $this->configModel->get('mail_transport'); - if (!empty($transport)) { - return $transport; + if (! empty($transport)) { + return $transport; + } } return MAIL_TRANSPORT; diff --git a/app/Helper/ModalHelper.php b/app/Helper/ModalHelper.php new file mode 100644 index 00000000..efbe2c4d --- /dev/null +++ b/app/Helper/ModalHelper.php @@ -0,0 +1,83 @@ +<?php + +namespace Kanboard\Helper; + +use Kanboard\Core\Base; + +/** + * Class ModalHelper + * + * @package Kanboard\Helper + * @author Frederic Guillot + */ +class ModalHelper extends Base +{ + public function submitButtons(array $params = array()) + { + return $this->helper->app->component('submit-buttons', array( + 'submitLabel' => isset($params['submitLabel']) ? $params['submitLabel'] : t('Save'), + 'orLabel' => t('or'), + 'cancelLabel' => t('cancel'), + 'color' => isset($params['color']) ? $params['color'] : 'blue', + 'tabindex' => isset($params['tabindex']) ? $params['tabindex'] : null, + 'disabled' => isset($params['disabled']) ? true : false, + )); + } + + public function confirmButtons($controller, $action, array $params = array(), $submitLabel = '', $tabindex = null) + { + return $this->helper->app->component('confirm-buttons', array( + 'url' => $this->helper->url->href($controller, $action, $params, true), + 'submitLabel' => $submitLabel ?: t('Yes'), + 'orLabel' => t('or'), + 'cancelLabel' => t('cancel'), + 'tabindex' => $tabindex, + )); + } + + public function largeIcon($icon, $label, $controller, $action, array $params = array()) + { + $html = '<i class="fa fa-'.$icon.' fa-fw js-modal-large" aria-hidden="true"></i>'; + return $this->helper->url->link($html, $controller, $action, $params, false, 'js-modal-large', $label); + } + + public function large($icon, $label, $controller, $action, array $params = array()) + { + $html = '<i class="fa fa-'.$icon.' fa-fw js-modal-large" aria-hidden="true"></i>'.$label; + return $this->helper->url->link($html, $controller, $action, $params, false, 'js-modal-large'); + } + + public function medium($icon, $label, $controller, $action, array $params = array()) + { + $html = '<i class="fa fa-'.$icon.' fa-fw js-modal-medium" aria-hidden="true"></i>'.$label; + return $this->helper->url->link($html, $controller, $action, $params, false, 'js-modal-medium'); + } + + public function small($icon, $label, $controller, $action, array $params = array()) + { + $html = '<i class="fa fa-'.$icon.' fa-fw js-modal-small" aria-hidden="true"></i>'.$label; + return $this->helper->url->link($html, $controller, $action, $params, false, 'js-modal-small'); + } + + public function mediumButton($icon, $label, $controller, $action, array $params = array()) + { + $html = '<i class="fa fa-'.$icon.' fa-fw js-modal-medium" aria-hidden="true"></i>'.$label; + return $this->helper->url->link($html, $controller, $action, $params, false, 'js-modal-medium btn'); + } + + public function confirm($icon, $label, $controller, $action, array $params = array()) + { + $html = '<i class="fa fa-'.$icon.' fa-fw js-modal-confirm" aria-hidden="true"></i>'.$label; + return $this->helper->url->link($html, $controller, $action, $params, false, 'js-modal-confirm'); + } + + public function confirmLink($label, $controller, $action, array $params = array()) + { + return $this->helper->url->link($label, $controller, $action, $params, false, 'js-modal-confirm'); + } + + public function replaceLink($label, $controller, $action, array $params = array()) + { + return $this->helper->url->link($label, $controller, $action, $params, false, 'js-modal-replace'); + } +} diff --git a/app/Helper/ProjectActivityHelper.php b/app/Helper/ProjectActivityHelper.php index 704cd4fe..480db3d5 100644 --- a/app/Helper/ProjectActivityHelper.php +++ b/app/Helper/ProjectActivityHelper.php @@ -6,7 +6,6 @@ use Kanboard\Core\Base; use Kanboard\Filter\ProjectActivityProjectIdFilter; use Kanboard\Filter\ProjectActivityProjectIdsFilter; use Kanboard\Filter\ProjectActivityTaskIdFilter; -use Kanboard\Formatter\ProjectActivityEventFormatter; use Kanboard\Model\ProjectActivityModel; /** @@ -38,7 +37,7 @@ class ProjectActivityHelper extends Base ->limit(500) ; - $events = $queryBuilder->format(new ProjectActivityEventFormatter($this->container)); + $events = $queryBuilder->format($this->projectActivityEventFormatter); } return $events; @@ -62,7 +61,7 @@ class ProjectActivityHelper extends Base ->limit($limit) ; - return $queryBuilder->format(new ProjectActivityEventFormatter($this->container)); + return $queryBuilder->format($this->projectActivityEventFormatter); } /** @@ -83,7 +82,7 @@ class ProjectActivityHelper extends Base ->limit($limit) ; - return $queryBuilder->format(new ProjectActivityEventFormatter($this->container)); + return $queryBuilder->format($this->projectActivityEventFormatter); } /** @@ -100,6 +99,6 @@ class ProjectActivityHelper extends Base $queryBuilder->getQuery()->desc(ProjectActivityModel::TABLE.'.id'); - return $queryBuilder->format(new ProjectActivityEventFormatter($this->container)); + return $queryBuilder->format($this->projectActivityEventFormatter); } } diff --git a/app/Helper/ProjectRoleHelper.php b/app/Helper/ProjectRoleHelper.php index 5c80d42b..6f9cf10c 100644 --- a/app/Helper/ProjectRoleHelper.php +++ b/app/Helper/ProjectRoleHelper.php @@ -35,7 +35,7 @@ class ProjectRoleHelper extends Base */ public function isDraggable(array &$task) { - if ($task['is_active'] == 1 && $this->helper->user->hasProjectAccess('BoardViewController', 'save', $task['project_id'])) { + if ($task['is_active'] == 1 && $this->helper->user->hasProjectAccess('BoardAjaxController', 'save', $task['project_id'])) { return $this->isSortableColumn($task['project_id'], $task['column_id']); } diff --git a/app/Helper/SubtaskHelper.php b/app/Helper/SubtaskHelper.php index 833544a7..8e090f17 100644 --- a/app/Helper/SubtaskHelper.php +++ b/app/Helper/SubtaskHelper.php @@ -50,7 +50,7 @@ class SubtaskHelper extends Base return $this->helper->url->link($this->getTitle($subtask), 'SubtaskStatusController', 'change', $params, false, $class); } - public function selectTitle(array $values, array $errors = array(), array $attributes = array()) + public function renderTitleField(array $values, array $errors = array(), array $attributes = array()) { $attributes = array_merge(array('tabindex="1"', 'required', 'maxlength="255"'), $attributes); @@ -60,7 +60,7 @@ class SubtaskHelper extends Base return $html; } - public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) + public function renderAssigneeField(array $users, array $values, array $errors = array(), array $attributes = array()) { $attributes = array_merge(array('tabindex="2"'), $attributes); @@ -74,7 +74,7 @@ class SubtaskHelper extends Base return $html; } - public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) + public function renderTimeEstimatedField(array $values, array $errors = array(), array $attributes = array()) { $attributes = array_merge(array('tabindex="3"'), $attributes); @@ -85,7 +85,7 @@ class SubtaskHelper extends Base return $html; } - public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) + public function renderTimeSpentField(array $values, array $errors = array(), array $attributes = array()) { $attributes = array_merge(array('tabindex="4"'), $attributes); diff --git a/app/Helper/TaskHelper.php b/app/Helper/TaskHelper.php index 678b4bed..71596b60 100644 --- a/app/Helper/TaskHelper.php +++ b/app/Helper/TaskHelper.php @@ -40,34 +40,28 @@ class TaskHelper extends Base return $this->taskRecurrenceModel->getRecurrenceBasedateList(); } - public function selectTitle(array $values, array $errors) + public function renderTitleField(array $values, array $errors) { - $html = $this->helper->form->label(t('Title'), 'title'); - $html .= $this->helper->form->text('title', $values, $errors, array('autofocus', 'required', 'maxlength="200"', 'tabindex="1"'), 'form-input-large'); - return $html; - } - - public function selectDescription(array $values, array $errors) - { - $html = $this->helper->form->label(t('Description'), 'description'); - $html .= '<div class="markdown-editor-container">'; - $html .= $this->helper->form->textarea( - 'description', + return $this->helper->form->text( + 'title', $values, $errors, array( - 'placeholder="'.t('Leave a description').'"', - 'tabindex="2"', - 'data-mention-search-url="'.$this->helper->url->href('UserAjaxController', 'mention', array('project_id' => $values['project_id'])).'"' - ), - 'markdown-editor' + 'autofocus', + 'required', + 'maxlength="200"', + 'tabindex="1"', + 'placeholder="'.t('Title').'"' + ) ); + } - $html .= '</div>'; - return $html; + public function renderDescriptionField(array $values, array $errors) + { + return $this->helper->form->textEditor('description', $values, $errors, array('tabindex' => 2)); } - public function selectTags(array $project, array $tags = array()) + public function renderTagField(array $project, array $tags = array()) { $options = $this->tagModel->getAssignableList($project['id']); @@ -89,7 +83,7 @@ class TaskHelper extends Base return $html; } - public function selectColor(array $values) + public function renderColorField(array $values) { $colors = $this->colorModel->getList(); $html = $this->helper->form->label(t('Color'), 'color_id'); @@ -97,7 +91,7 @@ class TaskHelper extends Base return $html; } - public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) + public function renderAssigneeField(array $users, array $values, array $errors = array(), array $attributes = array()) { $attributes = array_merge(array('tabindex="3"'), $attributes); @@ -111,7 +105,7 @@ class TaskHelper extends Base return $html; } - public function selectCategory(array $categories, array $values, array $errors = array(), array $attributes = array(), $allow_one_item = false) + public function renderCategoryField(array $categories, array $values, array $errors = array(), array $attributes = array(), $allow_one_item = false) { $attributes = array_merge(array('tabindex="4"'), $attributes); $html = ''; @@ -124,7 +118,7 @@ class TaskHelper extends Base return $html; } - public function selectSwimlane(array $swimlanes, array $values, array $errors = array(), array $attributes = array()) + public function renderSwimlaneField(array $swimlanes, array $values, array $errors = array(), array $attributes = array()) { $attributes = array_merge(array('tabindex="5"'), $attributes); $html = ''; @@ -137,7 +131,7 @@ class TaskHelper extends Base return $html; } - public function selectColumn(array $columns, array $values, array $errors = array(), array $attributes = array()) + public function renderColumnField(array $columns, array $values, array $errors = array(), array $attributes = array()) { $attributes = array_merge(array('tabindex="6"'), $attributes); @@ -147,7 +141,7 @@ class TaskHelper extends Base return $html; } - public function selectPriority(array $project, array $values) + public function renderPriorityField(array $project, array $values) { $html = ''; @@ -163,9 +157,9 @@ class TaskHelper extends Base return $html; } - public function selectScore(array $values, array $errors = array(), array $attributes = array()) + public function renderScoreField(array $values, array $errors = array(), array $attributes = array()) { - $attributes = array_merge(array('tabindex="8"'), $attributes); + $attributes = array_merge(array('tabindex="13"'), $attributes); $html = $this->helper->form->label(t('Complexity'), 'score'); $html .= $this->helper->form->number('score', $values, $errors, $attributes); @@ -173,9 +167,9 @@ class TaskHelper extends Base return $html; } - public function selectReference(array $values, array $errors = array(), array $attributes = array()) + public function renderReferenceField(array $values, array $errors = array(), array $attributes = array()) { - $attributes = array_merge(array('tabindex="9"'), $attributes); + $attributes = array_merge(array('tabindex="14"'), $attributes); $html = $this->helper->form->label(t('Reference'), 'reference'); $html .= $this->helper->form->text('reference', $values, $errors, $attributes, 'form-input-small'); @@ -183,9 +177,9 @@ class TaskHelper extends Base return $html; } - public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) + public function renderTimeEstimatedField(array $values, array $errors = array(), array $attributes = array()) { - $attributes = array_merge(array('tabindex="10"'), $attributes); + $attributes = array_merge(array('tabindex="11"'), $attributes); $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); @@ -194,9 +188,9 @@ class TaskHelper extends Base return $html; } - public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) + public function renderTimeSpentField(array $values, array $errors = array(), array $attributes = array()) { - $attributes = array_merge(array('tabindex="11"'), $attributes); + $attributes = array_merge(array('tabindex="12"'), $attributes); $html = $this->helper->form->label(t('Time spent'), 'time_spent'); $html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); @@ -205,15 +199,15 @@ class TaskHelper extends Base return $html; } - public function selectStartDate(array $values, array $errors = array(), array $attributes = array()) + public function renderStartDateField(array $values, array $errors = array(), array $attributes = array()) { - $attributes = array_merge(array('tabindex="12"'), $attributes); + $attributes = array_merge(array('tabindex="10"'), $attributes); return $this->helper->form->datetime(t('Start Date'), 'date_started', $values, $errors, $attributes); } - public function selectDueDate(array $values, array $errors = array(), array $attributes = array()) + public function renderDueDateField(array $values, array $errors = array(), array $attributes = array()) { - $attributes = array_merge(array('tabindex="13"'), $attributes); + $attributes = array_merge(array('tabindex="9"'), $attributes); return $this->helper->form->date(t('Due Date'), 'date_due', $values, $errors, $attributes); } @@ -238,4 +232,32 @@ class TaskHelper extends Base return $this->taskModel->getProgress($task, $this->columns[$task['project_id']]); } + + public function getNewTaskDropdown($projectId, $swimlaneId, $columnId) + { + $providers = $this->externalTaskManager->getProvidersList(); + + if (empty($providers)) { + return ''; + } + + $html = '<small class="pull-right"><div class="dropdown">'; + $html .= '<a href="#" class="dropdown-menu"><i class="fa fa-cloud-download" aria-hidden="true"></i> <i class="fa fa-caret-down"></i></a><ul>'; + + foreach ($providers as $providerName) { + $link = $this->helper->url->link( + t('New External Task: %s', $providerName), + 'ExternalTaskCreationController', + 'step1', + array('project_id' => $projectId, 'swimlane_id' => $swimlaneId, 'column_id' => $columnId, 'provider_name' => $providerName), + false, + 'js-modal-replace' + ); + + $html .= '<li><i class="fa fa-fw fa-plus-square" aria-hidden="true"></i> '.$link.'</li>'; + } + + $html .= '</ul></div></small>'; + return $html; + } } diff --git a/app/Helper/TextHelper.php b/app/Helper/TextHelper.php index 654eb171..66583cd1 100644 --- a/app/Helper/TextHelper.php +++ b/app/Helper/TextHelper.php @@ -59,6 +59,10 @@ class TextHelper extends Base */ public function bytes($size, $precision = 2) { + if ($size == 0) { + return 0; + } + $base = log($size) / log(1024); $suffixes = array('', 'k', 'M', 'G', 'T'); diff --git a/app/Helper/UrlHelper.php b/app/Helper/UrlHelper.php index 93177ed5..94412cf5 100644 --- a/app/Helper/UrlHelper.php +++ b/app/Helper/UrlHelper.php @@ -42,9 +42,32 @@ class UrlHelper extends Base */ public function button($icon, $label, $controller, $action, array $params = array(), $class = '') { - $icon = '<i class="fa '.$icon.' fa-fw"></i> '; + $html = '<i class="fa fa-'.$icon.' fa-fw"></i> '.$label; $class = 'btn '.$class; - return $this->link($icon.$label, $controller, $action, $params, false, $class); + return $this->link($html, $controller, $action, $params, false, $class); + } + + /** + * Link element with icon + * + * @access public + * @param string $icon Icon name + * @param string $label Link label + * @param string $controller Controller name + * @param string $action Action name + * @param array $params Url parameters + * @param boolean $csrf Add a CSRF token + * @param string $class CSS class attribute + * @param string $title Link title + * @param boolean $newTab Open the link in a new tab + * @param string $anchor Link Anchor + * @param bool $absolute + * @return string + */ + public function icon($icon, $label, $controller, $action, array $params = array(), $csrf = false, $class = '', $title = '', $newTab = false, $anchor = '', $absolute = false) + { + $html = '<i class="fa fa-fw fa-'.$icon.'" aria-hidden="true"></i>'.$label; + return $this->helper->url->link($html, $controller, $action, $params, $csrf, $class, $title, $newTab, $anchor, $absolute); } /** @@ -58,14 +81,14 @@ class UrlHelper extends Base * @param boolean $csrf Add a CSRF token * @param string $class CSS class attribute * @param string $title Link title - * @param boolean $new_tab Open the link in a new tab + * @param boolean $newTab Open the link in a new tab * @param string $anchor Link Anchor * @param bool $absolute * @return string */ - public function link($label, $controller, $action, array $params = array(), $csrf = false, $class = '', $title = '', $new_tab = false, $anchor = '', $absolute = false) + public function link($label, $controller, $action, array $params = array(), $csrf = false, $class = '', $title = '', $newTab = false, $anchor = '', $absolute = false) { - return '<a href="'.$this->href($controller, $action, $params, $csrf, $anchor, $absolute).'" class="'.$class.'" title=\''.$title.'\' '.($new_tab ? 'target="_blank"' : '').'>'.$label.'</a>'; + return '<a href="'.$this->href($controller, $action, $params, $csrf, $anchor, $absolute).'" class="'.$class.'" title=\''.$title.'\' '.($newTab ? 'target="_blank"' : '').'>'.$label.'</a>'; } /** |
