Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#WIP Shift and room admin view #42

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ gem 'bcrypt', '~> 3.1.7'
# Create multi-language
# gem "rails-i18n", :git => "git://github.com/svenfuchs/rails-i18n.git", :branch => "master"

# Paginate helper gem
gem 'bootstrap-will_paginate'
# Devise
gem 'devise', "~> 3.0" # 4.0 needs ruby 2.2

# Let's get a copy of documentation
Expand Down
10 changes: 3 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ GEM
ansi (1.5.0)
arel (5.0.1.20140414130214)
ast (2.3.0)
autoprefixer-rails (6.4.0.2)
autoprefixer-rails (6.4.0.3)
execjs
bcrypt (3.1.11)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
bootstrap-will_paginate (0.0.10)
will_paginate
builder (3.2.2)
byebug (9.0.5)
capybara (2.7.1)
Expand Down Expand Up @@ -193,7 +191,7 @@ GEM
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-rails (3.5.1)
rspec-rails (3.5.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
Expand Down Expand Up @@ -254,7 +252,6 @@ GEM
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket (1.2.3)
will_paginate (3.1.0)
xpath (2.0.0)
nokogiri (~> 1.3)

Expand All @@ -263,7 +260,6 @@ PLATFORMS

DEPENDENCIES
bcrypt (~> 3.1.7)
bootstrap-will_paginate
byebug
capybara (~> 2.7.0)
coffee-rails (~> 4.1.0)
Expand Down Expand Up @@ -299,4 +295,4 @@ DEPENDENCIES
web-console (~> 2.0)

BUNDLED WITH
1.11.2
1.12.5
32 changes: 22 additions & 10 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ class AdminController < ApplicationController
before_action :admin_user?

def dashboard
@users = User.paginate(page: params[:users_page])
@offsprings = Offspring.paginate(page: params[:offsprings_page])
@rooms = Room.all
end

def offsprings
@offsprings = Offspring.paginate(page: params[:page])
end

def rooms
@users = User.all
@offsprings = Offspring.all
@rooms = Room.all
@users_count = User.where(admin: false).count
@offspring_count = Offspring.all.count
@zero_offspring_count = user_0_offspr_count
@users_with_at_least_2_offspring = user_2_offspr_count
end

private
Expand All @@ -26,4 +22,20 @@ def admin_user?
redirect_to home_path
end
end

def user_0_offspr_count
count = 0
User.all.each do |u|
count += 1 if u.no_offspring?
end
count
end

def user_2_offspr_count
count = 0
User.all.each do |u|
count += 1 if u.more_than_2_offspring?
end
count
end
end
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def show
end

def index
@users = User.paginate(page: params[:page])
@users = User.all
end

def destroy
Expand Down
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ class User < ActiveRecord::Base
validates :phone, format: { with: VALID_TELEPHONE_REGEX}
# The offspring need to have a parent, they will be destroyed if the parent is
has_many :offsprings, dependent: :destroy

def no_offspring?
offsprings.nil? || offsprings.count.zero?
end

def more_than_2_offspring?
!offsprings.nil? && offsprings.count >= 2
end
end
22 changes: 19 additions & 3 deletions app/views/admin/_principal.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<div id="navi_tabs">

<ul class="nav nav-tabs" role="tablist">
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#menu1">Padres</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#menu2" >Catecúmenos</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#menu2">Catecúmenos</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#menu3">Aulas</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#menu4">Administración del Sistema</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#menu5">Información del Sistema</a></li>
Expand Down Expand Up @@ -62,7 +61,24 @@
</div>

<div id="menu3" class="tab-pane" role="tabpanel">
<%= render partial: 'shift_view', collection: @rooms, as: :room %>
<div style="float:center; width: auto;">
<div class="panel-body">
<div class="container-fluid">
<div>
<!-- The functionality script should go here
<button class="btn btn-secondary btn-lg" type="button" onclick="myFunction()">Nuevo Aula</button>
<script>
function myFunction() {
alert("I am an alert box!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what you should comment or delete

}
</script> -->
</div>
</div>
</div>
</div>
<div>
<%= render partial: 'shift_view', collection: @rooms, as: :room %>
</div>
</div>

<div id="menu4" class="tab-pane" role="tabpanel">
Expand Down
9 changes: 4 additions & 5 deletions app/views/admin/_shift_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
</div>
<div class="panel-body">
<div class="container-fluid">
<% (1..7).each do |day| %>
<div class="col-md-1">
<% (1..5).each do |day| %>
<div class="col-sm-2">
<ul class="list-group">
<li class="list-group-item list-group-item-heading active"><%= week_day_convert(day) %></li>
<% room.shifts.where(day_of_week: day).order("start_time").each do |shift| %>
Expand All @@ -17,9 +17,8 @@
<% end %>
</ul>

</div>
<% end %>

</div>
<% end %>
</div>
</div>
</div>
78 changes: 38 additions & 40 deletions app/views/admin/_system_admin_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
<div class="panel panel-default">


<div style="float:left; width: 50%;">
<div class="panel-heading">
<h3 id= "blocker_panel_title" class="panel-title"><%="Bloqueo de cambios"%></h3>
</div>
<div class="panel-body">
<div class="container-fluid">
<p>
<ul class="list-group">
<li> Ésta acción permite al administrador bloquear cambios que puedan hacer los usuarios.
<ol>
<li> No se podrán añadir usuarios nuevos. </li>
<li> No se podrán agregar hijos. </li>
<li> No podrán cambiar o reasignar aulas/turnos a no ser que seas administrador. </li>
<li> Cada usuario <b>SÍ</b> podrá borrar su cuenta. </li>
</ol>
</li>
<div>

<input class="bootstrap-switch" id="bootstrap-switch-state" type="checkbox" checked>
<script>
jQuery(".bootstrap-switch").bootstrapSwitch();
</script>
</div>
</p>
</div>
</div>
</div>

<div style="float:left; width: 50%;">
<div class="panel-heading">
<h3 id= "blocker_panel_title" class="panel-title"><%="Borrado de la base de datos"%></h3>
<h3 id= "blocker_panel_title" class="panel-title"><%="Bloqueo de cambios"%></h3>
</div>
<div class="panel-body">
<div class="container-fluid">
<p>
<ul class="list-group">
<li> Ésta acción permite al administrador eliminar la base de datos. </li>

<button class="btn btn-danger btn-lg" type="button" onclick="myFunction()">Borrar BBDD</button>
<li> Ésta acción permite al administrador bloquear cambios que puedan hacer los usuarios.
<ol>
<li> No se podrán añadir usuarios nuevos. </li>
<li> No se podrán agregar hijos. </li>
<li> No podrán cambiar o reasignar aulas/turnos a no ser que seas administrador. </li>
<li> Cada usuario <b>SÍ</b> podrá borrar su cuenta. </li>
</ol>
</li>
<div>

<input class="bootstrap-switch" id="bootstrap-switch-state" type="checkbox" checked>
<script>
function myFunction() {
alert("I am an alert box!");
}
jQuery(".bootstrap-switch").bootstrapSwitch();
</script>
</p>
</div>
</p>
</div>
</div>
</div>
</div>
</div>

<div style="float:left; width: 50%;">
<div class="panel-heading">
<h3 id= "blocker_panel_title" class="panel-title"><%="Borrado de la base de datos"%></h3>
</div>
<div class="panel-body">
<div class="container-fluid">
<p>
<ul class="list-group">
<li> Ésta acción permite al administrador eliminar la base de datos. </li>

<!--<button class="btn btn-danger btn-lg" type="button" onclick="myFunction()">Borrar BBDD</button>
<script>
function myFunction() {
alert("I am an alert box!");
}
</script> -->
</p>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
</html>
46 changes: 26 additions & 20 deletions app/views/offsprings/_offspring.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
<div>
<div class="list-group-item">
<div class="list-view-pf-actions">
<tr>
<td>
<div class="list-view-pf-body">
<%= offspring.first_name %>
</div>
</td>
<td>
<div class="list-view-pf-body">
<%= offspring.last_name %>
</div>
</td>
<td>
<div class="list-view-pf-body">
<%= I18n.t offspring.grade %>
</div>
</td>
<td>
<div class="list-view-pf-body">
<%= link_to full_name_for(offspring.user),offspring.user %>
</div>
</td>
<td>
<div class="list-view-pf-actions">
<% if offspring.shift.nil? %>
<%= link_to "Asignar horario", new_assignment_path(offspring), class: "btn btn-warning"%>
<% else %>
<%= button_to "#{week_day_convert(offspring.shift.day_of_week)}: #{offspring.shift.start_time}", assignment_path(offspring), method: :delete, data: { confirm: 'Esto borrará la asignación y comenzará una nueva, ¿Está seguro?'}, class: "btn btn-success" %>
<% end %>
<%= button_to "Borrar niño", { action: "destroy", controller: 'offsprings', id: offspring.id} , method: :delete, data: { confirm: 'Esta acción no puede cancelarse, ¿Está seguro?'} , class:"btn btn-primary"%>
</div>

<div class="list-view-pf-body">
<%= offspring.first_name %>
</div>

<div class="list-view-pf-body">
<%= offspring.last_name %>
</div>

<div class="list-view-pf-body">
<%= I18n.t offspring.grade %>
</div>
<div class="list-view-pf-body">
<%= link_to full_name_for(offspring.user),offspring.user %>
</div>

</div>
</div>
</td>
</tr>
</div>
3 changes: 0 additions & 3 deletions app/views/offsprings/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<% provide(:title, 'Lista de catecúmenos') %>
<h1>Índice de catecúmenos</h1>

<%= will_paginate :previous_label => "Previo", :next_label => "Siguiente"%>
<table class="datatable table table-striped table-bordered table-hover">
<thead>
<tr>
Expand All @@ -22,5 +21,3 @@
$('.datatable').dataTable();
});
</script>

