Class: FunctionController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- FunctionController
- Defined in:
- app/controllers/function_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #create_setting_html ⇒ Object
- #details ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #list ⇒ Object
Instance Method Details
#create ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/function_controller.rb', line 10 def create user = (login=session[:user]) && User.find_by_login(login) @directory = "/usr/#{user.login}/functions" case request.method when :post @function = Function.new @function.attributes = params[:function] @function.owner = user @function.path = "#{@directory}/#{@function.name}" Node.make_user_directory(@directory, user, 0) groups = params[:groups] groups.shift if groups[0] == 'only me' if user.super_user? && groups[0] == 'everyone' && groups.shift @function.other_mode = 4 else @function.other_mode = 0 end @function.set_rgroups(groups) if groups.length > 0 if check_erb(@function) && check_script(@function) flag = nil Function.transaction do if flag = @function.save output_num = params[:output_num].to_i output_num.times{|i| fo = FunctionOutput.new( params[:output][i.to_s] ) fo.function = @function fo.save! } argument_num = params[:argument_num].to_i argument_num.times{|i| param = params[:argument][i.to_s] value_type = param.delete(:value_type) fa = FunctionArgument.new( param ) fa.function = @function fa.value_type = ValueType.find(:first,:conditions=>["name=?",value_type]) fa.save! } end end if flag flash[:notice] = "create successful" redirect_back_or_default :action => "list" else flash[:notice] = "create unsuccessful" end end when :get @function = Function.new end @groups = user.own_groups + user.belonging_groups @user = user end |
#create_setting_html ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/controllers/function_controller.rb', line 155 def create_setting_html unless request.xhr? render :nothing => true return end narg = params[:narg].to_i args = params[:argument] html = "" if narg > 0 html += "<table>\n" narg.times{|n| html += " <tr>\n" arg = args[n.to_s] html +=<<-"EOS" <td>#{arg["description"]}</td> <td>(#{arg["value_type"]})</td> <td><input type="text" size="5" value="#{arg["default"]}" name="analysis[function_arguments][#{n}]"/></td> EOS html += " </tr>\n" } html += "</table>\n" end render :update do |page| page << "$('function_setting_html').value='#{escape_javascript(html)}'" end end |
#details ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/controllers/function_controller.rb', line 142 def details name = params[:id] user = (login=session[:user]) && User.find_by_login(login) func = Function.find(:first, :conditions=>["name=?",name], :user=>user) if func @func = func @user = user else redirect_back_or_default :action => "list" return end end |
#edit ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/controllers/function_controller.rb', line 63 def edit user = (login=session[:user]) && User.find_by_login(login) @function = Function.find(:first, :conditions=>["name=?",params[:id]], :user=>user) unless @function && @function.owner==user redirect_back_or_default :action => "list" return end @directory = "/usr/#{user.login}/functions" case request.method when :post @function.attributes = params[:function] output_num = params[:output_num].to_i outputs = @function.function_outputs output_num.times{|i| param = params[:output][i.to_s] if outputs[i] fo = outputs[i] fo.attributes = param else fo = outputs.create(param) end fo.save } for i in output_num...outputs.length outputs[i].destroy end argument_num = params[:argument_num].to_i args = @function.function_arguments argument_num.times{|i| param = params[:argument][i.to_s] value_type = param.delete(:value_type) if args[i] fa = args[i] fa.attributes = param else fa = args.create(param) end fa.value_type = ValueType.find(:first,:conditions=>["name=?",value_type]) fa.save } for i in argument_num...args.length args[i].destroy end groups = params[:groups] groups.shift if groups[0] == 'only me' if user.super_user? && groups[0] == 'everyone' && groups.shift @function.other_mode = 4 else @function.other_mode = 0 end @function.set_rgroups(groups) if groups.length > 0 if check_erb(@function) && check_script(@function) if @function.save flash[:notice] = "edit successful" redirect_back_or_default :action => "list" else flash[:notice] = "edit unsuccessful" end end end @groups = user.own_groups + user.belonging_groups @user = user end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/function_controller.rb', line 6 def index redirect_to :action => "list" end |
#list ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/controllers/function_controller.rb', line 127 def list user = (login=session[:user]) && User.find_by_login(login) funcs = Function.find(:all, :user => user) @own_funcs = Array.new @other_funcs = Array.new funcs.each{|func| if func.owner == user @own_funcs.push func else @other_funcs.push func end } @super_user = user.super_user end |