Commit 11358561 authored by Sara Kuqi's avatar Sara Kuqi
Browse files

After update, show partial stays in the homepage

parent 61d6d5a1
...@@ -16,15 +16,15 @@ class SamplesController < ApplicationController ...@@ -16,15 +16,15 @@ class SamplesController < ApplicationController
flash[:danger] = @sample.errors.full_messages.to_sentence flash[:danger] = @sample.errors.full_messages.to_sentence
@samples = current_user.samples[0..-2] @samples = current_user.samples[0..-2]
end end
if operator? redirect_to :back
redirect_to root_url
else
redirect_to :back
end
end end
def index def index
@sample=Sample.new @sample = if params[:display_sample].present?
Sample.find(params[:display_sample].to_i)
else
current_user.samples.build
end
@title = "Listing Samples" @title = "Listing Samples"
status = params.delete :status status = params.delete :status
case status case status
...@@ -49,19 +49,15 @@ end ...@@ -49,19 +49,15 @@ end
@sample = params[:id] && Sample.find(params[:id]) || nil @sample = params[:id] && Sample.find(params[:id]) || nil
redirect_to(root_url) unless operator? || @user == current_user || @sample.status=="in preparation" redirect_to(root_url) unless operator? || @user == current_user || @sample.status=="in preparation"
if @sample.status == "measured" if @sample.status == "measured"
redirect_to(root_url) redirect_to :back
end end
end end
def update def update
sample = Sample.find(params[:id]) sample = Sample.find(params[:id])
if sample.update_attributes(sample_params) if sample.update_attributes(sample_params)
flash[:success] = "Sample updated" flash[:success] = "Sample updated"
if operator? redirect_to :back && "?display_sample=#{sample.id}"
redirect_to root_path
else
redirect_to :back
end
else else
#render 'root_path' #render 'root_path'
end end
...@@ -87,7 +83,7 @@ end ...@@ -87,7 +83,7 @@ end
sample.status = "submitted" sample.status = "submitted"
sample.save sample.save
end end
redirect_to root_path redirect_to :back && "?display_sample=#{sample.id}"
end end
def ReleaseMeasurment def ReleaseMeasurment
...@@ -96,7 +92,7 @@ end ...@@ -96,7 +92,7 @@ end
sample.status = "measured" sample.status = "measured"
sample.save sample.save
end end
redirect_to root_path redirect_to :back && "?display_sample=#{sample.id}"
end end
private private
......
class StaticPagesController < ApplicationController class StaticPagesController < ApplicationController
def home def home
if (logged_in?)
@sample = if params[:display_sample].present?
Sample.find(params[:display_sample].to_i)
else
current_user.samples.build
end
end
if (logged_in? && !operator? ) if (logged_in? && !operator? )
@samples = current_user.samples[0..-1] @samples = current_user.samples[0..-1]
@feed_items = current_user.feed.paginate(page: params[:page],per_page: 2 ) @feed_items = current_user.feed.paginate(page: params[:page],per_page: 2 )
@sample = current_user.samples.build
elsif (logged_in? && operator?) elsif (logged_in? && operator?)
@samples = Sample.where('status <> ? OR user_id = ?','in preparation',current_user.id) @samples = Sample.where('status <> ? OR user_id = ?','in preparation',current_user.id)
@sample = current_user.samples.build
end end
end end
......
...@@ -91,5 +91,10 @@ $(document).ready(function(){ ...@@ -91,5 +91,10 @@ $(document).ready(function(){
</div> </div>
</div> </div>
</div> </div>
<div class="panel panel-default" id="show" style="display:none;"> <%if @sample.persisted?%>
</div> <div class="panel panel-default" id="show">
<%= render 'samples/show'%>
</div>
<%else%>
<div class="panel panel-default" id="show" style="display:none;"></div>
<%end%>
...@@ -35,7 +35,7 @@ $(document).ready(function() { ...@@ -35,7 +35,7 @@ $(document).ready(function() {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<%[@sample].each do |sample|%> <% [@sample].each do |sample|%>
<tr class="selekt"> <tr class="selekt">
<td> <td>
<%= @sample.id%> <%= @sample.id%>
...@@ -52,7 +52,7 @@ $(document).ready(function() { ...@@ -52,7 +52,7 @@ $(document).ready(function() {
<td> <td>
<% if ((operator? && sample.status =="measured") || (!operator? && sample.status=="submitted" ||!operator? && sample.status=="measured")) %> <% if ((operator? && sample.status =="measured") || (!operator? && sample.status=="submitted" ||!operator? && sample.status=="measured")) %>
<%else%> <%else%>
<%= link_to '<i class="fa fa-pencil-square-o" aria-hidden="true"></i>'.html_safe, edit_sample_path, remote: true%> <%= link_to '<i class="fa fa-pencil-square-o" aria-hidden="true"></i>'.html_safe, edit_sample_path(sample), remote: true%>
<%end%> <%end%>
<% if current_user?(sample.user) && sample.status == "in preparation" %> <% if current_user?(sample.user) && sample.status == "in preparation" %>
<%= link_to '<i class="fa fa-trash" aria-hidden="true"></i>'.html_safe, sample, method: :delete, <%= link_to '<i class="fa fa-trash" aria-hidden="true"></i>'.html_safe, sample, method: :delete,
......
<% provide(:title, 'Samples') %> <% provide(:title, 'Samples') %>
<div class="col-md-8">
<h3>Samples (<%= @samples.count %>) </h3> <h3>Samples (<%= @samples.count %>) </h3>
<div class="panel panel-default">
<%= render 'samples/samples' %> <%= render 'samples/samples' %>
<br> </div>
</div><br>
<%#= link_to 'Back', root_path%>
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
<% if !operator?%> <% if !operator?%>
<%=render 'shared/sample_form'%></br> <%=render 'shared/sample_form'%></br>
<% end %> <% end %>
<div class="panel panel-default">
<%= render 'samples/samples' %> <%= render 'samples/samples' %>
</div>
<%= will_paginate @samples %> <%= will_paginate @samples %>
<% end %> <% end %>
</div> </div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment