From e12cea7bc13ed059a5ead5197a2214ce496bb690 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Fri, 24 Sep 2021 10:08:11 +0200
Subject: [PATCH] manager: remove toggle pages feature (#56791)

---
 combo/manager/static/css/combo.manager.css    | 17 -----
 combo/manager/static/js/combo.manager.js      | 74 +------------------
 .../manager/templates/combo/manager_home.html |  3 +-
 combo/manager/views.py                        |  1 -
 combo/settings.py                             |  3 -
 tests/test_manager.py                         | 12 ---
 6 files changed, 3 insertions(+), 107 deletions(-)

diff --git a/combo/manager/static/css/combo.manager.css b/combo/manager/static/css/combo.manager.css
index e777bb77..7e98a582 100644
--- a/combo/manager/static/css/combo.manager.css
+++ b/combo/manager/static/css/combo.manager.css
@@ -25,23 +25,6 @@ div#pages-list div.page {
 	align-items: center;
 }
 
-div#pages-list span.togglable {
-	padding: 1em 2ex;
-	cursor: pointer;
-}
-
-div#pages-list div.page.untoggled span.togglable:after {
-	font-family: FontAwesome;
-	content: "\f107"; /* angle-down */
-	cursor: pointer;
-}
-
-div#pages-list div.page.toggled span.togglable:after {
-	font-family: FontAwesome;
-	content: "\f106"; /* angle-up */
-	cursor: pointer;
-}
-
 div.cell-list > div {
 	background: white;
 	border: 1px solid #eee;
diff --git a/combo/manager/static/js/combo.manager.js b/combo/manager/static/js/combo.manager.js
index 318ce7fc..4a2542ad 100644
--- a/combo/manager/static/js/combo.manager.js
+++ b/combo/manager/static/js/combo.manager.js
@@ -79,64 +79,10 @@ function multisort(element)
   });
 }
 
