From 3d8636611e6139e831f80b68fa885a5584b8e96a Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Mon, 8 Mar 2010 13:50:30 +0000 Subject: [PATCH] web: introduce a devices tab in the account section --- web/drupal/modules/logger/logger.admin.inc | 61 +++++++++++++++++++++- web/drupal/modules/logger/logger.module | 16 +++++- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/web/drupal/modules/logger/logger.admin.inc b/web/drupal/modules/logger/logger.admin.inc index f702930..434c768 100644 --- a/web/drupal/modules/logger/logger.admin.inc +++ b/web/drupal/modules/logger/logger.admin.inc @@ -1,4 +1,5 @@ uid); + + function unix_to_userlocaltime($unix) { + global $user; + $unix_local = gmdate('r', $unix + $user->timezone); + return substr($unix_local, 0, strlen($unix_local)-6); + } + + function seconds_to_dayshours($seconds) { + $days = intval($seconds / 86400); + $hours = intval(($seconds % 86400) / 3600); + return sprintf('%d days %d hours', $days, $hours); + } + + while ($device = db_fetch_object($result)) { + $row = array(); + $row[] = $device->serial; + $row[] = $device->resets; + $row[] = unix_to_userlocaltime($device->access); + $row[] = seconds_to_dayshours($device->uptime); + + $rows[] = $row; + } + + return theme('logger_account_devices_list', $rows); +} + +/** + * Theme function for displaying the user's devices + * + * @param $items + * An array of table rows. + */ +function theme_logger_account_devices_list($items) { + if (count($items) > 0) { + $headers = array(t('Serial'), t('Resets'), t('Last heartbeat'), t('Uptime')); + $output = theme('table', $headers, $items); + } + else { + $output = t('No devices available.'); + } + + return $output; +} + /** * Callback function for the user/x/sensors page + * + * @param $type + * String defining the sensor type */ function _logger_account_sensors($type = 'electricity') { global $user; @@ -49,8 +108,6 @@ function _logger_account_sensors($type = 'electricity') { * * @param $items * An array of table rows. - * - * @ingroup themeable */ function theme_logger_account_sensors_list($items) { if (count($items) > 0) { diff --git a/web/drupal/modules/logger/logger.module b/web/drupal/modules/logger/logger.module index fee86aa..55bfc47 100644 --- a/web/drupal/modules/logger/logger.module +++ b/web/drupal/modules/logger/logger.module @@ -174,6 +174,16 @@ function logger_menu() { 'access arguments' => array('logger', 1), 'type' => MENU_LOCAL_TASK, 'file' => 'logger.admin.inc', + 'weight' => 2, + ); + $items['user/%user_uid_optional/devices'] = array( + 'title' => 'Devices', + 'page callback' => '_logger_account_devices', + 'access callback' => '_logger_account_access', + 'access arguments' => array('logger', 1), + 'type' => MENU_LOCAL_TASK, + 'file' => 'logger.admin.inc', + 'weight' => 3, ); $items['user/%user_uid_optional/sensors'] = array( 'title' => 'Sensors', @@ -182,12 +192,12 @@ function logger_menu() { 'access arguments' => array('logger', 1), 'type' => MENU_LOCAL_TASK, 'file' => 'logger.admin.inc', + 'weight' => 3, ); return $items; } - function _logger_installation(){ $output = '
'; $output .= "step 1"; @@ -477,6 +487,10 @@ function logger_theme() { 'logger_item_list' => array( 'arguments' => array('items' => NULL, 'title' => NULL), ), + 'logger_account_devices_list' => array( + 'arguments' => array('items' => NULL), + 'file' => 'logger.admin.inc', + ), 'logger_account_sensors_list' => array( 'arguments' => array('items' => NULL), 'file' => 'logger.admin.inc',