Class: DataAttributesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DataAttributesController
- Defined in:
- app/controllers/data_attributes_controller.rb
Instance Method Summary collapse
- #api_index ⇒ Object
- #api_params ⇒ Object private
- #api_show ⇒ Object
- #autocomplete ⇒ Object
-
#create ⇒ Object
POST /data_attributes POST /data_attributes.json.
- #data_attribute_params ⇒ Object private
-
#destroy ⇒ Object
DELETE /data_attributes/1 DELETE /data_attributes/1.json.
-
#download ⇒ Object
GET /data_attributes/download.
-
#edit ⇒ Object
GET /data_attributes/1/edit.
- #filter_params ⇒ Object private
-
#index ⇒ Object
GET /data_attributes GET /data_attributes.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /data_attributes/new.
-
#search ⇒ Object
GET /data_attributes/search.
- #set_data_attribute ⇒ Object private
-
#update ⇒ Object
PATCH/PUT /data_attributes/1 PATCH/PUT /data_attributes/1.json.
- #value_autocomplete ⇒ Object
- #value_autocomplete_params ⇒ Object private
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 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
#api_index ⇒ Object
22 23 24 25 26 27 |
# File 'app/controllers/data_attributes_controller.rb', line 22 def api_index @data_attributes = Queries::DataAttribute::Filter.new(api_params).all .where(project_id: sessions_current_project_id) .page(params[:page]).per(params[:per]) render '/data_attributes/api/v1/index' end |
#api_params ⇒ Object (private)
130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/controllers/data_attributes_controller.rb', line 130 def api_params params.permit( :value, :controlled_vocabulary_term_id, :import_predicate, :type, :object_global_id, :attribute_subject_type, :attribute_subject_id ) end |
#api_show ⇒ Object
29 30 31 |
# File 'app/controllers/data_attributes_controller.rb', line 29 def api_show render '/data_attributes/api/v1/show' end |
#autocomplete ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'app/controllers/data_attributes_controller.rb', line 96 def autocomplete render json: {} and return if params[:term].blank? @data_attributes = Queries::DataAttribute::Autocomplete.new( params.require(:term), project_id: sessions_current_project_id ).autocomplete end |
#create ⇒ Object
POST /data_attributes POST /data_attributes.json
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/data_attributes_controller.rb', line 45 def create @data_attribute = DataAttribute.new(data_attribute_params) respond_to do |format| if @data_attribute.save format.html { redirect_to url_for(@data_attribute.attribute_subject.), notice: 'Data attribute was successfully created.' } format.json { render action: 'show', status: :created, location: @data_attribute. } else format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Data attribute was NOT successfully created.')} format.json { render json: @data_attribute.errors, status: :unprocessable_entity } end end end |
#data_attribute_params ⇒ Object (private)
153 154 155 156 157 158 159 160 161 162 163 |
# File 'app/controllers/data_attributes_controller.rb', line 153 def data_attribute_params params.require(:data_attribute).permit( :type, :attribute_subject_id, :attribute_subject_type, :controlled_vocabulary_term_id, :import_predicate, :value, :annotated_global_entity ) end |
#destroy ⇒ Object
DELETE /data_attributes/1 DELETE /data_attributes/1.json
75 76 77 78 79 80 81 |
# File 'app/controllers/data_attributes_controller.rb', line 75 def destroy @data_attribute.destroy respond_to do |format| format.html { destroy_redirect @data_attribute, notice: 'Data attribute was successfully destroyed.' } format.json { head :no_content } end end |
#download ⇒ Object
GET /data_attributes/download
112 113 114 |
# File 'app/controllers/data_attributes_controller.rb', line 112 def download send_data Export::Download.generate_csv(DataAttribute.where(project_id: sessions_current_project_id)), type: 'text', filename: "data_attributes_#{DateTime.now}.csv" end |
#edit ⇒ Object
GET /data_attributes/1/edit
39 40 41 |
# File 'app/controllers/data_attributes_controller.rb', line 39 def edit @data_attribute = DataAttribute.find_by_id(params[:id]) end |
#filter_params ⇒ Object (private)
118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/data_attributes_controller.rb', line 118 def filter_params params.permit( :value, :controlled_vocabulary_term_id, :import_predicate, :type, :object_global_id, :attribute_subject_type, :attribute_subject_id ) end |
#index ⇒ Object
GET /data_attributes GET /data_attributes.json
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/data_attributes_controller.rb', line 9 def index respond_to do |format| format.html { @recent_objects = DataAttribute.where(project_id: sessions_current_project_id).order(updated_at: :desc).limit(10) render '/shared/data/all/index' } format.json { @data_attributes = Queries::DataAttribute::Filter.new(params).all .where(project_id: sessions_current_project_id).page(params[:page] || 1).per(params[:per] || 500) } end end |
#list ⇒ Object
83 84 85 |
# File 'app/controllers/data_attributes_controller.rb', line 83 def list @data_attributes = DataAttribute.where(project_id: sessions_current_project_id).order(:attribute_subject_type).page(params[:page]) end |
#new ⇒ Object
GET /data_attributes/new
34 35 36 |
# File 'app/controllers/data_attributes_controller.rb', line 34 def new @data_attribute = DataAttribute.new(data_attribute_params) end |
#search ⇒ Object
GET /data_attributes/search
88 89 90 91 92 93 94 |
# File 'app/controllers/data_attributes_controller.rb', line 88 def search if @data_attribute = DataAttribute.find(params[:id]) redirect_to url_for(@data_attribute.attribute_subject.) else redirect_to data_attribute_path, alert: 'You must select an item from the list with a click or tab press before clicking show.' end end |
#set_data_attribute ⇒ Object (private)
146 147 148 149 150 151 |
# File 'app/controllers/data_attributes_controller.rb', line 146 def set_data_attribute @data_attribute = DataAttribute.find(params[:id]) if !@data_attribute.project_id.blank? && (sessions_current_project_id != @data_attribute.project_id) render status: 404 and return end end |
#update ⇒ Object
PATCH/PUT /data_attributes/1 PATCH/PUT /data_attributes/1.json
61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/data_attributes_controller.rb', line 61 def update respond_to do |format| if @data_attribute.update(data_attribute_params) format.html { redirect_to url_for(@data_attribute.attribute_subject.), notice: 'Data attribute was successfully updated.' } format.json { render :show, status: :ok, location: @data_attribute. } else format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Data attribute was NOT successfully updated.')} format.json { render json: @data_attribute.errors, status: :unprocessable_entity } end end end |
#value_autocomplete ⇒ Object
105 106 107 108 109 |
# File 'app/controllers/data_attributes_controller.rb', line 105 def value_autocomplete render json: [] if params[:term].blank? || params[:predicate_id].blank? @values = ::Queries::DataAttribute::ValueAutocomplete.new(params[:term], **value_autocomplete_params).autocomplete render json: @values end |
#value_autocomplete_params ⇒ Object (private)
142 143 144 |
# File 'app/controllers/data_attributes_controller.rb', line 142 def value_autocomplete_params params.permit(:predicate_id).merge(project_id: sessions_current_project_id).to_h.symbolize_keys end |