Skip to content

Commit

Permalink
Merge pull request #625 from coopdevs/develop
Browse files Browse the repository at this point in the history
v3.16.0
  • Loading branch information
sseerrggii authored Apr 25, 2021
2 parents 369c9df + 6da895d commit 0827ec8
Show file tree
Hide file tree
Showing 25 changed files with 241 additions and 69 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ruby File.read('.ruby-version').strip
gem 'rails', '~> 6.1.1'
gem 'rails-i18n', '~> 6.0.0'
gem 'rdiscount', '~> 2.2.0.1'
gem 'rubyzip', '~> 2.3.0'
gem 'activeadmin', '~> 2.9.0'
gem 'bootsnap', '~> 1.7.3', require: false
gem 'has_scope', '~> 0.7.2'
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ DEPENDENCIES
rspec-rails (~> 4.0.0)
rubocop (~> 1.6)
rubocop-rails (~> 2.9)
rubyzip (~> 2.3.0)
sassc-rails (~> 2.1.2)
select2-rails (~> 4.0.13)
selenium-webdriver (~> 3.142)
Expand Down
7 changes: 5 additions & 2 deletions app/admin/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
index do
id_column
column :class
column :is_group
column :title
column :created_at do |post|
l post.created_at.to_date, format: :long
Expand All @@ -19,10 +20,11 @@
f.input :type, as: :radio, collection: %w[Offer Inquiry]
f.input :title
f.input :organization
f.input :user, hint: "* should be member of the selected organization"
f.input :user, hint: "Should be member of the selected organization"
f.input :category
f.input :description
f.input :tag_list
f.input :tag_list, hint: "Accepts comma separated values"
f.input :is_group
f.input :active
end
f.actions
Expand All @@ -36,6 +38,7 @@
filter :organization
filter :user
filter :category
filter :is_group
filter :active
filter :created_at
end
2 changes: 2 additions & 0 deletions app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
filter :organizations
filter :email
filter :username
filter :phone

form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs do
f.input :username
f.input :email
f.input :phone
f.input :gender, as: :select, collection: User::GENDERS
f.input :identity_document
end
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ html {
}

.row.exports {
padding: 10px;
padding: 20px 0;
}

.table-responsive {
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ class OrganizationsController < ApplicationController
before_action :load_resource, only: [:show, :edit, :update, :set_current]

def index
@organizations = Organization.all.page(params[:page]).per(25)
organizations = Organization.all
organizations = organizations.search_by_query(params[:q]) if params[:q].present?
@organizations = organizations.page(params[:page]).per(25)
end

def show
Expand Down
80 changes: 65 additions & 15 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,98 @@
require 'zip'

class ReportsController < ApplicationController
before_action :authenticate_user!

layout "report"

def user_list
@members = current_organization.members.active.
includes(:user).
order("members.member_uid")
@members = report_collection("Member")

report_responder('Member', current_organization, @members)
end

def post_list
@post_type = (params[:type] || "offer").capitalize.constantize
@posts = current_organization.posts.
of_active_members.
active.
merge(@post_type.all).
includes(:user, :category).
group_by(&:category).
to_a.
sort_by { |category, _| category.try(:name).to_s }
@posts = report_collection(@post_type)

report_responder('Post', current_organization, @posts, @post_type)
end

def transfer_list
@transfers = current_organization.all_transfers_with_accounts
@transfers = report_collection('Transfer')

report_responder('Transfer', current_organization, @transfers)
end

def download_all
filename = "#{current_organization.name.parameterize}_#{Date.today}.zip"
temp_file = Tempfile.new(filename)

begin
Zip::File.open(temp_file.path, Zip::File::CREATE) do |zipfile|
%w(Member Transfer Inquiry Offer).each do |report_class|
add_csv_to_zip(report_class, zipfile)
end
end
zip_data = File.read(temp_file.path)
send_data(zip_data, type: 'application/zip', disposition: 'attachment', filename: filename)
rescue Errno::ENOENT
redirect_to download_all_report_path
ensure
temp_file.close
temp_file.unlink
end
end

private

def report_responder(report_class, *args)
respond_to do |format|
format.html
format.csv { download_report("Report::Csv::#{report_class}", *args) }
format.pdf { download_report("Report::Pdf::#{report_class}", *args) }
format.csv { download_report("Csv::#{report_class}", *args) }
format.pdf { download_report("Pdf::#{report_class}", *args) }
end
end

def download_report(report_class, *args)
report = report_class.constantize.new(*args)
report = get_report(report_class, *args)
send_data report.run, filename: report.name, type: report.mime_type
end

def get_report(report_class, *args)
"Report::#{report_class}".constantize.new(*args)
end

def report_collection(report_class)
case report_class.to_s
when 'Member'
current_organization.members.active.includes(:user).order('members.member_uid')
when 'Transfer'
current_organization.all_transfers_with_accounts
when 'Inquiry', 'Offer'
report_class = report_class.constantize if report_class.is_a?(String)

current_organization.posts.of_active_members.active.
merge(report_class.all).
includes(:user, :category).
group_by(&:category).
sort_by { |category, _| category.try(:name).to_s }
end
end

def add_csv_to_zip(report_class, zip)
collection = report_collection(report_class)

report = if report_class.in? %w(Inquiry Offer)
get_report("Csv::Post", current_organization, collection, report_class.constantize)
else
get_report("Csv::#{report_class}", current_organization, collection)
end

file = Tempfile.new
file.write(report.run)
file.rewind

zip.add("#{report_class.pluralize}_#{Date.today}.csv", file.path)
end
end
6 changes: 4 additions & 2 deletions app/models/concerns/taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def tag_list
tags && tags.join(", ")
end

def tag_list=(tag_list)
self.tags = tag_list.reject(&:empty?)
def tag_list=(new_tags)
new_tags = new_tags.split(",").map(&:strip) if new_tags.is_a?(String)

self.tags = new_tags.reject(&:empty?)
end

module ClassMethods
Expand Down
11 changes: 11 additions & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
class Organization < ApplicationRecord
include PgSearch::Model

pg_search_scope :search_by_query,
against: %i[city neighborhood address name],
ignoring: :accents,
using: {
tsearch: {
prefix: true
}
}

has_many :members, dependent: :destroy
has_many :users, -> { order "members.created_at DESC" }, through: :members
has_many :all_accounts, class_name: "Account", inverse_of: :organization, dependent: :destroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@
<%= Transfer.model_name.human(count: :many) %>
<% end %>
</li>
<li class="divider" role="presentation"></li>
<li>
<%= link_to download_all_report_path do %>
<%= glyph :download %>
<%= t 'reports.download_all' %>
<% end %>
</li>
</ul>
</li>
1 change: 1 addition & 0 deletions app/views/application/menus/_visitor_menu.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<li><%= link_to t("layouts.application.login"), new_user_session_path %></li>
<li><%= link_to t("layouts.application.about"), page_path("about") %></li>
<li><%= link_to t("layouts.application.bdtnear"), organizations_path %></li>
15 changes: 15 additions & 0 deletions app/views/organizations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<%= Organization.model_name.human(count: :many) %>
</h1>

<div class="row">
<div class="col-md-6">
<form action="<%= organizations_path %>" class="navbar-form navbar-left" method="get">
<div class="form-group">
<input class="form-control"
name="q"
placeholder="<%= t "global.search_location" %>"
type="text"
value="<%= params[:q] %>">
</div>
<button class="btn btn-default" type="submit"><%= t "global.search" %></button>
</form>
</div>
</div>

<div class="panel panel-default table-responsive">
<div class="panel-body">
<table class="table table-hover table-condensed panel">
Expand Down
4 changes: 4 additions & 0 deletions app/views/organizations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,8 @@

<% if current_user %>
<%= render "shared/movements" %>
<% else %>
<div class='alert alert-info'>
<%= t ".join_timebank" %>
</div>
<% end %>
8 changes: 4 additions & 4 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ ca:
required_field: "* Camp obligatori"
save: Desar
search: Cercar
search_location: Cerca per localitat
show: Mostrar
source_destination: Origen/Destí
statistics: Estadístiques
Expand All @@ -309,6 +310,7 @@ ca:
layouts:
application:
about: Sobre TimeOverflow
bdtnear: Cerca Banc de Temps
edit_org: Modificar %{organization}
edit_profile: Modificar perfil
help: Ajuda
Expand Down Expand Up @@ -377,6 +379,7 @@ ca:
new: Nou banc
show:
contact_information: Informació de contacte
join_timebank: No dubtis en contactar amb el Banc de Temps per unir-te o per preguntar qualsevol dubte.
pages:
about:
app-mobile: Aplicació Mòbil
Expand Down Expand Up @@ -412,11 +415,8 @@ ca:
show:
info: Aquesta %{type} pertany a %{organization}.
reports:
cat_with_users:
title: Serveis ofertats
download: Descarregar
user_list:
title: Llistat d'usuaris
download_all: Descarregar tot
shared:
movements:
delete_reason: Esteu segur d'esborrar aquest comentari?
Expand Down
8 changes: 4 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ en:
required_field: "* Required field"
save: Save
search: Search
search_location: Search by location
show: Show
source_destination: From/to
statistics: Statistics
Expand All @@ -309,6 +310,7 @@ en:
layouts:
application:
about: About TimeOverflow
bdtnear: Search Timebank
edit_org: Update %{organization}
edit_profile: Update my profile
help: Help
Expand Down Expand Up @@ -377,6 +379,7 @@ en:
new: New bank
show:
contact_information: Contact information
join_timebank: Don't hesitate to contact the time bank to join it or ask any questions.
pages:
about:
app-mobile: Mobile App
Expand Down Expand Up @@ -412,11 +415,8 @@ en:
show:
info: This %{type} belongs to %{organization}.
reports:
cat_with_users:
title: Offered Services
download: Download
user_list:
title: User List
download_all: Download all
shared:
movements:
delete_reason: Are you sure to delete this comment?
Expand Down
8 changes: 4 additions & 4 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ es:
required_field: "* Campo obligatorio"
save: Guardar
search: Buscar
search_location: Buscar por localidad
show: Mostrar
source_destination: Origen/Destino
statistics: Estadísticas
Expand All @@ -309,6 +310,7 @@ es:
layouts:
application:
about: Sobre TimeOverflow
bdtnear: Busca Banco de Tiempo
edit_org: Modificar %{organization}
edit_profile: Modificar mi perfil
help: Ayuda
Expand Down Expand Up @@ -377,6 +379,7 @@ es:
new: Nuevo banco
show:
contact_information: Información de contacto
join_timebank: No dudes en contactar con el Banco de Tiempo para unirte o para resolver dudas.
pages:
about:
app-mobile: App Móvil
Expand Down Expand Up @@ -412,11 +415,8 @@ es:
show:
info: Esta %{type} pertenece a %{organization}.
reports:
cat_with_users:
title: Servicios ofrecidos
download: Descargar
user_list:
title: Listado usuarios
download_all: Descargar todo
shared:
movements:
delete_reason: "¿Está seguro de borrar este comentario?"
Expand Down
Loading

0 comments on commit 0827ec8

Please sign in to comment.