Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Adding pagination to flows page
Browse files Browse the repository at this point in the history
Can now display all flows entered in to OpenVBX.
Also changed previous update for SSL cert inclusion to hide behind
a flag.
Added try/catch around GitHub query for latest version to protect
against random connectivity errors.
  • Loading branch information
Gipetto committed Mar 29, 2012
1 parent 94eb226 commit d4b9101
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Next

- include and always use Twilio SSL Certificate
- include option to use Twilio SSL Certificate when making api requests. Fixes issue on some hosts where curl certs are out of date
- add pagination to Flows screen. Previous limit was 100 flows displayed on a single screen


## OpenVBX 1.2.5
Expand Down
14 changes: 14 additions & 0 deletions OpenVBX/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,20 @@
*/
$config['proxy_ips'] = '';


/*
|--------------------------------------------------------------------------
| Use Twilio API Certificate
|--------------------------------------------------------------------------
|
| Curl certificates on some systems are either incomplete or out of date and
| this can effect connectivity to the Twilio API. If you're getting an error
| "error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify
| failed (0)" then set the option below to true.
|
*/
$config['twilio_use_certificate'] = false;

/*
|--------------------------------------------------------------------------
| Local config overrides
Expand Down
23 changes: 22 additions & 1 deletion OpenVBX/controllers/flows.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@

class Flows extends User_Controller {

private $flows_per_page = '50';

function __construct()
{
parent::__construct();
$this->load->library('applet');
$this->section = 'flows';
$this->admin_only($this->section);
$this->load->library('pagination');
}

function index()
Expand All @@ -46,11 +49,18 @@ function index()

private function flows()
{
$max = $this->input->get_post('max');
$offset = $this->input->get_post('offset');

if (empty($max)) {
$max = $this->flows_per_page;
}

$this->template->add_js('assets/j/flows.js');

$data = $this->init_view_data();

$flows = VBX_Flow::search(array(), 100, 0);
$flows = VBX_Flow::search(array(), $max, $offset);
if(empty($flows))
{
set_banner('flows', $this->load->view('banners/flows-start', array(), true));
Expand All @@ -70,6 +80,17 @@ private function flows()

$data['items'] = $flows_with_numbers;
$data['highlighted_flows'] = array($this->session->flashdata('flow-first-save', 0));

// pagination
$total_items = VBX_Flow::count();
$page_config = array(
'base_url' => site_url('flows/'),
'total_rows' => $total_items,
'per_page' => $max
);
$this->pagination->initialize($page_config);
$data['pagination'] = CI_Template::literal($this->pagination->create_links());

$this->respond('Call Flows', 'flows', $data);
}

Expand Down
31 changes: 18 additions & 13 deletions OpenVBX/controllers/settings/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,23 +768,28 @@ public function get_latest_tag()
return $cache;
}

include_once(APPPATH.'libraries/Github/Autoloader.php');
Github_Autoloader::register();
try {
include_once(APPPATH.'libraries/Github/Autoloader.php');
Github_Autoloader::register();

$gh = new Github_Client;
$tags = $gh->getRepoApi()->getRepoTags('twilio', 'openvbx');
$gh = new Github_Client;
$tags = $gh->getRepoApi()->getRepoTags('twilio', 'openvbx');

$latest = false;
$latest = false;

if (is_array($tags) && count($tags) > 0)
{
$list = array_keys($tags);
usort($list, array($this, 'version_sort'));
$latest = array_pop($list);
}

$this->api_cache->set('latest_version', $latest, 'Site', $this->tenant->id);
if (is_array($tags) && count($tags) > 0)
{
$list = array_keys($tags);
usort($list, array($this, 'version_sort'));
$latest = array_pop($list);
}

$this->api_cache->set('latest_version', $latest, 'Site', $this->tenant->id);
}
catch (Exception $e) {
$latest = false;
error_log('Could not check latest OpenVBX Version: '.$e->getMessage());
}
return $latest;
}

Expand Down
10 changes: 7 additions & 3 deletions OpenVBX/libraries/OpenVBX.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,16 @@ protected static function get_http_opts()
'host' => 'https://api.twilio.com',
'opts' => array(
'curlopts' => array(
CURLOPT_USERAGENT => 'openvbx/'.OpenVBX::version(),
CURLOPT_CAINFO => APPPATH . 'libraries/Services/twilio_ssl_certificate.crt'
CURLOPT_USERAGENT => 'openvbx/'.OpenVBX::version()
)
)
);


// optionally load in the included cert for api communication
if ($use_certificate = $ci->config->item('twilio_use_certificate')) {
$_http_opts['opts']['curlopts'][CURLOPT_CAINFO] = APPPATH . 'libraries/Services/twilio_ssl_certificate.crt';
}
error_log($use_certificate);
// internal api development override, you'll never need this
if ($_http_settings = $ci->config->item('_http_settings'))
{
Expand Down
10 changes: 10 additions & 0 deletions OpenVBX/models/vbx_flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ static function nextId()
$sum = $ci->db->count_all_results();
return $sum + 1;
}

static function count() {
$obj = new self();
$ci = &get_instance();
$count = $ci->db->count_all_results($obj->table);
if ($count > 0) {
return $count;
}
return false;
}

static function search($search_options = array(), $limit = -1, $offset = 0)
{
Expand Down
3 changes: 2 additions & 1 deletion OpenVBX/views/flows.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="vbx-content-main">
<div class="vbx-content-main vbx-flows">

<div class="vbx-content-menu vbx-content-menu-top">
<h2 class="vbx-content-heading">Flows</h2>
Expand All @@ -7,6 +7,7 @@
<li class="menu-item"><button class="add-button add-flow" type="button"><span>New Flow</span></button></li>
</ul>
<?php endif; ?>
<?php echo $pagination; ?>
</div><!-- vbx-content-menu -->

<?php if(!empty($items)): ?>
Expand Down
3 changes: 3 additions & 0 deletions assets/c/controls.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
font-size: 16px;
font-weight: bold;
}
.vbx-flows .vbx-content-menu .pagination {
margin-right: 20px;
}

.pagination a,
.pagination .current {
Expand Down

0 comments on commit d4b9101

Please sign in to comment.