[Pkg-owncloud-commits] [php-sabredav] 106/275: Browser plugin: sort by type first, then display path.

David Prévot taffit at moszumanska.debian.org
Thu Sep 25 14:55:57 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit 0512338ea724f880ff68a146fb12875d55f946a6
Author: Alfred Klomp <git at alfredklomp.com>
Date:   Sat Jul 26 19:00:10 2014 +0200

    Browser plugin: sort by type first, then display path.
    
    The SabreDAV browser plugin previously displayed all entries in no
    particular order. To make the list easier to digest for the end user,
    sort all nodes based on their type (collection yes/no) first, and their
    display path second.
---
 ChangeLog.md               |  1 +
 lib/DAV/Browser/Plugin.php | 37 +++++++++++++++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index b26e459..ad66fa6 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -10,6 +10,7 @@ ChangeLog
 * Changed: Restructured the zip distribution to be a little bit more lean
   and consistent.
 * #472: Always returning lock tokens in the lockdiscovery property.
+* Directory entries in the Browser plugin are sorted by type and name.
 
 
 2.0.3 (2014-07-14)
diff --git a/lib/DAV/Browser/Plugin.php b/lib/DAV/Browser/Plugin.php
index 9af7533..b264ff7 100644
--- a/lib/DAV/Browser/Plugin.php
+++ b/lib/DAV/Browser/Plugin.php
@@ -253,16 +253,23 @@ HTML;
                 $fullPath = URLUtil::encodePath($this->server->getBaseUri() . $subPath);
                 list(, $displayPath) = URLUtil::splitPath($subPath);
 
+                $subNodes[$subPath]['subNode'] = $subNode;
+                $subNodes[$subPath]['fullPath'] = $fullPath;
+                $subNodes[$subPath]['displayPath'] = $displayPath;
+            }
+            uasort($subNodes, [$this, 'compareNodes']);
+
+            foreach($subNodes as $subProps) {
                 $type = [
                     'string' => 'Unknown',
                     'icon'   => 'cog',
                 ];
                 if (isset($subProps['{DAV:}resourcetype'])) {
-                    $type = $this->mapResourceType($subProps['{DAV:}resourcetype']->getValue(), $subNode);
+                    $type = $this->mapResourceType($subProps['{DAV:}resourcetype']->getValue(), $subProps['subNode']);
                 }
 
                 $html.= '<tr>';
-                $html.= '<td class="nameColumn"><a href="' . $this->escapeHTML($fullPath) . '"><span class="oi" data-glyph="'.$type['icon'].'"></span> ' . $this->escapeHTML($displayPath) . '</a></td>';
+                $html.= '<td class="nameColumn"><a href="' . $this->escapeHTML($subProps['fullPath']) . '"><span class="oi" data-glyph="'.$type['icon'].'"></span> ' . $this->escapeHTML($subProps['displayPath']) . '</a></td>';
                 $html.= '<td class="typeColumn">' . $type['string'] . '</td>';
                 $html.= '<td>';
                 if (isset($subProps['{DAV:}getcontentlength'])) {
@@ -430,6 +437,32 @@ HTML;
     }
 
     /**
+     * Sort helper function: compares two directory entries based on type and
+     * display name. Collections sort above other types.
+     *
+     * @param array $a
+     * @param array $b
+     * @return int
+     */
+    protected function compareNodes($a, $b) {
+
+        $typeA = (isset($a['{DAV:}resourcetype']))
+            ? (in_array('{DAV:}collection', $a['{DAV:}resourcetype']->getValue()))
+            : false;
+
+        $typeB = (isset($b['{DAV:}resourcetype']))
+            ? (in_array('{DAV:}collection', $b['{DAV:}resourcetype']->getValue()))
+            : false;
+
+        // If same type, sort alphabetically by filename:
+        if ($typeA === $typeB) {
+            return strnatcasecmp($a['displayPath'], $b['displayPath']);
+        }
+        return (($typeA < $typeB) ? 1 : -1);
+
+    }
+
+    /**
      * Maps a resource type to a human-readable string and icon.
      *
      * @param array $resourceTypes

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list