Skip to content

Commit

Permalink
Permit anonymous view
Browse files Browse the repository at this point in the history
  • Loading branch information
sachac committed Dec 27, 2011
1 parent bc40f89 commit 522ffff
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 49 deletions.
4 changes: 3 additions & 1 deletion app/assets/stylesheets/application.sass
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@ label.inline
.condensed-table
font-size: smaller
.right
text-align: right
text-align: right
.clearfix
clear: both
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ApplicationController < ActionController::Base
helper_method :current_account
helper_method :mobile?
helper_method :managing?
skip_filter :authenticate_user!

rescue_from NonexistentAccount do |e|
logger.info "NONEXISTENT #{current_subdomain}"
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/record_categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
class RecordCategoriesController < ApplicationController
autocomplete :record_category, :full_name, :full => true
respond_to :json
respond_to :html, :json

# GET /record_categories
# GET /record_categories.xml
def index
authorize! :manage_account, current_account
authorize! :view_time, current_account
@record_categories = current_account.record_categories.where('parent_id IS NULL').order('name')
respond_with @record_categories
end

# GET /record_categories/1
# GET /record_categories/1.xml
def show
authorize! :manage_account, current_account
authorize! :view_time, current_account
@record_category = RecordCategory.find(params[:id])
if html?
if @record_category.list?
Expand Down
9 changes: 3 additions & 6 deletions app/controllers/records_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class RecordsController < ApplicationController
respond_to :json
respond_to :html, :json
# GET /records
# GET /records.xml
def index
authorize! :manage_account, current_account
authorize! :view_time, current_account
@start = (!params[:start].blank? ? Time.zone.parse(params[:start]) : ((current_account.records.minimum('timestamp') || (Time.now - 1.week)))).in_time_zone.midnight
@end = (!params[:end].blank? ? Time.zone.parse(params[:end]) : ((current_account.records.maximum('timestamp') || Time.now) + 1.day)).in_time_zone.midnight

Expand All @@ -14,9 +14,6 @@ def index

@records = current_account.records.order('timestamp DESC')
@records = @records.where(:timestamp => @start..@end)
if cannot? :manage_account, current_account
@records = @records.public
end
unless params[:filter_string].blank?
query = "%" + params[:filter_string].downcase + "%"
@records = @records.joins(:record_category).where('LOWER(records.data) LIKE ? OR LOWER(record_categories.full_name) LIKE ?', query, query)
Expand All @@ -34,7 +31,7 @@ def index
# GET /records/1
# GET /records/1.xml
def show
authorize! :manage_account, current_account
authorize! :view_time, current_account
@record = current_account.records.find(params[:id])
@context = @record.context
if html?
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/time_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Challenges:
# I have to manually create my time graphs
class TimeController < ApplicationController
before_filter :authenticate_user!, :except => [:graph, :clock]

# POST
def refresh_from_csv
authorize! :manage_account, current_account
Expand Down
15 changes: 14 additions & 1 deletion app/models/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Record < ActiveRecord::Base
belongs_to :user
serialize :data
scope :activities, joins(:record_category).where(:record_categories => {:category_type => 'activity'}).readonly(false)
scope :public, where("LOWER(data) NOT LIKE '%!private%'")
scope :public, where("LOWER(records.data) NOT LIKE '%!private%'")
before_save :add_data
def add_data
self.date = self.timestamp.in_time_zone.to_date
Expand Down Expand Up @@ -46,6 +46,19 @@ def next
self.user.records.where('timestamp >= ? and records.id > ?', self.timestamp, self.id).order('timestamp asc, id asc')
end

def context
{
:current => self.current_activity,
:previous => {
:entry => self.previous.first,
:activity => self.previous.activities.first,
},
:next => {
:entry => self.next.first,
:activity => self.next.activities.first,
},
}
end
def self.choose_zoom_level(range)
diff = range.end.to_date - range.begin.to_date
if diff <= 14
Expand Down
7 changes: 4 additions & 3 deletions app/views/clothing/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

