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
flash[:danger] = @sample.errors.full_messages.to_sentence
@samples = current_user.samples[0..-2]
end
if operator?
redirect_to root_url
else
redirect_to :back
end
end
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"
status = params.delete :status
case status
......@@ -49,7 +49,7 @@ end
@sample = params[:id] && Sample.find(params[:id]) || nil
redirect_to(root_url) unless operator? || @user == current_user || @sample.status=="in preparation"
if @sample.status == "measured"
redirect_to(root_url)
redirect_to :back
end
end
......@@ -57,11 +57,7 @@ end
sample = Sample.find(params[:id])
if sample.update_attributes(sample_params)
flash[:success] = "Sample updated"
if operator?
redirect_to root_path
else
redirect_to :back
end
redirect_to :back && "?display_sample=#{sample.id}"
else
#render 'root_path'
end
......@@ -87,7 +83,7 @@ end
sample.status = "submitted"
sample.save
end
redirect_to root_path
redirect_to :back && "?display_sample=#{sample.id}"
end
def ReleaseMeasurment
......@@ -96,7 +92,7 @@ end
sample.status = "measured"
sample.save
end
redirect_to root_path
redirect_to :back && "?display_sample=#{sample.id}"
end
private
......
class StaticPagesController < ApplicationController
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? )
@samples = current_user.samples[0..-1]
@feed_items = current_user.feed.paginate(page: params[:page],per_page: 2 )
@sample = current_user.samples.build
elsif (logged_in? && operator?)
@samples = Sample.where('status <> ? OR user_id = ?','in preparation',current_user.id)
@sample = current_user.samples.build
end
end
......
......@@ -91,5 +91,10 @@ $(document).ready(function(){
</div>
</div>
</div>
<div class="panel panel-default" id="show" style="display:none;">
</div>
<%if @sample.persisted?%>
<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() {
</tr>
</thead>
<tbody>
<%[@sample].each do |sample|%>
<% [@sample].each do |sample|%>
<tr class="selekt">
<td>
<%= @sample.id%>
......@@ -52,7 +52,7 @@ $(document).ready(function() {
<td>
<% if ((operator? && sample.status =="measured") || (!operator? && sample.status=="submitted" ||!operator? && sample.status=="measured")) %>
<%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%>
<% 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,
......
<% provide(:title, 'Samples') %>
<div class="col-md-8">
<h3>Samples (<%= @samples.count %>) </h3>
<div class="panel panel-default">
<%= render 'samples/samples' %>
<br>
</div><br>
<%#= link_to 'Back', root_path%>
</div>
......@@ -6,7 +6,9 @@
<% if !operator?%>
<%=render 'shared/sample_form'%></br>
<% end %>
<div class="panel panel-default">
<%= render 'samples/samples' %>
</div>
<%= will_paginate @samples %>
<% end %>
</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