Commit 93a897a3 authored by TravisCarden's avatar TravisCarden

Issue #708586 by roborat, TravisCarden | frazras: Added progress bar and last...

Issue #708586 by roborat, TravisCarden | frazras: Added progress bar and last updated details to checklist form.
parent 2219b453
......@@ -30,13 +30,13 @@ function checklistapi_report_form() {
'data' => ($checklist->userHasAccess()) ? l($checklist->title, $checklist->path) : drupal_placeholder($checklist->title),
'title' => (!empty($checklist->description)) ? $checklist->description : '',
);
$row[] = t('@completed of @total (@percent%) complete', array(
'@completed' => $completed = (!empty($checklist->savedProgress['#completed_items'])) ? $checklist->savedProgress['#completed_items'] : 0,
'@total' => $checklist->totalItems,
'@percent' => round($completed / $checklist->totalItems * 100),
$row[] = t('@completed of @total (@percent%)', array(
'@completed' => $checklist->getNumberCompleted(),
'@total' => $checklist->getNumberOfItems(),
'@percent' => round($checklist->getPercentComplete()),
));
$row[] = (!empty($checklist->savedProgress['#changed'])) ? format_date($checklist->savedProgress['#changed']) : t('n/a');
$row[] = (isset($checklist->savedProgress['#changed_by'])) ? theme('username', array('account' => user_load($checklist->savedProgress['#changed_by']))) : t('n/a');
$row[] = $checklist->getLastUpdatedDate();
$row[] = $checklist->getLastUpdatedUser();
$row[] = ($checklist->userHasAccess('edit') && $checklist->hasSavedProgress()) ? l(t('clear saved progress'), $checklist->path . '/clear', array(
'query' => array('destination' => 'admin/reports/checklistapi'),
)) : '';
......
......@@ -9,3 +9,17 @@
#checklistapi-checklist-form.compact-mode div.description p {
display: none;
}
/**
* Progress bar.
*
* @see system.theme.css
*/
#checklistapi-checklist-form .progress {
font-weight: normal;
margin-bottom: 0.5em;
}
#checklistapi-checklist-form .progress .bar,
#checklistapi-checklist-form .progress .filled {
background-image: none;
}
......@@ -12,7 +12,7 @@
args['@complete'] = $(':checkbox.checklistapi-item:checked', context).size();
args['@total'] = total;
args['@percent'] = Math.round(args['@complete'] / args['@total'] * 100);
return Drupal.t('@complete of @total (@percent%) complete', args);
return Drupal.t('@complete of @total (@percent%)', args);
}
});
}
......
......@@ -281,8 +281,16 @@ function checklistapi_strtolowercamel($string) {
function checklistapi_theme() {
return array(
'checklistapi_compact_link' => array(
'variables' => array('id' => NULL),
'file' => 'checklistapi.pages.inc',
),
'checklistapi_progress_bar' => array(
'template' => 'checklistapi.progress-bar',
'variables' => array(
'message' => ' ',
'number_complete' => 0,
'number_of_items' => 0,
'percent_complete' => 0,
),
),
);
}
......@@ -54,6 +54,18 @@ function checklistapi_checklist_clear_confirm_submit($form, &$form_state) {
function checklistapi_checklist_form($form, &$form_state, $id) {
$form['#checklist'] = $checklist = checklistapi_checklist_load($id);
$form['progress_bar'] = array(
'#type' => 'markup',
'#markup' => theme('checklistapi_progress_bar', array(
'message' => ($checklist->hasSavedProgress()) ? t('Last updated @date by !user', array(
'@date' => $checklist->getLastUpdatedDate(),
'!user' => $checklist->getLastUpdatedUser(),
)) : ' ',
'number_complete' => $checklist->getNumberCompleted(),
'number_of_items' => $checklist->getNumberOfItems(),
'percent_complete' => round($checklist->getPercentComplete()),
)),
);
if (checklistapi_compact_mode()) {
$form['#attributes']['class'] = array('compact-mode');
}
......
<?php
/**
* @file
* Default theme implementation for the Checklist API progress bar.
*
* Available variables:
* - $message: The progress message.
* - $number_complete: The number of items complete.
* - $number_of_items: The total number of items.
* - $percent_complete: The percent of items complete.
*
* @see template_preprocess()
* @see template_preprocess_checklistapi_progress_bar()
* @see template_process()
*/
?>
<div class="progress">
<div class="bar"><div class="filled" style="width:<?php print $percent_complete; ?>%;"></div></div>
<div class="percentage"><?php print $number_complete; ?> of <?php print $number_of_items; ?> (<?php print $percent_complete; ?>%)</div>
<div class="message"><?php print $message; ?></div>
</div>
......@@ -64,7 +64,7 @@ class ChecklistapiChecklist {
*
* @var int
*/
public $totalItems = 0;
public $numberOfItems = 0;
/**
* The checklist groups and items.
......@@ -88,7 +88,7 @@ class ChecklistapiChecklist {
*/
public function __construct(array $definition) {
foreach (element_children($definition) as $group_key) {
$this->totalItems += count(element_children($definition[$group_key]));
$this->numberOfItems += count(element_children($definition[$group_key]));
$this->items[$group_key] = $definition[$group_key];
unset($definition[$group_key]);
}
......@@ -99,6 +99,67 @@ class ChecklistapiChecklist {
$this->savedProgress = variable_get($this->getSavedProgressVariableName(), array());
}
/**
* Gets the total number of completed items.
*
* @return int
* The number of completed items.
*/
public function getNumberCompleted() {
return (!empty($this->savedProgress['#completed_items'])) ? $this->savedProgress['#completed_items'] : 0;
}
/**
* Gets the total number of items.
*
* @return int
* The number of items.
*/
public function getNumberOfItems() {
return $this->numberOfItems;
}
/**
* Gets the name of the last user to update the checklist.
*
* @return string
* The themed name of the last user to update the checklist, or 'n/a' if
* there is no record of such a user.
*/
public function getLastUpdatedUser() {
if (isset($this->savedProgress['#changed_by'])) {
$last_updated_user = user_load($this->savedProgress['#changed_by']);
return theme('username', array('account' => $last_updated_user));
}
else {
return t('n/a');
}
}
/**
* Gets the last updated date.
*
* @return string
* The last updated date formatted with format_date(), or 'n/a' if there is
* no saved progress.
*/
public function getLastUpdatedDate() {
return (!empty($this->savedProgress['#changed'])) ? format_date($this->savedProgress['#changed']) : t('n/a');
}
/**
* Gets the percentage of items complete.
*
* @return float
* The percent complete.
*/
public function getPercentComplete() {
if ($this->getNumberOfItems() == 0) {
return 100;
}
return ($this->getNumberCompleted() / $this->getNumberOfItems()) * 100;
}
/**
* Clears the saved progress for the checklist.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment