Skip to content

Commit

Permalink
This commit contains the commits from the accidentaly merged and reve…
Browse files Browse the repository at this point in the history
  • Loading branch information
amiedes authored and Fernando Blat committed Jun 22, 2018
1 parent e52ff05 commit cbc9170
Show file tree
Hide file tree
Showing 28 changed files with 264 additions and 40 deletions.
12 changes: 9 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
RAILS_ENV: test
PGHOST: localhost
PGUSER: gobierto
# Disable spring so bin/rails works. See: https://github.com/rails/spring/pull/546
DISABLE_SPRING: true
- image: postgres:9.6
environment:
POSTGRES_USER: gobierto
Expand Down Expand Up @@ -69,10 +71,14 @@ jobs:
- run: cp .env.example .env

# Setup the database
- run: bundle exec rake db:setup
- run: bin/rails db:setup

# Run tests
- run: script/ci_test
- run: script/test

# Run tests from custom engines
- run: script/custom_engines_ci_setup
- run: bin/rails test vendor/gobierto_engines/**/test

staging-deploy:
machine:
Expand Down Expand Up @@ -114,4 +120,4 @@ workflows:
- build
filters:
branches:
only: master
only: master
17 changes: 13 additions & 4 deletions app/controllers/gobierto_people/api/v1/departments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ module V1
class DepartmentsController < Api::V1::BaseController

def index
query = DepartmentsQuery.new(
top_departments = DepartmentsQuery.new(
relation: Department.where(site: current_site),
conditions: permitted_conditions,
limit: params[:limit]
)
).results

if params[:include_history] == "true"
records = DepartmentsQuery.new(
relation: Department.where(id: query.results.map(&:id)),
relation: Department.where(id: top_departments.map(&:id)),
conditions: permitted_conditions
).results_with_history

Expand All @@ -34,10 +34,19 @@ def index
}
end
end

# sort result according to department events count
departments_order = Hash[
*top_departments.pluck(:name).each_with_index.collect do |department_name, index|
[department_name, index]
end.flatten
]
result.sort! { |x, y| departments_order[x[:key]] <=> departments_order[y[:key]] }

render json: result
else

render json: query.results, each_serializer: RowchartItemSerializer
render json: top_departments, each_serializer: RowchartItemSerializer
end
end

Expand Down
8 changes: 8 additions & 0 deletions app/controllers/gobierto_people/api/v1/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def index
end
end

# sort result according to person events count
people_order = Hash[
*top_people.pluck(:name).each_with_index.collect do |person_name, index|
[person_name, index]
end.flatten
]
result.sort! { |x, y| people_order[x[:key]] <=> people_order[y[:key]] }

render json: result
else
render json: top_people, each_serializer: RowchartItemSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module GobiertoPeople
module People
class PastPersonEventsController < People::PersonEventsController
Expand All @@ -6,16 +8,25 @@ def index
if params[:date]
@filtering_date = Date.parse(params[:date])
@events = @person.events.by_date(@filtering_date).sorted.page params[:page]
elsif params[:page] == "false"
# permit non-pagination and avoid N+1 queries for custom engines
@events = @person.events.past.sorted_backwards.includes(:interest_group)
else
@events = @person.events.past.sorted.page params[:page]
end

respond_to do |format|
format.js { render 'gobierto_people/people/person_events/index' }
format.html
format.js { render "#{views_path}index" }
format.html { render "#{views_path}index" }
end
end

private

def views_path
"gobierto_people/people/person_events/"
end

end
end
end
4 changes: 3 additions & 1 deletion app/controllers/gobierto_people/people/trips_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
module GobiertoPeople
module People
class TripsController < BaseController

def index
@person_trips = @person.trips
@person_trips = CollectionDecorator.new(@person.trips, decorator: TripDecorator)
end

def show
@trip = @person.trips.find(params[:id])
end

end
end
end
8 changes: 8 additions & 0 deletions app/controllers/gobierto_people/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class PeopleController < GobiertoPeople::ApplicationController

before_action :check_active_submodules, except: :show

LAST_ITEMS_SIZE = 4

def index
@political_groups = get_political_groups

Expand Down Expand Up @@ -43,6 +45,12 @@ def show

@upcoming_events = @person.attending_events.upcoming.sorted.first(3)
@latest_activity = ActivityCollectionDecorator.new(Activity.for_recipient(@person).limit(30).sorted.page(params[:page]))

# custom engine
@last_events = @person.attending_events.with_interest_group.sorted_backwards.limit(LAST_ITEMS_SIZE)
@last_trips = @person.trips.sorted.limit(LAST_ITEMS_SIZE)
@last_invitations = @person.invitations.sorted.limit(LAST_ITEMS_SIZE)
@last_gifts = @person.received_gifts.sorted.limit(LAST_ITEMS_SIZE)
end

private
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/gobierto_people/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module GobiertoPeople
class WelcomeController < GobiertoPeople::ApplicationController
include PoliticalGroupsHelper
Expand Down
8 changes: 8 additions & 0 deletions app/decorators/gobierto_people/person_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def has_statements?
statements.active.any?
end

def meetings_with_interest_groups
events.with_interest_group
end

def interest_groups_count
meetings_with_interest_groups.select(:interest_group_id).distinct.count
end

private

def person_contact_method_for(service_name, attribute_name)
Expand Down
24 changes: 24 additions & 0 deletions app/decorators/gobierto_people/trip_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module GobiertoPeople
class TripDecorator < BaseDecorator

CASE_CHANGE_REGEXP = /(?<=[a-z])(?=[A-Z])/
SPLIT_COMPANY_REGEXP = /\n|\s\s|#{CASE_CHANGE_REGEXP}/

