Class: Prosperity::GraphsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/prosperity/graphs_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/prosperity/graphs_controller.rb', line 52

def create
  @graph = Graph.new
  [:title, :period, :graph_type].each do |attr|
    @graph.send("#{attr}=", graph_params[attr])
  end

  if @graph.save
    redirect_to edit_graph_path(@graph)
  else
    set_error(@graph)
    render action: :new
  end
end

#editObject



10
11
12
13
14
15
16
17
# File 'app/controllers/prosperity/graphs_controller.rb', line 10

def edit
  @metrics = MetricFinder.all.map(&:new)
  @options = @metrics.inject({}) do |h, metric|
    h[metric.id] = metric.options.keys
    h
  end
  @graph.graph_lines.build
end

#newObject



6
7
8
# File 'app/controllers/prosperity/graphs_controller.rb', line 6

def new
  @graph = Graph.new
end

#showObject



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
# File 'app/controllers/prosperity/graphs_controller.rb', line 19

def show
  respond_to do |format|
    format.json do
      render json: {
        title: @graph.title,
        graph_type: @graph.graph_type,
        extractors: @graph.graph_lines.map do |line|
          {
            key: line.extractor,
            url: data_metric_path(id: line.metric, 
                                  extractor: line.extractor, 
                                  option: line.option, 
                                  period: @graph.period, 
                                  start_time: start_time, 
                                  end_time: end_time),
          }
        end
      }
    end

    format.html {
      render layout: 'prosperity/embedabble'
    }
  end
end

#updateObject



45
46
47
48
49
50
# File 'app/controllers/prosperity/graphs_controller.rb', line 45

def update
  unless @graph.update_attributes(graph_params)
    set_error(@graph)
  end
  redirect_to action: :edit
end