Sha256: 65e1d507dea00d4f78ada29fa2ae08d8fdd1287e8e058658dc2d128492e24e20
Contents?: true
Size: 1.05 KB
Versions: 3
Compression:
Stored size: 1.05 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.includes(:parent) }.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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mks_auth-1.0.14 | app/controllers/mks/auth/menus_controller.rb |
mks_auth-1.0.13 | app/controllers/mks/auth/menus_controller.rb |
mks_auth-1.0.12 | app/controllers/mks/auth/menus_controller.rb |