[gollem] backend configurable header displays
Liam Hoekenga
liamr at umich.edu
Mon Apr 28 14:43:35 PDT 2003
> > Ok.. I believe the attached diff should implement this behavior.
>
> This diff fails to apply for me - can you regenerate it against latest HEAD?
Try what I've attached.
Liam
-------------- next part --------------
diff -p -U 2 -N -x CVS -r /tmp/gollem/config/backends.php.dist gollem/config/backends.php.dist
--- /tmp/gollem/config/backends.php.dist Thu Feb 27 16:32:07 2003
+++ gollem/config/backends.php.dist Thu Apr 24 23:52:16 2003
@@ -44,5 +44,6 @@ $backends['ftp'] = array(
'driver' => 'ftp',
'params' => array('hostspec' => 'ftp.example.com',
- 'port' => 21)
+ 'port' => 21),
+ 'attributes' => array('type', 'name', 'download', 'modified', 'size', 'permission', 'owner', 'group')
);
@@ -54,5 +55,6 @@ $backends['hordeftp'] = array(
'hordeauth' => true,
'params' => array('hostspec' => 'ftp.example.com',
- 'port' => 21)
+ 'port' => 21),
+ 'attributes' => array('type', 'name', 'download', 'modified', 'size', 'permission', 'owner', 'group')
);
@@ -67,4 +69,5 @@ $backends['sql'] = array(
'password' => 'horde',
'table' => 'horde_vfs'),
+ 'attributes' => array('type', 'name', 'download', 'modified', 'size', 'permission', 'owner', 'group')
);
@@ -81,4 +84,5 @@ $backends['sqlhome'] = array(
'password' => 'horde',
'table' => 'horde_vfs'),
+ 'attributes' => array('type', 'name', 'download', 'modified', 'size', 'permission', 'owner', 'group'),
'root' => '/home',
'home' => '/home/' . Auth::getAuth(),
@@ -94,4 +98,5 @@ $backends['file'] = array(
'preferred' => '',
'params' => array('vfsroot' => '/usr/local/data/home/',
- 'home' => Auth::getAuth())
+ 'home' => Auth::getAuth()),
+ 'attributes' => array('type', 'name', 'download', 'modified', 'size', 'permission', 'owner', 'group')
);
diff -p -U 2 -N -x CVS -r /tmp/gollem/config/prefs.php.dist gollem/config/prefs.php.dist
--- /tmp/gollem/config/prefs.php.dist Thu Apr 24 16:45:16 2003
+++ gollem/config/prefs.php.dist Mon Apr 28 13:26:32 2003
@@ -15,5 +15,5 @@ $prefGroups['display'] = array(
'label' => _("Display Options"),
'desc' => _("Change your file sorting options."),
- 'members' => array('show_dotfiles', 'sortby', 'sortdir'));
+ 'members' => array('show_dotfiles', 'columnselect', 'sortby', 'sortdir'));
@@ -32,4 +32,18 @@ $_prefs['show_dotfiles'] = array('value'
'desc' => _("Show dotfiles?")
);
+
+// columns selection widget
+$_prefs['columnselect'] = array(
+ 'locked' => false,
+ 'type' => 'special'
+);
+
+// columns to be displayed
+$_prefs['columns'] = array(
+ 'value' => "ftp\ttype\tname\tdownload\tmodified\tsize\tpermission\towner\tgroup",
+ 'locked' => false,
+ 'shared' => false,
+ 'type' => 'implicit'
+);
// user preferred sorting column
diff -p -U 2 -N -x CVS -r /tmp/gollem/lib/Gollem.php gollem/lib/Gollem.php
--- /tmp/gollem/lib/Gollem.php Thu Apr 24 16:45:16 2003
+++ gollem/lib/Gollem.php Mon Apr 28 13:28:10 2003
@@ -536,3 +536,40 @@ class Gollem {
}
+ function string2Columns($string)
+ {
+ $ret = array();
+ $lines = explode("\n", $string);
+ foreach ($lines as $line) {
+ $line = trim($line);
+ if (!empty($line)) {
+ $columns = explode("\t", $line);
+ if (count($columns) > 1) {
+ $source = array_splice($columns, 0, 1);
+ $ret[$source[0]] = $columns;
+ }
+ }
+ }
+
+ return $ret;
+ }
+
+ function columns2String($hash)
+ {
+ foreach ($hash as $source => $columns) {
+ if (isset($string)) {
+ $string .= "\n";
+ } else {
+ $string = '';
+ }
+ $line = '';
+ foreach ($columns as $column) {
+ if (!empty($line)) {
+ $line .= "\t";
+ }
+ $line .= $column;
+ }
+ }
+
+ return $string;
+ }
}
diff -p -U 2 -N -x CVS -r /tmp/gollem/manager.php gollem/manager.php
--- /tmp/gollem/manager.php Thu Apr 24 16:45:15 2003
+++ gollem/manager.php Mon Apr 28 13:22:45 2003
@@ -266,4 +266,10 @@ foreach ($info as $backend_key => $vars)
require GOLLEM_TEMPLATES . '/manager/actions.inc';
+
+ /* Read the columns to display from the preferences. */
+ $sources = Gollem::string2Columns($prefs->getValue('columns'));
+ $columns = isset($sources[$backend_key])
+ ? $sources[$backend_key] : array();
+
if (is_array($list) && count($list)) {
require GOLLEM_TEMPLATES . '/manager/file_headers.inc';
diff -p -U 2 -N -x CVS -r /tmp/gollem/templates/manager/file_headers.inc gollem/templates/manager/file_headers.inc
--- /tmp/gollem/templates/manager/file_headers.inc Thu Apr 24 16:45:17 2003
+++ gollem/templates/manager/file_headers.inc Mon Apr 28 13:30:42 2003
@@ -3,31 +3,43 @@
<tr class="item">
<th nowrap="nowrap" width="3%" align="center"> <?php echo Horde::img('checkbox.gif', _("Checkbox")) ?></td>
- <th class="<?php echo ($prefs->getValue('sortby') == SORT_TYPE) ? 'selected' : 'item' ?>" width="5%" nowrap="nowrap" align="right">
- <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_TYPE . '&sortdir=' . abs(1 - $prefs->getValue('sortdir'))); ?>"><?php echo Horde::img($prefs->getValue('sortdir') ? 'down.gif' : 'up.gif', _("Sort Direction")); ?></a>
- <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_TYPE) ?>"><?php echo _("Type") ?></a>
- </th>
- <th class="<?php echo ($prefs->getValue('sortby') == SORT_NAME) ? 'selected' : 'item' ?>" width="57%" nowrap="nowrap" align="left">
- <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_NAME . '&sortdir=' . abs(1 - $prefs->getValue('sortdir'))); ?>"><?php echo Horde::img($prefs->getValue('sortdir') ? 'down.gif' : 'up.gif', _("Sort Direction")); ?></a>
- <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_NAME) ?>"><?php echo _("Name") ?></a>
- </th>
- <th class="item" width="1%" align="center">
- <?php echo Horde::img('download.gif', _("Download"), null, $registry->getParam('graphics', 'horde')) ?>
- </th>
- <th class="<?php echo ($prefs->getValue('sortby') == SORT_DATE) ? 'selected' : 'item' ?>" width="7%" nowrap="nowrap" align="right">
- <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_DATE . '&sortdir=' . abs(1 - $prefs->getValue('sortdir'))); ?>"><?php echo Horde::img($prefs->getValue('sortdir') ? 'down.gif' : 'up.gif', _("Sort Direction")); ?></a>
- <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_DATE); ?>"><?php echo _("Modified") ?></a>
- </th>
- <th class="<?php echo ($prefs->getValue('sortby') == SORT_SIZE) ? 'selected' : 'item' ?>" width="7%" nowrap="nowrap" align="right">
- <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_SIZE . '&sortdir=' . abs(1 - $prefs->getValue('sortdir'))); ?>"><?php echo Horde::img($prefs->getValue('sortdir') ? 'down.gif' : 'up.gif', _("Sort Direction")); ?></a>
- <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_SIZE) ?>"><?php echo _("Size") ?></a>
- </th>
- <th class="item" width="7%" nowrap="nowrap" align="right">
- <?php echo _("Permission") ?>
- </th>
- <th class="item" width="7%" nowrap="nowrap" align="right">
- <?php echo _("Owner") ?>
- </th>
- <th class="item" width="7%" nowrap="nowrap" align="right">
- <?php echo _("Group") ?>
- </th>
+ <?php foreach($columns as $heading):?>
+ <?php switch($heading):
+ case 'type': ?>
+ <th class="<?php echo ($prefs->getValue('sortby') == SORT_TYPE) ? 'selected' : 'item' ?>" width="5%" nowrap="nowrap" align="right">
+ <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_TYPE . '&sortdir=' . abs(1 - $prefs->getValue('sortdir'))); ?>"><?php echo Horde::img($prefs->getValue('sortdir') ? 'down.gif' : 'up.gif', _("Sort Direction")); ?></a>
+ <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_TYPE) ?>"><?php echo _("Type") ?></a>
+ </th>
+ <?php break; ?>
+ <?php case 'name': ?>
+ <th class="<?php echo ($prefs->getValue('sortby') == SORT_NAME) ? 'selected' : 'item' ?>" width="57%" nowrap="nowrap" align="left">
+ <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_NAME . '&sortdir=' . abs(1 - $prefs->getValue('sortdir'))); ?>"><?php echo Horde::img($prefs->getValue('sortdir') ? 'down.gif' : 'up.gif', _("Sort Direction")); ?></a>
+ <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_NAME) ?>"><?php echo _("Name") ?></a>
+ </th>
+ <?php break; ?>
+ <?php case 'download': ?>
+ <th class="item" width="1%" align="center">
+ <?php echo Horde::img('download.gif', _("Download"), null, $registry->getParam('graphics', 'horde')) ?>
+ </th>
+ <?php break; ?>
+ <?php case 'modified': ?>
+ <th class="<?php echo ($prefs->getValue('sortby') == SORT_DATE) ? 'selected' : 'item' ?>" width="7%" nowrap="nowrap" align="right">
+ <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_DATE . '&sortdir=' . abs(1 - $prefs->getValue('sortdir'))); ?>"><?php echo Horde::img($prefs->getValue('sortdir') ? 'down.gif' : 'up.gif', _("Sort Direction")); ?></a>
+ <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_DATE); ?>"><?php echo _("Modified") ?></a>
+ </th>
+ <?php break; ?>
+ <?php case 'size': ?>
+ <th class="<?php echo ($prefs->getValue('sortby') == SORT_SIZE) ? 'selected' : 'item' ?>" width="7%" nowrap="nowrap" align="right">
+ <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_SIZE . '&sortdir=' . abs(1 - $prefs->getValue('sortdir'))); ?>"><?php echo Horde::img($prefs->getValue('sortdir') ? 'down.gif' : 'up.gif', _("Sort Direction")); ?></a>
+ <a href="<?php echo Horde::applicationUrl('manager.php?sortby=' . SORT_SIZE) ?>"><?php echo _("Size") ?></a>
+ </th>
+ <?php break; ?>
+ <?php case 'permission':
+ case 'owner':
+ case 'group': ?>
+ <th class="item" width="7%" nowrap="nowrap" align="right">
+ <?php echo _(ucfirst($heading)) ?>
+ </th>
+ <?php break; ?>
+ <?php endswitch; ?>
+ <?php endforeach; ?>
</tr>
diff -p -U 2 -N -x CVS -r /tmp/gollem/templates/manager/file_summaries.inc gollem/templates/manager/file_summaries.inc
--- /tmp/gollem/templates/manager/file_summaries.inc Thu Apr 24 16:45:17 2003
+++ gollem/templates/manager/file_summaries.inc Mon Apr 28 13:31:14 2003
@@ -3,20 +3,40 @@
<input type="checkbox" name="items[]" value="<?php echo $item['name']; ?>" />
</td>
- <td align="right">
- <?php if (!empty($item['link'])): ?>
- <?php echo Horde::img('manager/symlink.gif', _("symlink")) ?>
- <?php elseif ($item['type'] == '**dir'): ?>
- <?php echo Horde::img('manager/folder.gif', _("folder")) ?>
- <?php else: ?>
- <?php echo Horde::img(MIME_Viewer::getIcon(MIME_Magic::extToMIME($item['type'])), '', '', '') ?>
- <?php endif; ?>
-
- </td>
- <td nowrap="nowrap"><?php echo $link ?></td>
- <td align="center"><?php echo is_null($dl) ? ' ' : $dl ?></td>
- <td align="right" nowrap="nowrap"><?php echo strftime($conf['manager']['date_format'], $item['date']); ?></td>
- <td align="right"><?php echo $item['type'] == '**dir' ? '-' : number_format($item['size'], 0, '.', ','); ?></td>
- <td align="right" nowrap="nowrap"><?php echo $item['perms'] ?></td>
- <td align="right" nowrap="nowrap"><?php echo $item['owner'] ?></td>
- <td align="right" nowrap="nowrap"><?php echo $item['group'] ?></td>
+ <?php foreach($columns as $heading): ?>
+ <?php switch($heading):
+ case 'type': ?>
+ <td align="right">
+ <?php if (!empty($item['link'])): ?>
+ <?php echo Horde::img('manager/symlink.gif', _("symlink")) ?>
+ <?php elseif ($item['type'] == '**dir'): ?>
+ <?php echo Horde::img('manager/folder.gif', _("folder")) ?>
+ <?php else: ?>
+ <?php echo Horde::img(MIME_Viewer::getIcon(MIME_Magic::extToMIME($item['type'])), '', '', '') ?>
+ <?php endif; ?>
+
+ </td>
+ <?php break; ?>
+ <?php case 'name': ?>
+ <td nowrap="nowrap"><?php echo $link ?></td>
+ <?php break; ?>
+ <?php case 'download': ?>
+ <td align="center"><?php echo is_null($dl) ? ' ' : $dl ?></td>
+ <?php break; ?>
+ <?php case 'modified': ?>
+ <td align="right" nowrap="nowrap"><?php echo strftime($conf['manager']['date_format'], $item['date']); ?></td>
+ <?php break; ?>
+ <?php case 'size': ?>
+ <td align="right"><?php echo $item['type'] == '**dir' ? '-' : number_format($item['size'], 0, '.', ','); ?></td>
+ <?php break; ?>
+ <?php case 'permission': ?>
+ <td align="right" nowrap="nowrap"><?php echo $item['perms'] ?></td>
+ <?php break; ?>
+ <?php case 'owner': ?>
+ <td align="right" nowrap="nowrap"><?php echo $item['owner'] ?></td>
+ <?php break; ?>
+ <?php case 'group': ?>
+ <td align="right" nowrap="nowrap"><?php echo $item['group'] ?></td>
+ <?php break; ?>
+ <?php endswitch; ?>
+ <?php endforeach; ?>
</tr>
diff -p -U 2 -N -x CVS -r /tmp/gollem/templates/prefs/columnselect.inc gollem/templates/prefs/columnselect.inc
--- /tmp/gollem/templates/prefs/columnselect.inc Wed Dec 31 19:00:00 1969
+++ gollem/templates/prefs/columnselect.inc Thu Apr 24 23:43:17 2003
@@ -0,0 +1,252 @@
+<?php if (!$prefs->isLocked('columns')):
+
+require GOLLEM_BASE . '/config/backends.php';
+
+$sources = Gollem::string2Columns($prefs->getValue('columns'));
+
+$js = "var columns = new Array();\n";
+$source_count = 0;
+foreach ($backends as $source => $info) {
+ $selected = isset($sources[$source]) ? array_flip($sources[$source]) : array();
+ $js .= "columns[$source_count] = new Array();\n";
+ $js .= "columns[$source_count][0] = '$source';\n";
+
+ $column_count = 1;
+ foreach ($info['attributes'] as $null => $column) {
+ $marked = isset($selected[$column]) ? 'true' : 'false';
+ $js .= "columns[$source_count][$column_count] = ['$column', '" . addslashes($column) . "', $marked, " . (($marked === 'true') ? $selected[$column] : 'null') . "];\n";
+ $column_count++;
+ }
+
+ $source_count++;
+}
+?>
+
+<script language="JavaScript1.1" type="text/javascript">
+<!--
+<?php echo $js ?>
+
+function selectSource()
+{
+ var f = document.prefs;
+ var fieldString = '';
+
+ while (f.unselected_columns.length > 1) {
+ f.unselected_columns.options[f.unselected_columns.length - 1] = null;
+ }
+ while (f.selected_columns.length > 1) {
+ f.selected_columns.options[f.selected_columns.length - 1] = null;
+ }
+
+ if (f.source.selectedIndex < 1) {
+ return;
+ }
+ var source = f.source.selectedIndex - 1;
+
+ var selected = new Array();
+ var unselected = new Array();
+ for (var i = 1; i < columns[source].length; i++) {
+ if (columns[source][i][2]) {
+ selected[columns[source][i][3]] = new Array(columns[source][i][1], columns[source][i][0]);
+ } else {
+ unselected[unselected.length] = new Array(columns[source][i][1], columns[source][i][0]);
+ }
+ }
+ for (i = 0; i < selected.length; i++) {
+ f.selected_columns.options[i + 1] = new Option(selected[i][0], selected[i][1]);
+ }
+ for (i = 0; i < unselected.length; i++) {
+ f.unselected_columns.options[i + 1] = new Option(unselected[i][0], unselected[i][1]);
+ }
+}
+
+function deselectHeaders()
+{
+ document.prefs.unselected_columns[0].selected = false;
+ document.prefs.selected_columns[0].selected = false;
+}
+
+function resetHidden()
+{
+ var tmp = '';
+ for (var i = 0; i < columns.length; i++) {
+ if (i > 0) {
+ tmp += '\n';
+ }
+ tmp += columns[i][0];
+ for (var j = 1; j < columns[i].length; j++) {
+ if (columns[i][j][2]) {
+ tmp += '\t' + columns[i][j][0];
+ }
+ }
+ }
+ document.prefs.columns.value = tmp;
+}
+
+function addColumn()
+{
+ var f = document.prefs;
+ var source = f.source.selectedIndex - 1;
+
+ for (i = 1; i < f.unselected_columns.length; i++) {
+ if (f.unselected_columns[i].selected) {
+ for (var j = 1; j < columns[source].length; j++) {
+ if (columns[source][j][0] == f.unselected_columns[i].value) {
+ columns[source][j][2] = true;
+ }
+ }
+ f.selected_columns[f.selected_columns.length] = new Option(f.unselected_columns[i].text, f.unselected_columns[i].value);
+ f.unselected_columns[i] = null;
+ i--;
+ }
+ }
+
+ resetHidden();
+}
+
+function removeColumn()
+{
+ var f = document.prefs;
+ var source = f.source.selectedIndex - 1;
+
+ for (i = 1; i < f.selected_columns.length; i++) {
+ if (f.selected_columns[i].selected) {
+ for (var j = 1; j < columns[source].length; j++) {
+ if (columns[source][j][0] == f.selected_columns[i].value) {
+ columns[source][j][2] = false;
+ }
+ }
+ f.unselected_columns[f.unselected_columns.length] = new Option(f.selected_columns[i].text, f.selected_columns[i].value)
+ f.selected_columns[i] = null;
+ i--;
+ }
+ }
+
+ resetHidden();
+}
+
+function moveColumnUp()
+{
+ var f = document.prefs;
+ var sel = f.selected_columns.selectedIndex;
+ var source = f.source.selectedIndex - 1;
+
+ if (sel <= 1 || f.selected_columns.length <= 2) return;
+
+ // deselect everything but the first selected item
+ f.selected_columns.selectedIndex = sel;
+ var up = f.selected_columns[sel].value;
+
+ tmp = new Array();
+
+ for (i = 1; i < f.selected_columns.length; i++) {
+ tmp[i - 1] = new Option(f.selected_columns[i].text, f.selected_columns[i].value)
+ }
+
+ for (i = 0; i < tmp.length; i++) {
+ if (i + 1 == sel - 1) {
+ f.selected_columns[i + 1] = tmp[i + 1];
+ } else if (i + 1 == sel) {
+ f.selected_columns[i + 1] = tmp[i - 1];
+ } else {
+ f.selected_columns[i + 1] = tmp[i];
+ }
+ }
+
+ f.selected_columns.selectedIndex = sel - 1;
+
+ for (i = 2; i < columns[source].length - 1; i++) {
+ if (columns[source][i][0] == up) {
+ column = columns[source][i];
+ columns[source][i] = columns[source][i - 1];
+ columns[source][i - 1] = column;
+ }
+ }
+
+ resetHidden();
+}
+
+function moveColumnDown()
+{
+ var f = document.prefs;
+ var sel = f.selected_columns.selectedIndex;
+ var source = f.source.selectedIndex - 1;
+
+ if (sel == -1 || f.selected_columns.length <= 2 || sel == f.selected_columns.length - 1) return;
+
+ // deselect everything but the first selected item
+ f.selected_columns.selectedIndex = sel;
+ var down = f.selected_columns[sel].value;
+
+ tmp = new Array();
+
+ for (i = 1; i < f.selected_columns.length; i++) {
+ tmp[i - 1] = new Option(f.selected_columns[i].text, f.selected_columns[i].value)
+ }
+
+ for (i = 0; i < tmp.length; i++) {
+ if (i + 1 == sel) {
+ f.selected_columns[i + 1] = tmp[i + 1];
+ } else if (i + 1 == sel + 1) {
+ f.selected_columns[i + 1] = tmp[i - 1];
+ } else {
+ f.selected_columns[i + 1] = tmp[i];
+ }
+ }
+
+ f.selected_columns.selectedIndex = sel + 1;
+
+ for (i = columns[source].length - 2; i > 0; i--) {
+ if (columns[source][i][0] == down || columns[source][i + 1][0] == down) {
+ column = columns[source][i];
+ columns[source][i] = columns[source][i + 1];
+ columns[source][i + 1] = column;
+ }
+ }
+
+ resetHidden();
+}
+
+// -->
+</script>
+
+<table>
+ <tr>
+ <td>
+ <select name="source" onchange="if (document.prefs.source.selectedIndex != 0) selectSource();">
+ <option value=""><?php echo _("Please select a backend:") ?></option>
+<?php foreach ($backends as $key => $info): ?>
+ <option value="<?php echo $key ?>"><?php echo $info['name'] ?></option>
+<?php endforeach; ?>
+ </select>
+ </td>
+ </tr>
+</table>
+
+<?php echo _("Choose the columns to display in the file manager.") ?><br />
+<input type="hidden" name="columns" value="<?php echo $prefs->getValue('columns') ?>" />
+<table>
+ <tr>
+ <td>
+ <select name="unselected_columns" multiple="multiple" size="5" width="20" onchange="deselectHeaders();">
+ <option value=""><?php echo _("Available Columns:") ?></option>
+ </select>
+ </td>
+ <td>
+ <a href="" onclick="addColumn(); return false;"><?php echo Horde::img('rhand.gif', _("add column")) ?></a>
+ <br />
+ <a href="" onclick="removeColumn(); return false;"><?php echo Horde::img('lhand.gif', _("remove column")) ?></a>
+ </td>
+ <td>
+ <select name="selected_columns" multiple="multiple" size="5" width="20" onchange="deselectHeaders();">
+ <option value=""><?php echo _("Selected Columns:") ?></option>
+ </select>
+ </td>
+ <td>
+ <a href="" onclick="moveColumnUp(); return false;"><?php echo Horde::img('up.gif', _("move left")) ?></a>
+ <br />
+ <a href="" onclick="moveColumnDown(); return false;"><?php echo Horde::img('down.gif', _("move right")) ?></a>
+ </td>
+ </tr>
+</table>
+<?php endif; ?>
More information about the gollem
mailing list