%p
= @clothing.status
- {'store' => 'stored', 'activate' => 'active', 'donate' => 'donated'}.each do |action,status|
- unless @clothing.status == status
= link_to action, clothing_path(@clothing.id) + '?clothing[status]=' + status, :method => :put
- if managing?
- {'store' => 'stored', 'activate' => 'active', 'donate' => 'donated'}.each do |action,status|
- unless @clothing.status == status
= link_to action, clothing_path(@clothing.id) + '?clothing[status]=' + status, :method => :put


.image
Expand Down
49 changes: 28 additions & 21 deletions app/views/record_categories/_list.html.haml
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
= form_tag bulk_update_record_categories_path(:destination => request.fullpath) do
- if managing?
- if managing?
= form_tag bulk_update_record_categories_path(:destination => request.fullpath) do
= submit_tag I18n.t('app.general.save'), :class => 'btn'
%table
%thead
%tr
- if managing?
%th{:width => 50} Actions
%th Name
- unless mobile?
%th Type
%tbody
- list.each do |c|
%table
%thead
%tr
%td= action_list(c)
%td
= link_to c.name, c
- if c.list?
&raquo;
- if !mobile? and managing?
%th{:width => 50} Actions
%th Name
- unless mobile?
%th Type
%tbody
- list.each do |c|
%tr
%td= action_list(c)
%td
- %w{list activity record}.each do |type|
= radio_button_tag "category_type[#{c.id}]", type, c.category_type == type
= label_tag "category_type[#{c.id}][#{type}]", type.humanize, :class => 'inline'
= link_to c.name, c
- if c.list?
&raquo;
- unless mobile?
%td
- %w{list activity record}.each do |type|
= radio_button_tag "category_type[#{c.id}]", type, c.category_type == type
= label_tag "category_type[#{c.id}][#{type}]", type.humanize, :class => 'inline'
- else
.clearfix
%ul
- list.each do |c|
%li
= link_to c.name, c
- if c.list?
&raquo;
3 changes: 2 additions & 1 deletion app/views/record_categories/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= setup_page 'categories', nil, 'time/nav'

= link_to 'New record category', new_record_category_path
- if managing?
= link_to 'New record category', new_record_category_path

= render 'list', :list => @record_categories
6 changes: 3 additions & 3 deletions app/views/record_categories/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

%p
= record_category_breadcrumbs(@record_category)
- if can? :manage_account, current_account
- if managing?
\|
= link_to t('app.general.edit'), edit_record_category_path(@record_category)
\|
- if @record_category.list?
= link_to t('.add_child'), new_record_category_path(:parent_id => @record_category.id)
\|
- unless @record_category.record?
= link_to t('.review'), time_review_path(:parent_id => @record_category.id)
\|
= link_to t('.review'), time_review_path(:parent_id => @record_category.id)
\|
= link_to t('app.general.back'), record_categories_path


Expand Down
20 changes: 12 additions & 8 deletions app/views/records/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
= setup_page 'records', @record.record_category.name + " - " + l(@record.timestamp), 'time/nav'
= after_title object_labels(@record)
= record_category_breadcrumbs(@record.record_category)
- if can? :manage_account, current_account
- if @record.record_category.category_type == 'activity'
Expand All @@ -23,14 +24,17 @@
- if @record.data?
- data = @record.record_category.data
- @record.data.each do |k,v|
- if can?(:manage_account, current_account) or !v.downcase.include?('!private')
%tr
%td.h
- if data and data[k]
= data[k][:label]
- else
= k.to_s.humanize
%td= v
%tr
%td.h
- if data and data[k]
= data[k][:label]
- else
= k.to_s.humanize
%td
- if can?(:manage_account, current_account) or !v.downcase.include?('!private')
= v
- else
%span{:class => 'private'}= t('app.general.private')
- if @context[:current] and @context[:current] != @record
%tr
%td.h= t('.current')
Expand Down
5 changes: 5 additions & 0 deletions public/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -3149,3 +3149,8 @@ label.inline {
.right {
text-align: right;
}

/* line 117, ../../app/assets/stylesheets/application.sass */
.clearfix {
clear: both;
}

0 comments on commit 522ffff

Please sign in to comment.