Class: DataAttributesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/data_attributes_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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/data_attributes_controller.rb', line 77

def autocomplete
  @data_attributes = DataAttribute.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)).limit(20)

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

  render :json => data
end

- (Object) create

POST /data_attributes POST /data_attributes.json



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/data_attributes_controller.rb', line 25

def create
  @data_attribute = DataAttribute.new(data_attribute_params)

  respond_to do |format|
    if @data_attribute.save
      format.html { redirect_to @data_attribute.attribute_subject.metamorphosize, notice: 'Data attribute was successfully created.' }
      format.json { render json: @data_attribute, 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

- (Object) data_attribute_params (private)

Never trust parameters from the scary internet, only allow the white list through.



109
110
111
112
113
114
115
116
117
# File 'app/controllers/data_attributes_controller.rb', line 109

def data_attribute_params
  params.require(:data_attribute).permit(
      :type,
      :attribute_subject_id,
      :attribute_subject_type,
      :controlled_vocabulary_term_id,
      :import_predicate,
      :value)
end

- (Object) destroy

DELETE /data_attributes/1 DELETE /data_attributes/1.json



56
57
58
59
60
61
62
# File 'app/controllers/data_attributes_controller.rb', line 56

def destroy
  @data_attribute.destroy
  respond_to do |format|
    format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Data attribute was successfully destroyed.')}
    format.json { head :no_content }
  end
end

- (Object) download

GET /data_attributes/download



94
95
96
# File 'app/controllers/data_attributes_controller.rb', line 94

def download
  send_data DataAttribute.generate_download( DataAttribute.where(project_id: $project_id) ), type: 'text', filename: "data_attributes_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /data_attributes/1/edit



19
20
21
# File 'app/controllers/data_attributes_controller.rb', line 19

def edit
  @data_attribute = DataAttribute.find_by_id(params[:id])
end

- (Object) index

GET /data_attributes GET /data_attributes.json



8
9
10
11
# File 'app/controllers/data_attributes_controller.rb', line 8

def index
  @recent_objects = DataAttribute.where(project_id: $project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



64
65
66
# File 'app/controllers/data_attributes_controller.rb', line 64

def list
  @data_attributes = DataAttribute.where(project_id: $project_id).order(:attribute_subject_type).page(params[:page])
end

- (Object) new

GET /data_attributes/new



14
15
16
# File 'app/controllers/data_attributes_controller.rb', line 14

def new
  @data_attribute = DataAttribute.new(data_attribute_params)
end

- (Object) search

GET /data_attributes/search



69
70
71
72
73
74
75
# File 'app/controllers/data_attributes_controller.rb', line 69

def search
  if params[:id].blank?
    redirect_to data_attribute_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to data_attribute_path(params[:id])
  end
end

- (Object) set_data_attribute (private)

Use callbacks to share common setup or constraints between actions.



101
102
103
104
105
106
# File 'app/controllers/data_attributes_controller.rb', line 101

def set_data_attribute
  @data_attribute = DataAttribute.find(params[:id])
  if !@data_attribute.project_id.blank? && ($project_id != @data_attribute.project_id)
    render status: 404 and return
  end
end

- (Object) update

PATCH/PUT /data_attributes/1 PATCH/PUT /data_attributes/1.json



42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/data_attributes_controller.rb', line 42

def update
  respond_to do |format|
    if @data_attribute.update(data_attribute_params)
      format.html { redirect_to @data_attribute.attribute_subject.metamorphosize, notice: 'Data attribute was successfully updated.' }
      format.json { head :no_content }
    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