Skip to content

Commit

Permalink
Merge branch 'csv_xls' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva committed Jun 20, 2017
2 parents 20934b9 + 0a462a8 commit 4015eee
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 135 deletions.
7 changes: 7 additions & 0 deletions app/controllers/alumns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ def index
@alumns = @current_user.alumns
elsif ( is_employee? )
@alumns = Alumn.all
@grades = Array.new
@subjects = Subject.all
respond_to do |format|
format.html
format.xls #{ send_data @alumns.to_csv (col_sep: "\t")}

end
if params[:search]
@alumns = Alumn.search(params[:search]).order("created_at DESC")
if (@alumns.empty?)
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/csv_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CsvHelper
end
1 change: 1 addition & 0 deletions app/models/alumn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def self.current
@current_alumn
end


private
def validates_password
if self.password_digest.nil?
Expand Down
6 changes: 6 additions & 0 deletions app/views/alumns/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@

<%= render "layouts/feedback_messages" %>




<section class="content-section" id="alumns-list">
<div class="container">
<%if is_principal? or is_secretary? %>
<%= link_to '<span class="fa fa-address-card"></span> Gerar XLS'.html_safe, alumns_path(format: "xls"),class: 'btn btn-success pull-right' %>
<% end %>
<% @alumns.each do |alumn| %>
<div class="row item">
<div class="col-sm-12 col-md-4">
Expand Down
68 changes: 68 additions & 0 deletions app/views/alumns/index.xls.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"></meta>
<table border="1">
<tr>
<th>Nome</th>
<th>Matrícula</th>
<th>Turma</th>
<th>Faltas</th>
<th>Advertências</th>
<th>Suspensões</th>
<th>Responsável</th>
<%@subjects.each do |subject|%>
<th><%=subject.name_subject%> 1°B</th>
<%end%>
<%@subjects.each do |subject|%>
<th><%=subject.name_subject%> 2°B</th>
<%end%>
<%@subjects.each do |subject|%>
<th><%=subject.name_subject%> 3°B</th>
<%end%>
<%@subjects.each do |subject|%>
<th><%=subject.name_subject%> 4°B</th>
<%end%>
<%@subjects.each do |subject|%>
<th><%=subject.name_subject%> Final</th>
<%end%>
</tr>

<% @alumns.each do |alumn| %>
<tr>
<td> <%= alumn.name%></td>
<td><%= alumn.registry%></td>
<td><%= alumn.classroom.name_classroom%></td>
<td><%= alumn.school_misses.count %>
</td>
<td><%= alumn.quantity_strike %></td>
<td><%= alumn.suspensions.count %>
<td><%= alumn.parent.name %></td>
<%alumn.classroom.subjects.each do |subject|%>
<%subject.grades.where(alumn_id: alumn.id).each do |grade|%>
<td><%=grade.grade_01%></td>
<%end%>
<%end%>
<%alumn.classroom.subjects.each do |subject|%>
<%subject.grades.where(alumn_id: alumn.id).each do |grade|%>
<td><%=grade.grade_02%></td>
<%end%>
<%end%>
<%alumn.classroom.subjects.each do |subject|%>
<%subject.grades.where(alumn_id: alumn.id).each do |grade|%>
<td><%=grade.grade_03%></td>
<%end%>
<%end%>
<%alumn.classroom.subjects.each do |subject|%>
<%subject.grades.where(alumn_id: alumn.id).each do |grade|%>
<td><%=grade.grade_04%></td>
<%end%>
<%end%>
<%alumn.classroom.subjects.each do |subject|%>
<%subject.grades.where(alumn_id: alumn.id).each do |grade|%>
<td><%=grade.grade_final%></td>
<%end%>
<%end%>
</tr>
<% end %>
<tr>
<td><strong>Data</strong></td>
<td><%=DateTime.now.to_date%></td>
</tr>
131 changes: 16 additions & 115 deletions app/views/alumns/report.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,134 +11,35 @@
Matéria
</th>
<th class="text-center">
Tri
Bi
</th>
<th class="text-center">
Tri
Bi
</th>
<th class="text-center">
Tri
Bi
</th>
<th class="text-center">
Tri
Bi
</th>
<th class="text-center">
Nota Final
</th>
<th class="text-center">
Status
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-center">Português</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">7</td>
<td class="text-center">APROVADO</td>
</tr>
<tr>
<td class="text-center">Matemática</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">7</td>
<td class="text-center">APROVADO</td>
</tr>
<tr>
<td class="text-center">Geografia</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">4</td>
<td class="text-center">REPROVADO</td>
</tr>
<tr>
<td class="text-center">Português</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">7</td>
<td class="text-center">APROVADO</td>
</tr>
<tr>
<td class="text-center">Matemática</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">7</td>
<td class="text-center">APROVADO</td>
</tr>
<tr>
<td class="text-center">Geografia</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">4</td>
<td class="text-center">REPROVADO</td>
</tr>
<tr>
<td class="text-center">Português</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">7</td>
<td class="text-center">APROVADO</td>
</tr>
<tr>
<td class="text-center">Matemática</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">7</td>
<td class="text-center">APROVADO</td>
</tr>
<tr>
<td class="text-center">Geografia</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">4</td>
<td class="text-center">REPROVADO</td>
</tr>
<tr>
<td class="text-center">Português</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">7</td>
<td class="text-center">APROVADO</td>
</tr>
<tr>
<td class="text-center">Matemática</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">7</td>
<td class="text-center">APROVADO</td>
</tr>
<tr>
<td class="text-center">Geografia</td>
<td class="text-center">8</td>
<td class="text-center">6</td>
<td class="text-center">5</td>
<td class="text-center">4</td>
<td class="text-center">4</td>
<td class="text-center">REPROVADO</td>
</tr>

