Skip to content

Commit

Permalink
Merge branch 'release/0.17.9.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashnikovisme committed May 9, 2017
2 parents 4cd223c + 15944b9 commit 7cd9923
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ gem 'reform'
gem 'rails_email_preview', '~> 0.2.29'
#gem 'scopes_rails', '>= 0.0.3'
gem 'scopes_rails', github: 'kalashnikovisme/scopes_rails', branch: 'list_of_scopes'
gem 'trap', '~> 1'
gem 'trap', '~> 1.1'
gem 'more_html_tags'
gem 'hashdiff'
gem 'react_webpack_rails'
Expand All @@ -71,6 +71,7 @@ gem 'youtube_rails', github: 'luizpicolo/youtube_rails'
gem 'unicorn-rails'
gem 'xls_exporter'
gem 'youtube_addy'
gem 'roo', '~> 2.7.0'

group :development, :test do
gem 'byebug'
Expand Down
9 changes: 7 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,13 @@ GEM
responders (2.1.0)
railties (>= 4.2.0, < 5)
rmagick (2.15.3)
roo (2.7.1)
nokogiri (~> 1)
rubyzip (~> 1.1, < 2.0.0)
ruby-ole (1.2.12)
ruby_parser (3.7.2)
sexp_processor (~> 4.1)
rubyzip (1.2.1)
russia_regions (0.0.4)
russian (0.6.0)
i18n (>= 0.5.0)
Expand Down Expand Up @@ -432,7 +436,7 @@ GEM
thread_safe (0.3.5)
tilt (2.0.1)
tins (1.13.2)
trap (1.0.0)
trap (1.1.0)
turbolinks (2.5.3)
coffee-rails
tzinfo (1.2.2)
Expand Down Expand Up @@ -527,6 +531,7 @@ DEPENDENCIES
reform
responders (~> 2.0)
rmagick (= 2.15.3)
roo (~> 2.7.0)
russia_regions (>= 0.0.4)
russian
russian_sex
Expand All @@ -543,7 +548,7 @@ DEPENDENCIES
state_machine!
tconsole-rails4
therubyracer
trap (~> 1)
trap (~> 1.1)
uglifier (>= 1.3.0)
unicorn-rails
validates
Expand Down
15 changes: 14 additions & 1 deletion app/controllers/web/admin/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ def edit

def create
@document_form = DocumentForm.new_with_model
import = params[:document][:import] == 'true'
params[:document].delete :import
@document_form.submit(params[:document])
if @document_form.save
redirect_to admin_documents_path
if import
collection = ::XlsParser.first_sheet_collection @document_form.model.file
collection.each do |item|
contact_email = Delivery::ContactEmail.new first_name: item[0], last_name: item[1], email: item[2]
if contact_email.save
Subscription.create receiver_type: 'Delivery::ContactEmail', receiver_id: contact_email.id, subscription_type: :deliveries
end
end
redirect_to admin_delivery_contact_emails_path
else
redirect_to admin_documents_path
end
else
render action: :new
end
Expand Down
4 changes: 4 additions & 0 deletions app/decorators/delivery/contact_email_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class Delivery::ContactEmailDecorator < ApplicationDecorator
delegate_all

def short_name
"#{first_name} #{last_name}"
end

