-
Notifications
You must be signed in to change notification settings - Fork 0
Navigation
The backend administration of ez-on-rails has a navbar on the top of the page. This navbar is meant to provide a navigation to all manageable scaffolds and administration areas like the user management.
The menu structure only has a main menu level and submenu level. Each submenu is shown as collapsable dropdown navigation.
The navigation can be automaticly generated using the eznav generator. In this case, every action that is found will be located in the menu, by the following rules:
- If the generator finds actions located in controllers that are not using namespaces, the actions will be located in the main menu level
- If the generator finds actions located in controllers that are using namespaces, a submenu will be created and all actions of the controller will be shown in the submenu
- If the generator finds a scaffold, meaing a resource having the default rest routes, it will only create a navigation entry to the index action. From there you should be able to navigate to the new, managemet and show pages. This will work with namespaces and non namespaced scaffolds. Like the default actions, the namespaced actions will be located in a submenu.
The information what navigation entries are available in your application, ez-on-rails provides a file called menu_structure_helper.rb. This is located in app/helpers/ez_on_rails/. If you want to change the menu structure without using the generator or you may want to change some details, you can manipulate the file here. The eznav generator will not change menu entries that already exists. Hence you can change the entries here and your changes will not be affected by calling the eznav generator again. See the [following section(## The menu structure helper) to learn more about changing the navigation structure yourself.
The file app/helpers/ez_on_rails/menu_structure_helper.rb provides the method menu_structure that returns a hash of menu entries the application uses in the navigation bar of the backend views.
Those hash has the following exemplary structure:
{
main_menus: [
{
controller: 'ez_on_rails/welcome',
action: 'index',
label: t(:welcome_title),
invisible: true
},
{
controller: 'articles',
action: 'index',
label: Article.model_name.human(count: 2),
invisible: false
}
{
namespace: 'configuration',
label: t(:confirguation),
sub_menus: [
{
controller: 'articles',
action: 'index',
label: t(:'articles.confirguation'),
invisible: false
},
{
controller: 'app',
action: 'index',
label: t(:'app.confirguation'),
invisible: false
}
]
}
]
}
main_menus is an array of hashes holding all menu entries of the first level. This is the bar you see on the top.__ Every hash can either have the controller, action, label and invisible option to define the action that is called if the user clicks the button, or can have the sub_menus option that holds also menu entries with the options to define the action.
The controller and action refer to the rails target controller and action that is called on click.
The label defines the title the button has.
The invisible action indicates that this action should not be shown in the menu. This is needed for the ezdev generator. If you use the generator, already existing routes will be identified and not be added again. If you would only remove the entry to hide it, the entry would be added on every call of the generator. Hence just leave the entry present and add the invisible flag to hide it.
The sub menu entry of the main menu also has the namespace property, that defines the rails namespace the target controllers and actions are located in.
The sub_menus are just the same items like the main menu items, but note that you can not nest sub menus into sub menus.
Es handelt sich also um ein Objekt, dass den main_menus enthält.
The navigation is rendered using a partial in the ez-on-rails engine. If you want to change those you have to eject the partial using the (ezviews generator)[https://github.com/D4uS1/ez-on-rails/wiki/ezviews]. This will copy all partials used by the ez-on-rails engine to your main application. Since rails main application sources will be prioritized, you can override the engines partials by changing the copied ones. If you do so, you can change the navigation bar in the _app/views/ez_on_rails/shared/navigation.html.slim file.