Commit b9613702 authored by merlinofchaos's avatar merlinofchaos

UI checkpoint checkin

parent 58e4ed44
......@@ -26,6 +26,8 @@ function node_views_data() {
$data['node']['table']['base'] = array(
'field' => 'nid',
'title' => t('Node'),
'help' => t('The node type allows views of your site\'s primary content.'),
'weight' => 10,
);
// For other base tables, explain how we join
......@@ -169,6 +171,7 @@ function node_views_data() {
$data['node_revisions']['table']['base'] = array(
'field' => 'vid',
'title' => t('Node revisions'),
'help' => t('Node revisions allow you to list revisions to nodes.'),
);
// For other base tables, explain how we join
......
......@@ -3,6 +3,7 @@ function user_views_data() {
$data['users']['table']['base'] = array(
'field' => 'uid',
'title' => t('User'),
'help' => t('The node type allows views of your site\'s users.'),
);
$data['users']['table']['join']['node']['handler'] = 'views_join';
......
......@@ -324,7 +324,7 @@ function views_fetch_base_table_names() {
$data = views_fetch_data();
foreach ($data as $table => $info) {
if (!empty($info['table']['base'])) {
$base_tables[$table] = $info['table']['base']['title'];
$base_tables[$table] = $info['table']['base']['title'] . '<br /><div class="description">' . $info['table']['base']['help'] . "</div>\n";
}
}
}
......
......@@ -4,68 +4,65 @@
/**
* @file views_ui.module
*
* Provide administrative interface to create and manipulate Views.
* Provide structure for the administrative interface to Views.
*/
function views_ui_menu() {
$items = array();
$items['admin/build/views'] = array(
'title' => t('Views'),
'page callback' => 'views_ui_list_views',
// Minor code reduction technique
$base = array(
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'file' => 'includes/admin.inc',
);
$items['admin/build/views'] = $base + array(
'title' => t('Views'),
'page callback' => 'views_ui_list_views',
'description' => t('Views are customized lists of content on your system; they are highly configurable and give you control over how lists of content are presented.'),
'type' => MENU_NORMAL_ITEM
);
$items['admin/build/views/list'] = array(
$items['admin/build/views/list'] = $base + array(
'title' => t('List'),
'page callback' => 'views_ui_list_views',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => '-1'
);
$items['admin/build/views/add'] = array(
$items['admin/build/views/add'] = $base + array(
'title' => t('Add'),
'page callback' => 'views_ui_add_page',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_LOCAL_TASK
);
$items['admin/build/views/import'] = array(
$items['admin/build/views/edit/%views_ui_cache'] = $base + array(
'title' => t('Edit'),
'page callback' => 'views_ui_edit_page',
'page arguments' => array(4),
'type' => MENU_CALLBACK
);
$items['admin/build/views/import'] = $base + array(
'title' => t('Import'),
'page callback' => 'views_ui_admin_import_page',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_LOCAL_TASK
);
$items['admin/build/views/tools'] = array(
$items['admin/build/views/tools'] = $base + array(
'title' => t('Tools'),
'page callback' => 'drupal_get_form',
'callback arguments' => array('views_ui_admin_tools'),
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_LOCAL_TASK
);
$items['admin/build/views/delete'] = array(
$items['admin/build/views/delete'] = $base + array(
'title' => t('Edit view'),
'page callback' => 'drupal_get_form',
'callback arguments' => array('views_ui_admin_delete_confirm'),
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_CALLBACK
);
$items['admin/build/views/enable'] = array(
$items['admin/build/views/enable'] = $base + array(
'page callback' => 'views_ui_admin_enable_page',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_CALLBACK
);
$items['admin/build/views/disable'] = array(
$items['admin/build/views/disable'] = $base + array(
'page callback' => 'views_ui_admin_disable_page',
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'type' => MENU_CALLBACK
);
return $items;
......@@ -79,156 +76,32 @@ function views_ui_perm() {
}
/**
* Page callback to list views in the system.
* Specialized menu callback to load a view either out of the cache or just
* load it.
*/
function views_ui_list_views() {
$items = array();
$sorts = array();
$header = array(
array('data' => t('View name'), 'field' => 'name', 'sort' => 'asc'),
array('data' => t('Description')),
array('data' => t('Title'), 'field' => 'title'),
array('data' => t('Type'), 'field' => 'type'),
array('data' => t('URL'), 'field' => 'url'),
array('data' => t('Operations')),
);
foreach (views_get_all_views() as $view) {
$ops = array();
if (empty($view->disabled)) {
$ops[] = l(t('Edit'), "admin/build/views/edit/$view->name");
$ops[] = l(t('Export'), "admin/build/views/$view->name/export");
}
if ($view->type != t('Default')) {
$text = $view->type == t('Overridden') ? t('Revert') : t('Delete');
$ops[] = l($text, "admin/build/views/$view->name/delete");
}
else {
if (empty($view->disabled)) {
$ops[] = l(t('Disable'), "admin/build/views/disable/$view->name", NULL, drupal_get_destination());
}
else {
$ops[] = l(t('Enable'), "admin/build/views/enable/$view->name", NULL, drupal_get_destination());
}
}
$path = 'Todo: path';
// $path = empty($view->disabled) && strpos($view->path, '%') === FALSE ? l($view->path, $view->path) : check_plain($view->path);
$item = array();
$item[] = check_plain($view->name);
$item[] = check_plain($view->description);
$item[] = check_plain($view->get_title());
$item[] = $view->type; // this is safe as it's always programmatic
$item[] = $path;
$item[] = implode(' | ', $ops);
$items[] = $item;
$ts = tablesort_init($header);
switch ($ts['sql']) {
case 'name':
default:
$sorts[] = $item[0];
break;
case 'title':
$sorts[] = $item[1];
break;
case 'url':
$sorts[] = 'todo: path'; // $path;
break;
case 'type':
$sorts[] = $view->type . $item[0];
break;
}
}
if (strtolower($ts['sort']) == 'desc') {
arsort($sorts);
}
else {
asort($sorts);
function views_ui_cache_load($name) {
views_include('cache');
views_include('view');
$view = views_object_cache_get('view', $name);
if (empty($view)) {
$view = views_get_view($name);
}
$i = array();
foreach ($sorts as $id => $title) {
$i[] = $items[$id];
if (empty($view)) {
return FALSE;
}
$output = theme('table', $header, $i);
return $output;
}
/**
* Page callback to add a new view.
*/
function views_ui_add_page() {
$view = views_new_view();
return drupal_get_form('views_ui_add_form', $view);
}
/**
* Form constructor callback to create the views Add Form, phase 1.
*/
function views_ui_add_form(&$form_state, $view) {
$form = array();
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('View name'),
'#description' => t('This is the unique name of the view. It must contain only alphanumeric characters and underscores; it is used to identify the view internally and to generate unique theming template names for this view. If overriding a module provided view, the name must not be changed or instead a new view will be created.'),
'#default_value' => $view->name,
'#required' => TRUE,
);
$form['description'] = array(
'#type' => 'textfield',
'#title' => t('View description'),
'#description' => t('This description will appear on the Views administrative UI to tell you what the view is about.'),
'#default_value' => $view->description,
);
$form['tag'] = array(
'#type' => 'textfield',
'#title' => t('View tag'),
'#description' => t('Enter an optional tag for this view; it is used only to help sort views on the administrative page.'),
'#default_value' => $view->tag,
// TODO: This should be an autocomplete field.
);
$form['base_table'] = array(
'#type' => 'select',
'#title' => t('Base table'),
'#description' => t('The base table is the primary table for which information is being retrieved. The base table controls what arguments, fields, sort criteria and filters are available, so once this is set it cannot be changed.'),
'#options' => views_fetch_base_table_names(),
'#default_value' => $view->base_table,
'#disabled' => !empty($view->vid) && $view->vid != 'new',
);
if (empty($view->vid) || $view->vid == 'new') {
$form['displays'] = array(
'#type' => 'checkboxes',
'#title' => t('Initial displays'),
'#description' => t('Select which displays you would like to have automatically created with this view.'),
'#options' => views_fetch_plugin_names('display'),
'#required' => TRUE,
);
else {
return $view;
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Next'),
'#submit' => array('views_ui_add_form_submit'),
);
$form_state['view'] = $view;
return $form;
}
/**
* Submit handler for the ui add form
* Specialized cache function to add a flag to our view, include an appropriate
* include, and cache more easily.
*/
function views_ui_add_form_submit($form, &$form_state) {
function views_ui_cache_set($view) {
views_include('cache');
$view->changed = TRUE; // let any future object know that this view has changed.
views_object_cache_set('view', $view->name, $view);
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment