Class: IdentifiersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- IdentifiersController
- Defined in:
- app/controllers/identifiers_controller.rb
Instance Method Summary collapse
- #api_autocomplete ⇒ Object
-
#api_index ⇒ Object
GET /api/v1/identifiers.
-
#api_show ⇒ Object
GET /api/v1/identifiers/:id.
- #autocomplete ⇒ Object
- #autocomplete_params ⇒ Object private
-
#create ⇒ Object
POST /identifiers POST /identifiers.json.
-
#destroy ⇒ Object
DELETE /identifiers/1 DELETE /identifiers/1.json.
-
#download ⇒ Object
GET /identifiers/download.
-
#edit ⇒ Object
GET /identifers/1/edit.
- #identifier_params ⇒ Object private
-
#identifier_types ⇒ Object
GET /identifiers/identifier_types.
-
#index ⇒ Object
GET /identifiers GET /identifiers.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /identifers.
-
#search ⇒ Object
GET /identifier/search.
- #set_identifier ⇒ Object private
-
#show ⇒ Object
GET /identifers/1.
-
#update ⇒ Object
PATCH/PUT /identifiers/1 PATCH/PUT /identifiers/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_autocomplete ⇒ Object
113 114 115 116 117 |
# File 'app/controllers/identifiers_controller.rb', line 113 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_index ⇒ Object
GET /api/v1/identifiers
98 99 100 101 102 103 104 105 |
# File 'app/controllers/identifiers_controller.rb', line 98 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_show ⇒ Object
GET /api/v1/identifiers/:id
108 109 110 111 |
# File 'app/controllers/identifiers_controller.rb', line 108 def api_show @identifier = Identifier.where(project_id: sessions_current_project_id).find(params[:id]) render '/identifiers/api/v1/show' end |
#autocomplete ⇒ Object
92 93 94 95 |
# File 'app/controllers/identifiers_controller.rb', line 92 def autocomplete render json: {} and return if params[:term].blank? @identifiers = Queries::Identifier::Autocomplete.new(params.require(:term), **autocomplete_params).autocomplete end |
#autocomplete_params ⇒ Object (private)
150 151 152 |
# File 'app/controllers/identifiers_controller.rb', line 150 def autocomplete_params params.permit(identifier_object_type: []).to_h.symbolize_keys.merge(project_id: sessions_current_project_id) # :exact end |
#create ⇒ Object
POST /identifiers POST /identifiers.json
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/identifiers_controller.rb', line 39 def create @identifier = Identifier.new(identifier_params) respond_to do |format| if @identifier.save format.html { redirect_to url_for(@identifier.identifier_object.), 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 |
#destroy ⇒ Object
DELETE /identifiers/1 DELETE /identifiers/1.json
70 71 72 73 74 75 76 77 |
# File 'app/controllers/identifiers_controller.rb', line 70 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 |
#download ⇒ Object
GET /identifiers/download
121 122 123 |
# File 'app/controllers/identifiers_controller.rb', line 121 def download send_data Export::Csv.generate_csv(Identifier.where(project_id: sessions_current_project_id)), type: 'text', filename: "identifiers_#{DateTime.now}.tsv" end |
#edit ⇒ Object
GET /identifers/1/edit
33 34 35 |
# File 'app/controllers/identifiers_controller.rb', line 33 def edit @identifier = Identifier.find_by_id(params[:id]). end |
#identifier_params ⇒ Object (private)
144 145 146 147 148 |
# File 'app/controllers/identifiers_controller.rb', line 144 def identifier_params params.require(:identifier).permit( :id, :identifier_object_id, :identifier_object_type, :identifier, :type, :namespace_id, :annotated_global_entity ) end |
#identifier_types ⇒ Object
GET /identifiers/identifier_types
126 127 128 |
# File 'app/controllers/identifiers_controller.rb', line 126 def identifier_types render json: IDENTIFIERS_JSON end |
#index ⇒ Object
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 { # 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 .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
79 80 81 |
# File 'app/controllers/identifiers_controller.rb', line 79 def list @identifiers = Identifier.where(project_id: sessions_current_project_id).includes(:updater).page(params[:page]) end |
#new ⇒ Object
GET /identifers
28 29 30 |
# File 'app/controllers/identifiers_controller.rb', line 28 def new @identifier = Identifier.new(identifier_params) end |
#search ⇒ Object
GET /identifier/search
84 85 86 87 88 89 90 |
# File 'app/controllers/identifiers_controller.rb', line 84 def search if @identifier = Identifier.find(params[:id]) redirect_to url_for(@identifier.identifier_object.) 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_identifier ⇒ Object (private)
132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/controllers/identifiers_controller.rb', line 132 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 |
#show ⇒ Object
GET /identifers/1
24 25 |
# File 'app/controllers/identifiers_controller.rb', line 24 def show end |
#update ⇒ Object
PATCH/PUT /identifiers/1 PATCH/PUT /identifiers/1.json
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/identifiers_controller.rb', line 55 def update respond_to do |format| if @identifier.update(identifier_params) format.html { redirect_to url_for(@identifier.identifier_object.), 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 |