'use strict';

var mean = require('meanio');

module.exports = function(System, app, auth, database) {

    app.route('/admin/menu/:name')
        .get(function(req, res) {
            var roles = (req.user ? req.user.roles : ['anonymous']);
            var menu = req.params.name ? req.params.name : 'main';
            var defaultMenu = (req.query.defaultMenu ? req.query.defaultMenu : []);

            defaultMenu.forEach(function(item, index) {
                defaultMenu[index] = JSON.parse(item);
            });

            var items = mean.menus.get({
                roles: roles,
                menu: menu,
                defaultMenu: defaultMenu
            });

            res.json(items);
        });

};

@@ -190,17 +190,16 @@
 roles = 
-(
 req.user
@@ -231,17 +231,16 @@
 nymous'%5D
-)
 ;%0A      
@@ -276,27 +276,10 @@
 ame 
-? req.params.name :
+%7C%7C
  'ma
@@ -313,17 +313,16 @@
 tMenu = 
-(
 req.quer
@@ -339,37 +339,13 @@
 enu 
-? req.query.defaultMenu :
+%7C%7C
  %5B%5D
-)
 ;%0A%0A 
@@ -359,121 +359,68 @@
     
-defaultMenu.forEach(function(item, index) %7B%0A                defaultMenu%5Bindex%5D = JSON.parse(item);%0A            %7D)
+if (!Array.isArray(defaultMenu)) defaultMenu = %5BdefaultMenu%5D
 ;%0A%0A 
@@ -557,16 +557,101 @@
 aultMenu
+.map(function(item) %7B%0A                    return JSON.parse(item);%0A                %7D)
 %0A       
@@ -701,12 +701,11 @@
     %7D);%0A
-%0A
 %7D;%0A

fix #605 allow for single menu object instead of array