Refactor web app to use "simple" menus

for sake of sharing between themes
This commit is contained in:
Lance Edgar 2018-11-29 01:40:18 -06:00
parent 15c44196bc
commit 599bf7cc32
4 changed files with 310 additions and 280 deletions

View file

@ -18,3 +18,4 @@ class DemoConfigExtension(ConfigExtension):
# tell rattail where our stuff lives
config.setdefault('rattail.mail', 'emails', 'rattail_demo.emails')
config.setdefault('tailbone', 'menus', 'rattail_demo.web.menus')

232
rattail_demo/web/menus.py Normal file
View file

@ -0,0 +1,232 @@
# -*- coding: utf-8; -*-
"""
Web Menus
"""
from __future__ import unicode_literals, absolute_import
def simple_menus(request):
url = request.route_url
menus = [
{
'title': "Time Clock",
'type': 'menu',
'items': [
{
'title': "Personal Schedule",
'url': url('schedule.employee'),
'perm': 'schedule.view',
},
{
'title': "Full Schedule",
'url': url('schedule'),
'perm': 'schedule.viewall',
},
{
'title': "Edit Schedule",
'url': url('schedule.edit'),
'perm': 'schedule.edit',
},
{
'title': "Raw Scheduled Shifts",
'url': url('scheduledshifts'),
'perm': 'scheduledshifts.list',
},
],
},
{
'title': "Products",
'type': 'menu',
'items': [
{
'title': "Products",
'url': url('products'),
'perm': 'products.list',
},
{
'title': "Vendors",
'url': url('vendors'),
'perm': 'vendors.list',
},
{
'title': "Departments",
'url': url('departments'),
'perm': 'departments.list',
},
{
'title': "Subdepartments",
'url': url('subdepartments'),
'perm': 'subdepartments.list',
},
{
'title': "Brands",
'url': url('brands'),
'perm': 'brands.list',
},
{
'title': "Families",
'url': url('families'),
'perm': 'families.list',
},
{
'title': "Report Codes",
'url': url('reportcodes'),
'perm': 'reportcodes.list',
},
],
},
{
'title': "People",
'type': 'menu',
'items': [
{
'title': "All People",
'url': url('people'),
'perm': 'people.list',
},
{
'title': "Customers",
'url': url('customers'),
'perm': 'customers.list',
},
{
'title': "Employees",
'url': url('employees'),
'perm': 'employees.list',
},
],
},
{
'title': "CORE-POS",
'type': 'menu',
'items': [
{
'title': "Departments",
'url': url('corepos.departments'),
'perm': 'corepos.departments.list',
},
{
'title': "Subdepartments",
'url': url('corepos.subdepartments'),
'perm': 'corepos.subdepartments.list',
},
{
'title': "Vendors",
'url': url('corepos.vendors'),
'perm': 'corepos.vendors.list',
},
{
'title': "Products",
'url': url('corepos.products'),
'perm': 'corepos.products.list',
},
{
'title': "Customers",
'url': url('corepos.customers'),
'perm': 'corepos.customers.list',
},
{
'title': "Employees",
'url': url('corepos.employees'),
'perm': 'corepos.employees.list',
},
{
'title': "Transaction Details",
'url': url('corepos.transaction_details'),
'perm': 'corepos.transaction_details.list',
},
],
},
{
'title': "Batches",
'type': 'menu',
'items': [
{
'title': "Handheld",
'url': url('batch.handheld'),
'perm': 'batch.handheld.list',
},
{
'title': "Inventory",
'url': url('batch.inventory'),
'perm': 'batch.inventory.list',
},
{
'title': "Import / Export",
'url': url('batch.importer'),
'perm': 'batch.importer.list',
},
],
},
{
'title': "TempMon",
'type': 'menu',
'items': [
{
'title': "Clients",
'url': url('tempmon.clients'),
'perm': 'tempmon.clients.list',
},
{
'title': "Probes",
'url': url('tempmon.probes'),
'perm': 'tempmon.probes.list',
},
{
'title': "Readings",
'url': url('tempmon.readings'),
'perm': 'tempmon.readings.list',
},
],
},
{
'title': "Admin",
'type': 'menu',
'items': [
{
'title': "Stores",
'url': url('stores'),
'perm': 'stores.list',
},
{
'title': "Users",
'url': url('users'),
'perm': 'users.list',
},
{
'title': "User Events",
'url': url('userevents'),
'perm': 'userevents.list',
},
{
'title': "Roles",
'url': url('roles'),
'perm': 'roles.list',
},
{
'title': "Email Settings",
'url': url('emailprofiles'),
'perm': 'emailprofiles.list',
},
{
'title': "Raw Settings",
'url': url('settings'),
'perm': 'settings.list',
},
{
'title': "DataSync Changes",
'url': url('datasyncchanges'),
'perm': 'datasync.list',
},
{
'title': "Rattail Demo Upgrades",
'url': url('upgrades'),
'perm': 'upgrades.list',
},
],
},
]
return menus

