Skip to content

Commit

Permalink
fix server views integration
Browse files Browse the repository at this point in the history
  • Loading branch information
VeggieMeat committed Oct 11, 2014
1 parent 80fafb6 commit ef665d5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,53 @@

class opencloud_server_views_handler_field extends views_handler_field {

function query() {
$this->add_additional_fields();
function init(&$view, &$options) {
parent::init($view, $options);

if (!empty($this->options['link_to_server'])) {
$this->additional_fields['server_id'] = 'server_id';
}
}

function render($values) {
if (isset($values->{$this->real_field})) {
return check_plain($values->{$this->real_field});
function option_definition() {
$options = parent::option_definition();

$options['link_to_server'] = array('default' => FALSE);

return $options;
}

/**
* Provide the link to server option.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);

$form['link_to_server'] = array(
'#title' => t("Link this field to the server's administrative view page"),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_server']),
);
}

/**
* Render whatever the data is as a link to the server.
*
* Data should be made XSS safe prior to calling this function.
*/
function render_link($data, $values) {
if (!empty($this->options['link_to_server']) && $data !== NULL && $data !== '') {
$server_id = $this->get_value($values, 'server_id');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'admin/opencloud/servers/' . $server_id;
}

return $data;
}

function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values);
}
}
72 changes: 25 additions & 47 deletions modules/server/includes/views/opencloud_server.views.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,90 +15,68 @@ function opencloud_server_views_data() {
$data['opencloud_server']['table']['base'] = array(
'title' => t('Opencloud Server'),
'help' => t('Queries an Openstack-based server.'),
'query class' => 'opencloud_server',
// 'query class' => 'opencloud_server',
);

// We need the tenant ID from the provider.
$data['opencloud_server']['table']['join']['opencloud_provider'] = array(
'left_field' => 'tenant_id',
'field' => 'tenant_id',
);

$data['opencloud_server']['id'] = array(
'title' => t('Remote ID'),
'help' => t('The remote ID of the server.'),
$data['opencloud_server']['server_id'] = array(
'title' => t('Server ID'),
'help' => t('The ID of the server.'),
'field' => array(
'handler' => 'opencloud_server_views_handler_field',
),
);

$data['opencloud_server']['hostId'] = array(
'title' => t('Host'),
'help' => t('The host node where the server resides.'),
$data['opencloud_server']['provider_id'] = array(
'title' => t('Provider ID'),
'help' => t('The ID of the Provider for the server.'),
'field' => array(
'handler' => 'opencloud_server_views_handler_field',
),
);

$data['opencloud_server']['uuid'] = array(
'title' => t('UUID'),
'help' => t('The remote UUID of the server (not used by all providers).'),
$data['opencloud_server']['name'] = array(
'title' => t('Name'),
'help' => t('The name of the server'),
'field' => array(
'handler' => 'opencloud_server_views_handler_field',
),
);

$data['opencloud_server']['user_id'] = array(
'title' => t('User ID'),
'help' => t('The remote User ID of the server.'),
$data['opencloud_server']['status'] = array(
'title' => t('Status'),
'help' => t('The status of the server.'),
'field' => array(
'handler' => 'opencloud_server_views_handler_field',
),
);

$data['opencloud_server']['tenant_id'] = array(
'title' => t('Tenant ID'),
'help' => t('The remote Tenant ID of the server.'),
$data['opencloud_server']['hostid'] = array(
'title' => t('Host'),
'help' => t('The host node where the server resides.'),
'field' => array(
'handler' => 'opencloud_server_views_handler_field',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'opencloud_provider',
'base field' => 'tenant_id',
'label' => t('Provider', array(), array('context' => 'an opencloud provider')),
'title' => t('Provider', array(), array('context' => 'an opencloud provider')),
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);

$data['opencloud_server']['name'] = array(
'title' => t('Name'),
'help' => t('The name of the server.'),
$data['opencloud_server']['uuid'] = array(
'title' => t('UUID'),
'help' => t('The UUID of the server (not used by all providers).'),
'field' => array(
'handler' => 'opencloud_server_views_handler_field',
),
);

$data['opencloud_server']['status'] = array(
'title' => t('Status'),
'help' => t('The status of the server.'),
$data['opencloud_server']['image'] = array(
'title' => t('Image'),
'help' => t('The image used to build the server.'),
'field' => array(
'handler' => 'opencloud_server_views_handler_field',
),
);

$data['opencloud_server']['progress'] = array(
'title' => t('Progress'),
'help' => t('The progress of the server in the current state.'),
$data['opencloud_server']['flavor'] = array(
'title' => t('Flavor'),
'help' => t('The flavor of the server.'),
'field' => array(
'handler' => 'opencloud_server_views_handler_field',
),
Expand Down

0 comments on commit ef665d5

Please sign in to comment.