Class: Backend::ActivitiesController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/activities_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Instance Method Summary collapse

Methods inherited from BaseController

accounts_range_crit, crit_params, journal_entries_states_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name

Instance Method Details

#duplicateObject

Duplicate activity basing on campaign


44
45
46
47
48
49
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
# File 'app/controllers/backend/activities_controller.rb', line 44

def duplicate
  source = if params[:source_campaign_id]
             Campaign.find(params[:source_campaign_id])
           else
             current_campaign.preceding
           end
  activity = Activity.find_by(id: params[:source_activity_id])

  new_campaign = Campaign.find_by(id: params[:campaign_id]) || current_campaign

  campaign_diff = new_campaign.harvest_year - source.harvest_year

  # Productions
  productions = ActivityProduction.of_campaign(source)
  productions = productions.of_activity(activity) if activity
  productions.each do |production|
    updates = { campaign: new_campaign }
    if production.started_on
      updates[:started_on] = production.started_on + campaign_diff.year
    end
    if production.stopped_on
      updates[:stopped_on] = production.stopped_on + campaign_diff.year
    end
    production.duplicate!(updates)
  end

  # Budgets
  budgets = ActivityBudget.of_campaign(source)
  budgets = budgets.of_activity(activity) if activity
  budgets.each do |budget|
    budget.duplicate!(activity, new_campaign)
  end
  redirect_to params[:redirect] || { action: :index }
end

#familyObject

Returns wanted varieties proposition for given family_name


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/backend/activities_controller.rb', line 80

def family
  unless family = Nomen::ActivityFamily[params[:name]]
    head :not_found
    return
  end
  data = {
    label: family.human_name,
    name: family.name
  }
  unless family.cultivation_variety.blank?
    data[:cultivation_varieties] = Nomen::Variety.selection_hash(family.cultivation_variety)
  end
  unless family.support_variety.blank?
    data[:support_varieties] = Nomen::Variety.selection_hash(family.support_variety)
  end
  render json: data
end

#showObject


38
39
40
41
# File 'app/controllers/backend/activities_controller.rb', line 38

def show
  return unless @activity = find_and_check
  t3e @activity
end