Skip to content

Commit

Permalink
Merge branch 'release/0.11.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashnikovisme committed Dec 11, 2016
2 parents 667670b + 94b6cfe commit 17090ba
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 13 deletions.
44 changes: 44 additions & 0 deletions app/controllers/web/admin/tags_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Web::Admin::TagsController < Web::Admin::ApplicationController
def index
if params[:search]
tags = Tag.active.search_everywhere params[:search]
else
tags = Tag.send params[:scope]
end
@tags = tags.page(params[:page]).decorate
end

def new
@tag_form = TagForm.new_with_model
end

def edit
@tag_form = TagForm.find_with_model params[:id]
end

def create
@tag_form = TagForm.new_with_model
@tag_form.submit(params[:tag])
if @tag_form.save
redirect_to admin_tags_path
else
render action: :new
end
end

def update
@tag_form = TagForm.find_with_model params[:id]
@tag_form.submit(params[:tag])
if @tag_form.save
redirect_to admin_tags_path
else
render action: :edit
end
end

def destroy
@tag = Tag.find params[:id]
@tag.remove
redirect_to admin_tags_path
end
end
2 changes: 1 addition & 1 deletion app/controllers/web/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def show
@parent = MemberDecorator.decorate member.parent
@registrations = ::Event::RegistrationDecorator.decorate_collection member.registrations.date_order
@news = NewsDecorator.decorate_collection member.tags.active.news.map &:record
@articles = member.tags.active.articles.map &:record
@articles = member.tags.active.articles.map(&:record).uniq
@teams = member.teams.active.visible.decorate
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/decorators/tag_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ def just_text
end
end
end

def self.collections
[:empty, :active, :removed]
end
end
5 changes: 5 additions & 0 deletions app/helpers/web/admin/tags_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Web::Admin::TagsHelper
def admin_tags_record_path(instance)
send("admin_#{instance.model_name.name.underscore.gsub('/', '_')}_path", instance.id)
end
end
1 change: 1 addition & 0 deletions app/scopes/tag_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ module TagScopes
scope :teams, -> { where target_type: 'Team' }
scope :news, -> { where record_type: 'News' }
scope :articles, -> { where record_type: 'Article' }
scope :empty, -> { active.where tag_type: :link, target_id: nil }
end
end
1 change: 1 addition & 0 deletions app/views/layouts/web/admin/_navbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
= admin_menu_item Document, admin_documents_path
= admin_menu_item Comment, admin_comments_path
= admin_menu_item RedirectRule, admin_redirect_rules_path
= admin_menu_item Tag, admin_tags_path
- if current_user.role.tech_admin?
= admin_menu_item LoggedAction, admin_logged_actions_path
= admin_menu_item Image, admin_images_path
Expand Down
2 changes: 1 addition & 1 deletion app/views/web/admin/articles/_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
%td= article.human_state_name
%td{ style: 'width: 200px' }
= render 'web/admin/tags/buttons'
= render 'web/admin/tags/list', record: article
= render 'web/admin/tags/tags_list', record: article
= render 'web/admin/tags/form', record_type: 'Article', record_id: article.id, index: article.id
%td.actions
- if article.unviewed? && current_user.has_permission_to?(:review, :article)
Expand Down
6 changes: 2 additions & 4 deletions app/views/web/admin/banners/_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
- if searching?
%td= banner.human_state_name
%td.actions
= link_to edit_admin_banner_path(banner), class: 'btn btn-warning btn-xs' do
%span.glyphicon.glyphicon-pencil
= link_to admin_banner_path(banner), method: :delete, class: 'btn btn-xs btn-danger' do
%span.glyphicon.glyphicon-remove
= link_to fa_icon(:pencil), edit_admin_banner_path(banner), class: 'btn btn-warning btn-xs'
= link_to fa_icon(:remove), admin_banner_path(banner), method: :delete, class: 'btn btn-xs btn-danger'
= paginate banners, theme: 'twitter-bootstrap-3'
33 changes: 27 additions & 6 deletions app/views/web/admin/tags/_list.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
%ul.list-group
- record.tags.active.each do |tag|
%li.list-group-item
= link_to api_admin_tag_path(tag), method: :delete, remote: true, class: 'badge tag_destroy' do
X
= render 'web/admin/tags/tag_element', tag: tag
= paginate tags, theme: 'twitter-bootstrap-3'
- model_class = Tag
%table.table.table-condensed.table-hover
%thead
%tr
%th= model_class.human_attribute_name(:id)
%th= model_class.human_attribute_name(:tag_type)
%th= model_class.human_attribute_name(:text)
%th= model_class.human_attribute_name(:target_type)
%th= model_class.human_attribute_name(:target_id)
- if searching?
%th= model_class.human_attribute_name(:state)
%th= t 'helpers.links.actions'
%tbody
- tags.each do |tag|
%tr.link{ class: state_color(tag), data: { href: edit_admin_tag_path(tag) } }
%td= tag.id
%td= enumerize_locales_value tag, :tag_type
%td= tag.text
%td= enumerize_locales_value tag, :target_type
%td= (link_to tag.target.decorate.name, admin_tags_record_path(tag.target)) if tag.target.present?
- if searching?
%td= tag.human_state_name
%td.actions
= link_to fa_icon(:pencil), edit_admin_tag_path(tag), class: 'btn btn-warning btn-xs'
= link_to fa_icon(:remove), admin_tag_path(tag), method: :delete, class: 'btn btn-xs btn-danger'
= paginate tags, theme: 'twitter-bootstrap-3'
6 changes: 6 additions & 0 deletions app/views/web/admin/tags/_tags_list.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%ul.list-group
- record.tags.active.each do |tag|
%li.list-group-item
= link_to api_admin_tag_path(tag), method: :delete, remote: true, class: 'badge tag_destroy' do
X
= render 'web/admin/tags/tag_element', tag: tag
1 change: 1 addition & 0 deletions app/views/web/admin/tags/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render partial: 'form', locals: { action: :update }
1 change: 1 addition & 0 deletions app/views/web/admin/tags/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render 'web/admin/default/index', items: @tags
1 change: 1 addition & 0 deletions app/views/web/admin/tags/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render partial: 'form', locals: { action: :create }
9 changes: 9 additions & 0 deletions config/locales/ru/enumerize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ ru:
status:
confirmed: Утверждённый
acting: Исполняющий обязанности
tag:
tag_type:
link: Ссылка
string: Текстовый
target_type:
Member: Член МИЦ
Event: Мероприятие
ActivityLine: Направление деятельности
Team: Команда
1 change: 1 addition & 0 deletions config/locales/ru/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ru:
delivery/campaign: Кампания
delivery/audience: Целевая аудитория
delivery/contact_email: Электронная почта
tag: Тег
attributes:
default: &default
created_at: Дата создания
Expand Down
5 changes: 5 additions & 0 deletions config/locales/ru/state_machines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,8 @@ ru:
states:
active: Активные
removed: Удалённые
tag:
state:
states:
<<: *default
empty: Пустые
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
resources :logged_actions, only: [ :index, :show ]
resources :redirect_rules, except: :show
resources :images, except: :show
resources :tags, except: :show
resources :trash, only: [] do
collection do
get 'index/:type' => 'trash#index', as: :type
Expand Down
64 changes: 64 additions & 0 deletions test/controllers/web/admin/tags_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'test_helper'

