Skip to content

Commit

Permalink
finish all moments
Browse files Browse the repository at this point in the history
update seed
  • Loading branch information
jasl committed Jun 30, 2012
1 parent 9dd63c9 commit 2a536cc
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 52 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Expand Up @@ -24,6 +24,9 @@ gem 'jquery-rails'

gem 'js-routes'

# Pagination
gem 'kaminari'

# Setting
gem 'settingslogic'

Expand Down
9 changes: 7 additions & 2 deletions Gemfile.lock
Expand Up @@ -83,6 +83,10 @@ GEM
js-routes (0.8.3)
rails (>= 3.2)
json (1.7.3)
kaminari (0.13.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
kgio (2.7.4)
less (2.2.1)
commonjs (~> 0.2.6)
Expand Down Expand Up @@ -155,7 +159,7 @@ GEM
json (~> 1.4)
rvm-capistrano (1.2.2)
capistrano (>= 2.0.0)
sass (3.1.19)
sass (3.1.20)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
Expand All @@ -168,7 +172,7 @@ GEM
subexec (0.2.2)
therubyracer (0.10.1)
libv8 (~> 3.3.10)
thor (0.15.3)
thor (0.15.4)
tilt (1.3.3)
treetop (1.4.10)
polyglot
Expand Down Expand Up @@ -196,6 +200,7 @@ DEPENDENCIES
devise
jquery-rails
js-routes
kaminari
mini_magick
mongo-rails-instrumentation
mongoid
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/moments_wall.js.coffee
Expand Up @@ -17,7 +17,7 @@ jQuery ->
, 5000, false
)
init = ->
$('#wall').load(Routes.moments_get_random_path(),
$('#wall').load(Routes.get_random_moments_path(),
->
moments_count = $('#wall').children().length
if moments_count > 0
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -4,6 +4,6 @@ class ApplicationController < ActionController::Base
private

def after_sign_in_path_for(resource_or_scope)
moments_wall_path
wall_moments_path
end
end
2 changes: 1 addition & 1 deletion app/controllers/moments_controller.rb
Expand Up @@ -37,7 +37,7 @@ def get_random
# GET /moments
# GET /moments.json
def index
@moments = current_user.moments.all
@moments = current_user.moments.page params[:page]
respond_to do |format|
format.html { @page_title = t("views.moment.titles.index") } # index.html.erb
Expand Down
6 changes: 3 additions & 3 deletions app/models/moment.rb
Expand Up @@ -89,8 +89,10 @@ def clean_embeds_one_obj
def even_error_messages
flag = self.type

self.errors.delete :type

if flag.nil?
self.errors.add(:moment, I18n.t('errors.moment.must_complete_one'))
self.errors.add(:type, I18n.t('errors.moment.must_complete_one'))
else
self.send(flag).errors.each{ |attr,msg| self.errors.add(attr, msg)}
end
Expand All @@ -99,7 +101,5 @@ def even_error_messages
self.send "build_#{type}" if type != flag and self.new_record?
self.errors.delete type unless self.errors.nil?
end

self.errors.delete :type
end
end
5 changes: 5 additions & 0 deletions app/views/kaminari/_next_page.html.erb
@@ -0,0 +1,5 @@
<% unless current_page.last? %>
<li class="next">
<%= link_to raw('Older &raquo;'), url, :remote => remote %>
</li>
<% end %>
3 changes: 3 additions & 0 deletions app/views/kaminari/_paginator.html.erb
@@ -0,0 +1,3 @@
<%= paginator.render do -%>
<ul class="pager"><%= prev_page_tag -%><%= next_page_tag -%></ul>
<% end -%>
5 changes: 5 additions & 0 deletions app/views/kaminari/_prev_page.html.erb
@@ -0,0 +1,5 @@
<% unless current_page.first? %>
<li class="previous">
<%= link_to raw('&laquo; Newer'), url, :remote => remote %>
</li>
<% end %>
8 changes: 8 additions & 0 deletions app/views/moments/_moment.html.erb
@@ -0,0 +1,8 @@
<div class="item">
<h2><%= link_to moment.full_time.strftime("%Y-%m-%d %H:%m"), moment %></h2>
<%= render "moments/types/index/#{moment.type}", :moment => moment %>
<div class="pull-right">
<%= link_to '删除', moment, data:{confirm: 'Are you sure?'}, method: :delete %>
</div>
<hr/>
</div>
27 changes: 5 additions & 22 deletions app/views/moments/index.html.erb
@@ -1,22 +1,5 @@
<table class="table">
<thead>
<tr>
<th style="width: 60%;">Note</th>
<th>时间</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @moments.each do |moment| %>
<tr>
<td><%= moment.note.body unless moment.note.nil? %></td>
<td><%= moment.full_time %></td>
<td><%= link_to 'Show', moment %></td>
<td><%= link_to 'Edit', edit_moment_path(moment) %></td>
<td><%= link_to 'Destroy', moment, data:{confirm: 'Are you sure?'}, method: :delete %></td>
</tr>
<% end %>
</tbody>
</table>
<%= render @moments %>

<div class="pull-right">
<%= paginate @moments %>
</div>
3 changes: 0 additions & 3 deletions app/views/moments/show.html.erb
Expand Up @@ -3,6 +3,3 @@
<% end %>
<%= render "moments/types/show/#{@moment.type}" %>
<%= link_to 'Edit', edit_moment_path(@moment) %> |
<%= link_to 'Back', moments_path %>
3 changes: 3 additions & 0 deletions app/views/moments/types/index/_note.html.erb
@@ -0,0 +1,3 @@
<div class="note">
<p><%= truncate moment.note.body, :length => 100 %></p>
</div>
4 changes: 2 additions & 2 deletions app/views/shared/_top_nav.html.erb
@@ -1,8 +1,8 @@
<div class="nav-collapse">
<ul class="nav">
<% if user_signed_in? %>
<li <%= 'class=active' if current_page? moments_wall_path %>>
<%= link_to t("views.moment.titles.wall"), moments_wall_path %>
<li <%= 'class=active' if current_page? wall_moments_path %>>
<%= link_to t("views.moment.titles.wall"), wall_moments_path %>
</li>
<li <%= 'class=active' if current_page? moments_path %>>
<%= link_to t("views.moment.titles.index"), moments_path %>
Expand Down
2 changes: 1 addition & 1 deletion config/application.yml
@@ -1,5 +1,5 @@
default: &default
version: 'Rush-6'
version: 'Root'
moments_on_wall: 20

development:
Expand Down
9 changes: 9 additions & 0 deletions config/initializers/kaminari_config.rb
@@ -0,0 +1,9 @@
Kaminari.configure do |config|
config.default_per_page = 15
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
end
7 changes: 5 additions & 2 deletions config/locales/mongoid.en.yml
Expand Up @@ -2,6 +2,7 @@ en:
mongoid:
models:
user: "User"
moment: "Moment"
attributes:
user:
name: "Name"
Expand All @@ -11,9 +12,11 @@ en:
last_logined_at: "Last signed in at"
remember_me: "Remember me"
current_password: "Current Password"
moment:
type: "Content"
note:
body: "Content"
errors:
models:
user: "User"
messages:
inclusion: "Inclusion"
exclusion: "Exclusion"
Expand Down
8 changes: 6 additions & 2 deletions config/locales/mongoid.zh-cn.yml
Expand Up @@ -2,6 +2,8 @@ zh-cn:
mongoid:
models:
user: "用户"
moment: "点滴"
note: "随笔"
attributes:
user:
name: "名字"
Expand All @@ -11,9 +13,11 @@ zh-cn:
last_logined_at: "上次登录时间"
remember_me: "记住登陆状态"
current_password: "旧密码"
note:
body: "内容"
moment:
type: "内容"
errors:
models:
user: "用户"
messages:
inclusion: "不包含于列表中"
exclusion: "是保留关键字"
Expand Down
10 changes: 7 additions & 3 deletions config/routes.rb
Expand Up @@ -4,9 +4,13 @@
get "dashboard/index"
end

match '/wall' => 'moments#wall', :via => :get, :as => 'moments_wall'
match 'moments/get_random' => 'moments#get_random', :via => :get, :as => 'moments_get_random'
resources :moments
#match '/wall' => 'moments#wall', :via => :get, :as => 'moments_wall'
#match 'moments/get_random' => 'moments#get_random', :via => :get, :as => 'moments_get_random'
resources :moments do
get 'page/:page', :action => :index, :on => :collection
get 'wall', :action => :wall, :on => :collection
get 'get_random', :action => :get_random, :on => :collection
end

get "/about", :to => 'home#about', :as => 'about'
root :to => 'home#index'
Expand Down
22 changes: 13 additions & 9 deletions db/seeds.rb
Expand Up @@ -21,16 +21,20 @@
demo = User.where(:email => 'demo@demo.com').first
if demo.moments.empty?
puts "Creating demo moments..."
1.upto(200) do |i|
moment = demo.moments.build :note_attributes => {:body => "日记#{i}"*100}
moment.theme = :classic
created_times = []
1.upto(200) do
# just a demo, avoid any wrong :-)
year, month, day, time = rand(11) + 2000, rand(11) + 1, rand(28) + 1, Time.parse("#{rand(22)+1}:#{rand(58)+1}:#{rand(58)+1}")
# p "#{year}-#{month}-#{day} #{time.hour}:#{time.min}:#{time.sec}"
moment.year = year
moment.month = month
moment.day = day
moment.time = time
created_times<< Time.new(rand(11) + 2000, rand(11) + 1, rand(28) + 1, rand(22)+1, rand(58)+1, rand(58)+1)
end
created_times.sort!

created_times.each_with_index do |time, i|
moment = demo.moments.build :note_attributes => {:body => "日记#{i+1}"*100}
moment.theme = :classic
moment.year = time.year
moment.month = time.month
moment.day = time.day
moment.time = Time.parse time.strftime "%H:%m"
moment.save!
end
end
Expand Down

0 comments on commit 2a536cc

Please sign in to comment.