Class: ConcertoTemplateScheduling::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/concerto_template_scheduling/engine.rb

Instance Method Summary collapse

Instance Method Details

#plugin_info(plugin_info_class) ⇒ 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
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/concerto_template_scheduling/engine.rb', line 10

def plugin_info(plugin_info_class)
  @plugin_info ||= plugin_info_class.new do
    
    # Make the engine's controller accessible at /template-scheduling
    add_route("template-scheduling", ConcertoTemplateScheduling::Engine)

    # Some code to run at app boot
    init do
      Rails.logger.info "ConcertoTemplateScheduling: Initialization code is running"
    end

    # show the schedule details alongside each screen

    add_controller_hook "ScreensController", :show, :before do
      @schedules = Schedule.where(:screen_id => @screen.id)
      # reject the schedules that specify templates that have been deleted
      @schedules.to_a.reject!{|s| s.template.nil?}
    end

    add_view_hook "ScreensController", :screen_details, :partial => "concerto_template_scheduling/screens/screen_link"

    # show that the template is in use
  
    add_controller_hook "TemplatesController", :show, :before do
      @schedules = Schedule.where(:template_id => @template.id)
    end

    add_view_hook "TemplatesController", :template_details, :partial => "concerto_template_scheduling/templates/in_use_by"

    # influence which template is the effective template for a screen
    # prepend these so that the EMS plugin can override them

    add_controller_hook "Screen", :frontend_display, [:before, :prepend => true] do
      # sets the template to the "effective" template
      schedules = Schedule.active.where(:screen_id => self.id)
      schedules.to_a.reject! {|s| !s.is_effective? }
      self.template = schedules.first.template if !schedules.empty?
    end

    add_controller_hook "Frontend::ContentsController", :index, [:after, :prepend => true]  do
      # sets the template to the "effective" template
      schedules = Schedule.active.where(:screen_id => @screen.id)
      schedules.to_a.reject! {|s| !s.is_effective? }
      @screen.template = schedules.first.template if !schedules.empty?
    end

    # delete schedules when a screen is deleted

    add_controller_hook "ScreensController", :destroy, :after do
      Schedule.destroy_all(:screen_id => @screen.id)
    end

    # indicate if a template has dependencies

    add_controller_hook "Template", :is_deletable, :after do
      @deletable = Schedule.where(:template_id => self.id).empty? if @deletable
    end        

    add_controller_hook "Template", :screen_dependencies, :after do
      @dependencies ||= []
      @dependencies << Schedule.where(:template_id => self.id).collect { |t| t.screen }
    end        

  end
end