Class: ForemanStatistics::TrendsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Parameters::Trend
Defined in:
app/controllers/foreman_statistics/trends_controller.rb

Instance Method Summary collapse

Instance Method Details

#countObject



49
50
51
52
# File 'app/controllers/foreman_statistics/trends_controller.rb', line 49

def count
  ForemanStatistics::TrendImporter.update!
  redirect_to trends_url
end

#createObject



19
20
21
22
23
24
25
26
# File 'app/controllers/foreman_statistics/trends_controller.rb', line 19

def create
  @trend = Trend.build_trend(trend_params)
  if @trend.save
    process_success
  else
    process_error
  end
end

#destroyObject



41
42
43
44
45
46
47
# File 'app/controllers/foreman_statistics/trends_controller.rb', line 41

def destroy
  if @trend.destroy
    process_success
  else
    process_error
  end
end

#editObject



39
# File 'app/controllers/foreman_statistics/trends_controller.rb', line 39

def edit; end

#indexObject



7
8
9
# File 'app/controllers/foreman_statistics/trends_controller.rb', line 7

def index
  @trends = Trend.types.includes(:trendable).sort_by { |e| e.type_name.downcase }.paginate(:page => params[:page], :per_page => params[:per_page])
end

#newObject



11
12
13
# File 'app/controllers/foreman_statistics/trends_controller.rb', line 11

def new
  @trend = Trend.new
end

#resource_classObject



54
55
56
# File 'app/controllers/foreman_statistics/trends_controller.rb', line 54

def resource_class
  ForemanStatistics::Trend
end

#showObject



15
16
17
# File 'app/controllers/foreman_statistics/trends_controller.rb', line 15

def show
  render 'foreman_statistics/trends/_empty_data' if @trend.values.joins(:trend_counters).empty?
end

#updateObject



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/foreman_statistics/trends_controller.rb', line 28

def update
  filter = self.class.trend_params_filter
  trend_attrs = params[:trend].values.map { |t| filter.filter_params(ActionController::Parameters.new(t), parameter_filter_context, :none) }
  @trends = Trend.update(params[:trend].keys, trend_attrs).reject { |p| p.errors.empty? }
  if @trends.empty?
    process_success
  else
    process_error
  end
end