Class: Heart::DashboardsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/heart/dashboards_controller.rb

Instance Method Summary collapse

Instance Method Details

#archiveObject



43
44
45
46
47
48
# File 'app/controllers/heart/dashboards_controller.rb', line 43

def archive
  dashboard = Heart::Dashboard.where(id: params[:dashboard_id]).first
  dashboard.status = Heart::Dashboard::INACTIVE
  dashboard.save
  redirect_to dashboards_path
end

#createObject



21
22
23
24
25
26
27
# File 'app/controllers/heart/dashboards_controller.rb', line 21

def create
  dashboard = Heart::Dashboard.new()
  dashboard.title = params[:title]
  dashboard.dashboard = params[:charts_serialized]
  dashboard.save
  redirect_to dashboards_path
end

#defaultObject



6
7
# File 'app/controllers/heart/dashboards_controller.rb', line 6

def default
end

#editObject



29
30
31
# File 'app/controllers/heart/dashboards_controller.rb', line 29

def edit
  @dashboard = Heart::Dashboard.find(params[:id])
end

#flotitObject



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
75
76
77
78
79
80
81
82
# File 'app/controllers/heart/dashboards_controller.rb', line 50

def flotit
  params[:date_from] ||= 30.days.ago.to_s
  params[:date_to] ||= 1.days.ago.to_s     
  @annotations = Heart::Annotation.visible(:from => params[:date_from], :to => params[:date_to])
  @description = Heart::Annotation.where(id: params[:description]).first.note if params[:description].to_i > 0
  
  # THE WHERE
  where = "WHERE fulldate >= '"+params[:date_from]+"' AND fulldate <= '"+params[:date_to]+"'"
  # THE GROUPBY
  groupby = ""
  if !params[:group_by].empty?
    counter = 0
    params[:group_by].each do |value|
      groupby += "," if counter >= 1
      groupby += " " + value
      counter += 1
    end
  end
  groupby = nil if groupby.empty?
  # THE MEASUREMENTS
  measurements = params[:measurements].empty? ? false : params[:measurements]
  
  @metrics = Hash.new
  if params[:moving_averages].kind_of?(Array)
    params[:moving_averages].each do |y|
      if(params[:method_sum] == "true")
        @metrics[y.to_s] = Heart::Metric.aggregate_daily_sums(y, where, groupby, measurements)
      else
        @metrics[y.to_s] = Heart::Metric.aggregate_daily_moving_averages(y, where, groupby, measurements)
      end
    end
  end
end

#indexObject



9
10
11
# File 'app/controllers/heart/dashboards_controller.rb', line 9

def index
  @dashboards = Heart::Dashboard.active.all
end

#newObject



18
19
# File 'app/controllers/heart/dashboards_controller.rb', line 18

def new
end

#showObject



13
14
15
16
# File 'app/controllers/heart/dashboards_controller.rb', line 13

def show
  @dashboard = Heart::Dashboard.find(params[:id])
  @charts = ActiveSupport::JSON.decode(@dashboard.dashboard)
end

#updateObject



33
34
35
36
37
38
39
40
41
# File 'app/controllers/heart/dashboards_controller.rb', line 33

def update
  dashboard = Heart::Dashboard.find(params[:id])
  dashboard.title = params[:title]
  dashboard.description = params[:description]
  dashboard.dashboard = params[:charts_serialized]
  dashboard.date_from = params[:date_from]
  dashboard.save
  redirect_to dashboards_path
end