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

Microposts created for the homepage of Chemists, layout of homepage

parent 83e4ffbe
......@@ -15,6 +15,7 @@ gem 'prawn-table'
gem 'unicorn'# gem 'therubyracer', platforms: :ruby
gem "cocoon"
gem "json"
gem "mail"
#bootstrap
gem 'bootstrap-sass', '~>3.3.6'
# Use sqlite3 as the database for Active Record
......
......@@ -194,6 +194,7 @@ DEPENDENCIES
jquery-rails
json
listen (~> 3.0.5)
mail
pg
prawn
prawn-table
......
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
......@@ -151,9 +151,9 @@ input {
border-bottom: 1px solid $gray-lighter;
}
}
/* samples */
/* microposts */
.samples {
.microposts {
list-style: none;
padding: 0;
li {
......@@ -175,12 +175,14 @@ input {
margin-right: 10px;
margin-top: 5px;
}
}
aside {
textarea {
height: 100px;
margin-bottom: 5px;
width: 700px;
margin-bottom: 0px;
}
}
......@@ -236,10 +238,10 @@ text-decoration: underline;
}
div.absolute {
margin-top:10px;
margin-left: 515px;
margin-left: 570px;
}
div.absolutem {
margin-top:10px;
margin-left: 530px;
margin-left: 590px;
}
// Place all the styles related to the Microposts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class MicropostsController < ApplicationController
before_action :logged_in_user, only: [:create, :destroy]
before_action :correct_user, only: :destroy
def create
@micropost = current_user.microposts.build(micropost_params)
if @micropost.save
flash[:success] = "Micropost created!"
redirect_to microposts_path
else
@microposts = current_user.microposts.paginate(:page => params[:page], :per_page => 6)
render 'static_pages/microposts'
end
end
def destroy
@micropost.destroy
flash[:success] = "Micropost deleted"
redirect_to request.referrer || root_url
end
private
def micropost_params
params.require(:micropost).permit(:content)
end
def correct_user
@micropost = current_user.microposts.find_by(id: params[:id])
redirect_to root_url if @micropost.nil?
end
end
......@@ -32,7 +32,6 @@ class SamplesController < ApplicationController
if operator?
@samples = Sample.where('status IN (?)' , ["submitted"])
end
when "measured"
if operator?
@samples = Sample.where('status IN (?)', ["measured"])
......@@ -41,8 +40,8 @@ class SamplesController < ApplicationController
if operator?
@samples = current_user.samples.where('status IN (?)' , ["in preparation"])
end
end
end
end
end
def edit
@sample = Sample.find(params[:id])
......@@ -57,14 +56,14 @@ end
sample = Sample.find(params[:id])
if sample.update_attributes(sample_params)
flash[:success] = "Sample updated"
redirect_to :back && "?display_sample=#{sample.id}"
redirect_to request.referrer && "?display_sample=#{sample.id}"
else
#render 'root_path'
end
end
def show
if operator?
if operator?
@sample = Sample.find(params[:id])
else
@sample = current_user.samples.find(params[:id])
......@@ -73,7 +72,7 @@ end
format.html
format.js
format.pdf do
pdf = SamplePdf.new(@sample)
pdf = SamplePdf.new(@sample,operator?)
send_data pdf.render, filename: "sample_#{@sample.id}.pdf",
type:"application/pdf",
disposition: "inline"
......@@ -84,7 +83,7 @@ end
def destroy
@sample.destroy
flash[:success] = "Sample deleted"
redirect_to request.referrer || root_url
redirect_to :back || root_url
end
def Measured
......
......@@ -14,11 +14,16 @@ class StaticPagesController < ApplicationController
elsif (logged_in? && operator?)
@samples = Sample.where('status <> ? OR user_id = ?','in preparation',current_user.id)
end
@microposts = Micropost.paginate(:page => params[:page], :per_page => 6 )
end
def help
def microposts
redirect_to(root_url) unless operator?
@micropost = current_user.microposts.build
@microposts = current_user.microposts.paginate(:page => params[:page], :per_page => 6)
end
def about
end
......
module MicropostsHelper
end
class Micropost < ApplicationRecord
belongs_to :user
default_scope -> { order(created_at: :desc) }
validates :user_id, presence: true
validates :content, presence: true, length: { maximum: 140 }
end
......@@ -5,7 +5,7 @@ class Sample < ApplicationRecord
has_many :results
accepts_nested_attributes_for :results, :reject_if => :all_blank, :allow_destroy => true
belongs_to :user
default_scope { order(updated_at: :desc) }
default_scope { order(updated_at: :desc) }
validates :user_id, presence: true
validates :name, presence: true, length: { maximum: 50 }
validates :formula, presence: true, length: { maximum: 140 }
......
class User < ApplicationRecord
has_many :samples, dependent: :destroy
has_many :microposts, dependent: :destroy
self.inheritance_column = :type
......
<footer class="container-fluid text-center">
<p style="text-align:left">© 2016 - mol_app</p>
</footer>
<header>
<nav class="navbar navbar-inverse">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"> <%= link_to "Home",root_path,{:class => "glyphicon glyphicon-home"}%></li>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li> <%= link_to "Home",root_path,{:class => "glyphicon glyphicon-home"}%></li>
<%if logged_in?%>
<li><%= link_to '<i class="fa fa-flask" aria-hidden="true"></i>Samples'.html_safe, current_user,{:class => "glyphicon glyphicon"} %></li>
<%end%>
<%if logged_in? && operator?%>
<li><%= link_to '<i class="fa fa-sticky-note " aria-hidden="true"></i>Microposts'.html_safe, microposts_path,{:class => "glyphicon glyphicon"} %></li>
<%end%>
<li><%= link_to "About", about_path, {:class => "glyphicon glyphicon-info-sign"} %></li>
<li><%= link_to "Help", help_path,{:class => "glyphicon glyphicon-search"} %></li>
<li><%= link_to "Contact", contact_path,{:class => "glyphicon glyphicon-user"} %></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<% if logged_in? && operator?%>
<li><%= link_to "Users", users_path %></li>
<%end%>
<%if logged_in? %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<%= current_user.name %> <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Log out", logout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Login", login_path ,{:class => "glyphicon glyphicon-log-in glyphicon-bold"}%></li>
<% end %>
</ul>
</nav>
</div>
</header>
<ul class="nav navbar-nav navbar-right">
<%if logged_in? && operator?%>
<li><%= link_to '<i class="fa fa-users" aria-hidden="true"></i> Users'.html_safe, users_path %></li>
<%end%>
<%if logged_in? %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<%= current_user.name %> <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li>
<li><%= link_to "Log out", logout_path, method: "delete" %></li>
</ul>
</li>
<% else %>
<li><%= link_to "Login", login_path ,{:class => "glyphicon glyphicon-log-in glyphicon-bold"}%></li>
<% end %>
</ul>
</div>
</div>
</nav>
</header>
<!DOCTYPE html>
<html>
<head>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all',
'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/r29/html5.min.js">
</script>
<![endif]-->
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container-fluid text-center">
<div class="row content", style=" margin: 50px 80px 50px 95px;">
<div class="col-sm-8 text-left">
<div class="container"></div>
<% flash.each do |message_type, message| %>
<%= content_tag(:div, message, class: "alert alert-#{message_type}") %>
<% end %>
<%= yield %>
<body>
<%= render 'layouts/header' %>
<div class="container-fluid text-center">
<div class="row content", style=" margin: 50px 0px 50px 80px;">
<div class="col-sm-8 text-left">
<div class="container"></div>
<% flash.each do |message_type, message| %>
<%= content_tag(:div, message, class: "alert alert-#{message_type}") %>
<% end %>
<%= yield %>
</div>
</div>
</div>
</div>
</div>
</div>
<%= render 'layouts/footer' %>
</div>
</body>
</html>
</div>
<%= render 'layouts/footer' %>
</div>
</body>
</html>
<li id="micropost-<%= micropost.id %>">
<span class="user" style="color:#63b4cf"><%= micropost.user.name%></span>
<span class="content"><%= micropost.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
<% if current_user?(micropost.user) %>
<%= link_to "delete", micropost, method: :delete,
data: { confirm: "You sure?" } %>
<% end %>
</span>
</li>
<% provide(:title, 'Reset password') %>
<div style="margin: 0px 0px 0px 150px">
<h1>Reset password</h1>
<div class="row">
......@@ -18,3 +19,4 @@
<% end %>
</div>
</div>
</div>
<% provide(:title, "Forgot password") %>
<div style="margin: 0px 0px 0px 150px">
<h1>Forgot password</h1>
<div class="row">
......@@ -11,3 +12,4 @@
<% end %>
</div>
</div>
</div>
......@@ -13,7 +13,6 @@ $(document).ready(function(){
}
});
});
</script>
<% if (current_page?('/samples, /index') || current_page?('/'))%>
......@@ -23,7 +22,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:85%" >
<thead>
<tr>
<th class="text-center">
......@@ -97,4 +96,4 @@ $(document).ready(function(){
</div>
<%else%>
<div class="panel panel-default" id="show" style="display:none;"></div>
<%end%>
<%end%>
......@@ -16,40 +16,22 @@ $(document).ready(function() {
</script>
<table id="tab_logic" class="table table-bordered table-hover table-width" style="margin-top:30px" >
<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>
<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>
<%[@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")) %>
<%else%>
<%= link_to '<i class="fa fa-pencil-square-o" aria-hidden="true"></i>'.html_safe, edit_sample_path(sample), remote: true%>
......@@ -58,22 +40,22 @@ $(document).ready(function() {
<%= 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" %>
<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" %>
<div class='absolutem'><%=link_to (@sample.status ? "Release Measurement" : "No"),
ReleaseMeasurment_sample_path(@sample), :action => 'solve', :class => 'btn btn-default' %></div>
<%end%>
</td>
</tr>
<%end%>
</tbody>
</table>
<%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" %>
<div class='absolutem'><%=link_to (@sample.status ? "Release Measurement" : "No"),
ReleaseMeasurment_sample_path(@sample), :action => 'solve', :class => 'btn btn-default' %>
</div>
<%end%>
<script type="text/javascript">
$(document).ready(function(){
$('#myTable td.y_n').each(function(){
if ($(this).text() < 0.4) {
......@@ -84,89 +66,76 @@ $(document).ready(function() {
}
});
});
</script>
<table class="table table-bordered table-hover table-width" 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%>
<%end%>
<%end if @sample.calculation %>
<% s = 100 - sum %>
<td><%=s.abs.round(2)%></td>
<% sum = sum + s%>
<td><%= "%.2f" %sum %></td>
</tr>
<%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_S %></td>
<% sum2=sum2.to_f+result.element_S.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 %>
<% 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_S.to_i
%>
</tr>
<tr>
<td> Difference (%) </td>
<%diff={}%>
<%Sample::PREDEF_ELEMENTS.each do |k| %>
<% v = @sample.calculation[k]%>
<% diff[k] = percentage_diff(v,result.send('element_'+k)) %>
<%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","S"]).each do |k| %>
<%=( (v.to_f - result.measurement[k].to_f) / ((v.to_f + result.measurement[k].to_f)/2) ) * 100 %>
<%end %>
<%end %>
</tr>
<%end%>
<%end %>
</tbody>
</table>
</tbody>
</table>
<p><%=link_to "Printable Receipt (PDF)", sample_path(@sample, format: "pdf") %><p>
</script>
<table class="table table-bordered table-hover table-width" 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%>
<%end%>
<%end if @sample.calculation %>
<% s = 100 - sum %>
<td><%=s.abs.round(2)%></td>
<% sum = sum + s%>
<td><%= "%.2f" %sum %></td>
</tr>