Class: DataAttributesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DataAttributesController
- Defined in:
- app/controllers/data_attributes_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #api_brief ⇒ Object
- #api_index ⇒ Object
- #api_show ⇒ Object
- #autocomplete ⇒ Object
- #base_params ⇒ Object private
-
#batch_create ⇒ Object
/data_attributes/batch_create.json?attribute_subject_type=Otu&attribute_subject_id[]=123&value=456.
- #batch_data_attribute_params ⇒ Object private
- #brief ⇒ 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.
- #import_predicate_autocomplete ⇒ Object
-
#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
#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification
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_brief ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/data_attributes_controller.rb', line 33 def api_brief q = ::Queries::DataAttribute::Filter.new(params) @data = q.all .page(params[:page]) .per(params[:per]) .pluck('data_attributes.attribute_subject_id as object_id, data_attributes.controlled_vocabulary_term_id, data_attributes.value') cols = @data.collect{|a| a[1]}.uniq @columns = Predicate.where(project_id: sessions_current_project_id, id: cols).order(:name).pluck(:id, :name).inject([]){|ary, a| ary.push(a[0] => a[1]); ary} render '/data_attributes/api/v1/brief' end |
#api_index ⇒ Object
46 47 48 49 50 51 52 |
# File 'app/controllers/data_attributes_controller.rb', line 46 def api_index @data_attributes = Queries::DataAttribute::Filter.new(params.merge!(api: true)).all .where(project_id: sessions_current_project_id) .page(params[:page]) .per(params[:per]) render '/data_attributes/api/v1/index' end |
#api_show ⇒ Object
54 55 56 |
# File 'app/controllers/data_attributes_controller.rb', line 54 def api_show render '/data_attributes/api/v1/show' end |
#autocomplete ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'app/controllers/data_attributes_controller.rb', line 131 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 |
#base_params ⇒ Object (private)
179 180 181 182 183 184 185 186 187 188 |
# File 'app/controllers/data_attributes_controller.rb', line 179 def base_params [ :type, :attribute_subject_id, :attribute_subject_type, :controlled_vocabulary_term_id, :import_predicate, :value, :annotated_global_entity ] end |
#batch_create ⇒ Object
/data_attributes/batch_create.json?attribute_subject_type=Otu&attribute_subject_id[]=123&value=456
109 110 111 112 113 114 115 116 |
# File 'app/controllers/data_attributes_controller.rb', line 109 def batch_create @data_attributes = InternalAttribute.batch_create(batch_data_attribute_params) if @data_attributes.present? render '/data_attributes/index' else render json: { failed: true, status: :unprocessable_entity} end end |
#batch_data_attribute_params ⇒ Object (private)
190 191 192 193 194 |
# File 'app/controllers/data_attributes_controller.rb', line 190 def batch_data_attribute_params p = base_params p << {attribute_subject_id: []} params.require(:data_attribute).permit(p) end |
#brief ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/data_attributes_controller.rb', line 23 def brief q = ::Queries::DataAttribute::Filter.new(params) render json: [], status: :unprocessable_entity and return if q.all.count > 30000 @data = q.all.pluck('data_attributes.attribute_subject_id as object_id, data_attributes.controlled_vocabulary_term_id, data_attributes.value') cols = @data.collect{|a| a[1]}.uniq @columns = Predicate.where(project_id: sessions_current_project_id, id: cols).order(:name).pluck(:id, :name).inject([]){|ary, a| ary.push(a[0] => a[1]); ary} end |
#create ⇒ Object
POST /data_attributes POST /data_attributes.json
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/data_attributes_controller.rb', line 70 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)
196 197 198 |
# File 'app/controllers/data_attributes_controller.rb', line 196 def data_attribute_params params.require(:data_attribute).permit(base_params) end |
#destroy ⇒ Object
DELETE /data_attributes/1 DELETE /data_attributes/1.json
100 101 102 103 104 105 106 |
# File 'app/controllers/data_attributes_controller.rb', line 100 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
162 163 164 |
# File 'app/controllers/data_attributes_controller.rb', line 162 def download send_data Export::Csv.generate_csv(DataAttribute.where(project_id: sessions_current_project_id)), type: 'text', filename: "data_attributes_#{DateTime.now}.tsv" end |
#edit ⇒ Object
GET /data_attributes/1/edit
64 65 66 |
# File 'app/controllers/data_attributes_controller.rb', line 64 def edit @data_attribute = DataAttribute.find_by_id(params[:id]) end |
#import_predicate_autocomplete ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/controllers/data_attributes_controller.rb', line 140 def import_predicate_autocomplete render json: [] and return if params[:term].blank? @internal_attributes = ::DataAttribute .where(project_id: sessions_current_project_id) .where('import_predicate ilike ?', '%' + params[:term] + '%' ) .order(:import_predicate) .distinct .limit(20) .pluck(:import_predicate) render json: @internal_attributes end |
#index ⇒ Object
GET /data_attributes GET /data_attributes.json
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
118 119 120 |
# File 'app/controllers/data_attributes_controller.rb', line 118 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
59 60 61 |
# File 'app/controllers/data_attributes_controller.rb', line 59 def new @data_attribute = DataAttribute.new(data_attribute_params) end |
#search ⇒ Object
GET /data_attributes/search
123 124 125 126 127 128 129 |
# File 'app/controllers/data_attributes_controller.rb', line 123 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)
172 173 174 175 176 177 |
# File 'app/controllers/data_attributes_controller.rb', line 172 def set_data_attribute @data_attribute = DataAttribute.find(params[:id]) if @data_attribute.project_id.present? && (sessions_current_project_id != @data_attribute.project_id) render status: :not_found and return end end |
#update ⇒ Object
PATCH/PUT /data_attributes/1 PATCH/PUT /data_attributes/1.json
86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/data_attributes_controller.rb', line 86 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
155 156 157 158 159 |
# File 'app/controllers/data_attributes_controller.rb', line 155 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)
168 169 170 |
# File 'app/controllers/data_attributes_controller.rb', line 168 def value_autocomplete_params params.permit(:predicate_id).merge(project_id: sessions_current_project_id).to_h.symbolize_keys end |