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

using ajax for specifying the layout for the show and edit page into the index...

using ajax for specifying the layout for the show and edit page into the index page, working on icons, panels and links
parent ea33bbe7
......@@ -8,6 +8,7 @@ gem 'bcrypt','~>3.1.11'
gem 'will_paginate', '~> 3.1.0'
gem 'bootstrap-will_paginate', '~> 0.0.10'
gem 'font-awesome-rails'
gem 'unicorn'# gem 'therubyracer', platforms: :ruby
gem "cocoon"
......
......@@ -62,6 +62,8 @@ GEM
erubis (2.7.0)
execjs (2.7.0)
ffi (1.9.14)
font-awesome-rails (4.6.3.1)
railties (>= 3.2, < 5.1)
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
......@@ -177,6 +179,7 @@ DEPENDENCIES
byebug
cocoon
coffee-rails (~> 4.2)
font-awesome-rails
jbuilder (~> 2.5)
jquery-rails
json
......
......@@ -12,4 +12,5 @@
*
*= require_tree .
*= require_self
*= require font-awesome
*/
@import "bootstrap-sprockets";
@import "bootstrap";
@import "font-awesome";
/* mixins, variables, etc. */
// @mixin box_sizing {
......@@ -231,3 +232,17 @@ color:#008fb3;
color: #006680;
text-decoration: underline;
}
.panel-default{
height:400px;
width: 145%;
border: 0;
overflow-y: auto;
overflow-x: hidden;
}
@font-face {
font-family: "FontAwesome";
src: url('<%= asset_path("fontawesome-webfont.eot") %>');
src: url('<%= asset_path("fontawesome-webfont.eot") + "?#iefix" %>') format('eot'), url('<%= asset_path("fontawesome-webfont.woff") %>') format('woff'), url('<%= asset_path("fontawesome-webfont.ttf") %>') format('truetype'), url('<%= asset_path("fontawesome-webfont.svg") + "#FontAwesome" %>') format('svg');
font-weight: normal;
font-style: normal;
}
......@@ -2,7 +2,7 @@ class SamplesController < ApplicationController
before_action :logged_in_user, only: [:create, :destroy]
before_action :correct_user, only: :destroy
before_action :set_sample, only: [:show, :edit, :update, :destroy,:update_status]
respond_to? :html, :js
def new
@sample=Sample.new
......@@ -45,7 +45,7 @@ class SamplesController < ApplicationController
end
def edit
#@sample = Sample.find(params[:id])
@sample = Sample.find(params[:id])
@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"
......@@ -57,9 +57,9 @@ end
sample = Sample.find(params[:id])
if sample.update_attributes(sample_params)
flash[:success] = "Sample updated"
redirect_to sample
redirect_to root_path
else
render 'edit'
#render 'root_path'
end
end
......
......@@ -18,7 +18,7 @@
<%= render 'layouts/header' %>
<div class="container-fluid text-center">
<div class="row content", style=" margin: 50px 80px 50px 80px;">
<div class="row content", style=" margin: 50px 80px 50px 95px;">
<div class="col-sm-8 text-left">
......
<% provide(:title, "Edit sample") %>
<table class="table table-bordered table-nonfluid" id="tab_logic" style="margin: 50px 0px 20px 15px">
<%if @sample.status=="in preparation"%>
<table class="table table-bordered table-nonfluid" id="tab_logic" style="margin: 70px 0px 20px 15px">
<thead>
<tr >
<th class="text-center">
......@@ -17,6 +18,7 @@
</tr>
</thead>
<tbody>
<%= form_for(@sample) do |f| %>
<td>
<%= @sample.id%>
......@@ -32,17 +34,17 @@
</td>
</tr>
<%end%>
<%end%>
</table>
<% if operator?%>
<div style='margin-top:50px'>
<% if operator? && @sample.status=="submitted"%>
<%= render 'form_operator' %>
<%#else %>
<%#= render 'shared/sample_form' %>
<%end%>
<div class="container">
<strong><em>
<%= link_to 'Show|', @sample %>
<%= link_to 'Back', sample_path(@sample) %>
<%#= link_to 'Back', root_path %>
</strong></em>
</form>
</div>
......
......@@ -17,12 +17,13 @@ $(document).ready(function(){
</script>
<% if (current_page?('/samples, /index') || current_page?('/'))%>
<div class="panel panel-default">
<%=render 'shared/sample_form'%><br>
<%end%>
<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:85%" >
<table id="tab_logic" class="table table-hover table table-bordered" style="width:75%" >
<thead>
<tr>
<th class="text-center">
......@@ -36,6 +37,11 @@ $(document).ready(function(){
</th>
<th class="text-center">
Status
<%if operator? && (current_page?('/samples, /index') || current_page?('/')) %>
<%= link_to '<i class="fa fa-hourglass-half" aria-hidden="true"></i>'.html_safe,samples_path(status: "in preparation"),{:style=>'color:#000;', class: "btn btn-default" }%>
<%= link_to '<i class="fa fa-line-chart" aria-hidden="true"></i>'.html_safe,samples_path(status: "submitted"),{:style=>'color:#000;', class: "btn btn-default" } %>
<%= link_to '<i class="fa fa-check-square-o" aria-hidden="true"></i>'.html_safe,samples_path(status: "measured"),{:style=>'color:#000;', class: "btn btn-default" }%>
<%end%>
</th>
<%if operator?%>
<th class="text-center">
......@@ -52,7 +58,9 @@ $(document).ready(function(){
<tr class="selekt">
<td>
<%="#{sample.id}"%>
</td>
<%=link_to '<i class="fa fa-caret-square-o-left" aria-hidden="true"></i>'.html_safe, sample, remote: true%>
</td>
<td>
<span class="name"><%= sample.name %></span>
</td>
......@@ -68,29 +76,17 @@ $(document).ready(function(){
</td>
<%end%>
<td>
<%= link_to "show", sample %>
<% if current_user?(sample.user) && sample.status == "in preparation" %>
<%= link_to "delete", sample, method: :delete,
data: { confirm: "You sure?" }%>
<%= link_to '<i class="fa fa-trash" aria-hidden="true"></i>'.html_safe, sample, method: :delete,
data: { confirm: "You sure?"}%>
<%end%>
</tr>
<%end%>
</tbody>
</table>
</div>
</div>
</div>
<%if operator? && (current_page?('/samples, /index') || current_page?('/')) %>
<%= link_to 'In_preparation Elements',samples_path(status: "in preparation"),{:style=>'color:#000;', class: "btn btn-default" } %>
<%= link_to 'Submitted Elements',samples_path(status: "submitted"),{:style=>'color:#000;', class: "btn btn-default" } %>
<%= link_to 'Measured Elements',samples_path(status: "measured"),{:style=>'color:#000;', class: "btn btn-default" }%>
<%end%>
</div>
<div class="panel panel-default" id="show" style="display:none;">
</div>
<script>
$(document).ready(function(){
$("#show").click(function(){
$(".new").show();
});
});
</script>
<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, 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?" } %>
<%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 %>
<% sum=sum.to_f+v.to_f %>
</td>
<%i=i+1%>
<%else
break%>
<%end if%>
<%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 %>
<%( 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%>
<%# 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 %>
<% c= ((v.to_f - result.element_N ) / ((v.to_f + result.element_N )/2) ) * 100
break %>
<% d= ((v.to_f - result.element_O) / ((v.to_f + result.element_O)/2) ) * 100
break%>
<%end if @sample.calculation %>
<% @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 %>
</tbody>
</table>
</tbody>
</table>
$('#show').html("<%= j (render 'samples/edit') %>");
$('#show').slideDown(350);
......@@ -3,5 +3,5 @@
<h3>Samples (<%= @samples.count %>) </h3>
<%= render 'samples/samples' %>
<br>
<%= link_to 'Back', root_path%>
</div>
</div><br>
<%#= link_to 'Back', root_path%>
<script>
<!-- <script>
$(document).ready(function() {
$('#tab_logic tr.selekt .status').each(function() {
console.log($(this).parent('.selekt'));
......@@ -12,7 +12,7 @@ $(document).ready(function() {
});
});
</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" style="margin-top:50px">
<thead>
<tr >
<th class="text-center">
......@@ -49,12 +49,12 @@ $(document).ready(function() {
</td>
<td>
<% if ((operator? && sample.status =="measured") || (!operator? && sample.status=="submitted" ||!operator? && sample.status=="measured")) %>
<%= link_to "back", root_path%>
<%= link_to '<i class="fa fa-backward" aria-hidden="true"></i>'.html_safe, root_path%>
<%else%>
<%= link_to "edit", edit_sample_path%>
<%= 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 "delete", sample, method: :delete,
<%= link_to '<i class="fa fa-trash" aria-hidden="true"></i>'.html_safe, sample, method: :delete,
data: { confirm: "You sure?" } %>
<%end%>
</td>
......@@ -192,5 +192,4 @@ $(document).ready(function() {
</table>
</tbody>
</table>
<strong><em><%= link_to 'Back', root_url%><strong><em>
</table> -->
$('#show').html("<%= j (render 'samples/show') %>");
$('#show').slideDown(350);
......@@ -2,7 +2,7 @@
<% provide(:title, "Home") %>
<% if logged_in? %>
<%= render 'samples/samples', samples:@samples %>
</div>
</div>
......
Supports Markdown
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