Class: Blazer::DashboardsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/blazer/dashboards_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/blazer/dashboards_controller.rb', line 13

def create
  @dashboard = Blazer::Dashboard.new
  # use creator_id instead of creator
  # since we setup association without checking if column exists
  @dashboard.creator = blazer_user if @dashboard.respond_to?(:creator_id=) && blazer_user

  if update_dashboard(@dashboard)
    redirect_to dashboard_path(@dashboard)
  else
    render :new
  end
end

#destroyObject



59
60
61
62
# File 'app/controllers/blazer/dashboards_controller.rb', line 59

def destroy
  @dashboard.destroy
  redirect_to dashboards_path
end

#editObject



48
49
# File 'app/controllers/blazer/dashboards_controller.rb', line 48

def edit
end

#indexObject



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

def index
  @dashboards = Blazer::Dashboard.order(:name)
end

#newObject



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

def new
  @dashboard = Blazer::Dashboard.new
end

#refreshObject



64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/blazer/dashboards_controller.rb', line 64

def refresh
  @dashboard.queries.each do |query|
    data_source = Blazer.data_sources[query.data_source]
    statement = query.statement.dup
    process_vars(statement, query.data_source)
    Blazer.transform_statement.call(data_source, statement) if Blazer.transform_statement
    data_source.clear_cache(statement)
  end
  redirect_to dashboard_path(@dashboard, variable_params)
end

#showObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/blazer/dashboards_controller.rb', line 26

def show
  @queries = @dashboard.dashboard_queries.order(:position).preload(:query).map(&:query)
  @queries.each do |query|
    process_vars(query.statement, query.data_source)
  end
  @bind_vars ||= []

  @smart_vars = {}
  @sql_errors = []
  @data_sources = @queries.map { |q| Blazer.data_sources[q.data_source] }.uniq
  @bind_vars.each do |var|
    @data_sources.each do |data_source|
      query = data_source.smart_variables[var]
      if query
        result = data_source.run_statement(query)
        ((@smart_vars[var] ||= []).concat(result.rows.map { |v| v.reverse })).uniq!
        @sql_errors << result.error if result.error
      end
    end
  end
end

#updateObject



51
52
53
54
55
56
57
# File 'app/controllers/blazer/dashboards_controller.rb', line 51

def update
  if update_dashboard(@dashboard)
    redirect_to dashboard_path(@dashboard, variable_params)
  else
    render :edit
  end
end