Class: IdentifiersController

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

#api_autocompleteObject



124
125
126
127
128
# File 'app/controllers/identifiers_controller.rb', line 124

def api_autocomplete
  render json: {} and return if params[:term].blank?
  @identifiers = Queries::Identifier::Autocomplete.new(params.require(:term), **autocomplete_params).autocomplete
  render '/identifiers/api/v1/autocomplete'
end

#api_indexObject

GET /api/v1/identifiers



109
110
111
112
113
114
115
116
# File 'app/controllers/identifiers_controller.rb', line 109

def api_index
  @identifiers = Queries::Identifier::Filter.new(params.merge!(api: true)).all
    .where(project_id: sessions_current_project_id)
    .order('identifiers.id')
    .page(params[:page])
    .per(params[:per])
  render '/identifiers/api/v1/index'
end

#api_showObject

GET /api/v1/identifiers/:id



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

def api_show
  @identifier = Identifier.where(project_id: sessions_current_project_id).find(params[:id])
  render '/identifiers/api/v1/show'
end

#autocompleteObject



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

def autocomplete
  render json: {} and return if params[:term].blank?
  @identifiers = Queries::Identifier::Autocomplete.new(params.require(:term), **autocomplete_params).autocomplete
end

#autocomplete_paramsObject (private)



161
162
163
# File 'app/controllers/identifiers_controller.rb', line 161

def autocomplete_params
  params.permit(identifier_object_type: []).to_h.symbolize_keys.merge(project_id: sessions_current_project_id) # :exact
end

#createObject

POST /identifiers POST /identifiers.json



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

def create
  @identifier = Identifier.new(identifier_params)
  respond_to do |format|
    if @identifier.save
      format.html { redirect_to url_for(@identifier.identifier_object.metamorphosize),
                    notice: 'Identifier was successfully created.' }
      format.json { render action: 'show', status: :created, location: @identifier.becomes(Identifier) }
    else
      format.html { render 'new', notice: 'Identifier was NOT successfully created.' }
      format.json { render json: @identifier.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /identifiers/1 DELETE /identifiers/1.json



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

def destroy
  @identifier.destroy

  respond_to do |format|
    format.html { destroy_redirect @identifier, notice: 'Identifier was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#downloadObject

GET /identifiers/download



132
133
134
# File 'app/controllers/identifiers_controller.rb', line 132

def download
  send_data Export::CSV.generate_csv(Identifier.where(project_id: sessions_current_project_id)), type: 'text', filename: "identifiers_#{DateTime.now}.tsv"
end

#editObject

GET /identifers/1/edit



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

def edit
  @identifier = Identifier.find_by_id(params[:id]).metamorphosize
end

#identifier_paramsObject (private)



155
156
157
158
159
# File 'app/controllers/identifiers_controller.rb', line 155

def identifier_params
  params.require(:identifier).permit(
    :id, :identifier_object_id, :identifier_object_type, :identifier, :type, :namespace_id, :annotated_global_entity
  )
end

#identifier_typesObject

GET /identifiers/identifier_types



137
138
139
# File 'app/controllers/identifiers_controller.rb', line 137

def identifier_types
  render json: IDENTIFIERS_JSON
end

#indexObject

GET /identifiers GET /identifiers.json



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

def index
  respond_to do |format|
    format.html {
      @recent_objects = Identifier.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      # project_id handling logic is in filter, it must be handled there. This contrasts pattern used elsewhere, but see alternate_values_controller.rb
      @identifiers = Queries::Identifier::Filter.new(params.merge(project_id: sessions_current_project_id)).all
       .order(:identifier_object_type, :identifier_object_id, :position)
       .page(params[:page])
       .per(params[:per])
    }
  end
end

#listObject



90
91
92
# File 'app/controllers/identifiers_controller.rb', line 90

def list
  @identifiers = Identifier.where(project_id: sessions_current_project_id).includes(:updater).page(params[:page])
end

#newObject

GET /identifers



31
32
33
# File 'app/controllers/identifiers_controller.rb', line 31

def new
  @identifier = Identifier.new(identifier_params)
end

#reorderObject

PATCH /identifiers/reorder?id[]=1



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

def reorder
  params[:id].reverse.each do |identifier_id|
    Identifier.find(identifier_id).move_to_top
  end
  render json: true
end

#searchObject

GET /identifier/search



95
96
97
98
99
100
101
# File 'app/controllers/identifiers_controller.rb', line 95

def search
  if @identifier = Identifier.find(params[:id])
    redirect_to url_for(@identifier.identifier_object.metamorphosize)
  else
    redirect_to identifier_path, alert: 'You must select an item from the list with a click or tab press before clicking show.'
  end
end

#set_identifierObject (private)



143
144
145
146
147
148
149
150
151
152
153
# File 'app/controllers/identifiers_controller.rb', line 143

def set_identifier
  @identifier = Identifier.find(params[:id])

  if !@identifier.is_community_annotation?
    if @identifier.project_id != sessions_current_project_id
      return nil
    end
  end

  @identifier
end

#showObject

GET /identifers/1



27
28
# File 'app/controllers/identifiers_controller.rb', line 27

def show
end

#updateObject

PATCH/PUT /identifiers/1 PATCH/PUT /identifiers/1.json



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

def update
  respond_to do |format|
    if @identifier.update(identifier_params)
      format.html { redirect_to url_for(@identifier.identifier_object.metamorphosize),
                    notice: 'Identifier was successfully updated.' }
      format.json { render :show, status: :ok, location: @identifier.becomes(Identifier) }
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Identifier was NOT successfully created.')}
      format.json { render json: @identifier.errors, status: :unprocessable_entity }
    end
  end
end