Skip to content

Commit

Permalink
Add more navigability
Browse files Browse the repository at this point in the history
  • Loading branch information
sachac committed Dec 7, 2011
1 parent b7466f8 commit 4400fec
Show file tree
Hide file tree
Showing 22 changed files with 254 additions and 86 deletions.
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
source 'http://rubygems.org'

gem 'rails', '3.0.10'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'arel', :git => 'git://github.com/rails/arel.git'
#gem 'journey', :git => 'git://github.com/rails/journey.git'

gem 'jquery-rails'
gem 'sqlite3'
gem 'isbndb'
gem 'haml'
gem 'mysql'

gem 'will_paginate'
gem 'haml-rails'
gem 'color'
gem 'narray'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ GEM
childprocess (0.2.2)
ffi (~> 1.0.6)
chronic (0.6.4)
chronic_duration (0.9.6)
numerizer (~> 0.1.1)
chunky_png (1.2.5)
color (1.4.1)
compass (0.11.5)
Expand Down Expand Up @@ -150,6 +152,7 @@ GEM
net-http-digest_auth (1.1.1)
net-http-persistent (1.9)
nokogiri (1.5.0)
numerizer (0.1.1)
orm_adapter (0.0.5)
polyglot (0.3.2)
rack (1.2.4)
Expand Down Expand Up @@ -213,6 +216,7 @@ GEM
web-app-theme (0.7.0)
webrobots (0.0.12)
nokogiri (>= 1.4.4)
will_paginate (3.0.2)
workflow (0.8.1)
xpath (0.1.4)
nokogiri (~> 1.3)
Expand All @@ -227,6 +231,7 @@ DEPENDENCIES
cancan
capybara
chronic
chronic_duration
color
compass
compass-bootstrap
Expand Down Expand Up @@ -261,5 +266,6 @@ DEPENDENCIES
sqlite3
subdomain-fu!
web-app-theme
will_paginate
workflow
yaml_db
16 changes: 16 additions & 0 deletions app/controllers/tap_log_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class TapLogRecordsController < ApplicationController
def index
authorize! :view_tap_log_records, current_account
@tap_log_records = current_account.tap_log_records.order('timestamp desc')
@start = (!params[:start].blank? ? Time.zone.parse(params[:start]) : (current_account.time_records.maximum('end_time') || Date.today) - 1.week).in_time_zone.midnight
@end = (!params[:end].blank? ? Time.zone.parse(params[:end]) : (current_account.time_records.maximum('end_time') || Date.today)).in_time_zone.midnight
[:catOne, :catTwo, :catThree, :status].each do |sym|
unless params[sym].blank?
@tap_log_records = @tap_log_records.where("#{sym}=?", params[sym])
Expand All @@ -16,6 +18,14 @@ def index
@tap_log_records = @tap_log_records.where("lower(note) LIKE ? AND lower(note) NOT LIKE '!private'", '%' + params[:filter_string].downcase + '%')
end
end
unless @start.blank?
@tap_log_records = @tap_log_records.where('timestamp >= ?', @start)
end
unless @end.blank?
@tap_log_records = @tap_log_records.where('timestamp <= ?', @end)
end

@tap_log_records = @tap_log_records.paginate :per_page => 20, :page => params[:page]
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @tap_log_records }
Expand All @@ -27,6 +37,12 @@ def index
def show
@tap_log_record = current_account.tap_log_records.find(params[:id])
authorize! :view, @tap_log_record
@current_activity = @tap_log_record.current_activity
@during_this = @tap_log_record.during_this
@previous_activity = @tap_log_record.previous.activity.first
@previous_entry = @tap_log_record.previous.first
@next_activity = @tap_log_record.next.activity.first
@next_entry = @tap_log_record.next.first

respond_to do |format|
format.html # show.html.erb
Expand Down
10 changes: 7 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ def access_collection
def title(s)
content_for(:title) { s }
end
def setup_page(active, title, nav_file = 'nav')
title(title)
render :partial => nav_file, :locals => { :active => active }
def setup_page(active, title = nil, nav_file = 'nav')
title(title) if title
content_for(:nav) { render nav_file, :active => active }
end

