Class: LeadItemsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/lead_items_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #cumulative_projects_created_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #sound_cumulative_gb_per_year, #sound_gb_per_year, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#add_lead_items_to_child_leadObject



75
76
77
78
79
80
81
82
83
# File 'app/controllers/lead_items_controller.rb', line 75

def add_lead_items_to_child_lead
  parent = Lead.find(params[:parent_id])
  otu_ids = params[:otu_ids]
  added = LeadItem.add_items_to_child_lead(parent, otu_ids)

  if !added
    render json: parent.errors, status: :unprocessable_entity
  end
end

#add_otu_indexObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/lead_items_controller.rb', line 85

def add_otu_index
  @lead = Lead.find(params[:lead_id])
  added = LeadItem.add_otu_index_for_lead(
    @lead, params[:otu_id], params[:exclusive]
  )
  if !added
    render json: @lead.errors, status: :unprocessable_entity
    return
  end

  @lead_item_otus = @lead.parent.apportioned_lead_item_otus
  render partial: 'leads/lead_item_otus',
    locals: { lead_item_otus: @lead_item_otus, lead: @lead }
end

#createObject

POST /lead_items or /lead_items.json



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/lead_items_controller.rb', line 24

def create
  @lead_item = LeadItem.new(lead_item_params)

  respond_to do |format|
    if @lead_item.save
      format.html { redirect_to @lead_item, notice: 'Lead item was successfully created.' }
      format.json { render :show, status: :created, location: @lead_item }
    else
      format.html { render :new, status: :unprocessable_entity }
      format.json { render json: @lead_item.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /lead_items/1 or /lead_items/1.json



52
53
54
55
56
57
58
59
# File 'app/controllers/lead_items_controller.rb', line 52

def destroy
  @lead_item.destroy!

  respond_to do |format|
    format.html { redirect_to lead_items_path, status: :see_other, notice: 'Lead item was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#destroy_item_in_childrenObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/lead_items_controller.rb', line 61

def destroy_item_in_children
  lead_ids = Lead.find(params[:parent_id]).children.map(&:id)
  # Only one child should ever have the lead_item we're looking for, the
  # following is just the most economical way of finding and destroying it.
  begin
    LeadItem
      .where(lead_id: lead_ids, otu_id: params[:otu_id])
      .destroy_all
  rescue ActiveRecord::RecordNotDestroyed => e
    errors.add(:base, "Destroy lead item failed! '#{e}'")
    return false
  end
end

#editObject

GET /lead_items/1/edit



20
21
# File 'app/controllers/lead_items_controller.rb', line 20

def edit
end

#indexObject

GET /lead_items or /lead_items.json



7
8
# File 'app/controllers/lead_items_controller.rb', line 7

def index
end

#lead_item_paramsObject (private)

Only allow a list of trusted parameters through.



120
121
122
# File 'app/controllers/lead_items_controller.rb', line 120

def lead_item_params
  params.require(:lead_item).permit(:lead_id, :otu_id, :project_id, :created_by_id, :updated_by_id, :position)
end

#newObject

GET /lead_items/new



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

def new
  @lead_item = LeadItem.new
end

#remove_otu_indexObject



100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/controllers/lead_items_controller.rb', line 100

def remove_otu_index
  @lead = Lead.find(params[:lead_id])
  removed = LeadItem.remove_otu_index_for_lead(@lead, params[:otu_id])
  if !removed
    render json: @lead.errors, status: :unprocessable_entity
    return
  end

  @lead_item_otus = @lead.parent.apportioned_lead_item_otus
  render partial: 'leads/lead_item_otus',
    locals: { lead_item_otus: @lead_item_otus, lead: @lead }
end

#set_lead_itemObject (private)

Use callbacks to share common setup or constraints between actions.



115
116
117
# File 'app/controllers/lead_items_controller.rb', line 115

def set_lead_item
  @lead_item = LeadItem.find(params[:id])
end

#showObject

GET /lead_items/1 or /lead_items/1.json



11
12
# File 'app/controllers/lead_items_controller.rb', line 11

def show
end

#updateObject

PATCH/PUT /lead_items/1 or /lead_items/1.json



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/lead_items_controller.rb', line 39

def update
  respond_to do |format|
    if @lead_item.update(lead_item_params)
      format.html { redirect_to @lead_item, notice: 'Lead item was successfully updated.' }
      format.json { render :show, status: :ok, location: @lead_item }
    else
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @lead_item.errors, status: :unprocessable_entity }
    end
  end
end