Class: ExtractsController

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



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

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

#createObject

POST /extracts POST /extracts.json



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/extracts_controller.rb', line 44

def create
  @extract = Extract.new(extract_params)

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

#destroyObject

DELETE /extracts/1 DELETE /extracts/1.json



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

def destroy
  @extract.destroy
  respond_to do |format|
    format.html { redirect_to extracts_url, notice: 'Extract was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /extracts/1/edit



35
36
# File 'app/controllers/extracts_controller.rb', line 35

def edit
end

#extract_paramsObject (private)

Never trust parameters from the scary internet, only allow the white list through.



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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/controllers/extracts_controller.rb', line 108

def extract_params
  params.require(:extract).permit(
    :repository_id,
    :verbatim_anatomical_origin,
    :year_made,
    :month_made,
    :day_made,

    roles_attributes: [
      :id,
      :_destroy,
      :type,
      :person_id,
      :position,
      person_attributes: [
        :last_name,
        :first_name,
        :suffix, :prefix
      ]
    ],

    identifiers_attributes: [
      :id,
      :namespace_id,
      :identifier,
      :type,
      :_destroy
    ],

    data_attributes_attributes: [
      :id,
      :_destroy,
      :controlled_vocabulary_term_id,
      :type,
      :attribute_subject_id,
      :attribute_subject_type,
      :value
    ],

    protocol_relationships_attributes: [
      :id,
      :_destroy,
      :protocol_id
    ],

    origin_relationships_attributes: [
      :id,
      :_destroy,
      :old_object_id,
      :old_object_type
    ]
  )
end

#indexObject

GET /extracts GET /extracts.json



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

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

#listObject



38
39
40
# File 'app/controllers/extracts_controller.rb', line 38

def list
  @extracts = Extract.with_project_id(sessions_current_project_id).page(params[:page])
end

#newObject

GET /extracts/new



30
31
32
# File 'app/controllers/extracts_controller.rb', line 30

def new
  @extract = Extract.new
end

#searchObject



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

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

#select_optionsObject

GET /extracts/select_options



98
99
100
# File 'app/controllers/extracts_controller.rb', line 98

def select_options
  @extracts = Extract.select_optimized(sessions_current_user_id, sessions_current_project_id)
end

#set_extractObject (private)



103
104
105
# File 'app/controllers/extracts_controller.rb', line 103

def set_extract
  @extract = Extract.where(project_id: sessions_current_project_id).find(params[:id])
end

#showObject

GET /extracts/1 GET /extracts/1.json



26
27
# File 'app/controllers/extracts_controller.rb', line 26

def show
end

#updateObject

PATCH/PUT /extracts/1 PATCH/PUT /extracts/1.json



60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/extracts_controller.rb', line 60

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