def active_class(variable, value)
Expand All @@ -163,4 +163,8 @@ def active_menu(crumb)
active ? 'active' : 'inactive'
end

def duration(seconds)
"%02d" % (seconds / 1.hour) + (":%02d" % ((seconds % 1.hour) / 1.minute))
end

end
14 changes: 14 additions & 0 deletions app/helpers/pagination_list_link_renderer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class PaginationListLinkRenderer < WillPaginate::ActionView::LinkRenderer
protected
def html_container(html)
tag :div, tag(:ul, html), container_attributes
end

def page_number(page)
tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page)
end

def previous_or_next_page(page, text, classname)
tag :li, link(text, page || '#'), :class => [classname[0..3], classname, ('disabled' unless page)].join(' ')
end
end
23 changes: 23 additions & 0 deletions app/models/tap_log_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,27 @@ def category_string
def private?
(self.note || '').downcase =~ /private/
end

# Return the Tap Log Record representing an activity during which this record occurred
def current_activity
if self.entry_type == 'activity'
self
else
self.user.tap_log_records.where('timestamp < ?', self.timestamp).order('timestamp desc').limit(1).first
end
end

def during_this
self.user.tap_log_records.where('timestamp >= ? and timestamp <= ? and id != ?', self.timestamp, self.end_timestamp, self.id).order('timestamp')
end

scope :activity, where('entry_type=?', 'activity')

def previous
self.user.tap_log_records.where('timestamp <= ? and id < ?', self.timestamp, self.id).order('timestamp desc, id desc').limit(1)
end

def next
self.user.tap_log_records.where('timestamp >= ? and id > ?', self.timestamp, self.id).order('timestamp asc, id asc').limit(1)
end
end
1 change: 1 addition & 0 deletions app/models/time_tracker_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def refresh_from_tap_log(file)
if x.time_category
if last_time_record
entries << {:start => last_time_record.timestamp, :end => x.timestamp, :text => last_time_record.time_category}
last_time_record.update_attributes(:end_timestamp => x.timestamp, :entry_type => 'activity')
end
last_time_record = x
end
Expand Down
6 changes: 6 additions & 0 deletions app/stylesheets/application.sass
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ a[data-method]
font-weight: normal
display: inline
@extend .label
.collapsible > legend
font-weight: bold
padding-left: 10px
margin-bottom: 10px
td.h
font-weight: bold
5 changes: 3 additions & 2 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
- flash.each do |type, message|
%div{:class => "alert-message #{type}"}
%p= message
- if content_for? :nav
= yield :nav
- if content_for? :title
%h2
= yield :title
%h2= yield :title
= yield
%footer
.block
Expand Down
33 changes: 33 additions & 0 deletions app/views/tap_log_records/_summary.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
- show_duration = false unless defined? show_duration

%table.condensed-table.zebra-striped
%thead
%tr
%th Timestamp
%th Categories
%th Data
- if show_duration
%th Duration
%tbody
- list.each do |tap_log_record|
%tr.tap_log_record
%td.timestamp= if tap_log_record.timestamp then link_to l(tap_log_record.timestamp), tap_log_record end
%td.categories
= tap_log_record.category_string
%td
= object_labels(tap_log_record)
- if tap_log_record.number
.number= t('app.tap_log_record.number', :number => tap_log_record.number)
- if tap_log_record.rating
.rating= t('app.tap_log_record.rating', :rating => tap_log_record.rating)
- unless tap_log_record.note.blank? or !can? :view_note, tap_log_record
.note= simple_format tap_log_record.note
- if can? :manage_account, @account
- note = tap_log_record.note
- if note =~ /!memory/i
= link_to t('app.tap_log_record.copy_memory'), copy_to_memory_tap_log_record_path(tap_log_record, :destination => request.fullpath), :method => :post
- if show_duration
%td
- if tap_log_record.end_timestamp
= duration tap_log_record.end_timestamp - tap_log_record.timestamp

