/
Menu Builder Script

Menu Builder Script

This script processes a solution.json file and combines the menus key from multiple module JSON files to build a complete menu structure (TO-DO: generation of openimis.json and merging roles to apply them in migration). The resulting menu is sorted by position at both the menu and submenu levels. The script outputs a new file named generated-menu.json containing the combined and sorted menu structure. This file can be pasted as a part of fe-core configuration. It can be changed either on database level or in django administration panel as superuser.

How It Works

  1. Input File:

    • The script reads solution.json from the current working directory.

    • The solution.json file should have a modules key containing a list of module file names (e.g., client-management.jsonuser-management.json, etc.).

  2. Module Files:

    • Each module file listed under the modules key should be present in the same directory as solution.json.

    • Each module file should contain a menus key, which defines its menu structure.

  3. Combining Menus:

    • The script reads all the module files, extracts their menus, and combines them.

    • Both menus and their submenus are sorted by the position field.

  4. Missing Files:

    • If any module file is missing, the script will print a warning but will continue processing the rest.

  5. Output File:

    • The script generates a generated-solution.json file in the same directory as the input files. This file contains the combined and sorted menu structure.

How to Use

Prerequisites

  • Python 3.x installed on your system.

Steps

  1. Prepare solution.json:

    • Create a file named solution.json in the directory where you will run the script.

    • Add a modules key listing all the module files you want to include. Example:

      { "modules": [ "client-management.json", "user-management.json", "grievance.json", "social-protection.json", "core.json" ] }
  2. Prepare Module Files:

    • Place all the module files listed in solution.json in the same directory. Each file should have a structure similar to the example below:

      { "menus": [ { "position": 1, "id": "MainMenu", "name": "Main", "icon": "main-icon", "description": "Main menu", "submenus": [ { "position": 1, "id": "submenu1" }, { "position": 2, "id": "submenu2" } ] } ] }
  3. Run the Script:

    • Save the script as menu_builder.py in the same directory as solution.json and the module files.

    • Open a terminal or command prompt and navigate to the directory.

    • Run the script using the command:

      python menu_builder.py
  4. View the Output:

    • After the script completes, a new file named generated-solution.json will be created in the same directory.

    • This file contains the combined and sorted menu structure.

Example Directory Structure

Notes

 

Did you encounter a problem or do you have a suggestion?

Please contact our Service Desk



This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. https://creativecommons.org/licenses/by-sa/4.0/