notee 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83505146122c8bcd81a55fe91e31b7bcb2bb1761
4
- data.tar.gz: 3189f0125d99d366d0e1f8f0216e566e3965ae33
3
+ metadata.gz: 70f31773687978bde09f4cad39620863730a3b75
4
+ data.tar.gz: 5a7a6e5313fba0e4c4fced6ee78c7f8e54a095aa
5
5
  SHA512:
6
- metadata.gz: 4b4028d73060476a190b34323eaefa7f225dafe6546fd3797ac851eb86ff3d3f6330bdb0bd43ac2c7db81f271272cbc9f55e212cb9e6f4c7771a66c72b2fbdf0
7
- data.tar.gz: bb5421bc887b93f3d285a22d000cf8afd95d2db69d36e699229228f198b1ebb531c8615b8b1aaad0de045765ce7697e91ab9ebf494fc1596a2dedf1304cd0c77
6
+ metadata.gz: 88b1b57a8136b57f514d7f6e5c2b2562e5bbf78bc762459af177df22f535a42f333e2ddaf4a01996150dc855dcec5bef3ce915469dc2dc349a1f67d8cc56c8f4
7
+ data.tar.gz: 2506dcd50f49351cec98c5b3901bf2490e59b699b593ce9ec1e44c22eb8050853616358890ca054b11c10d9b456c1a27dc41a83e550029633ed78aea91016a45
@@ -19,6 +19,7 @@ module Notee
19
19
  before_save :protect_default
20
20
 
21
21
  # relations
22
+ has_many :posts
22
23
  has_many :children, class_name: Notee::Category, foreign_key: 'parent_id', dependent: :destroy
23
24
 
24
25
  private
@@ -61,14 +61,28 @@ module Notee
61
61
 
62
62
 
63
63
  def notee_categories
64
- # DATA: {notee.category.name, notee.count}
65
- Notee::Post.find_by_sql("SELECT category_id as category_id, count(*) as count FROM notee_posts WHERE notee_posts.status=1 and notee_posts.is_deleted=false GROUP BY category_id;")
64
+ categories = Notee::Category.where(is_deleted: false)
65
+ published_categories = categories.select { |category| category if category.posts.count > 0 }.map { |category| category }
66
+
67
+ published_categories
66
68
  end
67
69
 
68
70
 
69
71
  def notee_archives
70
- # DATA: {notee.time, notee.count}
71
- Notee::Post.find_by_sql("SELECT DATE_FORMAT(published_at, '%Y-%m') as time, count(*) as count FROM notee_posts WHERE status=1 and is_deleted=false GROUP BY DATE_FORMAT(published_at, '%Y-%m') ORDER BY time DESC;")
72
+ posts = Notee::Post.select(:published_at).where(status: 1, is_deleted: false).order(created_at: :desc)
73
+
74
+ notee_archives = {}
75
+ posts.each do |post|
76
+ month_str = post.published_at.strftime("%Y/%m")
77
+ if notee_archives.has_key?(month_str)
78
+ notee_archives[month_str] = notee_archives[month_str] + 1
79
+ else
80
+ notee_archives.store(month_str, 1)
81
+ end
82
+ end
83
+
84
+ notee_archives
85
+ # Notee::Post.find_by_sql("SELECT DATE_FORMAT(published_at, '%Y-%m') as time, count(*) as count FROM notee_posts WHERE status=1 and is_deleted=false GROUP BY DATE_FORMAT(published_at, '%Y-%m') ORDER BY time DESC;")
72
86
  end
73
87
 
74
88
 
@@ -1,3 +1,3 @@
1
1
  module Notee
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -2,11 +2,10 @@
2
2
  <div class="notee_wrapper">
3
3
  <div class="notee_main">
4
4
  <h2>Archive List</h2>
5
- <% @archives.each do |archive| %>
6
- <% slash_time = archive.time.gsub("-","/") %>
5
+ <% @archives.each do |key, count| %>
7
6
  <div class="notee_list">
8
- <a href="/archives/<%= slash_time %>">
9
- <h3><%= slash_time %> (<%= archive.count %>)</h3>
7
+ <a href="/archives/<%= key %>">
8
+ <h3><%= key %> (<%= count %>)</h3>
10
9
  </a>
11
10
  </div>
12
11
  <% end %>
@@ -4,8 +4,8 @@
4
4
  <h2>Category List</h2>
5
5
  <% @categories.each do |category| %>
6
6
  <div class="notee_list">
7
- <a href="/categories/<%= category.category.name %>">
8
- <h3><%= category.category.name %> (<%= category.count %>)</h3>
7
+ <a href="/categories/<%= category.name %>">
8
+ <h3><%= category.name %> (<%= category.posts.count %>)</h3>
9
9
  </a>
10
10
  </div>
11
11
  <% end %>
@@ -3,19 +3,18 @@
3
3
  <div class="notee_sidebar_content">
4
4
  <ul class="notee_sidebar_ul">
5
5
  <% notee_categories.each do |category| %>
6
- <a href="/categories/<%= category.category.name %>">
7
- <li><%= category.category.name %> (<%= category.count %>)</li>
6
+ <a href="/categories/<%= category.name %>">
7
+ <li><%= category.name %> (<%= category.posts.count %>)</li>
8
8
  </a>
9
9
  <% end %>
10
10
  </ul>
11
11
  </div>
12
12
  <h3>Archive</h3>
13
13
  <div class="notee_sidebar_content">
14
- <% notee_archives.each do |archive| %>
15
- <% slash_time = archive.time.gsub("-","/") %>
14
+ <% notee_archives.each do |key, count| %>
16
15
  <ul class="notee_sidebar_ul">
17
- <a href="/archives/<%= slash_time %>">
18
- <li><%= slash_time %> (<%= archive.count %>)</li>
16
+ <a href="/archives/<%= key %>">
17
+ <li><%= key %> (<%= count %>)</li>
19
18
  </a>
20
19
  </ul>
21
20
  <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - funaota
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails