示例#1
0
 public function action_messages()
 {
     $current_page = (int) $this->request->query('page');
     $message = $this->request->query('message');
     $levels = $this->request->query('levels');
     $date_from = $this->request->query('date-from');
     $date_to = $this->request->query('date-to');
     $limit = $this->request->query('limit');
     $from_id = $this->request->query('last_message_id');
     $all_matches_before_id = (int) $this->request->query('all_matches_before_id');
     if ($current_page < 1) {
         $current_page = 1;
     }
     if (!is_array($levels)) {
         $levels = array();
     }
     $all_matches_before_id = $from_id ? $all_matches_before_id : 0;
     $filters = $this->logreader->create_filters($message, $levels, $date_from, $date_to, $limit);
     $filters_for_autorefresh = $this->logreader->create_filters($message, $levels, $date_from, NULL, $limit);
     $view = View::factory('logreader/messages');
     $view->levels = $this->logreader->get_levels();
     $view->filters = $filters;
     $view->auto_refresh_time = $this->logreader_config->get_auto_refresh_interval();
     $offset = ($current_page - 1) * $filters['limit'];
     $view->messages = $this->logreader->get_messages($filters['date-from'], $filters['date-to'], $filters['limit'], $offset, $filters['message']['text'] && $filters['message']['valid'] ? $filters['message']['text'] : NULL, $filters['levels'], array(), $from_id);
     $view->all_matches = $view->messages['all_matches'];
     $view->all_matches_before_id = $view->all_matches - $offset;
     $view->messages = $view->messages['messages'];
     $view->current_page = $current_page;
     $view->auto_refresh_url = LogReader_URL::api_base() . 'messages/?' . $filters_for_autorefresh['query_string'];
     $uri = LogReader_URL::base() . "?" . $filters['query_string'];
     $view->pages = LogReader_URL::pager($current_page, ceil(($view->all_matches + $all_matches_before_id) / $filters['limit']), $uri . "&page=%(page)s", $uri);
     $this->data['html'] = (string) $view;
     $this->data['all_matches'] = $view->all_matches;
 }
示例#2
0
 public function action_index()
 {
     $current_page = (int) $this->request->query('page');
     $message = $this->request->query('message');
     $levels = $this->request->query('levels');
     $date_from = $this->request->query('date-from');
     $date_to = $this->request->query('date-to');
     $limit = $this->request->query('limit');
     if ($current_page < 1) {
         $current_page = 1;
     }
     if (!is_array($levels)) {
         $levels = array();
     }
     $filters = $this->logreader->create_filters($message, $levels, $date_from, $date_to, $limit);
     $filters_for_autorefresh = $this->logreader->create_filters($message, $levels, $date_from, NULL, $limit);
     $view = View::factory('logreader/index');
     $view->stylesheets = array(LogReader_URL::static_base() . 'css/messages.css');
     $view->javascripts = array(LogReader_URL::static_base() . 'js/messages.js');
     $view->user = $this->user;
     $view->is_tester_available = $this->logreader_config->is_tester_available();
     $view->content = View::factory('logreader/messages');
     $view->content->name = 'messages';
     $view->content->levels = $this->logreader->get_levels();
     $view->content->filters = $filters;
     $view->content->auto_refresh_time = $this->logreader_config->get_auto_refresh_interval();
     $offset = ($current_page - 1) * $filters['limit'];
     $view->content->messages = $this->logreader->get_messages($filters['date-from'], $filters['date-to'], $filters['limit'], $offset, $filters['message']['text'] && $filters['message']['valid'] ? $filters['message']['text'] : NULL, $filters['levels'], array(), NULL);
     $view->content->all_matches = $view->content->messages['all_matches'];
     $view->content->all_matches_before_id = $view->content->all_matches - $offset;
     $view->content->messages = $view->content->messages['messages'];
     $view->content->current_page = $current_page;
     $view->content->auto_refresh_url = LogReader_URL::api_base() . 'messages/?' . $filters_for_autorefresh['query_string'];
     $uri = LogReader_URL::base() . "?" . $filters['query_string'];
     $view->content->pages = LogReader_URL::pager($current_page, ceil($view->content->all_matches / $filters['limit']), $uri . "&page=%(page)s", $uri);
     $this->response->body($view);
 }
示例#3
0
 /**
  * Test for getting page urls.
  * 
  * @dataProvider provider_pager
  * @test
  * @covers LogReader_URL::pager
  * @param  mixed   $expected  Expected result.
  * @param  int     $current   Current page number.
  * @param  int     $total     Number of pages.
  */
 public function test_pager($expected, $current, $total)
 {
     $this->assertSame($expected, LogReader_URL::pager($current, $total, 'http://example.com/page/%(page)s/', 'http://example.com/'));
 }