_show.html.erb 7.03 KB
Newer Older
1
<script>
2
    $(document).ready(function(){
ira.maier's avatar
ira.maier committed
3
4
5
        console.log($('#tb tr.y_n'));
        // let selectAllCheckbox = document.querySelector('#sample_delete_files');
        // console.log('all checkboxes? ', selectAllCheckbox.checked);
6
7
8
9
10
11
12
13
        $('#tb tr.y_n').each(function(i){
            let good = true;
            $(this).find('td.y_n').each(function(j){
                if ($(this).text() == 'NaN'){ return good = false}
                if ($(this).text() > 0.4){ return good = false}
            });
            good ? $(this).css('background-color','#a9edb8') : $(this).css('background-color','#eda9ca')
        });
14

15
16
17
18
        $('tbody#resultTable').on('cocoon:before-insert', function() {
            console.log('yepyep');
        });
    })
19
</script>
20

21
22
<br>
<%if @sample.status=="submitted"%>
23
  <p>Submitted at: <%=@sample.submitted_at%></p>
24
<%elsif @sample.status=="measured"%>
25
26
  <p>Measured at: <%=@sample.measured_at%></p>
  <p>Measured by: <b><%=@sample.operator_name%></b></p>
27
<%else%>
28
  <p>Created at: <%= @sample.created_at%></p>
29
<%end%>
30

31
32

<!--  right side-->
33
<table id="tab_logic" class="table table-bordered table-hover table-width" >
34
  <thead>
35
36
37
38
39
40
41
  <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>
42
43
  </thead>
  <tbody>
44
45
46
47
48
49
50
  <%[@sample].each do |sample|%>
    <tr class="<%="selekt sample-#{sample.status.gsub(/ /,"_")}" %>">
      <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>
51
        <% if (operator? && sample.status =="measured") || (!operator? && sample.status=="submitted" ||!operator? && sample.status=="measured") %>
52
        <%else%>
53
          <%= link_to '<i class="fa fa-pencil-square-o" aria-hidden="true"></i>'.html_safe, edit_sample_path(sample), remote: true%>
54
55
56
57
58
59
60
61
        <%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%>
62
63
  </tbody>
</table>
64

65
<%#, style="margin-top:50px;margin-left:25px;width:95%" %>
66
<table  class="table table-bordered  table-hover" id = "tb" style="width:45%">
67
  <thead>
68
69
70
  <tr>
    <th>ELEMENTS:</th>
    <% Sample::PREDEF_ELEMENTS.each do |k,v| %>
71
      <th><%= k %></th>
72
73
74
75
    <%end if @sample.calculation%>
    <th>Other</TH>
    <th>Total</th>
  </tr>
76
77
  </thead>
  <tbody >
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  <tr style="border:1pt solid black;">
    <td style=" border:1pt solid black;">Expected:</td>
    <%sum,i=0,0 %>
    <%@sample.formatted_calculation.each_pair do |k,v| %>
      <%if i<4 %>
        <td style=" border:1pt solid black;"><%= "%.2f" %v %>
          <% sum=sum.to_f+v.to_f %>
        </td>
        <%i=i+1%>
      <%end%>
    <%end if @sample.calculation %>
    <% s = 100 - sum %>
    <td style=" border:1pt solid black;"><%= "%.2f" % s.abs.round(2)%></td>
    <% sum = sum + s%>
    <td style=" border:1pt solid black;"><%= "%.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| %>
97
      <tr>
Sara Kuqi's avatar
Sara Kuqi committed
98
        <td>Result <%= i %> :<%#= @user.name %> </td>
pei-chi.huang's avatar
pei-chi.huang committed
99
100
        <td><%= result.element_N %>   </td>
        <% sum2=sum2.to_f+result.element_N.to_f %>
101
102
103
        <td><%= result.element_C %>  </td>
        <%sum2=sum2.to_f+result.element_C.to_f %>
        <td><%= result.element_H %></td>
pei-chi.huang's avatar
pei-chi.huang committed
104
        <% sum2=sum2.to_f+result.element_H.to_f %>
105
106
        <td><%= result.element_S %></td>
        <% sum2=sum2.to_f+result.element_S.to_f %>
pei-chi.huang's avatar
pei-chi.huang committed
107
        <%( result.measurement.keys - Sample::PREDEF_ELEMENTS).each do |k| %>
108
109
          <td> <%= if result.measurement[k] then "%.2f" % result.measurement[k].to_f else '' end%></td>
          <% sum2=sum2.to_f+result.measurement[k].to_f %>
110
111
112
        <%end if result.measurement %>
        <% i = i+1 %>
        <td></td>
113
        <td><%= "%.2f" % sum2.round(2)%></td>
114
115
        <%sum2=0%>
      </tr>
116
      <tr class="y_n">
117
118
        <td>  Difference (%) </td>
        <%diff={}%>
119
120
121
        <%Sample::PREDEF_ELEMENTS.each do |k| %>
          <% v = @sample.calculation[k]%>
          <% diff[k] = percentage_diff(v,result.send('element_'+k)) %>
122
        <%end if @sample.calculation %>
123
124
125
126
127
128
129
130
        <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 - 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 %>
131
        <%end %>
132
      </tr>
133
134
    <%end%>
  <%end %>
135
  </tbody>
136
</table>
137

138
<%if @sample.status == "in preparation" %>
chia-lin.lin's avatar
chia-lin.lin committed
139
  <div class='absolute'><%=link_to (@sample.status ? "Submit for Measurement" : "No"),
140
                                   Measured_sample_path(@sample), :action => 'solve', :class => 'btn btn-block btn-success', :style=>"width:99%"%>
141
  </div>
pei-chi.huang's avatar
pei-chi.huang committed
142
<%elsif current_user?(@sample.user) && @sample.status == "submitted" %>
chia-lin.lin's avatar
chia-lin.lin committed
143
  <div class='absolute'><%=link_to (@sample.status ? "Withdraw this Sample" : "No"),
144
                                   Withdraw_sample_path(@sample), :action => 'solve', :class => 'btn btn-block btn-danger', :style=>"width:99%" %>
pei-chi.huang's avatar
pei-chi.huang committed
145
  </div>
146
<%elsif operator? && @sample.status == "submitted" %>
chia-lin.lin's avatar
chia-lin.lin committed
147
  <div class='absolute'><%=link_to (@sample.status ? "Release Measurement" : "No"),
148
                                   ReleaseMeasurment_sample_path(@sample), :action => 'solve', :class => 'btn btn-block btn-success', :style=>"width:99%" %>
149
150
  </div>
<%end%>
151
152

<div style="display: inline-block">
ira.maier's avatar
ira.maier committed
153
154
155
  <h4 style="text-align: left">File Attachments</h4>
  <div style="float: left; width: auto;" >

156
    <%unless @sample.files.attached? %>
ira.maier's avatar
ira.maier committed
157
    <%= form_with model: @sample do |f| %>
ira.maier's avatar
ira.maier committed
158
        <div style="text-align: left">
ira.maier's avatar
ira.maier committed
159
          <%= f.label "Create new File Attachment:" %>
160
161
          <%= f.file_field :add_files, multiple: true, direct_upload: true, class: "file_storage_button", style: "width: 70%" %>
          <%= f.submit "Save Files", class: "file_storage_button", style: "width: 70%" %>
ira.maier's avatar
ira.maier committed
162
        </div>
163
  <% end %>
164
  <% end %>
ira.maier's avatar
ira.maier committed
165

166
    <%if @sample.files.attached? %>
ira.maier's avatar
ira.maier committed
167
168
      <div style="float: left; margin: 0.5rem; width: auto" ><%= render 'samples/form_delete_files'%></div>
      <div style="float: left; margin: 0.5rem; width: auto" ><%= render 'samples/form_add_files'%></div>
169
    <%end%>
ira.maier's avatar
ira.maier committed
170
171
172
        </div>
      </div>
  <%#= link_to 'Open Files List', files_sample_path, target: "_blank", class:'btn btn-info'%>
173

chia-lin.lin's avatar
chia-lin.lin committed
174
<%= render 'samples/comment' %>
175
<br>
ira.maier's avatar
ira.maier committed
176
177
<p><%=link_to "Download PDF", sample_path(@sample, format: "pdf"), target: "_blank" %>&nbsp;<%=link_to "Download PNG", sample_path(@sample, format: "png"), target: "_blank" %><p>