Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rendezvous
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VeNtura
rendezvous
Commits
28f34221
Commit
28f34221
authored
Mar 02, 2014
by
tady
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag move
parent
035c27af
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
10 deletions
+95
-10
app/controllers/tags_controller.rb
+17
-1
app/models/tag.rb
+6
-0
app/views/tags/show.html.erb
+55
-8
config/routes.rb
+1
-0
spec/models/tag_spec.rb
+16
-1
No files found.
app/controllers/tags_controller.rb
View file @
28f34221
class
TagsController
<
ApplicationController
before_action
:set_tag
,
only:
[
:show
,
:edit
,
:update
,
:destroy
]
before_action
:set_tag
,
only:
[
:show
,
:edit
,
:update
,
:destroy
,
:merge_to
,
:move_to
]
def
index
end
...
...
@@ -48,12 +48,28 @@ class TagsController < ApplicationController
end
end
# このタグを他のタグにマージ
# すべてのPostを移動先のタグに移動し
# このタグを削除する
def
merge_to
@merge_to_tag
=
Tag
.
find_by
(
name:
params
[
:merge_to_name
])
or
raise
ActiveRecord
::
RecordNotFound
@tag
.
move_all_posts_to!
(
@merge_to_tag
)
@tag
.
delete
flash
[
:notice
]
=
"「
#{
@tag
.
name
}
」は「
#{
@merge_to_tag
.
name
}
」にmergeされました"
render
json:
{
status:
'OK'
}
end
# このタグを他のタグの下に移動
def
move_to
@move_to_tag
=
Tag
.
find_by
(
name:
params
[
:move_to_name
])
or
raise
ActiveRecord
::
RecordNotFound
@tag
.
set_parent!
(
@move_to_tag
)
flash
[
:notice
]
=
"「
#{
@tag
.
name
}
」は「
#{
@move_to_tag
.
name
}
」の下に移動しました"
render
json:
{
status:
'OK'
}
end
...
...
app/models/tag.rb
View file @
28f34221
...
...
@@ -17,4 +17,10 @@ class Tag < ActiveRecord::Base
_post
.
tags
<<
other_tag
unless
_post
.
tags
.
include?
(
other_tag
)
end
end
# 親タグを設定する
def
set_parent!
(
other_tag
)
self
.
parent
=
other_tag
self
.
save!
end
end
app/views/tags/show.html.erb
View file @
28f34221
...
...
@@ -15,8 +15,7 @@
</button>
<ul
class=
"dropdown-menu"
role=
"menu"
>
<li><a
href=
"#"
data-toggle=
"modal"
data-target=
"#modal-merge"
>
Merge to...
</a></li>
<li><a
href=
"#"
data-toggle=
"modal"
data-target=
"#myModal"
>
Rename to...
</a></li>
<li><a
href=
"#"
data-toggle=
"modal"
data-target=
"#myModal"
>
Open Tag Tree editor...
</a></li>
<li><a
href=
"#"
data-toggle=
"modal"
data-target=
"#modal-moveUnder"
>
Move this tag under...
</a></li>
</ul>
</div>
</div>
...
...
@@ -52,8 +51,6 @@
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<%=
form_tag
'#'
,
method: :post
,
class:
'form-horizontal'
,
role:
'form'
do
%>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-hidden=
"true"
>
×
</button>
<h3
class=
"modal-title"
id=
"myModalLabel"
>
Merge to other tag
</h4>
...
...
@@ -66,7 +63,7 @@
</div>
</div>
<%
content_for
:footer_js
do
%>
<%
content_for
:footer_js
do
%>
<script
type=
"text/javascript"
>
$
(
function
(){
$
(
'#merge-tag-tree a'
).
on
(
'click'
,
function
(
e
){
...
...
@@ -91,15 +88,65 @@
})
})
</script>
<%
end
%>
<%
end
%>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
Close
</button>
</div>
</div>
<!-- /.modal-content -->
<%
end
%>
<%# form %>
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<!-- Modal -->
<div
class=
"modal fade"
id=
"modal-moveUnder"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-hidden=
"true"
>
×
</button>
<h3
class=
"modal-title"
id=
"myModalLabel"
>
Merge to other tag
</h4>
</div>
<div
class=
"modal-body"
>
<h4>
マージ先のTagを選んでください
</h4>
<div
id=
"move-tag-tree"
>
<%=
Tag
.
all
.
decorate
.
tree_view
%>
</div>
</div>
<%
content_for
:footer_js
do
%>
<script
type=
"text/javascript"
>
$
(
function
(){
$
(
'#move-tag-tree a'
).
on
(
'click'
,
function
(
e
){
console
.
log
(
e
)
e
.
preventDefault
();
var
$this
=
$
(
this
);
if
(
window
.
confirm
(
'「
<%=
j
@tag
.
name
%>
」を「'
+
$this
.
data
(
'name'
)
+
'」の下に移動します'
))
{
$
.
ajax
({
type
:
"POST"
,
url
:
"/tags/
<%=
@tag
.
name
%>
/move_to/"
+
encodeURIComponent
(
$this
.
data
(
'name'
))
}).
done
(
function
(
data
){
location
.
href
=
"/tags/
<%=
j
@tag
.
name
%>
"
;
}).
fail
(
function
(
data
){
alert
(
'error'
);
});
}
else
{
return
false
;
}
})
})
</script>
<%
end
%>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
Close
</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
config/routes.rb
View file @
28f34221
...
...
@@ -10,6 +10,7 @@ Rendezvous::Application.routes.draw do
resources
:posts
post
'tags/:name/merge_to/:merge_to_name'
=>
'tags#merge_to'
,
as:
'merge_to_tag'
post
'tags/:name/move_to/:move_to_name'
=>
'tags#move_to'
,
as:
'move_to_tag'
resources
:tags
,
:param
=>
:name
devise_for
:users
,
controllers:
{
omniauth_callbacks:
'users/omniauth_callbacks'
}
...
...
spec/models/tag_spec.rb
View file @
28f34221
require
'spec_helper'
describe
Tag
do
describe
'#move_
posts_to
'
do
describe
'#move_
all_posts_to!
'
do
before
:each
do
@tag_ruby
=
Tag
.
create
(
name:
'ruby'
)
@tag_java
=
Tag
.
create
(
name:
'java'
)
...
...
@@ -18,4 +18,19 @@ describe Tag do
expect
(
Tag
.
find_by
(
name:
'java'
).
posts
).
to
have
(
0
).
items
end
end
describe
'#set_parent!'
do
before
:each
do
@tag_ruby
=
Tag
.
create
(
name:
'ruby'
)
@tag_lang
=
Tag
.
create
(
name:
'lang'
)
end
it
'successfully moved'
do
expect
(
@tag_ruby
.
parent
).
not_to
eq
(
@tag_lang
)
expect
(
@tag_lang
.
children
).
not_to
include
(
@tag_ruby
)
@tag_ruby
.
set_parent!
(
@tag_lang
)
expect
(
@tag_ruby
.
parent
).
to
eq
(
@tag_lang
)
expect
(
@tag_lang
.
children
).
to
include
(
@tag_ruby
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment