Class: ProtocolsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/protocols_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

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, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#autocompleteObject



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

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

  data = @protocols.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

#createObject

POST /protocols POST /protocols.json



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

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

#destroyObject

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



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

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

#editObject

GET /protocols/1/edit



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

def edit
end

#indexObject

GET /protocols GET /protocols.json



8
9
10
11
12
13
14
15
16
17
18
# 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)
  respond_to do |format|
    format.html {
      render '/shared/data/all/index'
    }
    format.json {
      @protocols = Protocol.where(project_id: sessions_current_project_id).order(:name).all
    }
  end
end

#listObject



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

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

#newObject

GET /protocols/new



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

def new
  @protocol = Protocol.new
end

#protocol_paramsObject (private)



114
115
116
# File 'app/controllers/protocols_controller.rb', line 114

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

#searchObject



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

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

#select_optionsObject



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

def select_options
  @protocols = Protocol.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:klass))
end

#set_protocolObject (private)



110
111
112
# File 'app/controllers/protocols_controller.rb', line 110

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

#showObject

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



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

def show
end

#updateObject

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



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

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