-function get_page_children($page) {
-  var children = [];
-  $page.nextAll().each(function() {
-    var level = parseInt($(this).data('level'), 10);
-    if (level <= parseInt($page.data('level'), 10)) {
-      return false;
-    }
-    children.push($(this));
-  });
-  return children;
-}
-
-function show_page_children($page) {
-  $.each(get_page_children($page), function() {
-    $child = $(this);
-    var level = parseInt($child.data('level'), 10);
-    if (level == parseInt($page.data('level'), 10) + 1) {
-      $child.show();
-      if ($child.hasClass('toggled')) {
-        show_page_children($child);
-      }
-    }
-  });
-}
-
-function hide_page_children($page) {
-  $.each(get_page_children($page), function() {
-    $(this).hide();
-  });
-}
-
-function init_pages_toggle() {
-  $('.page').each(function() {
-    if (!get_page_children($(this)).length) {
-      $(this).removeClass('toggled').removeClass('untoggled').find('.togglable').remove();
-    }
-  });
-  $('div.page.untoggled').each(function() {
-    hide_page_children($(this));
-  });
-  $('div.page.toggled[level=1]').each(function() {
-    show_page_children($(this));
-  });
-}
-
-function init_pages_list(toggle_state)
+function init_pages_list()
 {
   if ($('#pages-list').length == 0)
     return;
-  init_pages_toggle();
-  // if toggle_state is defined, restore toggled pages
-  if (toggle_state) {
-    $('div.page').each(function() {
-      if (toggle_state.includes($(this).data('page-id'))) {
-        $('span.togglable', $(this)).trigger('click');
-      }
-    });
-  }
   var list_offset = $('#pages-list').offset().left;
   $('#pages-list').sortable({
      handle: '.handle',
@@ -166,14 +112,6 @@ function init_pages_list(toggle_state)
        $(ui.item).data('level', new_level).attr('data-level', new_level);
 
        var new_order = $('#pages-list div').map(function() { return $(this).data('page-id'); }).get().join();
-       // keep actuel toggled pages + new parent to restore display on init_pages_list
-       var old_toggle_state = [];
-       $('div.page.toggled').each(function() {
-         old_toggle_state.push($(this).data('page-id'));
-       });
-       if (!old_toggle_state.includes(new_parent)) {
-         old_toggle_state.push(new_parent);
-       }
 
        $.ajax({
            url: $('#pages-list').data('page-order-url'),
@@ -183,7 +121,7 @@ function init_pages_list(toggle_state)
            },
            success: function(data, status) {
              $('#pages-list').replaceWith($(data).find('#pages-list'));
-             init_pages_list(old_toggle_state);
+             init_pages_list();
            }
        });
      }
@@ -209,14 +147,6 @@ $(function() {
     return false;
   });
   init_pages_list();
-  $(document).on('click', 'div.page.untoggled span.togglable', function() {
-    $(this).parent().toggleClass('toggled').toggleClass('untoggled');
-    show_page_children($(this).parent());
-  });
-  $(document).on('click', 'div.page.toggled span.togglable', function() {
-    $(this).parent().toggleClass('toggled').toggleClass('untoggled');
-    hide_page_children($(this).parent());
-  });
 
   function init_cells_lists() {
     $('.cell-list').each(function() {
diff --git a/combo/manager/templates/combo/manager_home.html b/combo/manager/templates/combo/manager_home.html
index 7dcb1026..64bcc618 100644
--- a/combo/manager/templates/combo/manager_home.html
+++ b/combo/manager/templates/combo/manager_home.html
@@ -35,7 +35,7 @@ Use drag and drop with the ⣿ handles to reorder and change hierarchy of pages.
 
 <div class="objects-list" id="pages-list" data-page-order-url="{% url 'combo-manager-page-order' %}">
  {% for page in object_list %}
- <div class="page level-{{page.level}}{% if collapse_pages %} untoggled{% endif %}" data-page-id="{{page.id}}" data-level="{{page.level}}">
+ <div class="page level-{{page.level}}" data-page-id="{{page.id}}" data-level="{{page.level}}">
     {% if user.is_staff %}<span class="handle">⣿</span>{% endif %}
     <span class="group1">
       <a href="{% url 'combo-manager-page-view' pk=page.id %}">
@@ -53,7 +53,6 @@ Use drag and drop with the ⣿ handles to reorder and change hierarchy of pages.
     {% endwith %}
     </span>
     {% endif %}
-    {% if collapse_pages %}<span class="togglable"></span>{% endif %}
  </div>
  {% endfor %}
 </div>
diff --git a/combo/manager/views.py b/combo/manager/views.py
index db3aac07..e6966f9a 100644
--- a/combo/manager/views.py
+++ b/combo/manager/views.py
@@ -87,7 +87,6 @@ class HomepageView(ListView):
         )
         context = super().get_context_data(**kwargs)
         context['extra_actions'] = plugins.get_extra_manager_actions()
-        context['collapse_pages'] = settings.COMBO_MANAGE_HOME_COLLAPSE_PAGES
         context['can_add_page'] = can_add_page(self.request.user)
         return context
 
diff --git a/combo/settings.py b/combo/settings.py
index 952850a0..3d0f8aeb 100644
--- a/combo/settings.py
+++ b/combo/settings.py
@@ -278,9 +278,6 @@ COMBO_DASHBOARD_ENABLED = False
 
 COMBO_DASHBOARD_NEW_TILE_POSITION = 'last'
 
-# collapse pages on combo home
-COMBO_MANAGE_HOME_COLLAPSE_PAGES = False
-
 # default position on maps
 COMBO_MAP_DEFAULT_POSITION = {'lat': '48.83369263315934', 'lng': '2.3233688436448574'}
 
diff --git a/tests/test_manager.py b/tests/test_manager.py
index 6d70e976..b8caee8d 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -73,18 +73,6 @@ def test_access(app, admin_user):
     assert "This site doesn't have any page yet." in resp.text
 
 
-@pytest.mark.parametrize('collapse', [True, False])
-def test_pages_collapse(settings, app, admin_user, collapse):
-    Page.objects.create(title='One', slug='one')
-    settings.COMBO_MANAGE_HOME_COLLAPSE_PAGES = collapse
-
-    app = login(app)
-    resp = app.get('/manage/', status=200)
-    assert resp.context['collapse_pages'] is collapse
-    assert ('class="page level-0 untoggled"' in resp.text) is collapse
-    assert ('class="page level-0"' in resp.text) is not collapse
-
-
 def test_pages_redirection(app, admin_user):
     page = Page.objects.create(title='One', slug='one')
 
-- 
2.33.0

