-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
177 additions
and
13 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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
|
@@ -20,4 +20,8 @@ def just_text | |
end | ||
end | ||
end | ||
|
||
def self.collections | ||
[:empty, :active, :removed] | ||
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 @@ | ||
module Web::Admin::TagsHelper | ||
def admin_tags_record_path(instance) | ||
send("admin_#{instance.model_name.name.underscore.gsub('/', '_')}_path", instance.id) | ||
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
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 |
---|---|---|
@@ -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' |
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 @@ | ||
%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 |
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 @@ | ||
= render partial: 'form', locals: { action: :update } |
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 @@ | ||
= render 'web/admin/default/index', items: @tags |
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 @@ | ||
= render partial: 'form', locals: { action: :create } |
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 |
---|---|---|
|
@@ -167,3 +167,8 @@ ru: | |
states: | ||
active: Активные | ||
removed: Удалённые | ||
tag: | ||
state: | ||
states: | ||
<<: *default | ||
empty: Пустые |
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,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 |
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