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

#polymorphic_filter_params

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/identifiers_controller.rb', line 84

def autocomplete
  @identifiers = Identifier.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)).limit(20)

  data = @identifiers.collect do |t|
    str = render_to_string(
        partial: 'tag',
        locals: {identifier: t})
    {id: t.id,
     label: str,
     response_values: {
         params[:method] => t.id
     },
     label_html: str
    }
  end

  render :json => data
end

- (Object) create

POST /identifiers POST /identifiers.json



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/identifiers_controller.rb', line 34

def create
  @identifier = Identifier.new(identifier_params)
  respond_to do |format|
    if @identifier.save
      format.html { redirect_to @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



63
64
65
66
67
68
69
# File 'app/controllers/identifiers_controller.rb', line 63

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



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

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

- (Object) edit

GET /identifers/1/edit



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

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

- (Object) identifier_params (private)



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

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 /taxon_name_relationships/taxon_name_relationship_types



109
110
111
# File 'app/controllers/identifiers_controller.rb', line 109

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
20
21
# 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 = Identifier.where(project_id: sessions_current_project_id).where(
        polymorphic_filter_params(
          'identifier_object', Identifier.related_foreign_keys  )
      )
    }
  end
end

- (Object) list



71
72
73
# File 'app/controllers/identifiers_controller.rb', line 71

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

- (Object) new



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

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

- (Object) search

GET /identifier/search



76
77
78
79
80
81
82
# File 'app/controllers/identifiers_controller.rb', line 76

def search
  if @identifier = Identifier.find(params[:id])
    redirect_to @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)



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

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

- (Object) update

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



49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/identifiers_controller.rb', line 49

def update
  respond_to do |format|
    if @identifier.update(identifier_params)
      format.html { redirect_to @identifier.identifier_object.metamorphosize, notice: 'Identifier was successfully updated.' }
      format.json { head :no_content }
    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