Class: ProtocolsController

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



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

def autocomplete
  @protocol = Protocol.where(project_id: sessions_current_project_id).where('name ILIKE ?', "#{params[:term]}%")

  data = @protocol.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 /protocols POST /protocols.json



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

def create
  @protocol = Protocol.new(protocol_params)

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

- (Object) destroy

DELETE /protocols/1 DELETE /protocols/1.json



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

def destroy
  @protocol.destroy
  respond_to do |format|
    format.html { redirect_to protocols_url, notice: 'Protocol was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) edit

GET /protocols/1/edit



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

def edit
end

- (Object) index

GET /protocols GET /protocols.json



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

def index
  @recent_objects = Protocol.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



27
28
29
# File 'app/controllers/protocols_controller.rb', line 27

def list
  @protocols = Protocol.with_project_id(sessions_current_project_id).page(params[:page])
end

- (Object) new

GET /protocols/new



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

def new
  @protocol = Protocol.new
end

- (Object) protocol_params (private)



101
102
103
# File 'app/controllers/protocols_controller.rb', line 101

def protocol_params
  params.require(:protocol).permit(:name, :short_name, :description)
end

- (Object) search



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

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

- (Object) set_protocol (private)



97
98
99
# File 'app/controllers/protocols_controller.rb', line 97

def set_protocol
  @protocol = Protocol.find(params[:id])
end

- (Object) show

GET /protocols/1 GET /protocols/1.json



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

def show
end

- (Object) update

PATCH/PUT /protocols/1 PATCH/PUT /protocols/1.jsoned by Vsauce



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

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