Class: ResourcesRenderer
- Inherits:
-
DcRenderer
- Object
- DcRenderer
- ResourcesRenderer
- Includes:
- DcApplicationHelper
- Defined in:
- app/helpers/resources_renderer.rb
Overview
Resources usage renderer.
Instance Method Summary collapse
-
#default ⇒ Object
default renderer method will render application menu and usage table.
-
#resources_usage ⇒ Object
Render resources usage table.
Instance Method Details
#default ⇒ Object
default renderer method will render application menu and usage table.
53 54 55 56 57 |
# File 'app/helpers/resources_renderer.rb', line 53 def default html = @parent.render(partial: 'resources/menu', formats: [:html], locals: { parent: @parent }) # render error messages and usage table html << << resources_usage end |
#resources_usage ⇒ Object
Render resources usage table.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/resources_renderer.rb', line 33 def resources_usage # define currently selected week time = Date.parse(@parent.params[:selected_date]) rescue DateTime.now date_from = time.beginning_of_week date_to = time.end_of_week # scoupe selected resources and usage documents resources = Resource.where(category: @parent.params[:category], active: true).order_by(name: 1).to_a ids = resources.inject([]) { |r,e| r << e.id } usages = ResourceUsage.where(:resource_id.in => ids) .and(:time_from.lt => date_to, :time_to.gt => date_from) .order_by(resource_id: 1, time_from: 1).group_by(&:resource_id) # render rails usage views @parent.render(partial: 'resources/usage', formats: [:html], locals: { date_from: date_from, date_to: date_to, resources: resources, usages: usages }) end |