Class: Easypiechart::MainController

Inherits:
Volt::ModelController
  • Object
show all
Defined in:
app/easypiechart/controllers/main_controller.rb

Instance Method Summary collapse

Instance Method Details

#before_index_removeObject



36
37
38
39
40
# File 'app/easypiechart/controllers/main_controller.rb', line 36

def before_index_remove
  @watches.each do |watch|
    watch.stop
  end
end

#index_readyObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/easypiechart/controllers/main_controller.rb', line 4

def index_ready
  @watches = []
  @elem = `$(#{first_element}).children().first()`
  if @elem
    if attrs.options
      begin
        JSON.parse(attrs.options).each do |option, value|
          if option == 'size'
            value_in_px = "#{value}px"
            `#{@elem}.css("height",#{value_in_px});`
            `#{@elem}.css("width",#{value_in_px});`
            `#{@elem}.css("line-height",#{value_in_px});`
          end
          `#{@elem}.data(#{option}, #{value})`
        end
      rescue Object => e
        Volt.logger.error "'options' attribute passed to EasyPieChart must be a string that is valid, parsable JSON. Error was #{e}"
      end
    end
    `#{@elem}.easyPieChart();`
    @watches << -> { update_value(attrs.percent) }.watch!
  end
end

#update_valueObject



28
29
30
31
32
33
34
# File 'app/easypiechart/controllers/main_controller.rb', line 28

def update_value
  if @elem
    attrs.percent.then do |percent|
      `#{@elem}.data('easyPieChart').update(#{percent})`
    end
  end
end