Class: FieldOccurrencesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/field_occurrences_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, #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, #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

#autocompleteObject



74
75
76
77
78
79
# File 'app/controllers/field_occurrences_controller.rb', line 74

def autocomplete
  @field_occurrences = ::Queries::FieldOccurrence::Autocomplete.new(
    params[:term],
    project_id: sessions_current_project_id
  ).autocomplete
end

#createObject

POST /field_occurrences or /field_occurrences.json



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

def create
  @field_occurrence = ::FieldOccurrence.new(field_occurrence_params)

  respond_to do |format|
    if @field_occurrence.save
      format.html { redirect_to field_occurrence_url(@field_occurrence), notice: 'Field occurrence was successfully created.' }
      format.json { render :show, status: :created, location: @field_occurrence }
    else
      format.html { render :new, status: :unprocessable_entity }
      format.json { render json: @field_occurrence.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /field_occurrences/1 or /field_occurrences/1.json



65
66
67
68
69
70
71
72
# File 'app/controllers/field_occurrences_controller.rb', line 65

def destroy
  @field_occurrence.destroy

  respond_to do |format|
    format.html { redirect_to field_occurrences_url, notice: 'Field occurrence was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /field_occurrences/1/edit



33
34
# File 'app/controllers/field_occurrences_controller.rb', line 33

def edit
end

#field_occurrence_paramsObject (private)



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/controllers/field_occurrences_controller.rb', line 104

def field_occurrence_params
  params.require(:field_occurrence).permit(
    :total, :is_absent,
    :ranged_lot_category_id,
    :collecting_event_id,
    :taxon_determination_id,
    collecting_event_attributes: [],  # needs to be filled out!
    data_attributes_attributes: [ :id, :_destroy, :controlled_vocabulary_term_id, :type, :value ],
    tags_attributes: [:id, :_destroy, :keyword_id],
    depictions_attributes: [:id, :_destroy, :svg_clip, :svg_view_box, :position, :caption, :figure_label, :image_id],
    identifiers_attributes: [
      :id,
      :_destroy,
      :identifier,
      :namespace_id,
      :type,
      labels_attributes: [
        :text,
        :type,
        :text_method,
        :total
      ]
    ],
    taxon_determinations_attributes: [
      :id, :_destroy, :otu_id, :year_made, :month_made, :day_made, :position,
      roles_attributes: [:id, :_destroy, :type, :organization_id, :person_id, :position, person_attributes: [:last_name, :first_name, :suffix, :prefix]],
      otu_attributes: [:id, :_destroy, :name, :taxon_name_id]
    ],
    biocuration_classifications_attributes: [
      :id, :_destroy, :biocuration_class_id
    ])
end

#indexObject

GET /field_occurrences or /field_occurrences.json



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/field_occurrences_controller.rb', line 9

def index
  respond_to do |format|
    format.html do
      @recent_objects = FieldOccurrence.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @field_occurrences = ::Queries::FieldOccurrence::Filter.new(params).all
        .page(params[:page])
        .per(params[:per])
    }
  end
end

#listObject

GET /collection_objects/list



82
83
84
85
86
# File 'app/controllers/field_occurrences_controller.rb', line 82

def list
  @field_occurrences = FieldOccurrence.with_project_id(sessions_current_project_id)
    .order(:id)
    .page(params[:page]) #.per(10) #.per(3)
end

#newObject

GET /field_occurrences/new



28
29
30
# File 'app/controllers/field_occurrences_controller.rb', line 28

def new
  redirect_to new_field_occurrence_task_path
end

#searchObject



88
89
90
91
92
93
94
95
96
# File 'app/controllers/field_occurrences_controller.rb', line 88

def search
  if params[:id].blank?
    redirect_to(
      field_occurrences_path,
      alert: 'You must select an item from the list with a click or tab press before clicking show.')
  else
    redirect_to field_occurrence_path(params[:id])
  end
end

#set_field_occurrenceObject (private)



100
101
102
# File 'app/controllers/field_occurrences_controller.rb', line 100

def set_field_occurrence
  @field_occurrence = FieldOccurrence.where(project_id: sessions_current_project_id).find(params[:id])
end

#showObject

GET /field_occurrences/1 or /field_occurrences/1.json



24
25
# File 'app/controllers/field_occurrences_controller.rb', line 24

def show
end

#updateObject

PATCH/PUT /field_occurrences/1 or /field_occurrences/1.json



52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/field_occurrences_controller.rb', line 52

def update
  respond_to do |format|
    if @field_occurrence.update(field_occurrence_params)
      format.html { redirect_to field_occurrence_url(@field_occurrence), notice: 'Field occurrence was successfully updated.' }
      format.json { render :show, status: :ok, location: @field_occurrence }
    else
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @field_occurrence.errors, status: :unprocessable_entity }
    end
  end
end