Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup, added basic caching

  • Loading branch information...
commit 1624e7d28663b6a9eeba936a1419e0729ed7c921 1 parent 173b90a
@kattrali authored
View
39 app.rb
@@ -12,9 +12,20 @@ def get_stories filter=nil
# are ignored by Project.stories.all()
params = {:search => filter, :owner => user[:name]}
params[:search] = filter if filter
- stories = projects.map {|project|
+ stories = projects.map do |project|
project.stories.all(params)
- }.flatten.sort_by {|s| s.name}.sort_by {|s|s.current_state}
+ end.flatten.sort_by do |s|
+ s.name
+ end.sort_by do |s|
+ s.current_state
+ end.map do |s|
+ {
+ :name => s.name,
+ :url => s.url,
+ :type => s.story_type,
+ :state => s.current_state
+ }
+ end
end
def authenticate token, name
@@ -42,8 +53,8 @@ def logged_in?
not session[:token].nil?
end
-def render_stories title, stories
- @title, @stories = title, stories
+def render_stories title, stories, age
+ @title, @stories, @age = title, stories, age
haml :stories
end
@@ -61,11 +72,27 @@ def render_stories title, stories
end
post '/search' do
- render_stories("Search",get_stories(params[:search]))
+ render_stories(
+ "Search",
+ get_stories(params[:search]),
+ Time.now.strftime("%l:%M %P"))
+end
+
+get '/search' do
+ redirect to('/stories')
end
get '/stories', :auth => :user do
- render_stories(MY_STORIES,get_stories)
+ stories = session[:stories] ||= begin
+ session[:cache_time] = Time.now.strftime("%l:%M %P")
+ get_stories
+ end
+ render_stories(MY_STORIES, stories,session[:cache_time])
+end
+
+get '/refresh', :auth => :user do
+ session[:stories] = nil
+ redirect to('/stories')
end
get '/logout' do
View
7 public/less/stories.less
@@ -0,0 +1,7 @@
+.stories {
+ margin: 12px;
+}
+
+.main {
+ margin-top: 60px;
+}
View
3  views/layout.haml
@@ -5,6 +5,7 @@
%meta{:charset => "utf-8"}
%link{:href => "css/bootstrap-responsive.min.css", :rel => "stylesheet", :type => "text/css"}/
%link{:href => "css/bootstrap.min.css", :rel => "stylesheet", :type => "text/css"}/
+ %link{:href => "less/stories.less", :rel => "stylesheet/less", :type => "text/css"}/
%script{:src => "js/bootstrap.min.js", :type => "application/x-javascript"}
%script{:src => "js/jquery.min.js", :type => "application/x-javascript"}
%script{:src => "js/less.min.js", :type => "application/x-javascript"}
@@ -30,4 +31,4 @@
%a{:href => "/stories"} My Stories
%li
%a{:href => "/logout"} Log Out
- .container{:style => "margin-top:60px"}= yield
+ .container.main= yield
View
7 views/stories.haml
@@ -1,7 +1,10 @@
%h1 #{@title}
+- if @title == MY_STORIES
+ %a{:href => "/refresh"} Refresh List
+ (last refreshed at #{@age})
.stories
- @stories.each do |story|
.story
%span
- %a{:href => "#{story.url}"} #{story.name}
- [#{story.story_type}] [#{story.current_state}]
+ %a{:href => "#{story[:url]}"} #{story[:name]}
+ [#{story[:type]}] [#{story[:state]}]
Please sign in to comment.
Something went wrong with that request. Please try again.