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
043d601a
Commit
043d601a
authored
Nov 09, 2014
by
tady
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix stock view
parent
3684b76d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
20 deletions
+98
-20
app/decorators/tag_decorator.rb
+9
-0
app/models/post.rb
+2
-1
app/models/tag.rb
+46
-2
app/views/flow/show.html.slim
+2
-2
app/views/posts/_large_item.html.slim
+3
-4
app/views/stock/show.html.slim
+36
-11
No files found.
app/decorators/tag_decorator.rb
View file @
043d601a
...
...
@@ -26,6 +26,15 @@ class TagDecorator < Draper::Decorator
h
.
event_tag_path
(
name:
model
.
name
)
end
# TODO: module
def
created_date
model
.
created_at
.
strftime
(
'%Y-%m-%d'
)
end
def
structured_name
[
model
.
ancestors
.
map
(
&
:name
),
model
.
name
].
flatten
.
join
(
'/'
)
end
# tagをtree viewで表示する
def
tree_view_node
html
=
''
...
...
app/models/post.rb
View file @
043d601a
...
...
@@ -80,12 +80,13 @@ class Post < ActiveRecord::Base
where_list
end
)
# 最新のPostを取得
scope
:recent
,
(
lambda
do
|
limit
=
10
|
order
(
updated_at: :desc
).
limit
(
limit
)
end
)
scope
:today
,
->
{
where
(
arel_table
[
:updated_at
].
gt
1
.
day
.
ago
)
}
scope
:this_month
,
->
{
where
(
arel_table
[
:updated_at
].
gt
1
.
month
.
ago
)
}
scope
:last_month
,
->
{
where
(
arel_table
[
:updated_at
].
gt
2
.
month
.
ago
).
where
(
arel_table
[
:updated_at
].
lt
1
.
month
.
ago
)
}
######################################################################
# Class method
...
...
app/models/tag.rb
View file @
043d601a
...
...
@@ -12,8 +12,6 @@
#
class
Tag
<
ActiveRecord
::
Base
has_many
:post_tags
has_many
:posts
,
through: :post_tags
# for tree structure
has_ancestry
...
...
@@ -21,6 +19,15 @@ class Tag < ActiveRecord::Base
# for versioning
has_paper_trail
######################################################################
# Associations
######################################################################
has_many
:post_tags
has_many
:posts
,
through: :post_tags
######################################################################
# Named scope
######################################################################
default_scope
{
order
(
updated_at: :desc
)
}
scope
:posts_exist
,
lambda
{
...
...
@@ -30,13 +37,50 @@ class Tag < ActiveRecord::Base
.
having
(
'posts_count > 0'
)
}
scope
:recently_created
,
(
lambda
do
|
limit
=
10
|
order
(
created_at: :desc
).
limit
(
limit
)
end
)
######################################################################
# Class method
######################################################################
class
<<
self
# 最近投稿されたTagを取得
def
recent
(
limit
=
10
)
Post
.
recent
(
20
).
map
(
&
:tags
).
flatten
.
compact
.
uniq
.
take
(
limit
)
end
# TODO: cache
def
monthly_popular
(
limit
=
10
)
tags_this_month
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
0
}
# { <tag.id> => <count> }
tags_last_month
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
0
}
# { <tag.id> => <count> }
Post
.
this_month
.
each
do
|
post
|
post
.
tags
.
each
{
|
tag
|
tags_this_month
[
tag
.
id
]
+=
1
}
end
Post
.
last_month
.
each
do
|
post
|
post
.
tags
.
each
{
|
tag
|
tags_last_month
[
tag
.
id
]
+=
1
}
end
tags_this_month_with_score
=
{}
tags_this_month
.
each
do
|
tag_id
,
this_month_count
|
next
if
this_month_count
<=
3
tags_this_month_with_score
[
tag_id
]
=
this_month_count
.
to_f
/
(
tags_last_month
[
tag_id
]
+
1
)
end
sorted
=
tags_this_month_with_score
.
sort_by
{
|
k
,
v
|
-
v
}.
take
(
limit
).
to_h
Tag
.
find
(
sorted
.
keys
).
to_a
.
zip
(
sorted
.
values
).
to_h
end
end
######################################################################
# Instance method
######################################################################
def
recent_posts
(
limit
=
30
)
posts
.
recent
(
limit
)
end
...
...
app/views/flow/show.html.slim
View file @
043d601a
...
...
@@ -31,7 +31,7 @@
h2
.panel-title
i
.fa.fa-rss
|
Flow
span
.small
-
最近投稿された記事
span
.small
-
最近投稿された記事
ul
.list-group.panel-body
-
@posts
.
each
do
|
post
|
...
...
@@ -73,4 +73,4 @@
-
Tag
.
recent
(
10
).
each_with_index
do
|
tag
,
i
|
a
.list-group-item
data-tag-id
=
tag
.id
href
=
search_path
(
q:
"#
#{
tag
.
name
}
"
)
=
tag
.
name
span
.badge
.badge-transparent
=
tag
.
posts_count
span
.badge
=
tag
.
posts_count
app/views/posts/_large_item.html.slim
View file @
043d601a
...
...
@@ -8,16 +8,15 @@
h4
a
href
=
post_path
(
post
)
=
post
.
title
.col-xs-3
span
.label.label-danger.label-date
=
post
.
display_specified_date
if
post
.
specified_date
small
.pull-right
#
#{
post
.
id
}
span
.label.label-date.pull-right
=
post
.
display_specified_date
if
post
.
specified_date
.row
.col-xs-8
small
.text-success.posted-name
|
#{
post
.
author
.
name
}
posted
abbr
.js-time-ago
data-time-ago-at
=
post
.updated_at
|
.
-
post
.
tags
.
each
do
|
tag
|
a
.label.label-tag
href
=
tag
.
decorate.show_path
=
tag
.
name
-
post
.
tags
.
map
(
&
:decorate
).
each
do
|
tag
|
a
.label.label-tag
href
=
tag
.
show_path
=
tag
.
structured_
name
|
.col-xs-4
small
.pull-right
...
...
app/views/stock/show.html.slim
View file @
043d601a
/! view:stock/show
.row
.col-md-12
.panel.stock-wrapper
.col-xs-12.col-md-8
role
=
"navigation"
.panel.panem-main
.panel-heading
h1
|
Stocks
small
-
保存・蓄積された記事
.panel-body
#sidebar
role
=
"navigation"
#tab-tree
.tab-pane
-
cache
(
'tag-tree'
,
:expires_in
=>
1
.
hour
)
do
.list-group
=
Tag
.
posts_exist
.
decorate
.
tree_view
h2
.panel-title
i
.fa.fa-stack-overflow
|
Stock
span
.small
-
保存・蓄積された記事
.panel-body.list-group
#tab-tree
=
Tag
.
posts_exist
.
decorate
.
tree_view
.col-xs-12.col-md-4
.panel
.panel-heading
h3
.panel-title
i
.fa.fa-star
|
今月のホットタグ
.panel-body.list-group
-
Tag
.
monthly_popular
(
10
).
each
do
|
tag
,
score
|
a
.list-group-item
href
=
search_path
(
q:
"#
#{
tag
.
name
}
"
)
=
tag
.
name
span
.badge
#{
score
.
round
(
2
)
}
pt
.
.panel
.panel-heading
h3
.panel-title
i
.fa.fa-tags
|
最近作成されたタグ
.panel-body.list-group
-
Tag
.
recently_created
(
10
).
each
do
|
tag
|
a
.list-group-item
href
=
search_path
(
q:
"#
#{
tag
.
name
}
"
)
=
tag
.
name
span
.label.pull-right
=
tag
.
decorate
.
created_date
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