<%= will_paginate :previous_label => "Previo", :next_label => "Siguiente"%>
25 changes: 5 additions & 20 deletions app/views/rooms/_room.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,21 @@
</div>

<div class="panel-body">
<div class="col-md-6">
<div class="col-md-12">
<div class="row">
<% (1..4).each do |day| %>
<div class="col-lg-3">
<% (1..5).each do |day| %>
<div class="col-sm-2">
<ul class="list-group">
<li class="list-group-item list-group-item-heading active"><%= week_day_convert(day) %></li>
<% room.shifts.where(day_of_week: day).order("start_time").each do |shift| %>
<li class="list-group-item-text">
<%= "#{shift.start_time} , #{pluralize(shift.sites_available, "plaza")}"%>
</li>
<% end %>
<% end %>
</ul>
</div>
<% end %>
</div>
</div>
<div class="col-md-6">
<div class="row">
<% (5..7).each do |day| %>
<div class="col-lg-3">
<ul class="list-group">
<li class="list-group-item list-group-item-heading active"><%= week_day_convert(day) %></li>
<% room.shifts.where(day_of_week: day).order("start_time").each do |shift| %>
<li class="list-group-item-text">
<%= "#{shift.start_time} , #{pluralize(shift.sites_available, "plaza")}"%>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
</div>
</div>

Loading