Commit 61d6d5a1 authored by Sara Kuqi's avatar Sara Kuqi
Browse files

resizeing tables, fix the calculation, change the chemist view, edit from the...

resizeing tables, fix the calculation, change the chemist view, edit from the main table in operators view
parent f59dee09
......@@ -2,13 +2,6 @@
@import "bootstrap";
@import "font-awesome";
/* mixins, variables, etc. */
// @mixin box_sizing {
// -moz-box-sizing: border-box;
// -webkit-box-sizing: border-box;
// box-sizing: border-box;
// }
/* universal*/
h1 {
font-size: 4em;
......@@ -73,17 +66,7 @@ textarea {
.center h1 {
margin-bottom: 20px;
}
/* miscellaneous */
// .debug_dump {
// clear: both;
// float: left;
// width: 100%;
// margin-top: 45px;
// @include box_sizing;
// }
/* sidebar */
aside {
section.user_info {
margin-top: 20px;
......@@ -210,13 +193,18 @@ span.picture {
.table-sortable tbody tr {
cursor: move;
}
.table-nonfluid {
width: auto !important;
}
// .table-nonfluid {
// width: auto !important;
// }
.table-hover tbody tr:hover td, .table-hover tbody tr:hover th {
background-color: #f2f2f2;
}
// .table-width {
// margin-left: 20px;
// margin-right: 50px;
// border-style: solid;
// }
input.transparent-input{
background-color:transparent !important;
......@@ -246,3 +234,16 @@ text-decoration: underline;
font-weight: normal;
font-style: normal;
}
div.absolute {
position: absolute;
right: 0;
width: 150px;
}
div.absolutem {
position: absolute;
right: 0;
width: 115px;
}
......@@ -16,7 +16,11 @@ 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
......@@ -37,10 +41,6 @@ class SamplesController < ApplicationController
if operator?
@samples = current_user.samples.where('status IN (?)' , ["in preparation"])
end
#@samples = Sample.all
#if operator?
#@samples = Sample.where('status <> ? OR user_id = ?','in preparation',current_user.id).paginate(page: params[:page])
#end
end
end
......@@ -57,7 +57,11 @@ end
sample = Sample.find(params[:id])
if sample.update_attributes(sample_params)
flash[:success] = "Sample updated"
redirect_to root_path
if operator?
redirect_to root_path
else
redirect_to :back
end
else
#render 'root_path'
end
......@@ -83,7 +87,7 @@ end
sample.status = "submitted"
sample.save
end
redirect_to sample_path(sample)
redirect_to root_path
end
def ReleaseMeasurment
......@@ -92,7 +96,7 @@ end
sample.status = "measured"
sample.save
end
redirect_to sample_path(sample)
redirect_to root_path
end
private
......
module SamplesHelper
def add_subscript formula
render inline: formula.to_s.scan(/([A-Z][a-z]{0,2})(\d*)/).map { |el| "#{el[0]}<sub>#{el[1]}</sub>" }.join('')
render inline: formula.to_s.scan(/([A-Z][a-z]{0,2})(\d*)/).map { |el| "#{el[0]}<sub>#{el[1]}</sub>" }.join('')
end
#render :inline =>
def percentage_diff(expected,measured)
e = expected.to_f
m = measured.to_f
if m == e
0.0
else
# 200 * (m - e)/(m + e)
m - e
end
end
end
......@@ -2,7 +2,7 @@
<%if @sample.status=="in preparation"%>
<table class="table table-bordered table-nonfluid" id="tab_logic" style="margin: 70px 0px 20px 15px">
<thead>
<tr >
<tr>
<th class="text-center">
ID
</th>
......@@ -18,8 +18,8 @@
</tr>
</thead>
<tbody>
<%= form_for(@sample) do |f| %>
<tr>
<%= form_for(@sample) do |f| %>
<td>
<%= @sample.id%>
</td>
......@@ -29,14 +29,16 @@
<td>
<%= f.text_field :formula, class: 'form-control transparent-input' %>
</td>
<td>
<%= f.submit "save", class: "button-link" %>
<td>
<%= f.submit "save", class: 'button-link' %>
</td>
</tr>
<%end%>
<%end%>
</table>
<div style='margin-top:50px'>
</tr>
</tbody>
</table>
<%end%>
<div style='margin-top:50px'>
<% if operator? && @sample.status=="submitted"%>
<%= render 'form_operator' %>
<%#else %>
......
......@@ -13,7 +13,7 @@
<div class="col-sm-11">
<table class="table table-bordered" id = "myTable">
<table class="table table-bordered" id = "myTable" style="margin-left:20px">
<thead>
<tr>
<th>ELEMENTS:</th>
......@@ -57,13 +57,10 @@
</fieldset>
</tbody>
</table>
<!--input id="col" placeholder="Enter Element"/>
<button id="icol" class = "btn btn-primary " href="#">Add Element</button><br><br-->
<div class="links">
<div class="links" style="margin-left:30px">
<%= link_to_add_association 'Add Result', f, :results, 'data-association-insertion-node' => "tbody#resultTable ", 'data-association-insertion-method' => "append",
:wrap_object => Proc.new {|quantity| quantity } , :style=>'color: Black;' , :class=>"btn btn-block btn-success " %>
</div><br>
<br>
<%= f.submit %>
</div>
<% end %>
<tr class="nested-fields">
<td>Result <p align = "left"><%= link_to_remove_association "Remove", f, data: {confirm: 'Are you sure?'}%></p></td>
<td><%= f.text_field :element_C %></td>
<td><%= f.text_field :element_H %></td>
<td><%= f.text_field :element_N %></td>
<td><%= f.text_field :element_H %></td>
<td><%= f.text_field :element_O %></td>
</tr>
......@@ -2,15 +2,15 @@
$(document).ready(function(){
$('#tab_logic tr.selekt .status').each(function(){
console.log($(this).parent(".selekt"))
if ($(this).text() =="in preparation") {
$(this).parents(".selekt").css('background-color','#ccf3ff');
}
else if ($(this).text() =="submitted") {
$(this).parents(".selekt").css('background-color','#e6ffe6')
}
else {
$(this).parents(".selekt").css('background-color','#ffe5cc')
}
if ($(this).text() =="in preparation") {
$(this).parents(".selekt").css('background-color','#feffea');
}
else if ($(this).text() =="submitted") {
$(this).parents(".selekt").css('background-color','#e2f7e7')
}
else {
$(this).parents(".selekt").css('background-color','#f9e5ef')
}
});
});
......@@ -23,7 +23,7 @@ $(document).ready(function(){
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<table id="tab_logic" class="table table-hover table table-bordered" style="width:75%" >
<table id="tab_logic" class="table table-hover table table-bordered " style="width:75%" >
<thead>
<tr>
<th class="text-center">
......@@ -76,6 +76,9 @@ $(document).ready(function(){
</td>
<%end%>
<td>
<%if (operator? && (sample.status=="in preparation" || sample.status=="submitted")) || (!operator? && sample.status=='in preparation') %>
<%=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,
data: { confirm: "You sure?"}%>
......
......@@ -2,17 +2,19 @@
$(document).ready(function() {
$('#tab_logic tr.selekt .status').each(function() {
console.log($(this).parent('.selekt'));
if ($(this).text() == 'in preparation') {
$(this).parents('.selekt').css('background-color','#ccf3ff');
} else if ($(this).text() == 'submitted') {
$(this).parents('.selekt').css('background-color', '#e6ffe6');
} else {
$(this).parents('.selekt').css('background-color', '#ffe5cc');
if ($(this).text() =="in preparation") {
$(this).parents(".selekt").css('background-color','#feffea');
}
else if ($(this).text() =="submitted") {
$(this).parents(".selekt").css('background-color','#e2f7e7')
}
else {
$(this).parents(".selekt").css('background-color','#f9e5ef')
}
});
});
</script>
<table id="tab_logic" class="table table-bordered table-hover" style="margin-top:50px">
<table id="tab_logic" class="table table-bordered table-hover table-width" style="margin-top:30px" >
<thead>
<tr >
<th class="text-center">
......@@ -49,10 +51,8 @@ $(document).ready(function() {
</td>
<td>
<% if ((operator? && sample.status =="measured") || (!operator? && sample.status=="submitted" ||!operator? && sample.status=="measured")) %>
<%#= link_to '<i class="fa fa-backward" aria-hidden="true"></i>'.html_safe, root_path%>
<%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, 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,
......@@ -63,32 +63,33 @@ $(document).ready(function() {
<%end%>
</tbody>
</table>
<% if @sample.status == "in preparation" %>
<b>Change status to:</b> <%=link_to (@sample.status ? "submitted for measurement" : "No"),
Measured_sample_path(@sample), :action => 'solve', :class => 'btn btn-default' %>
<p> <% if @sample.status == "in preparation" %>
<div class='absolute'><%=link_to (@sample.status ? "submitted for measurement" : "No"),
Measured_sample_path(@sample), :action => 'solve', :class => 'btn btn-default' %></div>
<% elsif operator? && @sample.status == "submitted" %>
<b>Change status to measured:</b> <%=link_to (@sample.status ? "Realase Measurment" : "No"),
ReleaseMeasurment_sample_path(@sample), :action => 'solve', :class => 'btn btn-default' %>
<div class='absolutem'><%=link_to (@sample.status ? "Release Measurement" : "No"),
ReleaseMeasurment_sample_path(@sample), :action => 'solve', :class => 'btn btn-default' %></div>
<%end%>
</p>
<script type="text/javascript">
<script type="text/javascript">
$(document).ready(function(){
$('#myTable td.y_n').each(function(){
if ($(this).text() < 0.4) {
$(this).css('background-color','#56bf5b');
$(this).css('background-color','#a9edb8');
}
else {
$(this).css('background-color','#ff0000');
$(this).css('background-color','#eda9ca');
}
});
});
</script>
<table class="table table-bordered table-hover" id = "myTable" style="margin-top:50px">
<table class="table table-bordered table-hover table-width" id = "myTable" style="margin-top:50px">
<thead>
<tr>
......@@ -104,93 +105,69 @@ $(document).ready(function() {
<tbody >
<tr>
<td>Expected:</td>
<%sum,i=0,0 %>
<%sum,i=0,0 %>
<% @sample.formatted_calculation.each_pair do |k,v| %>
<%if i<4 %>
<td> <%= "%.2f" %v %>
<%if i<4 %>
<td> <%= "%.2f" %v %>
<% sum=sum.to_f+v.to_f %>
</td>
<%i=i+1%>
<%else
break%>
<%end if%>
</td>
<%i=i+1%>
<%end%>
<%end if @sample.calculation %>
<% s = 100 - sum %>
<td><%=s.abs.round(2)%></td>
<% sum = sum + s%>
<td><%= "%.2f" %sum %></td></tr>
<%sum2=0
i=1 %>
<% @sample.results.each do |result| %>
<tr>
<td>Result <%= i %> : </td>
<td><%= result.element_C %> </td>
<%sum2=sum2.to_f+result.element_C.to_f %>
<td><%= result.element_H %> </td>
<% sum2=sum2.to_f+result.element_H.to_f %>
<td><%= result.element_N %></td>
<% sum2=sum2.to_f+result.element_N.to_f %>
<td><%= result.element_O %></td>
<% sum2=sum2.to_f+result.element_O.to_f %>
<td><%=s.abs.round(2)%></td>
<% sum = sum + s%>
<td><%= "%.2f" %sum %></td>
</tr>
<%( result.measurement.keys - ["C","H","N","O"]).each do |k| %>
<td> <%= if result.measurement[k] then "%.2f" % result.measurement[k].to_f else '' end%></td>
<% sum2=sum2.to_f+result.measurement[k].to_f %>
<%if (operator? && (@sample.status=='submitted'|| @sample.status=='measured')) || (!operator? && @sample.status=='measured')%>
<%sum2=0;i=1 %>
<% @sample.results.each do |result| %> <tr>
<td>Result <%= i %> : </td>
<td><%= result.element_C %> </td>
<%sum2=sum2.to_f+result.element_C.to_f %>
<td><%= result.element_N %> </td>
<% sum2=sum2.to_f+result.element_H.to_f %>
<td><%= result.element_H %></td>
<% sum2=sum2.to_f+result.element_N.to_f %>
<td><%= result.element_O %></td>
<% sum2=sum2.to_f+result.element_O.to_f %>
<%( result.measurement.keys - ["C","H","N","O"]).each do |k| %>
<td> <%= if result.measurement[k] then "%.2f" % result.measurement[k].to_f else '' end%></td>
<% sum2=sum2.to_f+result.measurement[k].to_f %>
<%end if result.measurement %>
<%#end if result.measurement %>
<% i = i+1 %>
<td></td>
<td><%= sum2%></td>
<%sum2=0%>
<td><%= sum2%></td>
<%sum2=0%>
<%# end if result
+result.element_C.to_i+result.element_H.to_i+result.element_N.to_i +result.element_O.to_i
%>
<%#end if result.measurement %>
</tr>
<tr>
<td> Difference (%) </td>
<%d=0
c=0
b=0
a=0
e=0%>
<% @sample.formatted_calculation.each_pair do |k,v| %>
<% a = ( ( v.to_f - result.element_C) / ((v.to_f + result.element_C)/2) ) * 100
break %>
<% b=( (v.to_f - result.element_H) / ((v.to_f + result.element_H)/2) ) * 100
break %>
</tr>
<tr>
<td> Difference (%) </td>
<%diff={}%>
<%@sample.formatted_calculation.each_pair do |k,v| %>
<% c= ((v.to_f - result.element_N ) / ((v.to_f + result.element_N )/2) ) * 100
break %>
<% kk = (k == 'S' && 'O') || k%>
<% diff[k] = percentage_diff(v,result.send('element_'+kk)) %>
<%end if @sample.calculation %>
<% d= ((v.to_f - result.element_O) / ((v.to_f + result.element_O)/2) ) * 100
break%>
<%end if @sample.calculation %>
<td class="y_n"><%=diff['C'].abs.round(2)%></td>
<td class="y_n"><%=diff['N'].abs.round(2)%></td>
<td class="y_n"><%=diff['H'].abs.round(2)%></td>
<td class="y_n"><%=diff['S'].abs.round(2)%></td>
<%@sample.formatted_calculation.each_pair do |k,v| %>
<%( result.measurement.keys - ["C","H","N","O"]).each do |k| %>
<%=( (v.to_f - result.measurement[k].to_f) / ((v.to_f + result.measurement[k].to_f)/2) ) * 100 %>
<%end %>
<%end %>
<% @sample.formatted_calculation.each_pair do |k,v| %>
<%( result.measurement.keys - ["C","H","N","O"]).each do |k| %>
<% e=( (v.to_f - result.measurement[k].to_f) / ((v.to_f + result.measurement[k].to_f)/2) ) * 100 %>
<%end %>
<%end %>
<td class="y_n"><%=a.abs.round(2)%></td>
<td class="y_n"><%=b.abs.round(2)%></td>
<td class="y_n"><%=c.abs.round(2)%></td>
<td class="y_n"><%=d.abs.round(2)%> </td>
<td class="y_n"> <%=e.abs.round(2) %></td>
<%#end if @sample.calculation %>
</tr>
<%end%>
<%end %>
</tbody>
</table>
</tbody>
</tbody>
</table>
</tbody>
</table>
<!-- <script>
$(document).ready(function() {
$('#tab_logic tr.selekt .status').each(function() {
console.log($(this).parent('.selekt'));
if ($(this).text() == 'in preparation') {
$(this).parents('.selekt').css('background-color','#ccf3ff');
} else if ($(this).text() == 'submitted') {
$(this).parents('.selekt').css('background-color', '#e6ffe6');
} else {
$(this).parents('.selekt').css('background-color', '#ffe5cc');
}
});
});
</script>
<table id="tab_logic" class="table table-bordered table-hover" style="margin-top:50px">
<thead>
<tr >
<th class="text-center">
ID
</th>
<th class="text-center">
Name
</th>
<th class="text-center">
Formula
</th>
<th class="text-center">
Status
</th>
<th class="text-center">
Action
</th>
</tr>
</thead>
<tbody>
<%[@sample].each do |sample|%>
<tr class="selekt">
<td>
<%= @sample.id%>
</td>
<td>
<span class="name"><%= sample.name %></span>
</td>
<td>
<span class="formula"><%=add_subscript(sample.formula) %></span>
</td>
<td>
<span class="status"><%= sample.status %></span>
</td>
<td>
<% if ((operator? && sample.status =="measured") || (!operator? && sample.status=="submitted" ||!operator? && sample.status=="measured")) %>
<%= link_to '<i class="fa fa-backward" aria-hidden="true"></i>'.html_safe, root_path%>
<%else%>
<%= link_to '<i class="fa fa-pencil-square-o" aria-hidden="true"></i>'.html_safe, edit_sample_path%>
<%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,
data: { confirm: "You sure?" } %>
<%end%>
</td>
</tr>
<%end%>
</tbody>
</table>
<% if @sample.status == "in preparation" %>
<b>Change status to:</b> <%=link_to (@sample.status ? "submitted for measurement" : "No"),
Measured_sample_path(@sample), :action => 'solve', :class => 'btn btn-default' %>
<% elsif operator? && @sample.status == "submitted" %>
<b>Change status to measured:</b> <%=link_to (@sample.status ? "Realase Measurment" : "No"),
ReleaseMeasurment_sample_path(@sample), :action => 'solve', :class => 'btn btn-default' %>
<%end%>
<script type="text/javascript">
$(document).ready(function(){
$('#myTable td.y_n').each(function(){
if ($(this).text() < 0.4) {
$(this).css('background-color','#56bf5b');
}
else {
$(this).css('background-color','#ff0000');
}
});
});
</script>
<table class="table table-bordered table-hover" id = "myTable" style="margin-top:50px">
<thead>
<tr>
<th>ELEMENTS:</th>
<% (["C","N","H","S"]).each do |k,v| %>
<th><%= k %></th>
<%end if @sample.calculation%>
<th>Other</TH>
<th>Total</th>
</tr>
</thead>
<tbody >
<tr>
<td>Expected:</td>
<%sum,i=0,0 %>
<% @sample.formatted_calculation.each_pair do |k,v| %>
<%if i<4 %>
<td> <%= "%.2f" %v %>