summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-10-30 14:06:38 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-10-30 14:06:38 +0100
commit56fa09eb703c29568d9d04ab806c5e42a570fc4c (patch)
tree6f5488e715b77e96575c18a911491bb1ac2275fa /ishtar_common
parent2f0115da348110b0dbbadfbdb0a03790f60a7738 (diff)
downloadIshtar-56fa09eb703c29568d9d04ab806c5e42a570fc4c.tar.bz2
Ishtar-56fa09eb703c29568d9d04ab806c5e42a570fc4c.zip
UI: put actions on a top menu
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/context_processors.py1
-rw-r--r--ishtar_common/ishtar_menu.py1
-rw-r--r--ishtar_common/menu_base.py4
-rw-r--r--ishtar_common/menus.py77
-rw-r--r--ishtar_common/templates/actions.html53
-rw-r--r--ishtar_common/templates/base.html25
-rw-r--r--ishtar_common/templates/blocks/action_list.html12
-rw-r--r--ishtar_common/templates/navbar.html6
8 files changed, 149 insertions, 30 deletions
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 @@
+<ul class="navbar-nav action-menu">
+ {% with MENU.current_section as section_label %}
+ {% with MENU.current_sections as sections %}
+ {% include "blocks/action_list.html" %}
+ {% endwith %}{% endwith %}
+
+ {% if MENU.current_subsections %}
+ <li class="nav-item">
+ <span class="nav-link">&gt;</span>
+ </li>
+ {% with MENU.current_subsection as section_label %}
+ {% with MENU.current_subsections as sections %}
+ {% include "blocks/action_list.html" %}
+ {% endwith %}{% endwith %}
+ {% endif %}
+
+ {% if MENU.current_subsubsections %}
+ <li class="nav-item">
+ <span class="nav-link">&gt;</span>
+ </li>
+ {% with MENU.current_subsubsection as section_label %}
+ {% with MENU.current_subsubsections as sections %}
+ {% include "blocks/action_list.html" %}
+ {% endwith %}{% endwith %}
+ {% endif %}
+</ul>
+{% comment %}
+<div id="main_menu">
+ <ul>
+ {% for section in MENU.childs %}
+ {% if section.available %}
+ <li id='section-{{section.idx}}'{% if section.css %} class="{{section.css}}"{% endif %}>
+ {{section.label}}
+ <ul>
+ {% for menu_item in section.childs %}{%if menu_item.available%}
+ {% if menu_item.childs %}<li id='subsection-{{menu_item.idx}}'{% if menu_item.css %} class="{{menu_item.css}}"{% endif %}>{{menu_item.label}}
+ <ul>
+ {% for menu_subitem in menu_item.childs %}{% if menu_subitem.available %}
+ {% url 'action' menu_subitem.idx as item_url %}
+ <li id='{{menu_subitem.idx}}'{% if item_url in CURRENT_PATH %} class='selected'{% endif %}><a
+ href='{{item_url}}'>{{menu_subitem.label}}</a></li>
+ {%endif%}{% endfor %}</ul></li>
+ {% else %}
+ {% url 'action' menu_item.idx as item_url %}
+ <li id='{{menu_item.idx}}'
+ class="{% if item_url in CURRENT_PATH %}selected{% endif %} {% if menu_item.css %}{{menu_item.css}}{% endif %}"><a href="{{item_url}}">{{menu_item.label}}</a></li>
+ {%endif%}{% endif %}{% endfor %}
+ </ul>
+ </li>{%endif%}
+ {% endfor %}
+ </ul>
+</div>
+{% 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 @@
<p><strong class='lbl'>{{lbl}}{% trans ":"%}</strong> <span class='value'>{{value}}</span></p>
{% endfor %}
</fieldset>{%endif%}
- <div id="main_menu">
- <ul>
- {% for section in MENU.childs %}
- {% if section.available %}
- <li id='section-{{section.idx}}'{% if section.css %} class="{{section.css}}"{% endif %}>
- {{section.label}}
- <ul>
- {% for menu_item in section.childs %}{%if menu_item.available%}
- {% if menu_item.childs %}<li id='subsection-{{menu_item.idx}}'{% if menu_item.css %} class="{{menu_item.css}}"{% endif %}>{{menu_item.label}}
- <ul>
- {% for menu_subitem in menu_item.childs %}{% if menu_subitem.available %}
- {% url 'action' menu_subitem.idx as item_url %}
- <li id='{{menu_subitem.idx}}'{% if item_url in CURRENT_PATH %} class='selected'{% endif %}><a
- href='{{item_url}}'>{{menu_subitem.label}}</a></li>
- {%endif%}{% endfor %}</ul></li>
- {% else %}
- {% url 'action' menu_item.idx as item_url %}
- <li id='{{menu_item.idx}}'
- class="{% if item_url in CURRENT_PATH %}selected{% endif %} {% if menu_item.css %}{{menu_item.css}}{% endif %}"><a href="{{item_url}}">{{menu_item.label}}</a></li>
- {%endif%}{% endif %}{% endfor %}
- </ul>
- </li>{%endif%}
- {% endfor %}
- </ul>
- </div>
<div class="container">
{% if warnings %}{% for warning in warnings %}
<div class="alert alert-warning alert-dismissible fade show" role="alert">
diff --git a/ishtar_common/templates/blocks/action_list.html b/ishtar_common/templates/blocks/action_list.html
new file mode 100644
index 000000000..50a6554c4
--- /dev/null
+++ b/ishtar_common/templates/blocks/action_list.html
@@ -0,0 +1,12 @@
+<li class="nav-item dropdown">
+ <a class="nav-link dropdown-toggle"
+ data-toggle="dropdown" href="#" role="button" aria-haspopup="true"
+ aria-expanded="false">{{section_label}}</a>
+
+ <div class="dropdown-menu">
+ {% for label, url, has_children in sections %}
+ <a class="dropdown-item{% if has_children%} font-weight-bold{%endif%}" href="{{url}}">
+ {{ label }}
+ </a>{% endfor %}
+ </div>
+</li>
diff --git a/ishtar_common/templates/navbar.html b/ishtar_common/templates/navbar.html
index a8c764185..228f18530 100644
--- a/ishtar_common/templates/navbar.html
+++ b/ishtar_common/templates/navbar.html
@@ -8,11 +8,7 @@
</a>
</nav>
<div class="collapse navbar-collapse">
- <ul class="navbar-nav">
- <li class="nav-item active">
- <a class="nav-link" href="#">Operation...</a>
- </li>
- </ul>
+ {% include "actions.html" %}
</div>
<ul class="navbar-nav">
{% if APP_NAME %}