Skip to content

Commit

Permalink
Refactor render_machines_count
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanTG committed Jan 6, 2025
1 parent 36e4057 commit 4ce4b0e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
12 changes: 1 addition & 11 deletions app/controllers/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,7 @@ def render_machines
end

def render_machines_count
total_num_machines = Location.find(params[:id]).machine_names.size

if total_num_machines == 1
location_machine_count = total_num_machines.to_s + ' machine'
elsif total_num_machines > 1
location_machine_count = total_num_machines.to_s + ' machines'
else
location_machine_count = 'No machines'
end

render plain: location_machine_count
render partial: 'locations/render_machines_count', locals: { location: Location.find(params[:id]) }
end

def render_scores
Expand Down
1 change: 1 addition & 0 deletions app/views/locations/_render_add_machine.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$.post(this.action, $(this).serialize(), function (data) {
$('#show_machines_location_#{l.id}').load('/locations/#{l.id}/render_machines', function() {
updateLocationUpdatedText(#{l.id});
$('#show_machines_location_count_#{l.id}').load('/locations/#{l.id}/render_machines_count', function() {});
});
});

Expand Down
3 changes: 2 additions & 1 deletion app/views/locations/_render_location_detail.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
= render :partial => 'location_picture_xrefs/add_picture', :locals => {:location => l}
= render :partial => 'locations/recent_activity', :locals => {:location => l}
= render :partial => 'locations/former_machines', :locals => {:location => l}
= render :partial => 'locations/render_machines_count', :locals => {:location => l}
%div{:id => "show_machines_location_count_#{l.id}", :class => 'black font18 center lmx_count'}
= render :partial => 'locations/render_machines_count', :locals => {:location => l}
= render :partial => 'locations/show_machines', :locals => {:location => l}

:javascript
Expand Down
3 changes: 1 addition & 2 deletions app/views/locations/_render_machines_count.html.haml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
%div{:id => "show_machines_location_count_#{location.id}", :class => 'black font18 center lmx_count'}
= pluralize(location.machine_names.size, ' machine')
= pluralize(location.machine_names.size, ' machine')

0 comments on commit 4ce4b0e

Please sign in to comment.