Class: AlternateValuesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- AlternateValuesController
- Defined in:
- app/controllers/alternate_values_controller.rb
Instance Method Summary collapse
- #alternate_value_params ⇒ Object private
- #autocomplete ⇒ Object
- #breakout_types(collection) ⇒ Object private
-
#create ⇒ Object
POST /alternate_values POST /alternate_values.json.
-
#destroy ⇒ Object
DELETE /alternate_values/1 DELETE /alternate_values/1.json.
-
#download ⇒ Object
GET /alternate_values/download.
- #edit ⇒ Object
-
#index ⇒ Object
GET /alternate_values GET /alternate_values.json.
- #list ⇒ Object
-
#metadata ⇒ Object
GET /alternate_values/:global_id/metadata.
-
#search ⇒ Object
GET /alternate_values/search.
- #set_alternate_value ⇒ Object private
-
#update ⇒ Object
PATCH/PUT /alternate_values/1 PATCH/PUT /alternate_values/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form
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
#alternate_value_params ⇒ Object (private)
113 114 115 116 117 118 119 |
# File 'app/controllers/alternate_values_controller.rb', line 113 def alternate_value_params params.require(:alternate_value).permit( :value, :type, :language_id, :alternate_value_object_type, :alternate_value_object_id, :alternate_value_object_attribute, :is_community_annotation, :annotated_global_entity ) end |
#autocomplete ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/alternate_values_controller.rb', line 81 def autocomplete @alternate_values = AlternateValue.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)) data = @alternate_values.collect do |t| str = render_to_string(partial: 'tag', locals: {alternate_value: t}) {id: t.id, label: str, response_values: {params[:method] => t.id}, label_html: str } end render json: data end |
#breakout_types(collection) ⇒ Object (private)
121 122 123 |
# File 'app/controllers/alternate_values_controller.rb', line 121 def breakout_types(collection) collection end |
#create ⇒ Object
POST /alternate_values POST /alternate_values.json
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/alternate_values_controller.rb', line 27 def create @alternate_value = AlternateValue.new(alternate_value_params) respond_to do |format| @alternate_value.project_id = sessions_current_project_id if params[:project_members_only] == 'checked' if @alternate_value.save format.html { redirect_to url_for(@alternate_value.alternate_value_object.), notice: 'Alternate value was successfully created.' } format.json { render action: :show, status: :created, location: @alternate_value. } else format.html { render 'new', notice: 'Alternate value was NOT successfully created.' } format.json { render json: @alternate_value.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /alternate_values/1 DELETE /alternate_values/1.json
59 60 61 62 63 64 65 |
# File 'app/controllers/alternate_values_controller.rb', line 59 def destroy @alternate_value.destroy respond_to do |format| format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Alternate value was successfully destroyed.')} format.json { head :no_content } end end |
#download ⇒ Object
GET /alternate_values/download
97 98 99 |
# File 'app/controllers/alternate_values_controller.rb', line 97 def download send_data Export::Download.generate_csv(AlternateValue.where(project_id: sessions_current_project_id)), type: 'text', filename: "alternate_values_#{DateTime.now}.csv" end |
#edit ⇒ Object
21 22 23 |
# File 'app/controllers/alternate_values_controller.rb', line 21 def edit @alternate_value = AlternateValue.find_by_id(params[:id]). end |
#index ⇒ Object
GET /alternate_values GET /alternate_values.json
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/alternate_values_controller.rb', line 8 def index respond_to do |format| format.html { @recent_objects = AlternateValue.where(project_id: sessions_current_project_id).order(updated_at: :desc).limit(10) render '/shared/data/all/index' } format.json { @alternate_values = Queries::AlternateValue::Filter.new(params).all .where(project_id: sessions_current_project_id).page(params[:page]).per(500) } end end |
#list ⇒ Object
67 68 69 |
# File 'app/controllers/alternate_values_controller.rb', line 67 def list @alternate_values = AlternateValue.where(project_id: sessions_current_project_id).order(:alternate_value_object_type).page(params[:page]) end |
#metadata ⇒ Object
GET /alternate_values/:global_id/metadata
102 103 104 |
# File 'app/controllers/alternate_values_controller.rb', line 102 def @object = GlobalID::Locator.locate(params.require(:global_id)) end |
#search ⇒ Object
GET /alternate_values/search
72 73 74 75 76 77 78 79 |
# File 'app/controllers/alternate_values_controller.rb', line 72 def search if params[:id].blank? redirect_to alternate_values_path, notice: 'You must select an item from the list with a click or tab press before clicking show.' else altval = AlternateValue.find_by_id(params[:id]). redirect_to url_for(altval.alternate_value_object.) end end |
#set_alternate_value ⇒ Object (private)
108 109 110 111 |
# File 'app/controllers/alternate_values_controller.rb', line 108 def set_alternate_value @alternate_value = AlternateValue.find(params[:id]) render status: 404 if !@alternate_value.project_id.blank? && (sessions_current_project_id != @alternate_value.project_id) end |
#update ⇒ Object
PATCH/PUT /alternate_values/1 PATCH/PUT /alternate_values/1.json
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/alternate_values_controller.rb', line 44 def update respond_to do |format| @alternate_value.project_id = sessions_current_project_id if params[:project_members_only] == 'checked' if @alternate_value.update(alternate_value_params) format.html { redirect_to url_for(@alternate_value.alternate_value_object.), notice: 'Alternate value was successfully updated.' } format.json { render json: @alternate_value, status: :ok, location: @alternate_value. } else format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Alternate value was NOT successfully updated.')} format.json { render json: @alternate_value.errors, status: :unprocessable_entity } end end end |