Permalink
Browse files

soporte para ocultar verificentros suspendidos

  • Loading branch information...
manuel-rabade committed Aug 31, 2014
1 parent b265f0f commit e1d6ba33f8586498d55b0b01225514a5ae7af570
@@ -2,7 +2,7 @@
ActiveAdmin.register Verificentro do
menu(priority: 1)
permit_params(:number, :name, :address, :delegacion_id, :phone, :lat, :lon)
permit_params(:number, :name, :address, :delegacion_id, :phone, :lat, :lon, :suspended)
index do
selectable_column
@@ -12,12 +12,14 @@
column 'Delegación', :delegacion
column 'Latitud', :lat
column 'Longitud', :lon
column 'Suspendido', :suspended
actions
end
filter :number, label: 'Número'
filter :delegacion, label: 'Delegación'
filter :name, label: 'Razón Social'
filter :suspended, label: 'Suspendido'
form do |f|
f.inputs do
@@ -28,6 +30,7 @@
f.input :phone, label: 'Teléfono', hint: 'Para varios teléfonos separarlos con un espacio'
f.input :lat, label: 'Latitud', hint: 'En grados decimales'
f.input :lon, label: 'Longitud', hint: 'En grados decimales'
f.input :suspended, label: 'Suspendido'
end
f.actions
end
@@ -36,7 +36,7 @@ def answer
def verificentros
@answer = Answer.find(3)
answer_view(@answer.id)
@verificentros_count = Verificentro.count
@verificentros_count = Verificentro.not_suspended.count
@delegaciones = Delegacion.order('name')
end
@@ -50,7 +50,7 @@ def verificentros_search
return
end
begin
res = Verificentro.near(query, 60, {:order => "distance"})
res = Verificentro.not_suspended.near(query, 60, {:order => "distance"})
rescue
return
end
@@ -62,7 +62,7 @@ def verificentros_delegacion
url = verificentros_delegacion_param[:delegacion_url]
begin
@delegacion = Delegacion.find_by_url!(url)
@verificentros = @delegacion.verificentros
@verificentros = @delegacion.verificentros.not_suspended
rescue
redirect_to({ action: 'verificentros' })
end
@@ -2,7 +2,12 @@ class Verificentro < ActiveRecord::Base
validates :number, :name, :address, presence: true
validates :delegacion, presence: true
validates :lat, :lon, numericality: true
validates :suspended, inclusion: { in: [ true, false ] }
belongs_to :delegacion
reverse_geocoded_by :lat, :lon
def self.not_suspended
self.where(suspended: false)
end
end
@@ -19,14 +19,14 @@
<% g.each do |d| %>
<% next unless d %>
<p>
<% if d.verificentros.count > 0 %>
<% if d.verificentros.not_suspended.count > 0 %>
<a class="btn-delegacion"
href="<%= url_for({ controller: 'answers',
action: 'verificentros_delegacion',
delegacion_url: d.url })%>">
<%= d.name %></a><br/>
<% if d.verificentros.count > 1 %>
<small><%= d.verificentros.count %> verificentros</small>
<% if d.verificentros.not_suspended.count > 1 %>
<small><%= d.verificentros.not_suspended.count %> verificentros</small>
<% else %>
<small>1 verificentro</small>
<% end %>
@@ -0,0 +1,5 @@
class AddSuspendedToVerificentros < ActiveRecord::Migration
def change
add_column :verificentros, :suspended, :boolean, null: false, default: false
end
end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140706162710) do
ActiveRecord::Schema.define(version: 20140831195608) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -127,15 +127,16 @@
end
create_table "verificentros", force: true do |t|
t.integer "number", null: false
t.string "name", null: false
t.text "address", null: false
t.integer "delegacion_id", null: false
t.integer "number", null: false
t.string "name", null: false
t.text "address", null: false
t.integer "delegacion_id", null: false
t.string "phone"
t.float "lat", null: false
t.float "lon", null: false
t.float "lat", null: false
t.float "lon", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "suspended", default: false, null: false
end
end
@@ -92,10 +92,10 @@
describe 'GET verificentros' do
before do
@verificentros_count = Verificentro.count
@verificentros_count = Verificentro.not_suspended.count
@delegaciones_count = Delegacion.count
end
it 'should return verificentros count and delegaciones' do
it 'should return verificentros not suspended count and delegaciones' do
get :verificentros
response.should be_success
should render_template('verificentros')
@@ -135,7 +135,7 @@
describe 'with valid delegacion' do
before do
@delegacion = Delegacion.order('RANDOM()').first
@verificentros_count = @delegacion.verificentros.count
@verificentros_count = @delegacion.verificentros.not_suspended.count
end
it 'should return verificentros' do
get :verificentros_delegacion, { delegacion_url: @delegacion.url }
@@ -16,6 +16,7 @@
it { should respond_to(:phone) }
it { should respond_to(:lat) }
it { should respond_to(:lon) }
it { should respond_to(:suspended) }
it { should be_valid }
@@ -84,7 +84,7 @@
describe 'verificentros delegacion' do
before do
@delegacion = Delegacion.order('RANDOM()').first
@verificentros_count = @delegacion.verificentros.count
@verificentros_count = @delegacion.verificentros.not_suspended.count
click_link(@delegacion.name)
end

0 comments on commit e1d6ba3

Please sign in to comment.