-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ufacode/newsletter
Update Newsletter page
- Loading branch information
Showing
27 changed files
with
279 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,5 @@ bower.json | |
|
||
# Ignore vim files | ||
*.swp | ||
*.swo | ||
*.swo | ||
.vimrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,8 @@ | |
font-size: 18px; | ||
} | ||
} | ||
|
||
label.required:after { | ||
content: " *"; | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
class Flows::NewslettersController < ApplicationController | ||
def index | ||
@newsletters = current_user.newsletters.order(id: :asc) | ||
end | ||
|
||
def show | ||
@newsletter = newsletter | ||
# render "flows/#{params[:id]}" | ||
end | ||
|
||
def new | ||
@newsletter = current_user.newsletters.build | ||
end | ||
|
||
def create | ||
@newsletter = current_user.newsletters.build(newsletter_params) | ||
if @newsletter.save | ||
redirect_to flows_newsletters_path, notice: 'Newsletter has been created' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
@newsletter = newsletter | ||
if @newsletter.update(newsletter_params) | ||
redirect_to flows_newsletter_path(@newsletter), notice: 'Изменения сохранены' | ||
else | ||
render :show | ||
end | ||
end | ||
|
||
def destroy | ||
newsletter_name = newsletter.name | ||
newsletter.destroy | ||
redirect_to flows_newsletters_path, | ||
notice: "Newsletter \"#{newsletter_name}\" has been deleted" | ||
end | ||
|
||
private | ||
|
||
def newsletter | ||
@_newsletter ||= current_user.newsletters.find(params[:id]) | ||
end | ||
|
||
def newsletter_params | ||
params.require(:newsletter).permit(:name, :description, :link) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
class Newsletter < ApplicationRecord | ||
acts_as_paranoid | ||
|
||
belongs_to :owner, class_name: 'User', foreign_key: 'user_id' | ||
|
||
validates :name, :description, presence: true | ||
validates :name, length: { maximum: 255 } | ||
validates :link, format: { with: %r{\Ahttps?:\/\/+}, message: 'Invalid url format' }, | ||
allow_blank: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# frozen_string_literal: true | ||
class User < ApplicationRecord | ||
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable | ||
devise :database_authenticatable, :registerable, :recoverable, :rememberable, | ||
:trackable, :validatable | ||
|
||
has_many :newsletters | ||
|
||
validates :name, presence: true, length: { maximum: 255 } | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.col-lg-3.col-lg-offset-1 | ||
.form-group | ||
label Поиск контактов | ||
input type="search" value="E-mail - автокомплит добавление" class="form-control" | ||
|
||
.form-group | ||
label Подписчики | ||
ul | ||
- %w(Николай Иван Федор Джон Илья Стивен).each do |name| | ||
li | ||
= link_to name, flow_path(id: 'contact') | ||
.pull-right | ||
= link_to 'X', '#delete', class: 'label label-danger' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
= form_for newsletter, url: url, html: { class: 'for-horizontal' } do |f| | ||
.row | ||
= render 'shared/errors', model: newsletter | ||
.col-lg-8 | ||
.form-group | ||
= f.label :name, value: 'Заголовок', class: 'required' | ||
= f.text_field :name, class: 'form-control' | ||
.form-group | ||
= f.label :description, class: 'required', | ||
value: 'Описание (Визуальный редактор MarkitUp например)' | ||
= f.text_area :description, rows: '10', class: 'form-control' | ||
.form-group | ||
= f.label :link, value: 'Публичная ссылка для подписки' | ||
= f.text_field :link, class: 'form-control' | ||
|
||
- if show_contacts | ||
= render 'contacts' | ||
.row | ||
.form-group | ||
button class="btn btn-success" Сохранить |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
tr | ||
td= newsletter.id | ||
td= newsletter.created_at.strftime('%Y-%m-%d') | ||
td= link_to newsletter.name, flows_newsletter_path(newsletter) | ||
td.text-center= rand(100) | ||
td.text-center= rand(100) | ||
td.text-center= rand(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
h1 Мои рассылки | ||
|
||
.form-group | ||
= link_to '+ Создать рассылку', new_flows_newsletter_path, class: 'btn btn-primary' | ||
- unless @newsletters.present? | ||
.alert.alert-warning.text-center Нет созданных рассылок | ||
- else | ||
table.table.table-striped.table-hover | ||
tr | ||
th ID | ||
th Дата | ||
th Название | ||
th Кол-во подписчиков | ||
th Кол-во отписавшихся | ||
th Кол-во E-mail рассылок | ||
= render @newsletters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
h1 Создать рассылку | ||
= render 'form', newsletter: @newsletter, url: flows_newsletters_path, | ||
show_contacts: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
h1.pull-left Рассылка - #{@newsletter.name} | ||
= button_to 'Destroy', flows_newsletter_path(@newsletter), method: :delete, | ||
class: 'btn btn-md btn-danger pull-right', data: { confirm: 'Are you sure ?' } | ||
|
||
= render 'form', newsletter: @newsletter, url: flows_newsletter_path, | ||
show_contacts: true | ||
.row | ||
.panel.panel-default | ||
.panel-heading Письма | ||
.panel-body | ||
table.table-striped.table-hover.table | ||
tr | ||
th ID | ||
th Заголовок | ||
th Дата создания | ||
th Кол-во отправленных писем | ||
th Ошибка доставки | ||
tr | ||
td 101 | ||
td= link_to '%{user_name} послушай Сезоны Вивальди', flow_path(id: :email) | ||
td 20-06-2016 | ||
td.text-success.text-center 100 | ||
td.text-danger.text-center 5 | ||
tr | ||
td 100 | ||
td= link_to '%{user_name} послушай Сезоны Вивальди', flow_path(id: :email) | ||
td 20-06-2016 | ||
td.text-success.text-center 182 | ||
td.text-danger.text-center 2 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.col-md-12 | ||
- if model.errors.any? | ||
#error_explanation | ||
h2 #{pluralize(model.errors.count, 'error')} prohibited this #{model.class.name} from being saved: | ||
ul | ||
- model.errors.full_messages.each do |msg| | ||
li= msg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
Rails.application.routes.draw do | ||
devise_for :users | ||
namespace :flows do | ||
resources :newsletters, except: [:edit] | ||
end | ||
resources :flows, only: [:index, :show] | ||
root to: 'flows#index' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateNewsletters < ActiveRecord::Migration[5.0] | ||
def change | ||
create_table :newsletters do |t| | ||
t.string :name | ||
t.text :description | ||
t.string :link | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddOwnerIdToNewsletters < ActiveRecord::Migration[5.0] | ||
def change | ||
add_reference :newsletters, :user, foreign_key: true, index: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddDeletedAtToNewsletters < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :newsletters, :deleted_at, :datetime | ||
add_index :newsletters, :deleted_at | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddLimitNameToNewsletters < ActiveRecord::Migration[5.0] | ||
def up | ||
change_column :newsletters, :name, :string, limit: 255 | ||
end | ||
|
||
def down | ||
change_column :newsletters, :name, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddLimitNameToUsers < ActiveRecord::Migration[5.0] | ||
def up | ||
change_column :users, :name, :string, limit: 255 | ||
end | ||
|
||
def down | ||
change_column :users, :name, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
# describe Flows::NewslettersController, type: :controller do | ||
# describe 'GET #index' do | ||
# xit 'renders template' do | ||
# end | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
FactoryGirl.define do | ||
factory :newsletter do | ||
name { Faker::Name.title } | ||
description { Faker::Lorem.paragraph(4) } | ||
link { Faker::Internet.url } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
RSpec.describe Newsletter, type: :model do | ||
subject { FactoryGirl.build(:newsletter) } | ||
|
||
it { should belong_to(:owner).class_name('User') } | ||
|
||
context 'with validation' do | ||
it { should validate_presence_of(:name) } | ||
it { should validate_presence_of(:description) } | ||
it { should validate_length_of(:name).is_at_most(255) } | ||
it { should allow_value('http://foo.com').for(:link) } | ||
it { should_not allow_value('http:foo.com').for(:link) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters