Commit 3b4ec38ffa0cc4c3875bc124c881645204c54a66
1 parent
1eecb40a
Exists in
master
and in
79 other branches
Creates constroy_software method in mpog_software_plugin_myprofile_controller.
- Create private methods to use it in mpog_software_plugin_myprofile_controller actions. Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Showing
2 changed files
with
37 additions
and
17 deletions
Show diff stats
controllers/mpog_software_plugin_myprofile_controller.rb
... | ... | @@ -6,24 +6,22 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
6 | 6 | |
7 | 7 | def edit_institution |
8 | 8 | @show_sisp_field = environment.admins.include?(current_user.person) |
9 | - @state_list = NationalRegion.find(:all, :conditions => { :national_region_type_id => 2 }, :order => 'name') | |
9 | + @state_list = NationalRegion.find(:all, :conditions => | |
10 | + { :national_region_type_id => 2 }, | |
11 | + :order => 'name') | |
10 | 12 | @institution = @profile.institution |
11 | 13 | update_institution if request.post? |
12 | 14 | end |
13 | 15 | |
14 | 16 | def new_software |
15 | - software_template = Community['software'] | |
16 | - if !software_template.blank? && software_template.is_template | |
17 | - params["community"]["template_id"] = software_template.id unless params["community"].blank? | |
18 | - end | |
19 | - | |
17 | + set_software_as_template | |
20 | 18 | @community = Community.new(params[:community]) |
21 | 19 | @community.environment = environment |
22 | 20 | @software_info = SoftwareInfo.new(params[:software_info]) |
23 | 21 | @license_info = if params[:license_info].nil? |
24 | 22 | LicenseInfo.new |
25 | 23 | else |
26 | - LicenseInfo.find(:first, :conditions =>["version = ?","#{params[:license_info][:version]}"]) | |
24 | + LicenseInfo.find(:first, :conditions => ["version = ?","#{params[:license_info][:version]}"]) | |
27 | 25 | end |
28 | 26 | control_software_creation |
29 | 27 | end |
... | ... | @@ -38,7 +36,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
38 | 36 | update_software_atributes |
39 | 37 | |
40 | 38 | return unless request.post? |
41 | - constroy_software | |
39 | + @software_info = constroy_software | |
42 | 40 | software_info_insert_models.call(@list_libraries, 'libraries') |
43 | 41 | software_info_insert_models.call(@list_languages, 'software_languages') |
44 | 42 | software_info_insert_models.call(@list_operating_systems, 'operating_systems') |
... | ... | @@ -49,6 +47,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
49 | 47 | redirect_to :controller => 'profile_editor', :action => 'edit' |
50 | 48 | else |
51 | 49 | redirect_to :controller => 'profile_editor', :action => 'index' |
50 | + session[:notice] = _('Software updated sucessefuly') | |
52 | 51 | end |
53 | 52 | rescue ActiveRecord::RecordInvalid => invalid |
54 | 53 | end |
... | ... | @@ -117,6 +116,14 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
117 | 116 | @software_info.license_info = @license |
118 | 117 | @software_info.update_attributes(params[:software]) |
119 | 118 | |
119 | + create_list_model_helpers | |
120 | + | |
121 | + @software_categories = SoftwareCategories::new params[:software_categories] | |
122 | + @software_info.software_categories = @software_categories unless params[:software_categories].nil? | |
123 | + @software_info | |
124 | + end | |
125 | + | |
126 | + def create_list_model_helpers | |
120 | 127 | @list_libraries = LibraryHelper.list_libraries(params[:library]) |
121 | 128 | @list_languages = SoftwareLanguageHelper.list_language(params[:language]) |
122 | 129 | @list_databases = DatabaseHelper.list_database(params[:database]) |
... | ... | @@ -129,15 +136,10 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
129 | 136 | :environment => environment, |
130 | 137 | :name => params[:community][:name], |
131 | 138 | :license_info => @license_info })) |
132 | - unless params[:q].nil? | |
133 | - admins = params[:q].split(/,/).map{ |n| environment.people.find n.to_i } | |
134 | 139 | |
135 | - admins.each do |admin| | |
136 | - @community.add_member(admin) | |
137 | - @community.add_admin(admin) | |
138 | - end | |
139 | - end | |
140 | - if !environment.admins.include?(current_user.person) | |
140 | + add_admin_to_community | |
141 | + | |
142 | + if !environment.admins.include?(current_user.person) | |
141 | 143 | session[:notice] = _('Your new software request will be evaluated by an'\ |
142 | 144 | 'administrator. You will be notified.') |
143 | 145 | redirect_to user.admin_url |
... | ... | @@ -156,4 +158,22 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
156 | 158 | @list_operating_systems = @software_info.operating_systems |
157 | 159 | @disabled_public_software_field = disabled_public_software_field |
158 | 160 | end |
161 | + | |
162 | + def set_software_as_template | |
163 | + software_template = Community['software'] | |
164 | + software_valid = !software_template.blank? && software_template.is_template && !params['community'].blank? | |
165 | + if software_valid | |
166 | + params['community']['template_id'] = software_template.id if software_valid | |
167 | + end | |
168 | + end | |
169 | + | |
170 | + def add_admin_to_community | |
171 | + unless params[:q].nil? | |
172 | + admins = params[:q].split(/,/).map{ |n| environment.people.find n.to_i } | |
173 | + admins.each do |admin| | |
174 | + @community.add_member(admin) | |
175 | + @community.add_admin(admin) | |
176 | + end | |
177 | + end | |
178 | + end | |
159 | 179 | end | ... | ... |
lib/mpog_software_plugin.rb
... | ... | @@ -21,7 +21,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
21 | 21 | def profile_editor_extras |
22 | 22 | if context.profile.person? |
23 | 23 | expanded_template('person_editor_extras.html.erb') |
24 | - elsif context.profile.respond_to? :software_info && | |
24 | + elsif context.profile.respond_to?(:software_info) && | |
25 | 25 | !context.profile.software_info.nil? |
26 | 26 | |
27 | 27 | if context.profile.software_info.first_edit? | ... | ... |