<%@alumn.subjects.each do |subject|%>
<tr><td class="text-center"><%=subject.name_subject%></td>
<%subject.grades.where(alumn_id: @alumn.id).each do |grade|%>
<td class="text-center"><%=grade.grade_01%></td>
<td class="text-center"><%=grade.grade_02%></td>
<td class="text-center"><%=grade.grade_03%></td>
<td class="text-center"><%=grade.grade_04%></td>
<td class="text-center"><%=grade.grade_final%></td>
<%end%>
</tr>
<%end%>
</tbody>
</table>

Expand Down
48 changes: 29 additions & 19 deletions app/views/alumns/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@
<div class="col-sm-12 col-md-8 text-capitalize descript">
<ul>
<h4>Primeiro Bimestre</h4>
<% @alumn.classroom.subjects.each do |subjects| %>
<li class="text-danger"><%= subjects.name_subject%>
<% subjects.grades.each do |grades| %>
<%= grades.grade_01%></li>
<% @alumn.classroom.subjects.each do |subject| %>
<li class="text-danger"><%= subject.name_subject%>
<% subject.grades.where(alumn_id: @alumn.id).each do |grade| %>
<%= grade.grade_01%></li>
<%end%>
<%end%>
</ul>
Expand All @@ -88,11 +88,10 @@
<div class="col-sm-12 col-md-8 text-capitalize descript">
<ul>
<h4>Segundo Bimestre</h4>
<% @alumn.classroom.subjects.each do |subjects| %>
<li class="text-danger"><%= subjects.name_subject%>

<% subjects.grades.each do |grades| %>
<%= grades.grade_02%></li>
<% @alumn.classroom.subjects.each do |subject| %>
<li class="text-danger"><%= subject.name_subject%>
<% subject.grades.where(alumn_id: @alumn.id).each do |grade| %>
<%= grade.grade_02%></li>
<%end%>
<%end%>
</ul>
Expand All @@ -101,11 +100,10 @@
<div class="col-sm-12 col-md-8 text-capitalize descript">
<ul>
<h4>Terceiro Bimestre</h4>
<% @alumn.classroom.subjects.each do |subjects| %>
<li class="text-danger"><%= subjects.name_subject%>

<% subjects.grades.each do |grades| %>
<%= grades.grade_03%></li>
<% @alumn.classroom.subjects.each do |subject| %>
<li class="text-danger"><%= subject.name_subject%>
<% subject.grades.where(alumn_id: @alumn.id).each do |grade| %>
<%= grade.grade_03%></li>
<%end%>
<%end%>
</ul>
Expand All @@ -114,15 +112,27 @@
<div class="col-sm-12 col-md-8 text-capitalize descript">
<ul>
<h4>Quarto Bimestre</h4>
<% @alumn.classroom.subjects.each do |subjects| %>
<li class="text-danger"><%= subjects.name_subject%>

<% subjects.grades.each do |grades| %>
<%= grades.grade_04%></li>
<% @alumn.classroom.subjects.each do |subject| %>
<li class="text-danger"><%= subject.name_subject%>
<% subject.grades.where(alumn_id: @alumn.id).each do |grade| %>
<%= grade.grade_04%></li>
<%end%>
<%end%>
</ul>
</div>

<div class="col-sm-12 col-md-8 text-capitalize descript">
<ul>
<h4>Nota Final</h4>
<% @alumn.classroom.subjects.each do |subject| %>
<li class="text-danger"><%= subject.name_subject%>
<% subject.grades.where(alumn_id: @alumn.id).each do |grade| %>
<%= grade.grade_final%></li>
<%end%>
<%end%>
</ul>
</div>

</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative 'boot'

require 'rails/all'

require 'csv'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
Expand Down
1 change: 1 addition & 0 deletions config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
Mime::Type.register "application/xls", :xls
15 changes: 15 additions & 0 deletions spec/helpers/csv_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the CsvHelper. For example:
#
# describe CsvHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe CsvHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 4015eee

Please sign in to comment.