From 39319e08c9c8fd434b558ec307c6bda0287fd3c7 Mon Sep 17 00:00:00 2001
From: "Antoine R. Dumont (@ardumont)" <antoine.romain.dumont@gmail.com>
Date: Wed, 2 Dec 2015 12:50:03 +0100
Subject: [PATCH] Permit to display a visual difference in listing dir and
 files

TODO: define such style
---
 swh/web/ui/templates/directory.html | 2 +-
 swh/web/ui/tests/test_utils.py      | 9 ++++++---
 swh/web/ui/utils.py                 | 4 ++--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/swh/web/ui/templates/directory.html b/swh/web/ui/templates/directory.html
index 4cb9eca4c..e5955f28c 100644
--- a/swh/web/ui/templates/directory.html
+++ b/swh/web/ui/templates/directory.html
@@ -4,7 +4,7 @@
 {{ message }}
 {% if ls is not none %}
   {% for e in files %}
-    <div><p><a href="{{e.link}}">{{ e.name }}</a></p></div>
+    <div><p><a class="link{{e.type}}" href="{{e.link}}">{{ e.name }}</a></p></div>
   {% endfor %}
 {% endif %}
 {% endblock %}
diff --git a/swh/web/ui/tests/test_utils.py b/swh/web/ui/tests/test_utils.py
index a59e8768c..963ce5178 100644
--- a/swh/web/ui/tests/test_utils.py
+++ b/swh/web/ui/tests/test_utils.py
@@ -105,11 +105,14 @@ class UtilsTestCase(unittest.TestCase):
                    'name': 'some-other-dirname'}]
 
         expected_output = [{'link': '/path/to/url/dir/123',
-                            'name': 'some-dir-name'},
+                            'name': 'some-dir-name',
+                            'type': 'dir'},
                            {'link': '/path/to/url/file/654',
-                            'name': 'some-filename'},
+                            'name': 'some-filename',
+                            'type': 'file'},
                            {'link': '/path/to/url/dir/987',
-                            'name': 'some-other-dirname'}]
+                            'name': 'some-other-dirname',
+                            'type': 'dir'}]
 
         # when
         actual_outputs = utils.prepare_directory_listing(inputs)
diff --git a/swh/web/ui/utils.py b/swh/web/ui/utils.py
index 0c39b53a7..f6a75feb0 100644
--- a/swh/web/ui/utils.py
+++ b/swh/web/ui/utils.py
@@ -39,14 +39,14 @@ def prepare_directory_listing(files):
     """
     ls = []
     for entry in files:
-        new_entry = {}
+        new_entry = {'name': entry['name'],
+                     'type': entry['type']}
         if entry['type'] == 'dir':
             new_entry['link'] = flask.url_for('browse_directory',
                                               sha1_git=entry['target'])
         else:
             new_entry['link'] = flask.url_for('show_content',
                                               q=entry['sha1'])
-        new_entry['name'] = entry['name']
         ls.append(new_entry)
 
     return ls
-- 
GitLab