Class: Kaui::AccountTagsController

Inherits:
EngineController show all
Defined in:
app/controllers/kaui/account_tags_controller.rb

Instance Method Summary collapse

Methods inherited from EngineController

#current_user

Methods included from ErrorHelper

#as_string

Instance Method Details

#editObject



18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/kaui/account_tags_controller.rb', line 18

def edit
  @account_id = params[:account_id]
  begin
    @available_tags = Kaui::TagDefinition..sort
    @account = Kaui::KillbillHelper::(@account_id)
    @tag_names = Kaui::KillbillHelper::(@account.).map { |tag| tag.tag_definition_name }
  rescue => e
    flash[:error] = "Error while editing tags: #{as_string(e)}"
  end
end

#showObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/kaui/account_tags_controller.rb', line 3

def show
   = params[:id]

  if .present?
    begin
      tags = Kaui::KillbillHelper::()
    rescue => e
      flash[:error] = "Error while getting tags: #{as_string(e)}"

    end
  else
    flash[:error] = "No account id given"
  end
end

#updateObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/kaui/account_tags_controller.rb', line 29

def update
  begin
    current_tags = Kaui::KillbillHelper::(params[:account_id]).map { |tag| tag.tag_definition_id }

    new_tags = []
    params.each do |tag, tag_name|
      tag_info = tag.split('_')
      next if tag_info.size != 2 or tag_info[0] != 'tag'
      new_tags << tag_info[1]
    end

    # Find tags to remove
    tags_to_remove = []
    current_tags.each do |current_tag_definition_id|
      tags_to_remove << current_tag_definition_id unless new_tags.include?(current_tag_definition_id)
    end

    # Find tags to add
    tags_to_add = []
    new_tags.each do |new_tag_definition_id|
      tags_to_add << new_tag_definition_id unless current_tags.include?(new_tag_definition_id)
    end

    Kaui::KillbillHelper::(params[:account_id], tags_to_remove) unless tags_to_remove.empty?
    Kaui::KillbillHelper::(params[:account_id], tags_to_add) unless tags_to_add.empty?
  rescue => e
    flash[:error] = "Error while updating tags: #{as_string(e)}"
  end
  redirect_to kaui_engine.(params[:account_id])
end