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
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
131 additions
and
46 deletions
+131
-46
app/controllers/tags_controller.rb
+17
-1
app/models/tag.rb
+6
-0
app/views/tags/show.html.erb
+91
-44
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
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
def
index
end
end
...
@@ -48,12 +48,28 @@ class TagsController < ApplicationController
...
@@ -48,12 +48,28 @@ class TagsController < ApplicationController
end
end
end
end
# このタグを他のタグにマージ
# すべてのPostを移動先のタグに移動し
# このタグを削除する
def
merge_to
def
merge_to
@merge_to_tag
=
Tag
.
find_by
(
name:
params
[
:merge_to_name
])
or
raise
ActiveRecord
::
RecordNotFound
@merge_to_tag
=
Tag
.
find_by
(
name:
params
[
:merge_to_name
])
or
raise
ActiveRecord
::
RecordNotFound
@tag
.
move_all_posts_to!
(
@merge_to_tag
)
@tag
.
move_all_posts_to!
(
@merge_to_tag
)
@tag
.
delete
@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'
}
render
json:
{
status:
'OK'
}
end
end
...
...
app/models/tag.rb
View file @
28f34221
...
@@ -17,4 +17,10 @@ class Tag < ActiveRecord::Base
...
@@ -17,4 +17,10 @@ class Tag < ActiveRecord::Base
_post
.
tags
<<
other_tag
unless
_post
.
tags
.
include?
(
other_tag
)
_post
.
tags
<<
other_tag
unless
_post
.
tags
.
include?
(
other_tag
)
end
end
end
end
# 親タグを設定する
def
set_parent!
(
other_tag
)
self
.
parent
=
other_tag
self
.
save!
end
end
end
app/views/tags/show.html.erb
View file @
28f34221
...
@@ -15,8 +15,7 @@
...
@@ -15,8 +15,7 @@
</button>
</button>
<ul
class=
"dropdown-menu"
role=
"menu"
>
<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=
"#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=
"#modal-moveUnder"
>
Move this tag under...
</a></li>
<li><a
href=
"#"
data-toggle=
"modal"
data-target=
"#myModal"
>
Open Tag Tree editor...
</a></li>
</ul>
</ul>
</div>
</div>
</div>
</div>
...
@@ -52,54 +51,102 @@
...
@@ -52,54 +51,102 @@
<div
class=
"modal-dialog"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<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>
</div>
<div
class=
"modal-header"
>
<div
class=
"modal-body"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-hidden=
"true"
>
×
</button>
<h4>
マージ先のTagを選んでください
</h4>
<h3
class=
"modal-title"
id=
"myModalLabel"
>
Merge to other tag
</h4>
<div
id=
"merge-tag-tree"
>
<%=
Tag
.
all
.
decorate
.
tree_view
%>
</div>
</div>
</div>
<div
class=
"modal-body"
>
<%
content_for
:footer_js
do
%>
<h4>
マージ先のTagを選んでください
</h4>
<script
type=
"text/javascript"
>
<div
id=
"merge-tag-tree"
>
$
(
function
(){
<%=
Tag
.
all
.
decorate
.
tree_view
%>
$
(
'#merge-tag-tree a'
).
on
(
'click'
,
function
(
e
){
</div>
</div>
console
.
log
(
e
)
e
.
preventDefault
();
var
$this
=
$
(
this
);
if
(
window
.
confirm
(
'「
<%=
@tag
.
name
%>
」を「'
+
$this
.
data
(
'name'
)
+
'」にマージます'
))
{
$
.
ajax
({
type
:
"POST"
,
url
:
"/tags/
<%=
@tag
.
name
%>
/merge_to/"
+
$this
.
data
(
'name'
)
}).
done
(
function
(
data
){
location
.
href
=
"/tags/"
+
$this
.
data
(
'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 -->
<%
content_for
:footer_js
do
%>
</div>
<!-- /.modal-dialog -->
<script
type=
"text/javascript"
>
</div>
<!-- /.modal -->
$
(
function
(){
$
(
'#merge-tag-tree a'
).
on
(
'click'
,
function
(
e
){
<!-- Modal -->
console
.
log
(
e
)
<div
class=
"modal fade"
id=
"modal-moveUnder"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog"
>
e
.
preventDefault
();
<div
class=
"modal-content"
>
var
$this
=
$
(
this
);
<div
class=
"modal-header"
>
if
(
window
.
confirm
(
'「
<%=
@tag
.
name
%>
」を「'
+
$this
.
data
(
'name'
)
+
'」にマージます'
))
{
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-hidden=
"true"
>
×
</button>
$
.
ajax
({
<h3
class=
"modal-title"
id=
"myModalLabel"
>
Merge to other tag
</h4>
type
:
"POST"
,
</div>
url
:
"/tags/
<%=
@tag
.
name
%>
/merge_to/"
+
$this
.
data
(
'name'
)
}).
done
(
function
(
data
){
<div
class=
"modal-body"
>
location
.
href
=
"/tags/"
+
$this
.
data
(
'name'
);
<h4>
マージ先のTagを選んでください
</h4>
}).
fail
(
function
(
data
){
<div
id=
"move-tag-tree"
>
alert
(
'error'
);
<%=
Tag
.
all
.
decorate
.
tree_view
%>
});
}
else
{
return
false
;
}
})
})
</script>
<%
end
%>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
Close
</button>
</div>
</div>
</div>
<!-- /.modal-content -->
</div>
<%
end
%>
<%# form %>
<%
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-dialog -->
</div>
<!-- /.modal -->
</div>
<!-- /.modal -->
config/routes.rb
View file @
28f34221
...
@@ -10,6 +10,7 @@ Rendezvous::Application.routes.draw do
...
@@ -10,6 +10,7 @@ Rendezvous::Application.routes.draw do
resources
:posts
resources
:posts
post
'tags/:name/merge_to/:merge_to_name'
=>
'tags#merge_to'
,
as:
'merge_to_tag'
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
resources
:tags
,
:param
=>
:name
devise_for
:users
,
controllers:
{
omniauth_callbacks:
'users/omniauth_callbacks'
}
devise_for
:users
,
controllers:
{
omniauth_callbacks:
'users/omniauth_callbacks'
}
...
...
spec/models/tag_spec.rb
View file @
28f34221
require
'spec_helper'
require
'spec_helper'
describe
Tag
do
describe
Tag
do
describe
'#move_
posts_to
'
do
describe
'#move_
all_posts_to!
'
do
before
:each
do
before
:each
do
@tag_ruby
=
Tag
.
create
(
name:
'ruby'
)
@tag_ruby
=
Tag
.
create
(
name:
'ruby'
)
@tag_java
=
Tag
.
create
(
name:
'java'
)
@tag_java
=
Tag
.
create
(
name:
'java'
)
...
@@ -18,4 +18,19 @@ describe Tag do
...
@@ -18,4 +18,19 @@ describe Tag do
expect
(
Tag
.
find_by
(
name:
'java'
).
posts
).
to
have
(
0
).
items
expect
(
Tag
.
find_by
(
name:
'java'
).
posts
).
to
have
(
0
).
items
end
end
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
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