0.0.4 • Published 5 years ago

grfiltermenubyid v0.0.4

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

grFilterMenuById

Recebe um JSON para menu e um array de ID, retorna o JSON aplicando o filtro e mantendo toda a estrutura para menu.

####Instalação 

npm install grfiltermenubyid

####Teste 

const grFilterMenuById = require('grfiltermenubyid')

const menuFull = [
    {
        id: 1,
        title: 'Sistema',
        icon: 'gear',
        text: 'Sistema',
        subItem: [
            {
                id: 2,
                link: '/usuario',
                title: 'Usuários',
                icon: 'user',
                text: 'Usuários',
                subItem: [],
            },
            {
                id: 3,
                link: '/grupo',
                title: 'Grupos',
                icon: 'group',
                text: 'Grupos',
                subItem: [],
                subItem: [
                    {
                        id: 222,
                        link: '/usuario',
                        title: 'xxxxxx',
                        icon: 'user',
                        text: 'xxxxxx',
                        subItem: [],
                    },
                    {
                        id: 223,
                        link: '/aaaaa',
                        title: 'xx',
                        icon: 'user',
                        text: 'xxxxxx',
                        subItem: [],
                    }
                ]
            }
        ]
    },

    {
        id: 5,
        title: 'Cadastros',
        icon: 'pencil-square-o',
        text: 'Cadastros',
        subItem: [
            {
                id: 6,
                link: '/pessoa',
                title: 'Pessoas',
                icon: 'user',
                text: 'Pessoas',
                subItem: [],
            },
            {
                id: 7,
                link: '/teste',
                title: 'teste',
                icon: 'user',
                text: 'Teste',
                subItem: [],
            }
        ]
    }
]

const permissions = [222]

let result = grFilterMenuById(menuFull, permissions)

console.log(JSON.stringify(result, 0, 3))

// Resultado:

[
   {
      "id": 1,
      "title": "Sistema",
      "icon": "gear",
      "text": "Sistema",
      "subItem": [
         null,
         {
            "id": 3,
            "link": "/grupo",
            "title": "Grupos",
            "icon": "group",
            "text": "Grupos",
            "subItem": [
               {
                  "id": 222,
                  "link": "/usuario",
                  "title": "xxxxxx",
                  "icon": "user",
                  "text": "xxxxxx",
                  "subItem": []
               },
               null
            ]
         }
      ]
   },
   {
      "id": 5,
      "title": "Cadastros",
      "icon": "pencil-square-o",
      "text": "Cadastros",
      "subItem": [
         {
            "id": 6,
            "link": "/pessoa",
            "title": "Pessoas",
            "icon": "user",
            "text": "Pessoas",
            "subItem": []
         },
         null
      ]
   }
]
0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago