Class: ExtractsController

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

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

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

#createObject

POST /extracts POST /extracts.json



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

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



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

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



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

def edit
end

#extract_paramsObject (private)

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



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
161
162
163
164
165
166
167
168
# File 'app/controllers/extracts_controller.rb', line 116

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

#filter_paramsObject (private)



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/controllers/extracts_controller.rb', line 98

def filter_params
  params.permit(
    :id,
    :user_date_end,
    :user_date_start,
    :user_id,
    :identifier,
    :identifier_end,
    :identifier_exact,
    :identifier_start,
    :identifier_type,
    :recent,
    :repository_id,
    repository_id: [],
  )
end

#indexObject

GET /extracts GET /extracts.json



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

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(filter_params).all.where(project_id: sessions_current_project_id).
      page(params[:page]).per(params[:per] || 500)
    }
    end
end

#listObject



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

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

#newObject

GET /extracts/new



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

def new
  @extract = Extract.new
end

#searchObject



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

def search
  if params[:id].blank?
    redirect_to extracts_path, notice: '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



89
90
91
# File 'app/controllers/extracts_controller.rb', line 89

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

#set_extractObject (private)



94
95
96
# File 'app/controllers/extracts_controller.rb', line 94

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

#showObject

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



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

def show
end

#updateObject

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



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

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