Commit 54fe4dd0 authored by merlinofchaos's avatar merlinofchaos

Revamped view list page, plus the first advanced help file!

parent b7059adb
/* $Id */
table.views-entry {
margin: 2px 0;
border: 1px solid #ccc;
background-color: white;
clear: left;
}
table.views-entry tbody {
border: none;
}
table.views-entry td.view-ops {
width: 45%;
text-align: right;
background-color: #eee;
}
table.views-entry td.view-name {
background-color: #eee;
}
table.views-entry .description {
vertical-align: top;
}
body form#views-ui-list-views-form {
margin: 0 0 .5em 0;
}
#views-ui-list-views-form .form-item {
padding-right: 1em;
float: left;
}
#views-ui-list-views-form .form-submit {
clear: left;
position: relative;
top: .65em;
}
.advanced-help-link {
position: relative;
top: 2px;
padding-right: 3px;
}
<p>The <strong>view type</strong> describes how this view is stored; Views is capable of having
Views entirely in code that are not in the database. This allows modules to
easily ship with Views built in, and it allows you to create a module to
store your views for easy deployment between development and production servers.</p>
<dl>
<dt><strong>Normal</strong></dt>
<dd>Normal views are stored in your database and are completely local to your system.</dd>
<dt><strong>Default</strong></dt>
<dd>Default views are stored only in code and are not anywhere in your database. They may be <strong>enabled</strong> or <strong>disabled</strong> but you may not completely remove them from your system. You can <strong>override</strong> the view which will create a local copy of your view. If you do this, future updates to the version in code will not affect your view.</dd>
<dt><strong>Overridden</strong></dt>
<dd>Overridden views are stored both in code and in the database; while overridden, the version that is in code is completely dormant. If you <strong>revert</strong> the view, the version in the database will be deleted, and the version that is in code will once again be used.</dd>
</dl>
You may store your views in code with the following procedure:
<ol>
<li> Create a module to store the views. </li>
<li> Add the function <em>MODULENAME_views_default_views()</em> to this module. </li>
<li> Export the view you wish to store in your module in code. Cut and paste that into the abovenamed function. Make sure the last line of the view is: <em>$views[$view->name] = $view;</em></li>
<li> Make sure the last line of the function is <em>return $views;</em></li>
<li> After you make any changes, be sure to <strong>clear the Views' cache</strong>. You may do this from the <strong>Tools</strong> menu.
</ol>
[view-type]
title = "View types"
file = view-type
\ No newline at end of file
......@@ -7,86 +7,137 @@
/**
* Page callback to list views in the system.
*
* @todo: template.
*/
function views_ui_list_views($arg = NULL) {
if ($arg != NULL) {
return drupal_not_found();
}
return theme('views_ui_list_views');
}
function template_preprocess_views_ui_list_views(&$vars) {
$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')),
$views = views_get_all_views();
$form_state = array(
'views' => $views,
'input' => $_GET,
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
);
foreach (views_get_all_views() as $view) {
$ops = array();
$vars['widgets'] = drupal_build_form('views_ui_list_views_form', $form_state);
$vars['help_type_icon'] = theme('advanced_help_topic', 'views', 'view-type');
foreach ($views as $view) {
if ($form_state['values']['tag'] != 'all') {
if ($form_state['values']['tag'] == 'none') {
if (!empty($view->tag)) {
continue;
}
}
else if ($form_state['values']['tag'] != $view->tag) {
continue;
}
}
if ($form_state['values']['type'] != 'all' && $form_state['values']['type'] != $view->type) {
continue;
}
if ($form_state['values']['display'] != 'all' && empty($view->display[$form_state['values']['display']])) {
continue;
}
$item = new stdClass();
$item->ops = array();
if (empty($view->disabled)) {
$ops[] = l(t('Edit'), "admin/build/views/edit/$view->name");
$ops[] = l(t('Export'), "admin/build/views/export/$view->name");
$ops[] = l(t('Clone'), "admin/build/views/clone/$view->name");
$item->ops[] = l(t('Edit'), "admin/build/views/edit/$view->name");
$item->ops[] = l(t('Export'), "admin/build/views/export/$view->name");
$item->ops[] = l(t('Clone'), "admin/build/views/clone/$view->name");
}
if ($view->type != t('Default')) {
$text = $view->type == t('Overridden') ? t('Revert') : t('Delete');
$ops[] = l($text, "admin/build/views/delete/$view->name");
$item->ops[] = l($text, "admin/build/views/delete/$view->name");
}
else {
if (empty($view->disabled)) {
$ops[] = l(t('Disable'), "admin/build/views/disable/$view->name", array('query' => drupal_get_destination()));
$item->ops[] = l(t('Disable'), "admin/build/views/disable/$view->name", array('query' => drupal_get_destination()));
}
else {
$ops[] = l(t('Enable'), "admin/build/views/enable/$view->name", array('query' => drupal_get_destination()));
$item->ops[] = l(t('Enable'), "admin/build/views/enable/$view->name", array('query' => drupal_get_destination()));
}
}
$item->ops = implode(' | ', $item->ops);
if (empty($view->display)) {
$path = t('Warning! Broken view!');
$item->path = t('Warning! Broken view!');
}
else {
$path = $view->get_path();
$path = empty($view->disabled) && strpos($path, '%') === FALSE ? l($path, $path) : check_plain($path);
$item->path = $raw_path = $view->get_path();
$item->path = $item->path && empty($view->disabled) && strpos($item->path, '%') === FALSE ? l($item->path, $item->path) : check_plain($item->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);
$item->type = $view->type;
$item->name = $view->name;
if (!empty($view->tag)) {
$item->tag = $view->tag;
}
$item->title = $view->get_title();
$item->displays = array();
foreach ($view->display as $display) {
if (!empty($display->handler->definition['admin'])) {
$item->displays[$display->handler->definition['admin']] = TRUE;
}
}
if ($item->displays) {
ksort($item->displays);
$item->displays = implode(', ', array_keys($item->displays));
}
$item->description = check_plain($view->description);
$items[] = $item;
$ts = tablesort_init($header);
switch ($ts['sql']) {
switch ($form_state['values']['order']) {
case 'name':
default:
$sorts[] = $item[0];
$sorts[] = strtolower($view->name);
break;
case 'title':
$sorts[] = $item[1];
$sorts[] = strtolower($title);
break;
case 'url':
$sorts[] = 'todo: path'; // $path;
case 'path':
$sorts[] = strtolower($raw_path); // $path;
break;
case 'type':
$sorts[] = $view->type . $item[0];
$sorts[] = $view->type . $view->name;
break;
case 'tag':
$sorts[] = strtolower($view->tag);
break;
case 'desc':
$sorts[] = strtolower($view->description);
break;
}
}
if (!empty($ts)) {
if (strtolower($ts['sort']) == 'desc') {
arsort($sorts);
}
else {
asort($sorts);
}
if ($form_state['values']['sort'] == 'desc') {
arsort($sorts);
}
else {
asort($sorts);
}
$i = array();
......@@ -94,8 +145,103 @@ function views_ui_list_views($arg = NULL) {
$i[] = $items[$id];
}
$output = theme('table', $header, $i);
return $output;
views_add_css('views-list');
$vars['views'] = $i;
}
/**
* Provide a form for sorting and filtering the list of views.
*/
function views_ui_list_views_form(&$form_state) {
$all = array('all' => t('<All>'));
$none = array('none' => t('<None>'));
$tags = array();
$extras = array();
foreach ($form_state['views'] as $name => $view) {
if (!empty($view->tag)) {
$tags[$view->tag] = $view->tag;
}
}
asort($tags);
$form['tag'] = array(
'#type' => 'select',
'#title' => t('Tag'),
'#options' => array_merge($all, $none, $tags),
'#default_value' => 'all',
);
$displays = array();
foreach (views_fetch_plugin_data('display') as $id => $info) {
if (!empty($info['admin'])) {
$displays[$id] = $info['admin'];
}
}
asort($displays);
$form['display'] = array(
'#type' => 'select',
'#title' => t('Displays'),
'#options' => array_merge($all, $displays),
'#default_value' => 'all',
);
$form['type'] = array(
'#type' => 'select',
'#title' => t('View type'),
'#options' => array(
'all' => t('<All>'),
t('Normal') => t('Normal'),
t('Default') => t('Default'),
t('Overridden') => t('Overridden'),
),
'#default_value' => 'all',
);
$form['order'] = array(
'#type' => 'select',
'#title' => t('Sort by'),
'#options' => array(
'name' => t('Name'),
'title' => t('Title'),
'tag' => t('Tag'),
'path' => t('Path'),
'type' => t('Type'),
'desc' => t('Description'),
),
'#default_value' => 'name',
);
$form['sort'] = array(
'#type' => 'select',
'#title' => t('Order'),
'#options' => array(
'asc' => t('Ascending'),
'desc' => t('Descending'),
),
'#default_value' => 'asc',
);
$form['submit'] = array(
'#name' => '', // so it won't in the $_GET args
'#type' => 'submit',
'#value' => t('Apply'),
);
$form['#theme'] = array('views_ui_list_views_form');
return $form;
}
function theme_views_ui_list_views_form($form) {
// Don't render these:
unset($form['form_id']);
unset($form['form_build_id']);
unset($form['form_token']);
return drupal_render($form);
}
/**
......
......@@ -154,10 +154,6 @@ function drupal_process_form_new($form_id, &$form, &$form_state) {
// reference.
$form_state['values'] = array();
$form = form_builder($form_id, $form, $form_state);
// Only process the form if it is programmed or the form_id coming
// from the POST data is set and matches the current form_id.
// With $_GET, these forms are always submitted.
if ($form_state['method'] == 'get') {
if (!isset($form['#post']['form_build_id'])) {
......@@ -166,8 +162,15 @@ function drupal_process_form_new($form_id, &$form, &$form_state) {
if (!isset($form['#post']['form_id'])) {
$form['#post']['form_id'] = $form_id;
}
if (!isset($form['#post']['form_token'])) {
$form['#post']['form_token'] = drupal_get_token($form['#token']);
}
}
$form = form_builder($form_id, $form, $form_state);
// Only process the form if it is programmed or the form_id coming
// from the POST data is set and matches the current form_id.
if ((!empty($form['#programmed'])) || (!empty($form['#post']) && (isset($form['#post']['form_id']) && ($form['#post']['form_id'] == $form_id)))) {
drupal_validate_form($form_id, $form, $form_state);
......
......@@ -36,6 +36,7 @@ function views_views_plugins() {
'use ajax' => TRUE,
'use pager' => TRUE,
'accept attachments' => TRUE,
'admin' => t('Page'),
),
'block' => array(
'title' => t('Block'),
......@@ -47,6 +48,7 @@ function views_views_plugins() {
'use pager' => TRUE,
'use more' => TRUE,
'accept attachments' => TRUE,
'admin' => t('Block'),
),
'attachment' => array(
'title' => t('Attachment'),
......@@ -63,6 +65,7 @@ function views_views_plugins() {
'use ajax' => FALSE,
'use pager' => FALSE,
'accept attachments' => FALSE,
'admin' => t('Feed'),
),
),
'style' => array(
......@@ -1024,7 +1027,7 @@ class views_plugin_display extends views_plugin {
$form['markup'] = array(
'#prefix' => '<div class="form-item description">',
'#suffix' => '</div>',
'#value' => '<p>' . t('You may use any of the following possible theme files to modify individual parts of your view. In total, there are four parts to theming a view. The <strong>display</strong> theme is usually views-view.tpl.php and it largely controls the decorations around a view; where the header, footer, pager, more link, feed icon, etc, will be placed. The <strong>style</strong> will control how all of the results of the display are put together. It may be as simple as just displaying all of the rows, or it may be a complex table generator or something in between. The <strong>row</strong> style controls each individual row; not all styles utilize the row style (notably the table), but most others do. Finally, <strong>field</strong> themes allow you to override the look and even the data of each individual field, if the style uses fields.') . '</p>',
'#value' => '<p>' . t('You may use any of the following possible theme files to modify individual parts of your view. In total, there are four parts to theming a view. The <strong>display</strong> theme is usually views-view.tpl.php and it largely controls the decorations around a view; where the header, footer, pager, more link, feed icon, etc, will be placed. The <strong>style</strong> will control how all of the results of the display are put together. It may be as simple as just displaying all of the rows, or it may be a complex table generator or something in between. The <strong>row</strong> style controls each individual row; not all styles utilize the row style (notably the table), but most others do. Finally, <strong>field</strong> themes allow you to override the look and even the data of each individual field, if the style uses fields. The actual template the system will use should be hilighted in <strong>bold</strong>.') . '</p>',
);
$form['important'] = array(
......
......@@ -489,7 +489,7 @@ class view extends views_db_object {
'display' => &$this->display_handler->display,
'input' => $_GET,
'method' => 'get',
're_render' => TRUE,
'rerender' => TRUE,
'no_redirect' => TRUE,
);
......
<?php
// $Id*
/**
* @file
*
*/
?>
<?php if (!module_exists('advanced_help')): ?>
<?php print t('If you install the advanced help module from !href, Views will provide more and better help.', array('!href' => l('http://drupal.org/project/advanced_help', 'http://drupal.org/project/advanced_help'))); ?>
<?php endif; ?>
<?php print $widgets; ?>
<?php foreach ($views as $view): ?>
<table class="views-entry">
<tbody>
<tr>
<td class="view-name">
<?php print $help_type_icon; ?>
<?php print t('<em>@type</em> view: <strong>@view</strong>', array('@type' => $view->type, '@view' => $view->name)); ?>
<?php if (!empty($view->tag)): ?>
&nbsp;(<?php print $view->tag; ?>)
<?php endif; ?>
</td>
<td class="view-ops"><?php print $view->ops ?></td>
</tr>
<tr>
<td>
<?php if ($view->title): ?>
<?php print t('Title: @title', array('@title' => $view->title)); ?> <br />
<?php endif; ?>
<?php if ($view->path): ?>
<?php print t('Path: !path', array('!path' => $view->path)); ?> <br />
<?php endif; ?>
<?php if ($view->displays): ?>
<em><?php print $view->displays; ?> </em><br />
<?php endif; ?>
</td>
<td colspan="2" class="description">
<?php print $view->description; ?>
</td>
</tr>
</tbody>
</table>
<?php endforeach; ?>
......@@ -1281,7 +1281,7 @@ function views_theme_functions($hook, $view, $display = NULL) {
* - input: The source of input. If unset this will be $_POST.
* - no_redirect: Absolutely do not redirect the form even if instructed
* to do so.
* - re_render: If no_redirect is set and the form was successfully submitted,
* - rerender: If no_redirect is set and the form was successfully submitted,
* rerender the form. Otherwise it will just return.
*
*/
......
......@@ -195,6 +195,7 @@ function views_ui_theme() {
require_once "./$path/includes/admin.inc";
return array(
// edit a view
'views_ui_edit_view' => array(
'arguments' => array('view' => NULL),
'template' => 'views-ui-edit-view',
......@@ -214,6 +215,18 @@ function views_ui_theme() {
'arguments' => array('form' => NULL),
'file' => '/includes/admin.inc',
),
// list views
'views_ui_list_views' => array(
'template' => 'views-ui-list-views',
'path' => "$path/theme",
),
'views_ui_list_views_form' => array(
'file' => '/includes/admin.inc',
'arguments' => array('form' => NULL),
),
// tab themes
'views_tabset' => array(
'arguments' => array('tabs' => NULL),
'file' => '/includes/tabs.inc',
......@@ -223,10 +236,10 @@ function views_ui_theme() {
'file' => '/includes/tabs.inc',
),
// On behalf of a plugin
'views_ui_style_plugin_table' => array(
'arguments' => array('form' => NULL),
),
);
}
......
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