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
...
@@ -26,6 +26,15 @@ class TagDecorator < Draper::Decorator
h
.
event_tag_path
(
name:
model
.
name
)
h
.
event_tag_path
(
name:
model
.
name
)
end
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で表示する
# tagをtree viewで表示する
def
tree_view_node
def
tree_view_node
html
=
''
html
=
''
...
...
app/models/post.rb
View file @
043d601a
...
@@ -80,12 +80,13 @@ class Post < ActiveRecord::Base
...
@@ -80,12 +80,13 @@ class Post < ActiveRecord::Base
where_list
where_list
end
)
end
)
# 最新のPostを取得
scope
:recent
,
(
lambda
do
|
limit
=
10
|
scope
:recent
,
(
lambda
do
|
limit
=
10
|
order
(
updated_at: :desc
).
limit
(
limit
)
order
(
updated_at: :desc
).
limit
(
limit
)
end
)
end
)
scope
:today
,
->
{
where
(
arel_table
[
:updated_at
].
gt
1
.
day
.
ago
)
}
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
# Class method
...
...
app/models/tag.rb
View file @
043d601a
...
@@ -12,8 +12,6 @@
...
@@ -12,8 +12,6 @@
#
#
class
Tag
<
ActiveRecord
::
Base
class
Tag
<
ActiveRecord
::
Base
has_many
:post_tags
has_many
:posts
,
through: :post_tags
# for tree structure
# for tree structure
has_ancestry
has_ancestry
...
@@ -21,6 +19,15 @@ class Tag < ActiveRecord::Base
...
@@ -21,6 +19,15 @@ class Tag < ActiveRecord::Base
# for versioning
# for versioning
has_paper_trail
has_paper_trail
######################################################################
# Associations
######################################################################
has_many
:post_tags
has_many
:posts
,
through: :post_tags
######################################################################
# Named scope
######################################################################
default_scope
{
order
(
updated_at: :desc
)
}
default_scope
{
order
(
updated_at: :desc
)
}
scope
:posts_exist
,
lambda
{
scope
:posts_exist
,
lambda
{
...
@@ -30,13 +37,50 @@ class Tag < ActiveRecord::Base
...
@@ -30,13 +37,50 @@ class Tag < ActiveRecord::Base
.
having
(
'posts_count > 0'
)
.
having
(
'posts_count > 0'
)
}
}
scope
:recently_created
,
(
lambda
do
|
limit
=
10
|
order
(
created_at: :desc
).
limit
(
limit
)
end
)
######################################################################
# Class method
######################################################################
class
<<
self
class
<<
self
# 最近投稿されたTagを取得
# 最近投稿されたTagを取得
def
recent
(
limit
=
10
)
def
recent
(
limit
=
10
)
Post
.
recent
(
20
).
map
(
&
:tags
).
flatten
.
compact
.
uniq
.
take
(
limit
)
Post
.
recent
(
20
).
map
(
&
:tags
).
flatten
.
compact
.
uniq
.
take
(
limit
)
end
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
end
######################################################################
# Instance method
######################################################################
def
recent_posts
(
limit
=
30
)
def
recent_posts
(
limit
=
30
)
posts
.
recent
(
limit
)
posts
.
recent
(
limit
)
end
end
...
...
app/views/flow/show.html.slim
View file @
043d601a
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
h2
.panel-title
h2
.panel-title
i
.fa.fa-rss
i
.fa.fa-rss
|
Flow
|
Flow
span
.small
-
最近投稿された記事
span
.small
-
最近投稿された記事
ul
.list-group.panel-body
ul
.list-group.panel-body
-
@posts
.
each
do
|
post
|
-
@posts
.
each
do
|
post
|
...
@@ -73,4 +73,4 @@
...
@@ -73,4 +73,4 @@
-
Tag
.
recent
(
10
).
each_with_index
do
|
tag
,
i
|
-
Tag
.
recent
(
10
).
each_with_index
do
|
tag
,
i
|
a
.list-group-item
data-tag-id
=
tag
.id
href
=
search_path
(
q:
"#
#{
tag
.
name
}
"
)
a
.list-group-item
data-tag-id
=
tag
.id
href
=
search_path
(
q:
"#
#{
tag
.
name
}
"
)
=
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 @@
...
@@ -8,16 +8,15 @@
h4
h4
a
href
=
post_path
(
post
)
=
post
.
title
a
href
=
post_path
(
post
)
=
post
.
title
.col-xs-3
.col-xs-3
span
.label.label-danger.label-date
=
post
.
display_specified_date
if
post
.
specified_date
span
.label.label-date.pull-right
=
post
.
display_specified_date
if
post
.
specified_date
small
.pull-right
#
#{
post
.
id
}
.row
.row
.col-xs-8
.col-xs-8
small
.text-success.posted-name
small
.text-success.posted-name
|
#{
post
.
author
.
name
}
posted
|
#{
post
.
author
.
name
}
posted
abbr
.js-time-ago
data-time-ago-at
=
post
.updated_at
abbr
.js-time-ago
data-time-ago-at
=
post
.updated_at
|
.
|
.
-
post
.
tags
.
each
do
|
tag
|
-
post
.
tags
.
map
(
&
:decorate
).
each
do
|
tag
|
a
.label.label-tag
href
=
tag
.
decorate.show_path
=
tag
.
name
a
.label.label-tag
href
=
tag
.
show_path
=
tag
.
structured_
name
|
|
.col-xs-4
.col-xs-4
small
.pull-right
small
.pull-right
...
...
app/views/stock/show.html.slim
View file @
043d601a
/! view:stock/show
/! view:stock/show
.row
.row
.col-md-12
.panel.stock-wrapper
.col-xs-12.col-md-8
role
=
"navigation"
.panel.panem-main
.panel-heading
.panel-heading
h1
h2
.panel-title
|
Stocks
i
.fa.fa-stack-overflow
small
-
保存・蓄積された記事
|
Stock
.panel-body
span
.small
-
保存・蓄積された記事
#sidebar
role
=
"navigation"
#tab-tree
.tab-pane
.panel-body.list-group
-
cache
(
'tag-tree'
,
:expires_in
=>
1
.
hour
)
do
#tab-tree
.list-group
=
Tag
.
posts_exist
.
decorate
.
tree_view
=
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