Class: DescriptorsController

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

GET /annotations



103
104
105
106
# File 'app/controllers/descriptors_controller.rb', line 103

def annotations
  @object = @descriptor
  render '/shared/data/all/annotations'
end

- (Object) autocomplete



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

def autocomplete
  t = "#{params[:term]}%"
  @descriptors = Descriptor.where(project_id: sessions_current_project_id).where('name like ? or short_name like ?', t, t)
  data = @descriptors.collect do |t|
    {id:              t.id,
     label:           t.name, 
     gid: t.to_global_id.to_s,
     response_values: {
       params[:method] => t.id
     },
     label_html:      t.name 
    }
  end
  render :json => data
end

- (Object) create

POST /descriptors POST /descriptors.json



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

def create
  @descriptor = Descriptor.new(descriptor_params)

  respond_to do |format|
    if @descriptor.save
      format.html { redirect_to @descriptor.metamorphosize, notice: 'Descriptor was successfully created.' }
      format.json { render :show, status: :created, location: @descriptor.metamorphosize }
    else
      format.html { render :new }
      format.json { render json: @descriptor.metamorphosize.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) descriptor_params (private)



116
117
118
# File 'app/controllers/descriptors_controller.rb', line 116

def descriptor_params
  params.require(:descriptor).permit(:name, :short_name, :type)
end

- (Object) destroy

DELETE /descriptors/1 DELETE /descriptors/1.json



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

def destroy
  @descriptor.destroy
  respond_to do |format|
    format.html { redirect_to descriptors_url, notice: 'Descriptor was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) edit

GET /descriptors/1/edit



35
36
# File 'app/controllers/descriptors_controller.rb', line 35

def edit
end

- (Object) index

GET /descriptors GET /descriptors.json



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

def index
  respond_to do |format|
    format.html do
      @recent_objects = Descriptor.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @descriptors = Descriptor.all.limit(20)
    }
  end 
end

- (Object) list



25
26
27
# File 'app/controllers/descriptors_controller.rb', line 25

def list
  @descriptor = Descriptor.with_project_id(sessions_current_project_id).page(params[:page])
end

- (Object) new

GET /descriptors/new



30
31
32
# File 'app/controllers/descriptors_controller.rb', line 30

def new
  @descriptor = Descriptor.new
end

- (Object) search



94
95
96
97
98
99
100
# File 'app/controllers/descriptors_controller.rb', line 94

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

- (Object) set_descriptor (private)



112
113
114
# File 'app/controllers/descriptors_controller.rb', line 112

def set_descriptor
  @descriptor = Descriptor.find(params[:id])
end

- (Object) show

GET /descriptors/1 GET /descriptors/1.json



22
23
# File 'app/controllers/descriptors_controller.rb', line 22

def show
end

- (Object) update

PATCH/PUT /descriptors/1 PATCH/PUT /descriptors/1.json



56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/descriptors_controller.rb', line 56

def update
  respond_to do |format|
    if @descriptor.update(descriptor_params)
      format.html { redirect_to @descriptor.metamorphosize, notice: 'Descriptor was successfully updated.' }
      format.json { render :show, status: :ok, location: @descriptor.metamorphosize }
    else
      format.html { render :edit }
      format.json { render json: @descriptor.metamorphosize.errors, status: :unprocessable_entity }
    end
  end
end