Class: IdentifiersController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods inherited from ApplicationController

#digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #project_matches, #record_not_found, #set_project_from_params

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Methods included from InterceptApi

#intercept_api, #token_authenticate

Instance Method Details

- (Object) autocomplete



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

def autocomplete
  render json: {} and return if params[:term].blank?

  @identifiers = Queries::Identifier::Autocomplete.new(
    params.require(:term),
    autocomplete_params.to_h   
  ).autocomplete

end

- (Object) autocomplete_params (private)



122
123
124
# File 'app/controllers/identifiers_controller.rb', line 122

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

- (Object) create

POST /identifiers POST /identifiers.json



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

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

- (Object) destroy

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



68
69
70
71
72
73
74
# File 'app/controllers/identifiers_controller.rb', line 68

def destroy
  @identifier.destroy
  respond_to do |format|
    format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Identifier was successfully destroyed.')}
    format.json { head :no_content }
  end
end

- (Object) download

GET /identifiers/download



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

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

- (Object) edit

GET /identifers/1/edit



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

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

- (Object) identifier_params (private)



115
116
117
118
119
# File 'app/controllers/identifiers_controller.rb', line 115

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

- (Object) identifier_types

GET /identifiers/identifier_types



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

def identifier_types
  render json: IDENTIFIERS_JSON
end

- (Object) index

GET /identifiers GET /identifiers.json



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

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 {
      @identifiers = Queries::Identifier::Filter.new(params).all
        .where(project_id: sessions_current_project_id).page(params[:page]).per(params[:per] || 500)
    }
  end
end

- (Object) list



76
77
78
# File 'app/controllers/identifiers_controller.rb', line 76

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

- (Object) new

GET /identifers



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

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

- (Object) search

GET /identifier/search



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

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

- (Object) set_identifier (private)



111
112
113
# File 'app/controllers/identifiers_controller.rb', line 111

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

- (Object) show

GET /identifers/1



22
23
# File 'app/controllers/identifiers_controller.rb', line 22

def show
end

- (Object) update

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



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

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