Skip to content

Commit

Permalink
Merge branch 'master' into new-sorting-options
Browse files Browse the repository at this point in the history
  • Loading branch information
taitus committed Dec 12, 2017
2 parents 98a6448 + 00acbfb commit 1ebc824
Show file tree
Hide file tree
Showing 22 changed files with 186 additions and 47 deletions.
21 changes: 17 additions & 4 deletions app/assets/javascripts/events.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ $(function(){
weekStart: 1
});

$.validator.addMethod("valueNotEquals", function(value, element, arg){
agent = $("#new_event_agent > div > div.small-12.medium-6.columns > select").val();
if ($(element).is(':checked') && (agent == '' ||
typeof(agent) == 'undefined' ||
agent == "<%= I18n.translate('backend.event.not_available_agents')%>" ))
{return false }
else
{ return true }
}, "<%= I18n.translate('backend.event.event_agent_needed')%>");

$(".admin-form").validate({

ignore: [],
Expand All @@ -25,9 +35,6 @@ $(function(){
"event[position_id]" : {
required : true
},
"event[lobby_activity]" : {
required : true,
},
"event[attachments_attributes][0][title]" : {
required : true
},
Expand All @@ -37,6 +44,9 @@ $(function(){
"event[attachments_attributes][0][public]" : {
required : true
},
"event[lobby_activity]" : {
valueNotEquals: "<%= I18n.translate('backend.event.not_available_agents')%>"
},
"event[published_at]" : {
required : true
}
Expand Down Expand Up @@ -69,6 +79,9 @@ $(function(){
},
"event[published_at]" : {
required : "<%= I18n.translate('backend.mandatory_field')%>"
},
"event[event_agents_attributes][0][name]" : {
valueNotEquals: "<%= I18n.translate('backend.event.event_agent_needed')%>"
}
},

Expand Down Expand Up @@ -173,7 +186,7 @@ function fill_agents_select_options() {
}
});
}else {
select.append($('<option>', { value: "No hay agentes disponibles.", text: "No hay agentes disponibles." }));
select.append($('<option>', { value: "<%= I18n.translate('backend.event.not_available_agents')%>", text: "<%= I18n.translate('backend.event.not_available_agents')%>" }));
id_select_agent = $('#nested-event-agents select').attr('id');
set_option = $('select#' + id_select_agent + ' option').last().val();
$('#nested-event-agents select').val(set_option);
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def search(params)
fulltext params[:keyword] if params[:keyword].present?
with(:interest_ids, params[:interests]) if params[:interests].present?
with(:category_id, params[:category]) if params[:category].present?
any do
fulltext(params[:agent_name], :fields => [:agent_name]) if params[:agent_name].present?
fulltext(params[:agent_name], :fields => [:agent_first_surname]) if params[:agent_name].present?
fulltext(params[:agent_name], :fields => [:agent_second_surname]) if params[:agent_name].present?
end
order_by :created_at, :desc
paginate page: params[:format].present? ? 1 : params[:page] || 1, per_page: params[:format].present? ? 1000 : 10
end
Expand Down
8 changes: 7 additions & 1 deletion app/models/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def fullname
str
end

scope :by_organization, -> (organization_id) { where(organization_id: organization_id) }
scope :by_organization, ->(organization_id) { where(organization_id: organization_id) }
scope :from_active_organizations, -> { joins(:organization).where('canceled_at is NULL AND invalidate is FALSE') }

searchable do
text :name, :first_surname, :second_surname
integer :organization_id
end

end
7 changes: 7 additions & 0 deletions app/models/concerns/event_agent_existence_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class EventAgentExistenceValidator < ActiveModel::Validator
def validate(record)
if record.lobby_activity && record.event_agents.empty?
record.errors.add(:event_agents, I18n.translate('backend.event.event_agent_needed'))
end
end
end
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Event < ActiveRecord::Base
validates :title, :position, :location, presence: true
validates_inclusion_of :lobby_activity, :in => [true, false]
validate :participants_uniqueness, :position_not_in_participants, :role_validate_published_at, :role_validate_scheduled
validates_with EventAgentExistenceValidator

before_create :set_status
before_save :cancel_event
Expand Down
5 changes: 5 additions & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class Organization < ActiveRecord::Base
interests.map(&:id)
end
integer :category_id
integer :id
join(:name, :prefix => "agent", :target => Agent, :type => :text, :join => { :from => :organization_id, :to => :id })
join(:first_surname, :prefix => "agent", :target => Agent, :type => :text, :join => { :from => :organization_id, :to => :id })
join(:second_surname, :prefix => "agent", :target => Agent, :type => :text, :join => { :from => :organization_id, :to => :id })
end

scope :invalidated, -> { where('invalidate = ?', true) }
Expand Down Expand Up @@ -69,4 +73,5 @@ def set_invalidate
def interest?(id)
interests.pluck(:id).include?(id)
end

end
4 changes: 2 additions & 2 deletions app/views/events/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<thead>
<tr>
<th><%= t('backend.date')%></th>
<th><%= t('backend.event')%></th>
<th><%= t('backend.event.title')%></th>
<th><%= t('backend.holder')%></th>
<th><%= t('backend.actions')%></th>
</tr>
</thead>
<tfoot>
<tr>
<th><%= t('backend.date')%></th>
<th><%= t('backend.event')%></th>
<th><%= t('backend.event.title')%></th>
<th><%= t('backend.holder')%></th>
<th><%= t('backend.actions')%></th>
</tr>
Expand Down
4 changes: 4 additions & 0 deletions app/views/organizations/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
class: "dropdown" %>
</div>

<div class="mb20">
<%= text_field_tag :agent_name, params[:agent_name], placeholder: t("main.form.agent") %>
</div>

<div class="mb20">
<%= link_to t("main.form.reset"), organizations_path, class: "button secondary" %>
<%= submit_tag t("main.form.search"), class: "button" %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/organizations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</p>
</div>
</div>

<div class="small-12 columns">
<ul class="accordion" data-accordion role = "tablist">
<li class="accordion-navigation active">
Expand Down Expand Up @@ -201,7 +201,7 @@
<ul>
<% if @organization.interests.each do |interest| %>
<li>
<%= interest.name %>
<p><%= interest.name %></p>
</li>
<% end.empty? %>
<%= t('organizations.show.no_results') %>
Expand Down
3 changes: 2 additions & 1 deletion bin/rails
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
rescue LoadError => e
raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
Expand Down
3 changes: 2 additions & 1 deletion bin/rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
rescue LoadError => e
raise unless e.message.include?('spring')
end
require_relative '../config/boot'
require 'rake'
Expand Down
3 changes: 2 additions & 1 deletion bin/rspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
rescue LoadError => e
raise unless e.message.include?('spring')
end
require 'bundler/setup'
load Gem.bin_path('rspec-core', 'rspec')
14 changes: 8 additions & 6 deletions bin/spring
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
# It gets overwritten when you run the `spring binstub` command.

unless defined?(Spring)
require "rubygems"
require "bundler"
require 'rubygems'
require 'bundler'

if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m))
Gem.paths = { "GEM_PATH" => [Bundler.bundle_path.to_s, *Gem.path].uniq }
gem "spring", match[1]
require "spring/binstub"
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
spring = lockfile.specs.detect { |spec| spec.name == "spring" }
if spring
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
gem 'spring', spring.version
require 'spring/binstub'
end
end
5 changes: 4 additions & 1 deletion config/locales/admin.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ es:
must_have_position: "Es necesario añadir al menos un cargo"

events: "Eventos"
event: "Evento"
event_history_updates: "Última actualización"
event_update_user: "Usuario"
event_update_date: "Fecha"
event:
title: 'Event'
event_agent_needed: "There should be at least one agent on lobby events"
not_available_agents: "Not available agents."
search:
title: "Búsqueda por título"
placeholder_title: "Búsqueda por título"
Expand Down
5 changes: 4 additions & 1 deletion config/locales/admin.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ es:
must_have_position: "Es necesario añadir al menos un cargo"

events: "Eventos"
event: "Evento"
event_history_updates: "Última actualización"
event_update_user: "Usuario"
event_update_date: "Fecha"
event:
title: "Evento"
event_agent_needed: "En los eventos de lobbies hace falta, al menos, un agente."
not_available_agents: "No hay agentes disponibles."
search:
title: "Búsqueda por título"
placeholder_title: "Búsqueda por título"
Expand Down
1 change: 1 addition & 0 deletions config/locales/public.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ en:
name_desc: "Name DESC"
inscription_date_asc: "Inscription date ASC"
inscription_date_desc: "Inscription date DESC"
agent: "Agent's name or surname"
1 change: 1 addition & 0 deletions config/locales/public.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ es:
name_desc: "Alfabético descendente"
inscription_date_asc: "Fecha de inscripción ascendente"
inscription_date_desc: "Fecha de inscripción descendente"
agent: "Nombre o apellido del agente"
show:
participants: "Asisten"
location: "Lugar"
Expand Down
5 changes: 3 additions & 2 deletions spec/factories/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
factory :event do
title "Event title"
description "Event description"
lobby_activity true
published_at Date.yesterday
lobby_activity false
published_at Date.current
scheduled Time.now
location "Ayuntamiento de Madrid"
association :position, factory: :position
association :user, factory: :user
end

end

0 comments on commit 1ebc824

Please sign in to comment.