From c660d45f4897358cc30b5e2359701c56f78fa4a1 Mon Sep 17 00:00:00 2001 From: Robin Sonefors Date: Tue, 6 May 2014 17:45:01 +0200 Subject: [PATCH] reports: Generalize dates, saved reports Copy-pasta with some olive oil, some garlic, and a bit of basil is, of course, delicious, but I'm on a diet. Change-Id: I78b0b032439e674b6ea66966c2d3e2ba5aca609e Signed-off-by: Robin Sonefors --- modules/reports/controllers/base_reports.php | 26 +++++++++++ modules/reports/controllers/reports.php | 21 +-------- modules/reports/controllers/summary.php | 9 +--- modules/reports/views/reports/saveselector.php | 25 ++++++++++ modules/reports/views/reports/setup.php | 62 +++++++------------------ modules/reports/views/summary/setup.php | 63 ++++++++------------------ 6 files changed, 89 insertions(+), 117 deletions(-) create mode 100644 modules/reports/views/reports/saveselector.php rewrite modules/reports/views/reports/setup.php (84%) rewrite modules/reports/views/summary/setup.php (68%) diff --git a/modules/reports/controllers/base_reports.php b/modules/reports/controllers/base_reports.php index bd14ae6d9..7298c833d 100644 --- a/modules/reports/controllers/base_reports.php +++ b/modules/reports/controllers/base_reports.php @@ -224,4 +224,30 @@ abstract class Base_reports_Controller extends Authenticated_Controller echo sprintf(_("This helptext ('%s') is not translated yet"), $id); } } + + /** + * All reports must display the time range they cover, and this helper + * helps them do so with some amount of consistency. + * + * @param $date_format string Format string for date(), probably nagstat::date_format() + * @returns string Formatted date for this report + */ + protected function format_report_time($date_format) + { + if($this->options['report_period'] && $this->options['report_period'] != 'custom') + $report_time_formatted = sprintf( + _('%s (%s to %s)'), + $this->options->get_value('report_period'), + "".date($date_format, $this->options['start_time'])."", + "".date($date_format, $this->options['end_time'])."" + ); + else + $report_time_formatted = sprintf(_("%s to %s"), + date($date_format, $this->options['start_time']), + date($date_format, $this->options['end_time'])); + + if($this->options['rpttimeperiod'] != '') + $report_time_formatted .= " - {$this->options['rpttimeperiod']}"; + return $report_time_formatted; + } } diff --git a/modules/reports/controllers/reports.php b/modules/reports/controllers/reports.php index 6d980296e..8c5f0cd0d 100644 --- a/modules/reports/controllers/reports.php +++ b/modules/reports/controllers/reports.php @@ -69,12 +69,10 @@ class Reports_Controller extends Base_reports_Controller $this->xtra_css[] = $this->add_path('reports/css/datePicker.css'); # what scheduled reports are there? - $scheduled_ids = array(); $scheduled_periods = null; $scheduled_res = Scheduled_reports_Model::get_scheduled_reports($this->type); if ($scheduled_res && count($scheduled_res)!=0) { foreach ($scheduled_res as $sched_row) { - $scheduled_ids[] = $sched_row->report_id; $scheduled_periods[$sched_row->report_id] = $sched_row->periodname; } } @@ -95,13 +93,11 @@ class Reports_Controller extends Base_reports_Controller $this->js_strings .= "var _reports_name_empty = '"._("Please give your report a meaningful name.")."';\n"; - $template->new_saved_title = sprintf(_('Create new saved %s report'), $type_str); $template->report_options->months = date::abbr_month_names(); $saved_reports = $this->options->get_all_saved(); $template->report_options->saved_reports = $saved_reports; $template->saved_reports = $saved_reports; - $template->scheduled_ids = $scheduled_ids; $template->scheduled_periods = $scheduled_periods; $this->js_strings .= "var _reports_no_sla_str = '"._('Please enter at least one SLA value')."';\n"; @@ -184,20 +180,6 @@ class Reports_Controller extends Base_reports_Controller $sub_type = false; $date_format = $this->type == 'sla' ? cal::get_calendar_format(true) : nagstat::date_format(); - if($this->options['report_period'] && $this->options['report_period'] != 'custom') - $report_time_formatted = sprintf( - _('%s (%s to %s)'), - $this->options->get_value('report_period'), - "".date($date_format, $this->options['start_time'])."", - "".date($date_format, $this->options['end_time'])."" - ); - else - $report_time_formatted = sprintf(_("%s to %s"), - date($date_format, $this->options['start_time']), - date($date_format, $this->options['end_time'])); - - if($this->options['rpttimeperiod'] != '') - $report_time_formatted .= " - {$this->options['rpttimeperiod']}"; switch ($this->options['report_type']) { case 'hostgroups': @@ -280,10 +262,9 @@ class Reports_Controller extends Base_reports_Controller $template->header = $this->add_view('reports/header'); $template->header->title = $template->title; - $template->header->report_time_formatted = $report_time_formatted; + $template->header->report_time_formatted = $this->format_report_time($date_format); # avail, more than one object - $get_vars = $this->options->as_keyval_string(true); if ($this->type == 'avail' && ($is_group || count($this->options['objects']) > 1)) { $template_values = array(); $template->content = $this->add_view('reports/multiple_'.$sub_type.'_states'); diff --git a/modules/reports/controllers/summary.php b/modules/reports/controllers/summary.php index 1d04a736c..07b6a2bb5 100644 --- a/modules/reports/controllers/summary.php +++ b/modules/reports/controllers/summary.php @@ -147,13 +147,6 @@ class Summary_Controller extends Base_reports_Controller $this->xtra_js[] = $this->add_path('reports/js/common.js'); $this->xtra_js[] = $this->add_path('summary/js/summary.js'); $this->xtra_css[] = $this->add_path('reports/css/datePicker.css'); - if($this->options['report_period'] && $this->options['report_period'] != 'custom') - $report_time_formatted = $this->options->get_value('report_period'); - else - $report_time_formatted = sprintf(_("%s to %s"), date(nagstat::date_format(), $this->options['start_time']), date(nagstat::date_format(), $this->options['end_time'])); - - if($this->options['rpttimeperiod'] != '') - $report_time_formatted .= " - {$this->options['rpttimeperiod']}"; $views = array( Summary_options::TOP_ALERT_PRODUCERS => 'toplist', @@ -166,7 +159,7 @@ class Summary_Controller extends Base_reports_Controller $this->template->content->header->standard_header = $this->add_view('reports/header'); $header = $this->template->content->header->standard_header; $this->template->content->report_options = $this->add_view('summary/options'); - $header->report_time_formatted = $report_time_formatted; + $header->report_time_formatted = $this->format_report_time(nagstat::date_format()); $this->template->content->content = $this->add_view("summary/" . $views[$this->options['summary_type']]); diff --git a/modules/reports/views/reports/saveselector.php b/modules/reports/views/reports/saveselector.php new file mode 100644 index 000000000..5a1d02ab3 --- /dev/null +++ b/modules/reports/views/reports/saveselector.php @@ -0,0 +1,25 @@ + 'saved_report_form', 'class' => 'report-block', 'method' => 'get')); ?> +
+
+ + + + + +
+ + + [] + +
+ +
+ + diff --git a/modules/reports/views/reports/setup.php b/modules/reports/views/reports/setup.php dissimilarity index 84% index d552b0598..9679d30ac 100644 --- a/modules/reports/views/reports/setup.php +++ b/modules/reports/views/reports/setup.php @@ -1,45 +1,17 @@ - - -
-
-
  • '.$error_msg.'
  • '; - } - ?>
    -
    - - 'saved_report_form', 'class' => 'report-block', 'method' => 'get')); ?> -
    -
    - - - - - -
    - - - [] - -
    - -
    - -
    - - 'report_form')); ?> - - -
    -
    + +
  • '.$error_msg.'
  • '; + } +?>
    + +
    +
    + $saved_reports, 'scheduled_info' => $scheduled_info)); ?> +
    + + 'report_form')); ?> + + +
    + diff --git a/modules/reports/views/summary/setup.php b/modules/reports/views/summary/setup.php dissimilarity index 68% index 6464abad4..19cdef3cf 100644 --- a/modules/reports/views/summary/setup.php +++ b/modules/reports/views/summary/setup.php @@ -1,44 +1,19 @@ - -
  • '.$error_msg.'
  • '; - } -?>
    - -
    - 'saved_report_form', 'style' => 'margin-top: 7px;', 'method' => 'get')); - ?> -
    -
    - - - - - -
    - - - -
    - -
    - - -

    -
    -

    -     -
    -
    - - -
    + +
  • '.$error_msg.'
  • '; + } +?>
    + +
    + + +

    +
    +

    +     +
    +
    + + +
    -- 2.11.4.GIT