From 56fa09eb703c29568d9d04ab806c5e42a570fc4c Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 30 Oct 2017 14:06:38 +0100 Subject: UI: put actions on a top menu --- ishtar_common/context_processors.py | 1 + ishtar_common/ishtar_menu.py | 1 + ishtar_common/menu_base.py | 4 ++ ishtar_common/menus.py | 77 +++++++++++++++++++++++++ ishtar_common/templates/actions.html | 53 +++++++++++++++++ ishtar_common/templates/base.html | 25 -------- ishtar_common/templates/blocks/action_list.html | 12 ++++ ishtar_common/templates/navbar.html | 6 +- scss/custom.scss | 11 ++++ 9 files changed, 160 insertions(+), 30 deletions(-) create mode 100644 ishtar_common/templates/actions.html create mode 100644 ishtar_common/templates/blocks/action_list.html diff --git a/ishtar_common/context_processors.py b/ishtar_common/context_processors.py index 1c3babb8f..8cef32d9f 100644 --- a/ishtar_common/context_processors.py +++ b/ishtar_common/context_processors.py @@ -51,6 +51,7 @@ def get_base_context(request): if menu.selected_idx is not None: dct['current_theme'] = "theme-%d" % (menu.selected_idx + 1) dct['MENU'] = menu + menu.get_current_selection(request.path) dct['JQUERY_URL'] = settings.JQUERY_URL dct['JQUERY_UI_URL'] = settings.JQUERY_UI_URL dct['COUNTRY'] = settings.COUNTRY diff --git a/ishtar_common/ishtar_menu.py b/ishtar_common/ishtar_menu.py index 5ed8cad37..f925936e9 100644 --- a/ishtar_common/ishtar_menu.py +++ b/ishtar_common/ishtar_menu.py @@ -26,6 +26,7 @@ import models # be carreful: each access_controls must be relevant with check_rights in urls MENU_SECTIONS = [ + (1, SectionItem('home', _(u"Home"), childs=[])), (5, SectionItem('admin', _(u"Administration"), childs=[ SectionItem( diff --git a/ishtar_common/menu_base.py b/ishtar_common/menu_base.py index c6d02daa5..7913bd470 100644 --- a/ishtar_common/menu_base.py +++ b/ishtar_common/menu_base.py @@ -40,12 +40,16 @@ class SectionItem: def can_be_available(self, user, session=None): if not self.check_profile_restriction(): return False + if not self.childs: + return True for child in self.childs: if child.can_be_available(user, session=session): return True return False def is_available(self, user, obj=None, session=None): + if not self.childs: + return True for child in self.childs: if child.is_available(user, obj, session=session): return True diff --git a/ishtar_common/menus.py b/ishtar_common/menus.py index 7d24b0fd2..c3d54a30c 100644 --- a/ishtar_common/menus.py +++ b/ishtar_common/menus.py @@ -22,6 +22,7 @@ Menus """ from django.conf import settings +from django.core.urlresolvers import reverse _extra_menus = [] # collect menu from INSTALLED_APPS @@ -56,6 +57,14 @@ class Menu: self.initialized = False self.items = {} self.current_action = current_action + self.current_section = None + self.current_url = None + self.current_section = "" + self.current_sections = [] + self.current_subsection = "" + self.current_subsections = [] + self.current_subsubsection = "" + self.current_subsubsections = [] self.selected_idx = None self.session = session self.items_by_idx = {} @@ -79,5 +88,73 @@ class Menu: self.selected_idx = idx self.initialized = True + def get_current_selection(self, current_path): + # current_section, current_subsection, etc. are current labels + # current_sections, current_subsections, etc. are list of: + # (label, url, has_children) + + self.current_section = '' + self.current_sections = [] + + self.current_subsection = "" + self.current_subsections = [] + + self.current_subsubsection = "" + self.current_subsubsections = [] + self.current_url = None + for section in self.childs: + if not section.available: + continue + section_url = None + subsections = [] + if not self.current_section: + # initialize by default with the first section + self.current_section = section.label + selected_section = None + + for menu_item in section.childs: + if not menu_item.available: + continue + if not hasattr(menu_item, 'childs') or not menu_item.childs: + item_url = reverse('action', args=[menu_item.idx]) + if not section_url: + section_url = item_url + subsections.append([menu_item.label, item_url, False]) + if item_url in current_path: + self.current_url = item_url + self.current_section = section.label + self.current_subsection = menu_item.label + selected_section = True + continue + subsection_url = None + selected_subsection = None + subsubsections = [] + for menu_subitem in menu_item.childs: + if not menu_subitem.available: + continue + item_url = reverse('action', args=[menu_subitem.idx]) + if not section_url: + section_url = item_url + if not subsection_url: + subsection_url = item_url + subsections.append([menu_item.label, item_url, True]) + subsubsections.append([menu_subitem.label, item_url, False]) + if item_url in current_path: + self.current_url = item_url + self.current_section = section.label + self.current_subsection = menu_item.label + self.current_subsubsection = menu_subitem.label + selected_section = True + selected_subsection = True + if selected_subsection: + self.current_subsubsections = subsubsections + + if selected_section: + self.current_subsections = subsections + if not section_url: + section_url = "#" + self.current_sections.append([section.label, section_url, + bool(subsections)]) + menu = Menu(None) menu.init() diff --git a/ishtar_common/templates/actions.html b/ishtar_common/templates/actions.html new file mode 100644 index 000000000..a42581049 --- /dev/null +++ b/ishtar_common/templates/actions.html @@ -0,0 +1,53 @@ + +{% comment %} + +{% endcomment %} diff --git a/ishtar_common/templates/base.html b/ishtar_common/templates/base.html index ce383ba6c..5a61d72e9 100644 --- a/ishtar_common/templates/base.html +++ b/ishtar_common/templates/base.html @@ -64,31 +64,6 @@

{{lbl}}{% trans ":"%} {{value}}

{% endfor %} {%endif%} -
{% if warnings %}{% for warning in warnings %}