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



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/data_attributes_controller.rb', line 85

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



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/data_attributes_controller.rb', line 34

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 action: 'show', status: :created, location: @data_attribute.metamorphosize }
    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)



115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/data_attributes_controller.rb', line 115

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

- (Object) destroy

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



64
65
66
67
68
69
70
# File 'app/controllers/data_attributes_controller.rb', line 64

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



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

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

- (Object) edit

GET /data_attributes/1/edit



28
29
30
# File 'app/controllers/data_attributes_controller.rb', line 28

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

- (Object) index

GET /data_attributes GET /data_attributes.json



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/data_attributes_controller.rb', line 8

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 = DataAttribute.where(project_id: sessions_current_project_id).where(
        polymorphic_filter_params( 'attribute_subject', DataAttribute.related_foreign_keys )
      )
    }
  end
end

- (Object) list



72
73
74
# File 'app/controllers/data_attributes_controller.rb', line 72

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

- (Object) new

GET /data_attributes/new



23
24
25
# File 'app/controllers/data_attributes_controller.rb', line 23

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

- (Object) search

GET /data_attributes/search



77
78
79
80
81
82
83
# File 'app/controllers/data_attributes_controller.rb', line 77

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)



108
109
110
111
112
113
# File 'app/controllers/data_attributes_controller.rb', line 108

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

- (Object) update

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



50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/data_attributes_controller.rb', line 50

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 { render :show, status: :ok, location: @data_attribute.metamorphosize }
    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