Use handler to build menus

This commit is contained in:
Lance Edgar 2023-01-14 16:13:58 -06:00
parent 6a8096391f
commit 316bdfe1aa
2 changed files with 327 additions and 323 deletions

View file

@ -20,7 +20,7 @@ class DemoConfigExtension(ConfigExtension):
config.setdefault('rattail', 'model', 'rattail_demo.db.model') config.setdefault('rattail', 'model', 'rattail_demo.db.model')
config.setdefault('rattail.trainwreck', 'model', 'rattail.trainwreck.db.model.defaults') config.setdefault('rattail.trainwreck', 'model', 'rattail.trainwreck.db.model.defaults')
config.setdefault('rattail.mail', 'emails', 'rattail_demo.emails') config.setdefault('rattail.mail', 'emails', 'rattail_demo.emails')
config.setdefault('tailbone', 'menus', 'rattail_demo.web.menus') config.setdefault('tailbone.menus', 'handler', 'rattail_demo.web.menus:DemoMenuHandler')
# default app handlers # default app handlers
config.setdefault('rattail', 'products.handler', 'rattail_corepos.products:CoreProductsHandler') config.setdefault('rattail', 'products.handler', 'rattail_corepos.products:CoreProductsHandler')

View file

@ -3,343 +3,347 @@
Web Menus Web Menus
""" """
from tailbone import menus as base
from tailbone_corepos.menus import make_corepos_menu from tailbone_corepos.menus import make_corepos_menu
def simple_menus(request): class DemoMenuHandler(base.MenuHandler):
url = request.route_url """
rattail_config = request.rattail_config Demo menu handler
"""
people_menu = { def make_menus(self, request, **kwargs):
'title': "People",
'type': 'menu',
'items': [
{
'title': "Members",
'route': 'members',
'perm': 'members.list',
},
{
'title': "Customers",
'route': 'customers',
'perm': 'customers.list',
},
{
'title': "Employees",
'route': 'employees',
'perm': 'employees.list',
},
{
'title': "All People",
'route': 'people',
'perm': 'people.list',
},
],
}
products_menu = { people_menu = {
'title': "Products", 'title': "People",
'type': 'menu', 'type': 'menu',
'items': [ 'items': [
{ {
'title': "Products", 'title': "Members",
'route': 'products', 'route': 'members',
'perm': 'products.list', 'perm': 'members.list',
}, },
{ {
'title': "Departments", 'title': "Customers",
'route': 'departments', 'route': 'customers',
'perm': 'departments.list', 'perm': 'customers.list',
}, },
{ {
'title': "Subdepartments", 'title': "Employees",
'route': 'subdepartments', 'route': 'employees',
'perm': 'subdepartments.list', 'perm': 'employees.list',
}, },
{ {
'title': "Brands", 'title': "All People",
'route': 'brands', 'route': 'people',
'perm': 'brands.list', 'perm': 'people.list',
}, },
{ ],
'title': "Families", }
'route': 'families',
'perm': 'families.list',
},
{
'title': "Report Codes",
'route': 'reportcodes',
'perm': 'reportcodes.list',
},
{
'title': "Units of Measure",
'route': 'uoms',
'perm': 'uoms.list',
},
],
}
vendors_menu = { products_menu = {
'title': "Vendors", 'title': "Products",
'type': 'menu', 'type': 'menu',
'items': [ 'items': [
{ {
'title': "Vendors", 'title': "Products",
'route': 'vendors', 'route': 'products',
'perm': 'vendors.list', 'perm': 'products.list',
}, },
{'type': 'sep'}, {
{ 'title': "Departments",
'title': "Ordering", 'route': 'departments',
'route': 'ordering', 'perm': 'departments.list',
'perm': 'ordering.list', },
}, {
{ 'title': "Subdepartments",
'title': "Receiving", 'route': 'subdepartments',
'route': 'receiving', 'perm': 'subdepartments.list',
'perm': 'receiving.list', },
}, {
{'type': 'sep'}, 'title': "Brands",
{ 'route': 'brands',
'title': "Purchases", 'perm': 'brands.list',
'route': 'purchases', },
'perm': 'purchases.list', {
}, 'title': "Families",
{ 'route': 'families',
'title': "Credits", 'perm': 'families.list',
'route': 'purchases.credits', },
'perm': 'purchases.credits.list', {
}, 'title': "Report Codes",
], 'route': 'reportcodes',
} 'perm': 'reportcodes.list',
},
{
'title': "Units of Measure",
'route': 'uoms',
'perm': 'uoms.list',
},
],
}
corepos_menu = make_corepos_menu(request) vendors_menu = {
'title': "Vendors",
'type': 'menu',
'items': [
{
'title': "Vendors",
'route': 'vendors',
'perm': 'vendors.list',
},
{'type': 'sep'},
{
'title': "Ordering",
'route': 'ordering',
'perm': 'ordering.list',
},
{
'title': "Receiving",
'route': 'receiving',
'perm': 'receiving.list',
},
{'type': 'sep'},
{
'title': "Purchases",
'route': 'purchases',
'perm': 'purchases.list',
},
{
'title': "Credits",
'route': 'purchases.credits',
'perm': 'purchases.credits.list',
},
],
}
shopfoo_menu = { corepos_menu = make_corepos_menu(request)
'title': "Shopfoo",
'type': 'menu',
'items': [
{
'title': "Products",
'route': 'shopfoo.products',
'perm': 'shopfoo.products.list',
},
{
'title': "Product Exports",
'route': 'shopfoo.product_exports',
'perm': 'shopfoo.product_exports.list',
},
{'type': 'sep'},
{
'title': "WooCommerce Products",
'route': 'woocommerce.products',
'perm': 'woocommerce.products.list',
},
],
}
reporting_menu = { shopfoo_menu = {
'title': "Reporting", 'title': "Shopfoo",
'type': 'menu', 'type': 'menu',
'items': [ 'items': [
{ {
'title': "New Report", 'title': "Products",
'route': 'report_output.create', 'route': 'shopfoo.products',
'perm': 'report_output.create', 'perm': 'shopfoo.products.list',
}, },
{ {
'title': "Generated Reports", 'title': "Product Exports",
'route': 'report_output', 'route': 'shopfoo.product_exports',
'perm': 'report_output.list', 'perm': 'shopfoo.product_exports.list',
}, },
{ {'type': 'sep'},
'title': "Problem Reports", {
'route': 'problem_reports', 'title': "WooCommerce Products",
'perm': 'problem_reports.list', 'route': 'woocommerce.products',
}, 'perm': 'woocommerce.products.list',
], },
} ],
}
batch_menu = { reporting_menu = {
'title': "Batches", 'title': "Reporting",
'type': 'menu', 'type': 'menu',
'items': [ 'items': [
{ {
'title': "Handheld", 'title': "New Report",
'route': 'batch.handheld', 'route': 'report_output.create',
'perm': 'batch.handheld.list', 'perm': 'report_output.create',
}, },
{ {
'title': "Inventory", 'title': "Generated Reports",
'route': 'batch.inventory', 'route': 'report_output',
'perm': 'batch.inventory.list', 'perm': 'report_output.list',
}, },
{ {
'title': "Import / Export", 'title': "Problem Reports",
'route': 'batch.importer', 'route': 'problem_reports',
'perm': 'batch.importer.list', 'perm': 'problem_reports.list',
}, },
], ],
} }
trainwreck_menu = { batch_menu = {
'title': "Trainwreck", 'title': "Batches",
'type': 'menu', 'type': 'menu',
'items': [ 'items': [
{ {
'title': "Transactions", 'title': "Handheld",
'route': 'trainwreck.transactions', 'route': 'batch.handheld',
'perm': 'trainwreck.transactions.list', 'perm': 'batch.handheld.list',
}, },
], {
} 'title': "Inventory",
'route': 'batch.inventory',
'perm': 'batch.inventory.list',
},
{
'title': "Import / Export",
'route': 'batch.importer',
'perm': 'batch.importer.list',
},
],
}
tempmon_menu = { trainwreck_menu = {
'title': "TempMon", 'title': "Trainwreck",
'type': 'menu', 'type': 'menu',
'items': [ 'items': [
{ {
'title': "Appliances", 'title': "Transactions",
'route': 'tempmon.appliances', 'route': 'trainwreck.transactions',
'perm': 'tempmon.appliances.list', 'perm': 'trainwreck.transactions.list',
}, },
{ ],
'title': "Clients", }
'route': 'tempmon.clients',
'perm': 'tempmon.clients.list',
},
{
'title': "Probes",
'route': 'tempmon.probes',
'perm': 'tempmon.probes.list',
},
{
'title': "Readings",
'route': 'tempmon.readings',
'perm': 'tempmon.readings.list',
},
],
}
other_menu = { tempmon_menu = {
'title': "Other", 'title': "TempMon",
'type': 'menu', 'type': 'menu',
'items': [ 'items': [
{ {
'title': "Documentation", 'title': "Appliances",
'url': 'https://rattailproject.org/moin/RattailDemo', 'route': 'tempmon.appliances',
'target': '_blank', 'perm': 'tempmon.appliances.list',
}, },
{ {
'title': "Source Code", 'title': "Clients",
'url': 'https://kallithea.rattailproject.org/rattail-project/rattail-demo', 'route': 'tempmon.clients',
'target': '_blank', 'perm': 'tempmon.clients.list',
}, },
{ {
'title': "RattailProject.org", 'title': "Probes",
'url': 'https://rattailproject.org', 'route': 'tempmon.probes',
'target': '_blank', 'perm': 'tempmon.probes.list',
}, },
{'type': 'sep'}, {
{ 'title': "Readings",
'title': "Generate New Project", 'route': 'tempmon.readings',
'route': 'generate_project', 'perm': 'tempmon.readings.list',
'perm': 'common.generate_project', },
}, ],
], }
}
admin_menu = { other_menu = {
'title': "Admin", 'title': "Other",
'type': 'menu', 'type': 'menu',
'items': [ 'items': [
{ {
'title': "Stores", 'title': "Documentation",
'route': 'stores', 'url': 'https://rattailproject.org/moin/RattailDemo',
'perm': 'stores.list', 'target': '_blank',
}, },
{ {
'title': "Users", 'title': "Source Code",
'route': 'users', 'url': 'https://kallithea.rattailproject.org/rattail-project/rattail-demo',
'perm': 'users.list', 'target': '_blank',
}, },
{ {
'title': "User Events", 'title': "RattailProject.org",
'route': 'userevents', 'url': 'https://rattailproject.org',
'perm': 'userevents.list', 'target': '_blank',
}, },
{ {'type': 'sep'},
'title': "Roles", {
'route': 'roles', 'title': "Generate New Project",
'perm': 'roles.list', 'route': 'generate_project',
}, 'perm': 'common.generate_project',
{'type': 'sep'}, },
{ ],
'title': "App Settings", }
'route': 'appsettings',
'perm': 'settings.list',
},
{
'title': "Email Settings",
'route': 'emailprofiles',
'perm': 'emailprofiles.list',
},
{
'title': "Email Attempts",
'route': 'email_attempts',
'perm': 'email_attempts.list',
},
{
'title': "Raw Settings",
'route': 'settings',
'perm': 'settings.list',
},
{'type': 'sep'},
{
'title': "DataSync Changes",
'route': 'datasyncchanges',
'perm': 'datasync_changes.list',
},
{
'title': "DataSync Status",
'route': 'datasync.status',
'perm': 'datasync.status',
},
{
'title': "Luigi Tasks",
'route': 'luigi',
'perm': 'luigi.list',
},
{
'title': "Tables",
'route': 'tables',
'perm': 'tables.list',
},
{
'title': "Upgrades",
'route': 'upgrades',
'perm': 'upgrades.list',
},
],
}
menus = [ admin_menu = {
people_menu, 'title': "Admin",
products_menu, 'type': 'menu',
vendors_menu, 'items': [
corepos_menu, {
shopfoo_menu, 'title': "Stores",
reporting_menu, 'route': 'stores',
batch_menu, 'perm': 'stores.list',
] },
{
'title': "Users",
'route': 'users',
'perm': 'users.list',
},
{
'title': "User Events",
'route': 'userevents',
'perm': 'userevents.list',
},
{
'title': "Roles",
'route': 'roles',
'perm': 'roles.list',
},
{'type': 'sep'},
{
'title': "App Settings",
'route': 'appsettings',
'perm': 'settings.list',
},
{
'title': "Email Settings",
'route': 'emailprofiles',
'perm': 'emailprofiles.list',
},
{
'title': "Email Attempts",
'route': 'email_attempts',
'perm': 'email_attempts.list',
},
{
'title': "Raw Settings",
'route': 'settings',
'perm': 'settings.list',
},
{'type': 'sep'},
{
'title': "DataSync Changes",
'route': 'datasyncchanges',
'perm': 'datasync_changes.list',
},
{
'title': "DataSync Status",
'route': 'datasync.status',
'perm': 'datasync.status',
},
{
'title': "Luigi Tasks",
'route': 'luigi',
'perm': 'luigi.list',
},
{
'title': "Tables",
'route': 'tables',
'perm': 'tables.list',
},
{
'title': "Upgrades",
'route': 'upgrades',
'perm': 'upgrades.list',
},
],
}
if rattail_config.trainwreck_engine: menus = [
menus.append(trainwreck_menu) people_menu,
products_menu,
vendors_menu,
corepos_menu,
shopfoo_menu,
reporting_menu,
batch_menu,
]
menus.extend([ if self.config.trainwreck_engine:
tempmon_menu, menus.append(trainwreck_menu)
other_menu,
admin_menu,
])
return menus menus.extend([
tempmon_menu,
other_menu,
admin_menu,
])
return menus