Skip to content

Commit

Permalink
Move protocols and protocol drugs into the admin namespace.
Browse files Browse the repository at this point in the history
- Change paths everywhere
- Fix tests
- Remove json from controllers
  • Loading branch information
ssrihari committed Jun 5, 2018
1 parent 4342c48 commit efe609e
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 172 deletions.
54 changes: 54 additions & 0 deletions app/controllers/admin/protocol_drugs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class Admin::ProtocolDrugsController < ApplicationController
before_action :set_protocol_drug, only: %i[show edit update destroy]
before_action :set_protocols, only: %i[create edit update new]

def index
@protocol_drugs = ProtocolDrug.all
end

def show
end

def new
@protocol_drug = ProtocolDrug.new
end

def edit
end

def create
@protocol_drug = ProtocolDrug.new(protocol_drug_params)
if @protocol_drug.save
redirect_to [:admin, :protocols], notice: 'Protocol drug was successfully created.'
else
render :new
end
end

def update
if @protocol_drug.update(protocol_drug_params)
redirect_to [:admin, :protocols], notice: 'Protocol drug was successfully updated.'
else
render :edit
end
end

def destroy
@protocol_drug.destroy
redirect_to [:admin, :protocols], notice: 'Protocol drug was successfully destroyed.'
end

private

def set_protocols
@protocols = Protocol.all
end

def set_protocol_drug
@protocol_drug = ProtocolDrug.find(params[:id])
end

def protocol_drug_params
params.require(:protocol_drug).permit(:name, :dosage, :rxnorm_code, :protocol_id)
end
end
49 changes: 49 additions & 0 deletions app/controllers/admin/protocols_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Admin::ProtocolsController < ApplicationController
before_action :set_protocol, only: %i[show edit update destroy]

def index
@protocols = Protocol.all
end

def show
end

def new
@protocol = Protocol.new
end

def edit
end

def create
@protocol = Protocol.new(protocol_params)
if @protocol.save
redirect_to [:admin, @protocol], notice: 'Protocol was successfully created.'
else
render :new
end
end

def update
if @protocol.update(protocol_params)
redirect_to [:admin, @protocol], notice: 'Protocol was successfully updated.'
else
render :edit
end
end

def destroy
@protocol.destroy
redirect_to admin_protocols_url, notice: 'Protocol was successfully destroyed.'
end

private

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

def protocol_params
params.require(:protocol).permit(:name, :follow_up_days)
end
end
66 changes: 0 additions & 66 deletions app/controllers/protocol_drugs_controller.rb

This file was deleted.

61 changes: 0 additions & 61 deletions app/controllers/protocols_controller.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_with(model: protocol_drug, local: true) do |form| %>
<%= form_with(model: [:admin, protocol_drug], local: true) do |form| %>
<% if protocol_drug.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(protocol_drug.errors.count, "error") %> prohibited this protocol_drug from being saved:</h2>
Expand Down
6 changes: 6 additions & 0 deletions app/views/admin/protocol_drugs/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Protocol Drug</h1>

<%= render 'form', protocol_drug: @protocol_drug %>
<%= link_to 'Show', [:admin, @protocol_drug] %> |
<%= link_to 'Back', admin_protocol_drugs_path %>
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
<td><%= protocol_drug.dosage %></td>
<td><%= protocol_drug.rxnorm_code %></td>
<td><%= protocol_drug.protocol %></td>
<td><%= link_to 'Show', protocol_drug %></td>
<td><%= link_to 'Edit', edit_protocol_drug_path(protocol_drug) %></td>
<td><%= link_to 'Destroy', protocol_drug, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Show', [:admin, protocol_drug] %></td>
<td><%= link_to 'Edit', edit_admin_protocol_drug_path(protocol_drug) %></td>
<td><%= link_to 'Destroy', [:admin, protocol_drug], method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Protocol Drug', new_protocol_drug_path %>
<%= link_to 'New Protocol Drug', new_admin_protocol_drug_path %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

<%= render 'form', protocol_drug: @protocol_drug %>
<%= link_to 'Back', protocol_drugs_path %>
<%= link_to 'Back', admin_protocol_drugs_path %>
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_with(model: protocol, local: true) do |form| %>
<%= form_with(model: [:admin, protocol], local: true) do |form| %>
<% if protocol.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(protocol.errors.count, "error") %> prohibited this protocol from being saved:</h2>
Expand Down
6 changes: 6 additions & 0 deletions app/views/admin/protocols/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Protocol</h1>

<%= render 'form', protocol: @protocol %>
<%= link_to 'Show', [:admin, @protocol]%> |
<%= link_to 'Back', admin_protocols_path %>
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
<tr>
<td><%= protocol.name %></td>
<td><%= protocol.follow_up_days %></td>
<td><%= link_to 'Show', protocol %></td>
<td><%= link_to 'Edit', edit_protocol_path(protocol) %></td>
<td><%= link_to 'Destroy', protocol, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Show', [:admin, protocol] %></td>
<td><%= link_to 'Edit', edit_admin_protocol_path(protocol) %></td>
<td><%= link_to 'Destroy', [:admin, protocol], method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Protocol', new_protocol_path %>
<%= link_to 'New Protocol', new_admin_protocol_path %>
<% @protocols.each do |protocol| %>
<h1>Protocol Drugs for <%= protocol.name %> </h1>
Expand All @@ -47,15 +47,15 @@
<td><%= protocol_drug.name %></td>
<td><%= protocol_drug.dosage %></td>
<td><%= protocol_drug.rxnorm_code %></td>
<td><%= link_to 'Show', protocol_drug %></td>
<td><%= link_to 'Edit', edit_protocol_drug_path(protocol_drug) %></td>
<td><%= link_to 'Destroy', protocol_drug, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Show', [:admin, protocol_drug] %></td>
<td><%= link_to 'Edit', edit_admin_protocol_drug_path(protocol_drug) %></td>
<td><%= link_to 'Destroy', [:admin, protocol_drug], method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Protocol Drug', new_protocol_drug_path %>
<%= link_to 'New Protocol Drug', new_admin_protocol_drug_path %>
<% end %>
5 changes: 5 additions & 0 deletions app/views/admin/protocols/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New Protocol</h1>

<%= render 'form', protocol: @protocol%>
<%= link_to 'Back', admin_protocols_path %>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<%= @protocol.follow_up_days %>
</p>

<%= link_to 'Edit', edit_protocol_path(@protocol) %> |
<%= link_to 'Back', protocols_path %>
<%= link_to 'Edit', edit_admin_protocol_path(@protocol) %> |
<%= link_to 'Back', admin_protocols_path %>
6 changes: 0 additions & 6 deletions app/views/protocol_drugs/edit.html.erb

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/protocols/edit.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/protocols/new.html.erb

This file was deleted.

7 changes: 5 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Rails.application.routes.draw do
resources :protocol_drugs
resources :protocols
mount Rswag::Ui::Engine => '/api-docs'
mount Rswag::Api::Engine => '/api-docs'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
Expand All @@ -20,4 +18,9 @@
end
end
end

namespace :admin do
resources :protocol_drugs
resources :protocols
end
end
Loading

0 comments on commit efe609e

Please sign in to comment.