Commit 7c1f07d7 authored by pei-chi.huang's avatar pei-chi.huang
Browse files

feature on 0818

parent acb943cd
......@@ -264,3 +264,10 @@ div.absolute {
font: 100 70px/1.2 'Merienda One', Helvetica, sans-serif;
}
.remember-me {
display: flex;
#user_remember_me {
width: 10%;
}
}
\ No newline at end of file
......@@ -57,6 +57,13 @@ class SamplesController < ApplicationController
def update
sample = Sample.find(params[:id])
unless sample_params.nil?
sample_params['results_attributes'] && sample_params['results_attributes'].each do |key, val|
Sample::PREDEF_ELEMENTS.each do |el|
if val["element_#{el}"]&.include? ','
sample_params['results_attributes'][key]["element_#{el}"] = val["element_#{el}"].gsub!(',', '.')
end
end
end
if sample.update_attributes(sample_params)
sample.touch
flash[:success] = "Sample updated"
......@@ -106,6 +113,16 @@ class SamplesController < ApplicationController
redirect_to URI(request.referer).path + "?display_sample=#{sample.id}"
end
def Withdraw
sample = Sample.find(params[:id])
if sample.status == "submitted"
sample.status = "in preparation"
sample.submitted_at = nil
sample.save
end
redirect_to URI(request.referer).path + "?display_sample=#{sample.id}"
end
def ReleaseMeasurment
sample = Sample.find(params[:id])
@user = sample && sample.user
......@@ -124,7 +141,7 @@ class SamplesController < ApplicationController
def sample_params
keys=Sample::ELEMENTS.keys
params.require(:sample).permit(:name, :formula, results_attributes: [:id, :_destroy, :element_C,:element_H,:element_N,:element_S]) if params[:sample].present?
params.require(:sample).permit(:name, :formula, results_attributes: [:id, :_destroy, :element_N, :element_C,:element_H, :element_S]) if params[:sample].present?
end
def correct_user
......
......@@ -31,7 +31,7 @@ class SamplePdf < Prawn::Document
end
def table_header
["Elements:","C","N","H","S","Other","Total"]
["Elements:"] + Sample::PREDEF_ELEMENTS + ["Other","Total"]
end
def table_rows
......@@ -70,13 +70,13 @@ class SamplePdf < Prawn::Document
def res(result)
update = []
values = ['C','N','H','S'].map do |a|
values = Sample::PREDEF_ELEMENTS.map do |a|
result.send('element_'+a).to_f
end
sum = values.inject(0){|sum,x| sum + x }
update += values.map{|x| "%.2f" % x}
update +=[""]
( result.measurement.keys - ["C","H","N","S"]).each do |k|
( result.measurement.keys - Sample::PREDEF_ELEMENTS).each do |k|
if result.measurement[k] then "%.2f" % result.measurement[k].to_f else '' end
update += ["%.2f" %sum=sum+result.measurement[k].to_f]
end if result.measurement
......@@ -91,15 +91,15 @@ class SamplePdf < Prawn::Document
diff[k] = percentage_diff(v,result.send('element_'+k))
end if @sample.calculation
update +=[ diff['C']]
update +=[ diff['N']]
update +=[ diff['H']]
update +=[ diff['S']]
update +=[""]
update +=[""]
@sample.formatted_calculation.each_pair do |k,v|
( result.measurement.keys - ["C","H","N","S"]).each do |k|
( (v.to_f - result.measurement[k].to_f) / ((v.to_f + result.measurement[k].to_f)/2) ) * 100
Sample::PREDEF_ELEMENTS.each do |el|
update += [diff[el]]
end
update += [""]
update += [""]
@sample.formatted_calculation.each_pair do |k, v|
( result.measurement.keys - Sample::PREDEF_ELEMENTS).each do |k|
( (v.to_f - result.measurement[k].to_f) / ((v.to_f + result.measurement[k].to_f)/2) ) * 100
end
end
update
......
......@@ -31,7 +31,7 @@ class SamplePdf < Prawn::Document
end
def table_header
["Elements:","C","N","H","S","Other","Total"]
["Elements:"] + Sample::PREDEF_ELEMENTS + ["Other","Total"]
end
def table_rows
......@@ -70,13 +70,13 @@ class SamplePdf < Prawn::Document
def res(result)
update = []
values = ['C','N','H','S'].map do |a|
values = Sample::PREDEF_ELEMENTS.map do |a|
result.send('element_'+a).to_f
end
sum = values.inject(0){|sum,x| sum + x }
update += values.map{|x| "%.2f" % x}
update +=[""]
( result.measurement.keys - ["C","H","N","S"]).each do |k|
( result.measurement.keys - Sample::PREDEF_ELEMENTS).each do |k|
if result.measurement[k] then "%.2f" % result.measurement[k].to_f else '' end
update += ["%.2f" %sum=sum+result.measurement[k].to_f]
end if result.measurement
......@@ -91,14 +91,13 @@ class SamplePdf < Prawn::Document
diff[k] = percentage_diff(v,result.send('element_'+k))
end if @sample.calculation
update +=[ diff['C']]
update +=[ diff['N']]
update +=[ diff['H']]
update +=[ diff['S']]
Sample::PREDEF_ELEMENTS.each do |el|
update +=[ diff[el]]
end
update +=[""]
update +=[""]
@sample.formatted_calculation.each_pair do |k,v|
( result.measurement.keys - ["C","H","N","S"]).each do |k|
( result.measurement.keys - Sample::PREDEF_ELEMENTS).each do |k|
( (v.to_f - result.measurement[k].to_f) / ((v.to_f + result.measurement[k].to_f)/2) ) * 100
end
end
......
......@@ -16,7 +16,7 @@ class Sample < ApplicationRecord
end
include MolApp::PeriodicTable
PREDEF_ELEMENTS = %w(C N H S)
PREDEF_ELEMENTS = %w(N C H S)
REG = /(#{ELEMENTS.keys.map(&:to_s).sort.reverse.join("|")})(\d*)/
......
......@@ -12,11 +12,12 @@
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
<%= f.label :remember_me, class: "checkbox inline" do %>
<div class="remember-me">
<%= f.label :remember_me do %>
Remember me on this computer
<% end %>
<%= f.check_box :remember_me %>
<span>Remember me on this computer</span>
<% end %>
</div>
<%= f.submit "Log in", class: "btn btn-success" %>
<% 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_N %></td>
<td><%= f.text_field :element_C %></td>
<td><%= f.text_field :element_H %></td>
<td><%= f.text_field :element_S %></td>
</tr>
......@@ -60,7 +60,7 @@ $(document).ready(function(){
<thead>
<tr>
<th>ELEMENTS:</th>
<% (["C","N","H","S"]).each do |k,v| %>
<% Sample::PREDEF_ELEMENTS.each do |k,v| %>
<th><%= k %></th>
<%end if @sample.calculation%>
<th>Other</TH>
......@@ -89,15 +89,15 @@ $(document).ready(function(){
<% @sample.results.each do |result| %>
<tr>
<td>Result <%= i %> :<%#= @user.name %> </td>
<td><%= result.element_N %> </td>
<% sum2=sum2.to_f+result.element_N.to_f %>
<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 %>
<% sum2=sum2.to_f+result.element_H.to_f %>
<td><%= result.element_S %></td>
<% sum2=sum2.to_f+result.element_S.to_f %>
<%( result.measurement.keys - ["C","H","N","O"]).each do |k| %>
<%( result.measurement.keys - Sample::PREDEF_ELEMENTS).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 %>
......@@ -113,12 +113,12 @@ $(document).ready(function(){
<% v = @sample.calculation[k]%>
<% diff[k] = percentage_diff(v,result.send('element_'+k)) %>
<%end if @sample.calculation %>
<td class="y_n"><%=diff['C']%></td>
<td class="y_n"><%=diff['N']%></td>
<td class="y_n"><%=diff['C']%></td>
<td class="y_n"><%=diff['H']%></td>
<td class="y_n"><%=diff['S']%></td>
<%@sample.formatted_calculation.each_pair do |k,v| %>
<%( result.measurement.keys - ["C","H","N","S"]).each do |k| %>
<%( result.measurement.keys - Sample::PREDEF_ELEMENTS).each do |k| %>
<%=( (v.to_f - result.measurement[k].to_f) / ((v.to_f + result.measurement[k].to_f)/2) ) * 100 %>
<%end %>
<%end %>
......@@ -132,6 +132,10 @@ $(document).ready(function(){
<div class='container absolute'><%=link_to (@sample.status ? "Submit for Measurement" : "No"),
Measured_sample_path(@sample), :action => 'solve', :class => 'btn btn-block btn-success' %>
</div>
<%elsif current_user?(@sample.user) && @sample.status == "submitted" %>
<div class='container absolute'><%=link_to (@sample.status ? "Withdraw this Sample" : "No"),
Withdraw_sample_path(@sample), :action => 'solve', :class => 'btn btn-block btn-danger' %>
</div>
<%elsif operator? && @sample.status == "submitted" %>
<div class='container absolute'><%=link_to (@sample.status ? "Release Measurement" : "No"),
ReleaseMeasurment_sample_path(@sample), :action => 'solve', :class => 'btn btn-block btn-success' %>
......
......@@ -36,6 +36,7 @@ Rails.application.routes.draw do
member do
get :Measured
get :ReleaseMeasurment
get :Withdraw
end
end
......
......@@ -2,8 +2,8 @@ class CreateResults < ActiveRecord::Migration[5.0]
def change
create_table :results do |t|
t.integer :sample_id
t.float :element_C, default: 0
t.float :element_N, default: 0
t.float :element_C, default: 0
t.float :element_S, default: 0
t.float :element_H, default: 0
t.string :name
......
......@@ -2,16 +2,16 @@
one:
sample_id: 1
element_C: 1.5
element_N: 1.5
element_C: 1.5
element_S: 1.5
element_H: 1.5
name: MyString
two:
sample_id: 1
element_C: 1.5
element_N: 1.5
element_C: 1.5
element_S: 1.5
element_H: 1.5
name: MyString
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