def self.collections
[ :subscribed_to_deliveries, :active ]
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/delivery/audience.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def contacts
User.presented.subscribed_to_deliveries.with_email
when 'members'
Member.presented.subscribed_to_deliveries.with_email
when 'contacts_emails'
[User, ContactEmail].reduce([]) do |contacts, type|
when 'contact_emails'
[User, Delivery::ContactEmail].reduce([]) do |array, type|
type.presented.subscribed_to_deliveries.with_email.find_each(batch_size: 1000) do |instance|
contacts << OpenStruct.new(email: instance.email, first_name: instance.first_name, last_name: instance.last_name)
array << OpenStruct.new(email: instance.email, first_name: instance.first_name, last_name: instance.last_name)
end
end
when 'team'
Expand Down
1 change: 1 addition & 0 deletions app/scopes/delivery/contact_email_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module Delivery::ContactEmailScopes
included do
scope :subscribed_to_deliveries, -> { joins(:subscriptions).where 'subscriptions.subscription_type = ?', :deliveries }
scope :with_email, -> { where.not email: nil }
scope :presented, -> { active }
end
end
2 changes: 1 addition & 1 deletion app/uploaders/file_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class FileUploader < ApplicationUploader
def extension_white_list
%w(pdf doc docx)
%w(pdf doc docx xls csv xlsx)
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/web/admin/_navbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
= admin_menu_item Feedback, admin_feedbacks_path, :share
= dropdown t('.delivery') do
= admin_menu_item Delivery::Campaign, admin_delivery_campaigns_path, :send
= admin_menu_item Delivery::ContactEmail, admin_delivery_contact_emails_path, 'hand-pointer-o'
= admin_menu_item Delivery::ContactEmail, admin_delivery_contact_emails_path, 'address-book'
- elsif current_user.role.author?
= admin_menu_item Event, admin_events_path, :calendar
= admin_menu_item News, admin_news_index_path, 'list-alt'
Expand Down
11 changes: 5 additions & 6 deletions app/views/web/admin/delivery/contact_emails/_list.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
= paginate delivery_contact_emails, theme: 'twitter-bootstrap-3'
- model_class = Delivery::ContactEmail
%br
= link_to new_admin_document_path(document: { title: "#{t('.import_from_file')}_#{l(DateTime.now, format: "%d.%m.%y")}" }, import: true), class: 'btn btn-success' do
= fa_icon :download
= t('helpers.import')
%br
%table.table.table-condensed.table-hover
%thead
%tr
Expand All @@ -18,12 +23,6 @@
- if searching?
%td= delivery_contact_email.human_state_name
%td.actions
- if delivery_contact_email.subscribed?
= link_to admin_delivery_contact_email_path(delivery_contact_email, contact_email: { state: :unsubscribed }), method: :patch, class: 'btn btn-danger btn-xs' do
= fa_icon 'hand-pointer-o'
- if delivery_contact_email.unsubscribed?
= link_to admin_delivery_contact_email_path(delivery_contact_email, contact_email: { state: :subscribed }), method: :patch, class: 'btn btn-success btn-xs' do
= fa_icon 'hand-pointer-o'
= link_to admin_delivery_contact_email_path(delivery_contact_email), method: :delete, class: 'btn btn-xs btn-danger' do
= fa_icon :remove
= paginate delivery_contact_emails, theme: 'twitter-bootstrap-3'
4 changes: 3 additions & 1 deletion app/views/web/admin/documents/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
= simple_form_for [:admin, @document_form], input_html: { class: 'form-horizontal' } do |f|
= f.button :submit, t('helpers.links.save'), class: 'btn-success'
= link_to t('helpers.links.back'), admin_documents_path, class: 'btn btn-default'
= f.input :title, as: :string
= f.input :title, as: :string, input_html: { value: params[:document][:title] }
= hint @document_form.model.class.to_s, :file, place: :admin
= f.input :file, as: :attachment_preview
- if params[:import] == "true"
= f.hidden_field :import, value: :true
= f.button :submit, t('helpers.links.save'), class: 'btn-success'
= link_to t('helpers.links.back'), admin_documents_path, class: 'btn btn-default'
2 changes: 1 addition & 1 deletion app/views/web/admin/feedbacks/_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
%tr.link{ class: state_color(feedback), data: { href: edit_admin_feedback_path(feedback) } }
%td= feedback.id
%td= link_to feedback.url, feedback.url
%td= feedback.user.short_name if feedback.user
%td= link_to admin_user_path(feedback.user), feedback.user.short_name
%td= feedback.text
%td=l feedback.created_at
%td.actions
Expand Down
2 changes: 1 addition & 1 deletion app/views/web/users/account/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.container.mic-form-container.account-form
%h3.title
= t('.title')
- if @user.corrupted_email?
- if @user.email_corrupted?
%span.label.alert
= t('.you_have_corrupted_email')
.row
Expand Down
7 changes: 7 additions & 0 deletions config/locales/ru/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ ru:
title: Действия с записью
comment_form:
receivers: Оповещение о комментарии получат
shared:
importer:
import: Импортировать
you_should_use_xls: Вы можете загрузить XLS файл со списком рассылки. Формат файл должен содержать в первой колонке Имя человека, второй колонке - Фамилию, в третьей - email.
welcome:
index:
title: Админка
Expand Down Expand Up @@ -99,6 +103,9 @@ ru:
select_team: Выберите команду
select_event_registrations: Выберите мероприятие
add_audience: Добавить
contact_emails:
list:
import_from_file: Импортировать контакты
helps:
tags:
form:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/ru/helpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ ru:
share: Поделиться
share_us: Расскажите о нас
download: Скачать
upload: Загрузить
search: Найти
found: Найденные
remind: Отправить пароль
submit: Отправить
link: Ссылка
import: Импортировать
actions:
update: Редактировать
create: Создать
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,13 @@
resources :activity_lines, only: :index
resources :teams, only: :index
resources :tags, only: [ :create, :destroy, :index ]
resources :documents, only: :create
namespace :event do
resources :registrations, only: :create
end
namespace :delivery do
resources :contact_emails, only: :create
end
end
namespace :members do
resources :members, only: :index
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ReinitStateColumnInDeliveryContactEmails < ActiveRecord::Migration
def change
remove_column :delivery_contact_emails, :state
add_column :delivery_contact_emails, :state, :text, default: :active
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170424202422) do
ActiveRecord::Schema.define(version: 20170501205256) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down
9 changes: 9 additions & 0 deletions lib/parsers/xls_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'roo'

module XlsParser
class << self
def first_sheet_collection(file)
Roo::Spreadsheet.open(file, extension: :xlsx).sheet(0).to_a
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
require 'test_helper'

class Web::Admin::Delivery::ContactEmailsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
setup do
admin = create :admin
sign_in admin
end

test 'should get index' do
get :index
assert_response :success
end
end
Binary file added test/fixtures/1.xlsx
Binary file not shown.

0 comments on commit 7cd9923

Please sign in to comment.