66 changes: 26 additions & 40 deletions app/views/tap_log_records/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
= setup_page 'tap_logs', 'Tap Log records', 'time/nav'
= setup_page 'tap_logs', nil, 'time/nav'

.filters
= form_tag tap_log_records_path, :method => :get do
- ['catOne', 'catTwo', 'catThree'].each do |cat|
.filters.collapsible.collapsed.fieldset
%legend Filters [+]
.details
= form_tag tap_log_records_path, :method => :get do
.clearfix
= label_tag cat.to_sym, I18n.t("formtastic.labels.tap_log_record.#{cat}")
= label_tag :start, 'Start'
.input= text_field_tag :start, @start.strftime("%Y-%m-%d"), :class => 'datepicker'
.clearfix
= label_tag :end, 'End'
.input= text_field_tag :end, @end.strftime("%Y-%m-%d"), :class => 'datepicker'
- ['catOne', 'catTwo', 'catThree'].each do |cat|
.clearfix
= label_tag cat.to_sym, I18n.t("formtastic.labels.tap_log_record.#{cat}")
.input
= select_tag cat.to_sym, options_for_select([['', '']] + TapLogRecord.select("DISTINCT #{cat}").order(cat).collect { |x| [ x.send(cat), x.send(cat) ] }, params[cat.to_sym])
.clearfix
= label_tag :status, "Status"
.input
= select_tag :status, options_for_select([['', '']] + TapLogRecord.select("DISTINCT status").order('status').collect { |x| [ x.send('status'), x.send('status') ] }, params[:status])
.clearfix
= label_tag :filter, "Filter"
.input
= select_tag cat.to_sym, options_for_select([['', '']] + TapLogRecord.select("DISTINCT #{cat}").order(cat).collect { |x| [ x.send(cat), x.send(cat) ] }, params[cat.to_sym])
.clearfix
= label_tag :status, "Status"
.input
= select_tag :status, options_for_select([['', '']] + TapLogRecord.select("DISTINCT status").order('status').collect { |x| [ x.send('status'), x.send('status') ] }, params[:status])
.clearfix
= label_tag :filter, "Filter"
.input
= text_field_tag :filter_string, params[:filter_string]
.actions
= submit_tag t('app.general.filter'), :class => 'btn primary'
= text_field_tag :filter_string, params[:filter_string]
.actions
= submit_tag t('app.general.filter'), :class => 'btn primary'

%table.condensed-table.zebra-striped
%thead
%tr
%th Timestamp
%th Categories
%th Data
%tbody
- @tap_log_records.each do |tap_log_record|
%tr.tap_log_record
%td.timestamp= if tap_log_record.timestamp then link_to l(tap_log_record.timestamp), tap_log_record end
%td.categories
= tap_log_record.category_string
%td
= object_labels(tap_log_record)
- if tap_log_record.number
.number= t('app.tap_log_record.number', :number => tap_log_record.number)
- if tap_log_record.rating
.rating= t('app.tap_log_record.rating', :rating => tap_log_record.rating)
- unless tap_log_record.note.blank? or !can? :view_note, tap_log_record
.note= simple_format tap_log_record.note
- if can? :manage_account, @account
- note = tap_log_record.note
- if note =~ /!memory/i
= link_to t('app.tap_log_record.copy_memory'), copy_to_memory_tap_log_record_path(tap_log_record, :destination => request.fullpath), :method => :post
= render 'summary', :list => @tap_log_records, :show_duration => true
= will_paginate @tap_log_records, :renderer => PaginationListLinkRenderer
75 changes: 52 additions & 23 deletions app/views/tap_log_records/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
%h1
= @tap_log_record.category_string
\-
= l @tap_log_record.timestamp
= object_labels @tap_log_record
- if can? :update, @tap_log_record
= link_to 'Edit', edit_tap_log_record_path(@tap_log_record)
\|
= link_to 'Back', tap_log_records_path
%p
&laquo;
= link_to t('app.tap_log_record.previous_activity'), @previous_activity if @previous_activity
\-
= link_to t('app.tap_log_record.previous_entry'), @previous_entry if @previous_entry
|
- if can? :update, @tap_log_record
= link_to 'Edit', edit_tap_log_record_path(@tap_log_record)
\|
= link_to t('app.tap_log_record.next_entry'), @next_entry if @next_entry
\-
= link_to t('app.tap_log_record.next_activity'), @next_activity if @next_activity
&raquo;


%table
%tr
%td= t('formtastic.labels.tap_log_record.catOne')
%td= @tap_log_record.catOne
%tr
%td= t('formtastic.labels.tap_log_record.catTwo')
%td= @tap_log_record.catTwo
%tr
%td= t('formtastic.labels.tap_log_record.catThree')
%td= @tap_log_record.catThree
%tr
%td= t('formtastic.labels.tap_log_record.number')
%td= @tap_log_record.number
%tr
%td= t('formtastic.labels.tap_log_record.rating')
%td= @tap_log_record.rating
- if can? :view_note, @tap_log_record
%tr
%td= t('formtastic.labels.tap_log_record.note')
%td= @tap_log_record.note
%tbody
- if @tap_log_record.end_timestamp?
%tr
%td.h= t('formtastic.labels.tap_log_record.end_timestamp')
%td= "#{l(@tap_log_record.end_timestamp)} (#{duration @tap_log_record.end_timestamp - @tap_log_record.timestamp})"
- if @tap_log_record.number?
%tr
%td.h= t('formtastic.labels.tap_log_record.number')
%td= @tap_log_record.number
- if @current_activity and @current_activity != @tap_log_record
%tr
%td.h= t('app.tap_log_record.current_activity')
%td= link_to @current_activity.category_string, @current_activity
- if @tap_log_record.rating?
%tr
%td.h= t('formtastic.labels.tap_log_record.rating')
%td= @tap_log_record.rating
- if @tap_log_record.note? and can? :view_note, @tap_log_record
%tr
%td.h= t('formtastic.labels.tap_log_record.note')
%td= @tap_log_record.note

- if @during_this and @during_this.length > 0
%h2= t('app.tap_log_record.during_this_time')
= render 'summary', :list => @during_this

%p
&laquo;
= link_to t('app.tap_log_record.previous_activity'), @previous_activity if @previous_activity
\-
= link_to t('app.tap_log_record.previous_entry'), @previous_entry if @previous_entry
|
= link_to t('app.tap_log_record.next_entry'), @next_entry if @next_entry
\-
= link_to t('app.tap_log_record.next_activity'), @next_activity if @next_activity
&raquo;
2 changes: 1 addition & 1 deletion app/views/time/_nav.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%ul.tabs
%li{:class => active_class(active, 'graph')}= link_to 'Graph', time_graph_path(:start => @start ? @start.strftime("%Y-%m-%d") : nil, :end => @end ? @end.strftime("%Y-%m-%d") : nil)
%li{:class => active_class(active, 'clock')}= link_to 'Clock', time_clock_path(:start => @start ? @start.strftime("%Y-%m-%d") : nil, :end => @end ? @end.strftime("%Y-%m-%d") : nil)
%li{:class => active_class(active, 'index')}= link_to 'Summary', time_path
%li{:class => active_class(active, 'index')}= link_to 'Summary', time_summary_path
- if current_user == current_account
%li{:class => active_class(active, 'refresh')}= link_to 'Upload data', refresh_time_path
%li{:class => active_class(active, 'tap_logs')}= link_to 'Logs', tap_log_records_path
Expand Down
2 changes: 1 addition & 1 deletion app/views/time/clock.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= setup_page('clock', 'Time versus probability of activity') %>
<%= setup_page 'clock', 'Time and probability of activity' %>
<%= render :partial => 'start_end_form' %>
<%
radius = 200
Expand Down
Loading

0 comments on commit 4400fec

Please sign in to comment.