View file

@ -1,161 +1,58 @@
## -*- coding: utf-8; -*-
<%def name="make_simple_menu()">
% for topitem in menus:
<li>
<a>${topitem.title}</a>
<ul>
% for subitem in topitem.items:
<li>${h.link_to(subitem.title, subitem.url)}</li>
% endfor
</ul>
</li>
% endfor
## User Menu
% if request.user:
<li>
<a${' class="root-user"' if request.is_root else ''|n}>${request.user}${" ({})".format(inbox_count) if inbox_count else ''}</a>
<ul>
% if request.is_root:
<li class="root-user">${h.link_to("Stop being root", url('stop_root'))}</li>
% elif request.is_admin:
<li class="root-user">${h.link_to("Become root", url('become_root'))}</li>
% endif
<li>${h.link_to("Messages{}".format(" ({})".format(inbox_count) if inbox_count else ''), url('messages.inbox'))}</li>
<li>${h.link_to("Change Password", url('change_password'))}</li>
<li>${h.link_to("Logout", url('logout'))}</li>
</ul>
</li>
% else:
<li>${h.link_to("Login", url('login'))}</li>
% endif
</%def>
<%def name="main_menu_items()">
% if request.has_any_perm('schedule.view', 'schedule.viewall', 'schedule.edit', 'scheduledshifts.list'):
<li>
<a>Time Clock</a>
<ul>
% if request.has_perm('schedule.view'):
<li>${h.link_to("Personal Schedule", url('schedule.employee'))}</li>
% endif
% if request.has_perm('schedule.viewall'):
<li>${h.link_to("Full Schedule", url('schedule'))}</li>
% endif
% if request.has_perm('schedule.edit'):
<li>${h.link_to("Edit Schedule", url('schedule.edit'))}</li>
% endif
% if request.has_perm('scheduledshifts.list'):
<li>${h.link_to("Raw Scheduled Shifts", url('scheduledshifts'))}</li>
% endif
</ul>
</li>
% endif
% if request.rattail_config.getbool('tailbone', 'menus.simple', default=False):
${self.make_simple_menu()}
% else:
% if request.has_any_perm('products.list', 'vendors.list', 'departments.list', 'subdepartments.list', 'brands.list', 'families.list', 'reportcodes.list'):
<li>
<a>Products</a>
<ul>
% if request.has_perm('products.list'):
<li>${h.link_to("Products", url('products'))}</li>
% endif
% if request.has_perm('vendors.list'):
<li>${h.link_to("Vendors", url('vendors'))}</li>
% endif
% if request.has_perm('departments.list'):
<li>${h.link_to("Departments", url('departments'))}</li>
% endif
% if request.has_perm('subdepartments.list'):
<li>${h.link_to("Subdepartments", url('subdepartments'))}</li>
% endif
% if request.has_perm('brands.list'):
<li>${h.link_to("Brands", url('brands'))}</li>
% endif
% if request.has_perm('families.list'):
<li>${h.link_to("Families", url('families'))}</li>
% endif
% if request.has_perm('reportcodes.list'):
<li>${h.link_to("Report Codes", url('reportcodes'))}</li>
% endif
</ul>
</li>
% endif
% if request.has_any_perm('people.list', 'customers.list', 'employees.list'):
<li>
<a>People</a>
<ul>
% if request.has_perm('people.list'):
<li>${h.link_to("All People", url('people'))}</li>
% endif
% if request.has_perm('customers.list'):
<li>${h.link_to("Customers", url('customers'))}</li>
% endif
% if request.has_perm('employees.list'):
<li>${h.link_to("Employees", url('employees'))}</li>
% endif
</ul>
</li>
% endif
% if request.has_any_perm('corepos.departments.list', 'corepos.subdepartments.list', 'corepos.vendors.list', 'corepos.products.list', 'corepos.customers.list', 'corepos.employees.list', 'corepos.transaction_details.list'):
<li>
<a>CORE-POS</a>
<ul>
% if request.has_perm('corepos.departments.list'):
<li>${h.link_to("Departments", url('corepos.departments'))}</li>
% endif
% if request.has_perm('corepos.subdepartments.list'):
<li>${h.link_to("Subdepartments", url('corepos.subdepartments'))}</li>
% endif
% if request.has_perm('corepos.vendors.list'):
<li>${h.link_to("Vendors", url('corepos.vendors'))}</li>
% endif
% if request.has_perm('corepos.products.list'):
<li>${h.link_to("Products", url('corepos.products'))}</li>
% endif
% if request.has_perm('corepos.customers.list'):
<li>${h.link_to("Customers", url('corepos.customers'))}</li>
% endif
% if request.has_perm('corepos.employees.list'):
<li>${h.link_to("Employees", url('corepos.employees'))}</li>
% endif
% if request.has_perm('corepos.transaction_details.list'):
<li>${h.link_to("Transaction Details", url('corepos.transaction_details'))}</li>
% endif
</ul>
</li>
% endif
% if request.has_any_perm('batch.handheld.list', 'batch.inventory.list', 'batch.importer.list'):
<li>
<a>Batches</a>
<ul>
% if request.has_perm('batch.handheld.list'):
<li>${h.link_to("Handheld", url('batch.handheld'))}</li>
% endif
% if request.has_perm('batch.inventory.list'):
<li>${h.link_to("Inventory", url('batch.inventory'))}</li>
% endif
% if request.has_perm('batch.importer.list'):
<li>${h.link_to("Import / Export", url('batch.importer'))}</li>
% endif
</ul>
</li>
% endif
% if request.has_any_perm('tempmon.clients.list', 'tempmon.probes.list', 'tempmon.readings.list'):
<li>
<a>TempMon</a>
<ul>
% if request.has_perm('tempmon.clients.list'):
<li>${h.link_to("Clients", url('tempmon.clients'))}</li>
% endif
% if request.has_perm('tempmon.probes.list'):
<li>${h.link_to("Probes", url('tempmon.probes'))}</li>
% endif
% if request.has_perm('tempmon.readings.list'):
<li>${h.link_to("Readings", url('tempmon.readings'))}</li>
% endif
</ul>
</li>
% endif
% if request.has_any_perm('stores.list', 'users.list', 'userevents.list', 'roles.list', 'emailprofiles.list', 'datasync.list', 'settings.list', 'upgrades.list'):
% if request.has_any_perm('users.list', 'roles.list', 'settings.list', 'upgrades.list'):
<li>
<a>Admin</a>
<ul>
% if request.has_perm('stores.list'):
<li>${h.link_to("Stores", url('stores'))}</li>
% endif
% if request.has_perm('users.list'):
<li>${h.link_to("Users", url('users'))}</li>
% endif
% if request.has_perm('userevents.list'):
<li>${h.link_to("User Events", url('userevents'))}</li>
% endif
% if request.has_perm('roles.list'):
<li>${h.link_to("Roles", url('roles'))}</li>
% endif
% if request.has_perm('emailprofiles.list'):
<li>${h.link_to("Email Settings", url('emailprofiles'))}</li>
% endif
% if request.has_perm('settings.list'):
<li>${h.link_to("Raw Settings", url('settings'))}</li>
% endif
% if request.has_perm('datasync.list'):
<li>${h.link_to("DataSync Changes", url('datasyncchanges'))}</li>
% endif
% if request.has_perm('upgrades.list'):
<li>${h.link_to("Rattail Demo Upgrades", url('upgrades'))}</li>
% endif
@ -181,4 +78,5 @@
<li>${h.link_to("Login", url('login'))}</li>
% endif
% endif
</%def>