class Web::Admin::TagsControllerTest < ActionController::TestCase
setup do
@tag = create :tag
admin = create :admin
sign_in admin
@exceptions_attributes = ['id', 'created_at', 'updated_at']
end

test 'should get new' do
get :new
assert_response :success, @response.body
end

test 'should get index' do
get :index
assert_response :success, @response.body
end

test 'should get index with search' do
get :index, search: @tag.tag_type
assert_response :success, @response.body
end

test 'should get index without instances' do
Tag.destroy_all
get :index
assert_response :success, @response.body
end

test 'should create tag' do
attributes = attributes_for :tag
post :create, tag: attributes
assert_response :redirect, @response.body
assert_redirected_to admin_tags_path
tag = Tag.last
tag.attributes.keys.except(*@exceptions_attributes).each do |key|
assert_equal attributes[key.to_sym], tag.send(key), key
end
end

test 'should get edit' do
get :edit, id: @tag
assert_response :success, @response.body
end

test 'should patch update' do
attributes = attributes_for :tag
patch :update, tag: attributes, id: @tag
assert_response :redirect, @response.body
assert_redirected_to admin_tags_path
@tag.reload
@tag.attributes.keys.except(*@exceptions_attributes).each do |key|
assert_equal attributes[key.to_sym], @tag.send(key), key
end
end

test 'should delete destroy' do
delete :destroy, id: @tag
@tag.reload
assert @tag.removed?
end
end
3 changes: 2 additions & 1 deletion test/factories/tags.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FactoryGirl.define do
factory :tag do
text { generate :string }
tag_type :link
tag_type 'link'
state { Tag.state_machines[:state].states.map(&:name).first.to_s }
record_type ['News', 'Article'].sample
record_id do
create(record_type.underscore).id
Expand Down

0 comments on commit 17090ba

Please sign in to comment.