Commit d0ce2a13477406da2526aa87d0ef98f591b943c6
Committed by
David Silva
1 parent
b78b06e2
Exists in
master
and in
79 other branches
Refactor mpog_software_plugin_controller
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com>
Showing
4 changed files
with
74 additions
and
119 deletions
Show diff stats
controllers/mpog_software_plugin_controller.rb
@@ -7,8 +7,8 @@ class MpogSoftwarePluginController < ApplicationController | @@ -7,8 +7,8 @@ class MpogSoftwarePluginController < ApplicationController | ||
7 | result = "" | 7 | result = "" |
8 | user = User.where(:email => params[:email]) | 8 | user = User.where(:email => params[:email]) |
9 | 9 | ||
10 | - if user.length == 1 | ||
11 | - result = "<span id='forgot_link'><a href='/account/forgot_password'> Reactive account</a></span>" unless user[0].person.visible | 10 | + if user.length == 1 && !user[0].person.visible |
11 | + result = "<span id='forgot_link'><a href='/account/forgot_password'> Reactive account</a></span>" | ||
12 | end | 12 | end |
13 | 13 | ||
14 | render :json => result.to_json | 14 | render :json => result.to_json |
@@ -28,7 +28,7 @@ class MpogSoftwarePluginController < ApplicationController | @@ -28,7 +28,7 @@ class MpogSoftwarePluginController < ApplicationController | ||
28 | 28 | ||
29 | def create_institution | 29 | def create_institution |
30 | @show_sisp_field = environment.admins.include?(current_user.person) | 30 | @show_sisp_field = environment.admins.include?(current_user.person) |
31 | - @estate_list = get_state_list() | 31 | + @state_list = get_state_list() |
32 | 32 | ||
33 | if request.xhr? | 33 | if request.xhr? |
34 | render :layout=>false | 34 | render :layout=>false |
@@ -46,7 +46,7 @@ class MpogSoftwarePluginController < ApplicationController | @@ -46,7 +46,7 @@ class MpogSoftwarePluginController < ApplicationController | ||
46 | 46 | ||
47 | def create_institution_admin | 47 | def create_institution_admin |
48 | @show_sisp_field = environment.admins.include?(current_user.person) | 48 | @show_sisp_field = environment.admins.include?(current_user.person) |
49 | - @estate_list = get_state_list() | 49 | + @state_list = get_state_list() |
50 | 50 | ||
51 | @url_token = split_http_referer request.original_url() | 51 | @url_token = split_http_referer request.original_url() |
52 | end | 52 | end |
@@ -81,14 +81,6 @@ class MpogSoftwarePluginController < ApplicationController | @@ -81,14 +81,6 @@ class MpogSoftwarePluginController < ApplicationController | ||
81 | render :json=>already_exists.to_json | 81 | render :json=>already_exists.to_json |
82 | end | 82 | end |
83 | 83 | ||
84 | - def download | ||
85 | - respond_to do |format| | ||
86 | - format.html | ||
87 | - format_xml_download format | ||
88 | - format_csv_download format | ||
89 | - end | ||
90 | - end | ||
91 | - | ||
92 | def get_institutions | 84 | def get_institutions |
93 | redirect_to "/" if !request.xhr? || params[:query].blank? | 85 | redirect_to "/" if !request.xhr? || params[:query].blank? |
94 | 86 | ||
@@ -119,20 +111,21 @@ class MpogSoftwarePluginController < ApplicationController | @@ -119,20 +111,21 @@ class MpogSoftwarePluginController < ApplicationController | ||
119 | end | 111 | end |
120 | 112 | ||
121 | def get_field_data | 113 | def get_field_data |
122 | - return render :json=>{} if !request.xhr? || params[:query].nil? || params[:field].nil? | 114 | + condition = !request.xhr? || params[:query].nil? || params[:field].nil? |
115 | + return render :json=>{} if condition | ||
123 | 116 | ||
124 | model = case params[:field] | 117 | model = case params[:field] |
125 | - when "database" | ||
126 | - DatabaseDescription | ||
127 | - when "software_language" | ||
128 | - ProgrammingLanguage | ||
129 | - else | ||
130 | - DatabaseDescription | ||
131 | - end | ||
132 | - | ||
133 | - data = model.where("name ILIKE ?", "%#{params[:query]}%").select("id, name").collect { |db| | 118 | + when "software_language" |
119 | + ProgrammingLanguage | ||
120 | + else | ||
121 | + DatabaseDescription | ||
122 | + end | ||
123 | + | ||
124 | + data = model.where("name ILIKE ?", "%#{params[:query]}%").select("id, name") | ||
125 | + data.collect { |db| | ||
134 | {:id=>db.id, :label=>db.name} | 126 | {:id=>db.id, :label=>db.name} |
135 | } | 127 | } |
128 | + | ||
136 | other = [model.select("id, name").last].collect { |db| | 129 | other = [model.select("id, name").last].collect { |db| |
137 | {:id=>db.id, :label=>db.name} | 130 | {:id=>db.id, :label=>db.name} |
138 | } | 131 | } |
@@ -148,34 +141,55 @@ class MpogSoftwarePluginController < ApplicationController | @@ -148,34 +141,55 @@ class MpogSoftwarePluginController < ApplicationController | ||
148 | def get_state_list | 141 | def get_state_list |
149 | redirect_to "/" unless request.xhr? | 142 | redirect_to "/" unless request.xhr? |
150 | 143 | ||
151 | - NationalRegion.find(:all, :conditions=>["national_region_type_id = ?", 2], :order=>"name") | 144 | + NationalRegion.find( |
145 | + :all, | ||
146 | + :conditions=>["national_region_type_id = ?", 2], | ||
147 | + :order=>"name" | ||
148 | + ) | ||
149 | + end | ||
150 | + | ||
151 | + def set_institution_type | ||
152 | + institution_params = params[:institutions].except( | ||
153 | + :governmental_power, | ||
154 | + :governmental_sphere, | ||
155 | + :juridical_nature | ||
156 | + ) | ||
157 | + if params[:institutions][:type] == "PublicInstitution" | ||
158 | + PublicInstitution::new institution_params | ||
159 | + else | ||
160 | + PrivateInstitution::new institution_params | ||
161 | + end | ||
162 | + end | ||
163 | + | ||
164 | + def set_public_institution_fields institution | ||
165 | + inst_fields = params[:institutions] | ||
166 | + | ||
167 | + begin | ||
168 | + gov_power = GovernmentalPower.find inst_fields[:governmental_power] | ||
169 | + gov_sphere = GovernmentalSphere.find inst_fields[:governmental_sphere] | ||
170 | + jur_nature = JuridicalNature.find inst_fields[:juridical_nature] | ||
171 | + | ||
172 | + institution.juridical_nature = jur_nature | ||
173 | + institution.governmental_power = gov_power | ||
174 | + institution.governmental_sphere = gov_sphere | ||
175 | + rescue | ||
176 | + institution.errors.add( | ||
177 | + :governmental_fields, | ||
178 | + _("Could not find Governmental Power or Governmental Sphere") | ||
179 | + ) | ||
180 | + end | ||
152 | end | 181 | end |
153 | 182 | ||
154 | def private_create_institution | 183 | def private_create_institution |
155 | community = Community.new(params[:community]) | 184 | community = Community.new(params[:community]) |
156 | community.environment = environment | 185 | community.environment = environment |
157 | - | ||
158 | - institution = if params[:institutions][:type] == "PublicInstitution" | ||
159 | - PublicInstitution::new params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature) | ||
160 | - else | ||
161 | - PrivateInstitution::new params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature) | ||
162 | - end | 186 | + institution = set_institution_type |
163 | 187 | ||
164 | institution.name = community[:name] | 188 | institution.name = community[:name] |
165 | institution.community = community | 189 | institution.community = community |
166 | 190 | ||
167 | if institution.type == "PublicInstitution" | 191 | if institution.type == "PublicInstitution" |
168 | - begin | ||
169 | - govPower = GovernmentalPower.find params[:institutions][:governmental_power] | ||
170 | - govSphere = GovernmentalSphere.find params[:institutions][:governmental_sphere] | ||
171 | - jur_nature = JuridicalNature.find params[:institutions][:juridical_nature] | ||
172 | - | ||
173 | - institution.juridical_nature = jur_nature | ||
174 | - institution.governmental_power = govPower | ||
175 | - institution.governmental_sphere = govSphere | ||
176 | - rescue | ||
177 | - institution.errors.add(:governmental_fields, _("Could not find Governmental Power or Governmental Sphere")) | ||
178 | - end | 192 | + set_public_institution_fields institution |
179 | end | 193 | end |
180 | 194 | ||
181 | InstitutionHelper.register_institution_modification institution | 195 | InstitutionHelper.register_institution_modification institution |
@@ -183,41 +197,16 @@ class MpogSoftwarePluginController < ApplicationController | @@ -183,41 +197,16 @@ class MpogSoftwarePluginController < ApplicationController | ||
183 | institution | 197 | institution |
184 | end | 198 | end |
185 | 199 | ||
186 | - def software_list_to_correct_format software_list=[] | ||
187 | - if !software_list.empty? | ||
188 | - software_list.each do |software| | ||
189 | - software[:name] = Community.find(software.community_id).name | ||
190 | - software[:languages_list] = [] | ||
191 | - | ||
192 | - software.software_languages.each do |sl| | ||
193 | - software[:languages_list] << {} | ||
194 | - index = software[:languages_list].count - 1 | ||
195 | - software[:languages_list][index][:name] = ProgrammingLanguage.find(sl.programming_language_id).name | ||
196 | - software[:languages_list][index][:version] = sl.version | ||
197 | - software[:languages_list][index][:operating_system] = sl.operating_system | ||
198 | - end | ||
199 | - | ||
200 | - software[:database_list] = [] | ||
201 | - software.software_databases.each do |dd| | ||
202 | - software[:database_list] << {} | ||
203 | - index = software[:database_list].count - 1 | ||
204 | - software[:database_list][index][:name] = DatabaseDescription.find(dd.database_description_id).name | ||
205 | - software[:database_list][index][:version] = dd.version | ||
206 | - software[:database_list][index][:operating_system] = dd.operating_system | ||
207 | - end | ||
208 | - end | ||
209 | - end | ||
210 | - software_list | ||
211 | - end | ||
212 | - | ||
213 | def add_template_in_params institution_template | 200 | def add_template_in_params institution_template |
214 | - if (!institution_template.blank? && institution_template.is_template) | ||
215 | - params[:community][:template_id] = institution_template.id unless params[:community].blank? | 201 | + com_fields = params[:community] |
202 | + if !institution_template.blank? && institution_template.is_template | ||
203 | + com_fields[:template_id]= institution_template.id unless com_fields.blank? | ||
216 | end | 204 | end |
217 | end | 205 | end |
218 | 206 | ||
219 | def add_environment_admins_to_institution institution | 207 | def add_environment_admins_to_institution institution |
220 | - if environment.admins.include?(current_user.person) && params[:edit_institution_page] == false | 208 | + edit_page = params[:edit_institution_page] == false |
209 | + if environment.admins.include?(current_user.person) && edit_page | ||
221 | environment.admins.each do |adm| | 210 | environment.admins.each do |adm| |
222 | institution.community.add_admin(adm) | 211 | institution.community.add_admin(adm) |
223 | end | 212 | end |
@@ -225,10 +214,19 @@ class MpogSoftwarePluginController < ApplicationController | @@ -225,10 +214,19 @@ class MpogSoftwarePluginController < ApplicationController | ||
225 | end | 214 | end |
226 | 215 | ||
227 | def save_institution institution | 216 | def save_institution institution |
228 | - if institution.errors.full_messages.empty? and institution.community.errors.full_messages.empty? and institution.valid? and institution.save | ||
229 | - {:success => true, :message => _("Institution successful created!"), :institution_data=>{:name=>institution.name, :id=>institution.id}} | 217 | + inst_errors = institution.errors.full_messages |
218 | + com_errors = institution.community.errors.full_messages | ||
219 | + | ||
220 | + if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save | ||
221 | + { :success => true, | ||
222 | + :message => _("Institution successful created!"), | ||
223 | + :institution_data => {:name=>institution.name, :id=>institution.id} | ||
224 | + } | ||
230 | else | 225 | else |
231 | - {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages << institution.community.errors.full_messages} | 226 | + { :success => false, |
227 | + :message => _("Institution could not be created!"), | ||
228 | + :errors => inst_errors << com_errors | ||
229 | + } | ||
232 | end | 230 | end |
233 | end | 231 | end |
234 | 232 | ||
@@ -240,47 +238,4 @@ class MpogSoftwarePluginController < ApplicationController | @@ -240,47 +238,4 @@ class MpogSoftwarePluginController < ApplicationController | ||
240 | redirect_to :controller => "mpog_software_plugin", :action => "create_institution_admin" | 238 | redirect_to :controller => "mpog_software_plugin", :action => "create_institution_admin" |
241 | end | 239 | end |
242 | end | 240 | end |
243 | - | ||
244 | - def format_xml_download format | ||
245 | - format.xml do | ||
246 | - softwares = software_list_to_correct_format(SoftwareInfo.all) | ||
247 | - send_data( | ||
248 | - softwares.to_xml( | ||
249 | - :skip_types => true, | ||
250 | - :only => %w[name acronym demonstration_url e_arq e_mag e_ping features icp_brasil objectives operating_platform languages_list database_list] | ||
251 | - ), | ||
252 | - :type => 'text/xml', | ||
253 | - :disposition => "attachment; filename=softwares.xml") | ||
254 | - end | ||
255 | - end | ||
256 | - | ||
257 | - def format_csv_download format | ||
258 | - format.csv do | ||
259 | - softwares = software_list_to_correct_format(SoftwareInfo.all) | ||
260 | - csv_content = "" | ||
261 | - | ||
262 | - softwares.each do |s| | ||
263 | - csv_content << "name;acronym;demonstration_url;e_arq;e_mag;e_ping;features;icp_brasil;objectives;operating_platform\n" | ||
264 | - csv_content << CSV.generate_line([s['name'], s['acronym'], s['demonstration_url'], s['e_arq'], s['e_mag'], s['e_ping'], s['features'], s['icp_brasil'], s['objectives'], s['operating_platform']], {:col_sep => ';'}) | ||
265 | - | ||
266 | - csv_content << "\nlanguage_name;language_version;language_operating_system\n" | ||
267 | - s[:languages_list].each { |sl| | ||
268 | - csv_content << CSV.generate_line([sl[:name], sl[:version], sl[:operating_system]], {:col_sep => ';'}) | ||
269 | - } | ||
270 | - | ||
271 | - csv_content << "\ndatabase_name;database_version;database_operating_system\n" | ||
272 | - s[:database_list].each { |dl| | ||
273 | - csv_content << CSV.generate_line([dl[:name], dl[:version], dl[:operating_system]], {:col_sep => ';'}) | ||
274 | - } | ||
275 | - | ||
276 | - csv_content << "\n\n" | ||
277 | - end | ||
278 | - | ||
279 | - if csv_content.blank? | ||
280 | - csv_content = "name;acronym;demonstration_url;e_arq;e_mag;e_ping;features;icp_brasil;objectives;operating_platform\n" | ||
281 | - end | ||
282 | - | ||
283 | - render :text => csv_content, :content_type => 'text/csv', :layout => false | ||
284 | - end | ||
285 | - end | ||
286 | end | 241 | end |
controllers/mpog_software_plugin_myprofile_controller.rb
@@ -6,7 +6,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | @@ -6,7 +6,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | ||
6 | 6 | ||
7 | def edit_institution | 7 | def edit_institution |
8 | @show_sisp_field = environment.admins.include?(current_user.person) | 8 | @show_sisp_field = environment.admins.include?(current_user.person) |
9 | - @estate_list = NationalRegion.find(:all, :conditions=>["national_region_type_id = ?", 2], :order=>"name") | 9 | + @state_list = NationalRegion.find(:all, :conditions=>["national_region_type_id = ?", 2], :order=>"name") |
10 | 10 | ||
11 | @institution = @profile.institution | 11 | @institution = @profile.institution |
12 | 12 |
views/mpog_software_plugin/_institution.html.erb
@@ -55,7 +55,7 @@ | @@ -55,7 +55,7 @@ | ||
55 | <span class='required-field'> | 55 | <span class='required-field'> |
56 | <div class="formfield"> | 56 | <div class="formfield"> |
57 | <label for="community_state" class="formlabel"><%= _("State") %></label> | 57 | <label for="community_state" class="formlabel"><%= _("State") %></label> |
58 | - <%= f.select(:state, @estate_list.collect {|state| [state.name, state.name]}) %> | 58 | + <%= f.select(:state, @state_list.collect {|state| [state.name, state.name]}) %> |
59 | </div> | 59 | </div> |
60 | </span> | 60 | </span> |
61 | 61 |
views/mpog_software_plugin_myprofile/edit_institution.html.erb
@@ -55,7 +55,7 @@ | @@ -55,7 +55,7 @@ | ||
55 | <span class='required-field'> | 55 | <span class='required-field'> |
56 | <div class="formfield"> | 56 | <div class="formfield"> |
57 | <label for="community_state" class="formlabel"><%= _("State") %></label> | 57 | <label for="community_state" class="formlabel"><%= _("State") %></label> |
58 | - <%= f.select(:state, @estate_list.collect {|state| [state.name, state.name]}, :selected => @institution.community.state) %> | 58 | + <%= f.select(:state, @state_list.collect {|state| [state.name, state.name]}, :selected => @institution.community.state) %> |
59 | </div> | 59 | </div> |
60 | </span> | 60 | </span> |
61 | 61 |