View file

@ -1,170 +1,67 @@
## -*- coding: utf-8; -*-
<%def name="main_menu_items()">
<%def name="make_simple_menu()">
<div class="navbar-start">
## Time Clock
% if request.has_any_perm('schedule.view', 'schedule.viewall', 'schedule.edit', 'scheduledshifts.list'):
% for topitem in menus:
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">Time Clock</a>
<a class="navbar-link">${topitem.title}</a>
<div class="navbar-dropdown">
% if request.has_perm('schedule.view'):
${h.link_to("Personal Schedule", url('schedule.employee'), class_='navbar-item')}
% endif
% if request.has_perm('schedule.viewall'):
${h.link_to("Full Schedule", url('schedule'), class_='navbar-item')}
% endif
% if request.has_perm('schedule.edit'):
${h.link_to("Edit Schedule", url('schedule.edit'), class_='navbar-item')}
% endif
% if request.has_perm('scheduledshifts.list'):
${h.link_to("Raw Scheduled Shifts", url('scheduledshifts'), class_='navbar-item')}
% endif
% for subitem in topitem.items:
${h.link_to(subitem.title, subitem.url, class_='navbar-item root-user')}
% endfor
</div>
</div>
% endfor
</div><!-- navbar-start -->
<div class="navbar-end">
## User Menu
% if request.user:
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link ${'root-user' if request.is_root else ''}">${request.user}${" ({})".format(inbox_count) if inbox_count else ''}</a>
<div class="navbar-dropdown">
% if request.is_root:
${h.link_to("Stop being root", url('stop_root'), class_='navbar-item root-user')}
% elif request.is_admin:
${h.link_to("Become root", url('become_root'), class_='navbar-item root-user')}
% endif
${h.link_to("Messages{}".format(" ({})".format(inbox_count) if inbox_count else ''), url('messages.inbox'), class_='navbar-item')}
${h.link_to("Change Password", url('change_password'), class_='navbar-item')}
${h.link_to("Logout", url('logout'), class_='navbar-item')}
</div>
</div>
% else:
${h.link_to("Login", url('login'), class_='navbar-item')}
% endif
## Products
% if request.has_any_perm('products.list', 'vendors.list', 'departments.list', 'subdepartments.list', 'brands.list', 'families.list', 'reportcodes.list'):
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">Products</a>
<div class="navbar-dropdown">
% if request.has_perm('products.list'):
${h.link_to("Products", url('products'), class_='navbar-item')}
% endif
% if request.has_perm('vendors.list'):
${h.link_to("Vendors", url('vendors'), class_='navbar-item')}
% endif
% if request.has_perm('departments.list'):
${h.link_to("Departments", url('departments'), class_='navbar-item')}
% endif
% if request.has_perm('subdepartments.list'):
${h.link_to("Subdepartments", url('subdepartments'), class_='navbar-item')}
% endif
% if request.has_perm('brands.list'):
${h.link_to("Brands", url('brands'), class_='navbar-item')}
% endif
% if request.has_perm('families.list'):
${h.link_to("Families", url('families'), class_='navbar-item')}
% endif
% if request.has_perm('reportcodes.list'):
${h.link_to("Report Codes", url('reportcodes'), class_='navbar-item')}
% endif
</div>
</div>
% endif
</div><!-- navbar-end -->
</%def>
## People
% if request.has_any_perm('people.list', 'customers.list', 'employees.list'):
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">People</a>
<div class="navbar-dropdown">
% if request.has_perm('people.list'):
${h.link_to("All People", url('people'), class_='navbar-item')}
% endif
% if request.has_perm('customers.list'):
${h.link_to("Customers", url('customers'), class_='navbar-item')}
% endif
% if request.has_perm('employees.list'):
${h.link_to("Employees", url('employees'), class_='navbar-item')}
% endif
</div>
</div>
% endif
<%def name="main_menu_items()">
## CORE-POS
% if request.has_any_perm('corepos.departments.list', 'corepos.subdepartments.list', 'corepos.vendors.list', 'corepos.products.list', 'corepos.customers.list', 'corepos.employees.list', 'corepos.transaction_details.list'):
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">CORE-POS</a>
<div class="navbar-dropdown">
% if request.has_perm('corepos.departments.list'):
${h.link_to("Departments", url('corepos.departments'), class_='navbar-item')}
% endif
% if request.has_perm('corepos.subdepartments.list'):
${h.link_to("Subdepartments", url('corepos.subdepartments'), class_='navbar-item')}
% endif
% if request.has_perm('corepos.vendors.list'):
${h.link_to("Vendors", url('corepos.vendors'), class_='navbar-item')}
% endif
% if request.has_perm('corepos.products.list'):
${h.link_to("Products", url('corepos.products'), class_='navbar-item')}
% endif
% if request.has_perm('corepos.customers.list'):
${h.link_to("Customers", url('corepos.customers'), class_='navbar-item')}
% endif
% if request.has_perm('corepos.employees.list'):
${h.link_to("Employees", url('corepos.employees'), class_='navbar-item')}
% endif
% if request.has_perm('corepos.transaction_details.list'):
${h.link_to("Transaction Details", url('corepos.transaction_details'), class_='navbar-item')}
% endif
</div>
</div>
% endif
% if request.rattail_config.getbool('tailbone', 'menus.simple', default=False):
${self.make_simple_menu()}
% else:
## Batches
% if request.has_any_perm('batch.handheld.list', 'batch.inventory.list', 'batch.importer.list'):
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">Batches</a>
<div class="navbar-dropdown">
% if request.has_perm('batch.handheld.list'):
${h.link_to("Handheld", url('batch.handheld'), class_='navbar-item')}
% endif
% if request.has_perm('batch.inventory.list'):
${h.link_to("Inventory", url('batch.inventory'), class_='navbar-item')}
% endif
% if request.has_perm('batch.importer.list'):
${h.link_to("Import / Export", url('batch.importer'), class_='navbar-item')}
% endif
</div>
</div>
% endif
## TempMon
% if request.has_any_perm('tempmon.clients.list', 'tempmon.probes.list', 'tempmon.readings.list'):
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">TempMon</a>
<div class="navbar-dropdown">
% if request.has_perm('tempmon.clients.list'):
${h.link_to("Clients", url('tempmon.clients'), class_='navbar-item')}
% endif
% if request.has_perm('tempmon.probes.list'):
${h.link_to("Probes", url('tempmon.probes'), class_='navbar-item')}
% endif
% if request.has_perm('tempmon.readings.list'):
${h.link_to("Readings", url('tempmon.readings'), class_='navbar-item')}
% endif
</div>
</div>
% endif
<div class="navbar-start">
## Admin
% if request.has_any_perm('stores.list', 'users.list', 'userevents.list', 'roles.list', 'emailprofiles.list', 'datasync.list', 'settings.list', 'upgrades.list'):
% if request.has_any_perm('users.list', 'roles.list', 'settings.list', 'upgrades.list'):
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">Admin</a>
<div class="navbar-dropdown">
% if request.has_perm('stores.list'):
${h.link_to("Stores", url('stores'), class_='navbar-item')}
% endif
% if request.has_perm('users.list'):
${h.link_to("Users", url('users'), class_='navbar-item')}
% endif
% if request.has_perm('userevents.list'):
${h.link_to("User Events", url('userevents'), class_='navbar-item')}
% endif
% if request.has_perm('roles.list'):
${h.link_to("Roles", url('roles'), class_='navbar-item')}
% endif
% if request.has_perm('emailprofiles.list'):
${h.link_to("Email Settings", url('emailprofiles'), class_='navbar-item')}
% endif
% if request.has_perm('settings.list'):
${h.link_to("Raw Settings", url('settings'), class_='navbar-item')}
% endif
% if request.has_perm('datasync.list'):
${h.link_to("DataSync Changes", url('datasyncchanges'), class_='navbar-item')}
% endif
% if request.has_perm('upgrades.list'):
${h.link_to("Rattail Demo Upgrades", url('upgrades'), class_='navbar-item')}
% endif
@ -195,4 +92,6 @@
% endif
</div><!-- navbar-end -->
% endif
</%def>