def initialize(trip)
@object = trip
end

def company_members
company ? company.split(SPLIT_COMPANY_REGEXP).map(&:strip).uniq : []
end

def formatted_start_date
I18n.l(start_date, format: "%-d/%-m/%Y")
end

def formatted_end_date
I18n.l(end_date, format: "%-d/%-m/%Y")
end

end
end
15 changes: 15 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ def whom(entity_name)
end
end

def meaningful_date_range?(date_range, options = {})
return false unless date_range.is_a?(Array)

date_range.map! { |d| d.change(hour: 0, min: 0, sec: 0) } if options[:only_date]
date_range.first != date_range.last
end

def simple_pluralize(count, singular, plural)
if count == 1 || count =~ /^1(\.0+)?$/
singular
else
plural
end
end

private

def parse_max_length(params)
Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/gobierto_common/url_buildable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def to_url(options = {})
)
end

def to_anchor
"#{model_name.human.downcase}-#{id}"
end

private

def parameterize
Expand Down
5 changes: 1 addition & 4 deletions app/models/gobierto_people/gift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module GobiertoPeople
class Gift < ApplicationRecord

include GobiertoCommon::Metadatable
include GobiertoCommon::UrlBuildable

belongs_to :person
belongs_to :department
Expand All @@ -22,9 +23,5 @@ def parameterize
{ person_slug: person.slug, id: id }
end

def to_path
url_helpers.gobierto_people_person_gift_path(parameterize)
end

end
end
11 changes: 6 additions & 5 deletions app/models/gobierto_people/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module GobiertoPeople
class Invitation < ApplicationRecord

include GobiertoCommon::Metadatable
include GobiertoCommon::UrlBuildable

belongs_to :person
belongs_to :department
Expand All @@ -16,15 +17,15 @@ class Invitation < ApplicationRecord

validates :person, :organizer, :title, :start_date, :end_date, presence: true

metadata_attributes :organic_unit, :expenses_financed_by_organizer
metadata_attributes(
:organic_unit,
:expenses_financed_by_organizer,
:original_destinations_attribute
)

def parameterize
{ person_slug: person.slug, id: id }
end

def to_path
url_helpers.gobierto_people_person_invitation_path(parameterize)
end

end
end
29 changes: 27 additions & 2 deletions app/models/gobierto_people/trip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ module GobiertoPeople
class Trip < ApplicationRecord

include GobiertoCommon::Metadatable
include GobiertoCommon::UrlBuildable

belongs_to :person
belongs_to :department

scope :sorted, -> { order(start_date: :desc) }

validates :person, :title, :start_date, :end_date, presence: true

metadata_attributes(
Expand All @@ -18,13 +21,35 @@ class Trip < ApplicationRecord
:transport_expenses,
:other_expenses,
:total_expenses,
:trip_party,
:comments
:company,
:comments,
:original_destinations_attribute,
:purpose
)

def destinations
destinations_meta["destinations"] if destinations_meta
end

def duration_dates
[start_date, end_date]
end

def expenses
[
{ kind: meta_attribute_translation(:food_expenses), amount: food_expenses },
{ kind: meta_attribute_translation(:accomodation_expenses), amount: accomodation_expenses },
{ kind: meta_attribute_translation(:transport_expenses), amount: transport_expenses },
{ kind: meta_attribute_translation(:other_expenses), amount: other_expenses },
{ kind: meta_attribute_translation(:total_expenses), amount: total_expenses }
].reject { |expense| expense[:amount].to_i.zero? }
end

private

def meta_attribute_translation(attribute)
I18n.t "activerecord.attributes.gobierto_people/#{model_name.human.downcase}.#{attribute}"
end

end
end
7 changes: 7 additions & 0 deletions config/locales/gobierto_people/models/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ ca:
models:
gobierto_people/person_message: Missatge
activerecord:
attributes:
gobierto_people/trip:
accomodation_expenses: Hotels i allotjament
food_expenses: Dietes i manutenció
other_expenses: Altres despeses
total_expenses: Despeses totals
transport_expenses: Transport
models:
gobierto_people/person: Càrrec
gobierto_people/person_post: Post
Expand Down
7 changes: 7 additions & 0 deletions config/locales/gobierto_people/models/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ en:
models:
gobierto_people/person_message: Message
activerecord:
attributes:
gobierto_people/trip:
accomodation_expenses: Accomodation expenses
food_expenses: Food expenses
other_expenses: Other expenses
total_expenses: Total expenses
transport_expenses: Transport
models:
gobierto_people/person: Officer
gobierto_people/person_post: Post
Expand Down
7 changes: 7 additions & 0 deletions config/locales/gobierto_people/models/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ es:
models:
gobierto_people/person_message: Mensaje
activerecord:
attributes:
gobierto_people/trip:
accomodation_expenses: Hoteles y alojamiento
food_expenses: Dietas y manutención
other_expenses: Otros gastos
total_expenses: Gastos totales
transport_expenses: Transporte
models:
gobierto_people/person: Cargo
gobierto_people/person_post: Post
Expand Down
9 changes: 0 additions & 9 deletions script/ci_test

This file was deleted.

7 changes: 7 additions & 0 deletions script/custom_engines_ci_setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# Setup custom engine 1
git clone [email protected]:PopulateTools/$CUSTOM_ENGINE_NAME_1.git ~/$CUSTOM_ENGINE_NAME_1
cd ~/$CUSTOM_ENGINE_NAME_1
./script/setup.sh
./script/create_webpacker_symlinks.sh
Loading

0 comments on commit cbc9170

Please sign in to comment.