<commit_before>module WulinMaster
  class HomeController < ApplicationController  
    self.view_paths = [File.join(Rails.root, 'app', 'views'), File.join(File.dirname(__FILE__), '..', '..', 'views')]
    
    def change_password
      if defined?(WulinOAuth) 
        if request.post?
          response = HTTParty.post(WulinOAuth.configuration['change_password_uri'], :body => { :user => {
            :email => User.current_user.email,
            :current_password => params[:current_password], 
            :password => params[:password], 
            :password_confirmation => params[:password_confirmation]}}
          )
          render text: response
        else
          begin
            render 'change_password', layout: false
          rescue ActionView::MissingTemplate
            render '/change_password', layout: false
          end
        end
      else
        render text: "WulinOAuth is not install, Install it first!"
      end
    end

    def index
      dashboard if self.respond_to?(:dashboard)
      respond_to do |format|
        format.html do
          if request.xhr?
            begin
              render :template => 'homepage/dashboard', :layout => false
            rescue
              render :text => ''
            end
          else
            begin
              render 'index'
            rescue ActionView::MissingTemplate
              render '/home'
            end
          end
        end
      end
    end
    
    class << self
      attr_accessor :menu_block, :menu, :context

      # Menu definition
      def menu(&block)
        @menu_block = block
      end

      # Called within the block
      def submenu(title=nil)
        if block_given?
          @submenu = SubMenu.new(title)
          yield
          @menu << @submenu if @submenu.size > 0
          @submenu = nil
        end 
        return @submenu   
      end

      def item(title_or_screen_class, options={})
        return unless @menu
        title = options[:label] ||
                (title_or_screen_class.respond_to?(:title) ? title_or_screen_class.title : title_or_screen_class.to_s)
        path = options[:url] ||
               (title_or_screen_class.respond_to?(:path) ? title_or_screen_class.path : '/')
        if options[:authorized?]
          if options[:authorized?].kind_of?(Proc)
            is_authorized = (context && context.respond_to?(:current_user)) ? options[:authorized?].call(context.current_user) : options[:authorized?].call(nil)
            return unless is_authorized
          else
            return unless (is_authorized == true)
          end
        elsif title_or_screen_class.kind_of?(Class)
          screen_instance = title_or_screen_class.new(options, context) if title_or_screen_class.kind_of?(Class)
          path = screen_instance.path
          if screen_instance.respond_to?(:authorized?)
            is_authorized = (context && context.respond_to?(:current_user)) ? screen_instance.authorized?(context.current_user) : screen_instance.authorized?(nil)
            return unless is_authorized
          end
        end
        if @submenu
          @submenu << MenuEntry.new(title, path)
        else
          @menu << MenuEntry.new(title, path)
        end
      end
      
      def get_menu
        @menu
      end
    end

    # Generate menu
    def menu<commit_msg>BUG 1h - fixed the menu item path when there is authorized? option<commit_after>module WulinMaster
  class HomeController < ApplicationController  
    self.view_paths = [File.join(Rails.root, 'app', 'views'), File.join(File.dirname(__FILE__), '..', '..', 'views')]
    
    def change_password
      if defined?(WulinOAuth) 
        if request.post?
          response = HTTParty.post(WulinOAuth.configuration['change_password_uri'], :body => { :user => {
            :email => User.current_user.email,
            :current_password => params[:current_password], 
            :password => params[:password], 
            :password_confirmation => params[:password_confirmation]}}
          )
          render text: response
        else
          begin
            render 'change_password', layout: false
          rescue ActionView::MissingTemplate
            render '/change_password', layout: false
          end
        end
      else
        render text: "WulinOAuth is not install, Install it first!"
      end
    end

    def index
      dashboard if self.respond_to?(:dashboard)
      respond_to do |format|
        format.html do
          if request.xhr?
            begin
              render :template => 'homepage/dashboard', :layout => false
            rescue
              render :text => ''
            end
          else
            begin
              render 'index'
            rescue ActionView::MissingTemplate
              render '/home'
            end
          end
        end
      end
    end
    
    class << self
      attr_accessor :menu_block, :menu, :context

      # Menu definition
      def menu(&block)
        @menu_block = block
      end

      # Called within the block
      def submenu(title=nil)
        if block_given?
          @submenu = SubMenu.new(title)
          yield
          @menu << @submenu if @submenu.size > 0
          @submenu = nil
        end 
        return @submenu   
      end

      def item(title_or_screen_class, options={})
        return unless @menu
        screen_instance = title_or_screen_class.new(options, context) if title_or_screen_class.kind_of?(Class)

        title = options[:label] ||
                (title_or_screen_class.respond_to?(:title) ? title_or_screen_class.title : title_or_screen_class.to_s)
        path = options[:url] ||
               (screen_instance.respond_to?(:path) ? screen_instance.path : '/')

        if options[:authorized?]
          if options[:authorized?].kind_of?(Proc)
            is_authorized = (context && context.respond_to?(:current_user)) ? options[:authorized?].call(context.current_user) : options[:authorized?].call(nil)
            return unless is_authorized
          else
            return unless (is_authorized == true)
          end
        elsif title_or_screen_class.kind_of?(Class)
          if screen_instance.respond_to?(:authorized?)
            is_authorized = (context && context.respond_to?(:current_user)) ? screen_instance.authorized?(context.current_user) : screen_instance.authorized?(nil)
            return unless is_authorized
          end
        end
        if @submenu
          @submenu << MenuEntry.new(title, path)
        else
          @menu << MenuEntry.new(title, path)
        end
      end
      
      def get_menu
        @menu
      end
    end

    # Generate menu
    def menu
{'fraction_non_alphanumeric': 0.09442701329747498, 'fraction_numerical': 0.00044822949350067237, 'mean_word_length': 1.9463028169014085, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5004110', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1801, 'n_words': 412}