Sha256: 02aed393d1d203aa4de39c692fa25b417a78f2adce75183e38782d8c14a069bd
Contents?: true
Size: 1.04 KB
Versions: 8
Compression:
Stored size: 1.04 KB
Contents
module Mks module Auth class MenusController < ApplicationController before_action :set_user, only: [:menus] def menus roles = @user.roles.joins(:application_module) .where('mks_auth_application_modules.code = ?', params[:app_module]) menus = [] menu_list = roles.inject([]) { |items, r| items += r.menus }.uniq parents = menu_list.select { |menu| menu.parent.nil? } parents.each do |parent| children = (menu_list.select { |menu| menu.parent == parent }).uniq .map { |menu| { 'text': menu.text, 'location': menu.location, 'iconCls': menu.icon_cls } } menus << { 'text': parent.text, 'className': parent.class_name, 'iconCls': parent.icon_cls, children: children } end render json: { success: true, data: menus } end private def set_user @user = User.find(params[:id]) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems