Skip to content

Commit

Permalink
User tweaks - always create records with user IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
sachac committed Nov 9, 2011
1 parent c636a40 commit e3b6b6d
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/controllers/clothing_controller.rb
Expand Up @@ -19,7 +19,7 @@ def index
end
@clothing = current_account.clothing
@clothing = @clothing.find(:all,
:conditions => ["status IS 'active' OR status IS NULL OR status=''"],
:conditions => ["status='active' OR status IS NULL OR status=''"],
:order => order)
respond_to do |format|
format.html # index.html.erb
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/clothing_logs_controller.rb
Expand Up @@ -52,6 +52,7 @@ def create
params[:clothing_id] = @clothing.id
else
@clothing = Clothing.new(:name => params[:clothing])
@clothing.user_id = current_account.id
@clothing.save
flash[:notice] = "Saved new clothing ID #{@clothing.id}."
params[:clothing_id] = @clothing.id
Expand All @@ -62,7 +63,7 @@ def create
else
@clothing_log = ClothingLog.new(params[:clothing_log])
end

@clothing_log.user_id = current_account.id
respond_to do |format|
if @clothing_log.save
format.html { redirect_to(:back, :notice => "Logged #{@clothing_log.date}.") }
Expand Down
1 change: 1 addition & 0 deletions app/controllers/csa_foods_controller.rb
Expand Up @@ -59,6 +59,7 @@ def create
end
params[:csa_food][:food_id] = food.id
@csa_food = CsaFood.new(params[:csa_food])
@csa_food.user_id = current_account.id
respond_to do |format|
if @csa_food.save
format.html { redirect_to(new_csa_food_path, :notice => 'Csa food was successfully created.') }
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/days_controller.rb
Expand Up @@ -25,7 +25,7 @@ def show
# GET /days/new.xml
def new
@day = Day.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @day }
Expand All @@ -41,7 +41,7 @@ def edit
# POST /days.xml
def create
@day = Day.new(params[:day])

@day.user_id = current_account.id
respond_to do |format|
if @day.save
format.html { redirect_to(:back, :notice => 'Day was successfully created.') }
Expand Down
1 change: 1 addition & 0 deletions app/controllers/decision_logs_controller.rb
Expand Up @@ -29,6 +29,7 @@ def new
if params[:decision_id] then
@decision_log.decision_id = params[:decision_id]
end
@decision_log.user_id = current_account.id
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @decision_log }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/foods_controller.rb
Expand Up @@ -51,7 +51,7 @@ def edit
# POST /foods.xml
def create
@food = Food.new(params[:food])

@food.user_id = current_account.id
respond_to do |format|
if @food.save
format.html { redirect_to(@food, :notice => 'Food was successfully created.') }
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/library_items_controller.rb
Expand Up @@ -33,7 +33,7 @@ def show
# GET /library_items/new.xml
def new
@library_item = LibraryItem.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @library_item }
Expand All @@ -52,7 +52,7 @@ def edit
# POST /library_items.xml
def create
@library_item = LibraryItem.new(params[:library_item])

@library_item.user_id = current_account.id
respond_to do |format|
if @library_item.save
format.html { redirect_to(@library_item, :notice => 'Library item was successfully created.') }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/location_histories_controller.rb
Expand Up @@ -42,7 +42,7 @@ def edit
# POST /location_histories.xml
def create
@location_history = LocationHistory.new(params[:location_history])

@location_history.user = current_account
respond_to do |format|
if @location_history.save
format.html { redirect_to(@location_history, :notice => 'Location history was successfully created.') }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/locations_controller.rb
Expand Up @@ -43,7 +43,7 @@ def edit
# POST /locations.xml
def create
@location = Location.new(params[:location])

@location.user = current_account
respond_to do |format|
if @location.save
format.html { redirect_to(@location, :notice => 'Location was successfully created.') }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/measurement_logs_controller.rb
Expand Up @@ -43,7 +43,7 @@ def edit
# POST /measurement_logs.xml
def create
@measurement_log = MeasurementLog.new(params[:measurement_log])
@measurement_log.user = current_user
@measurement_log.user = current_account
respond_to do |format|
if @measurement_log.save
format.html { redirect_to(measurements_path, :notice => 'Measurement log was successfully created.') }
Expand Down
7 changes: 2 additions & 5 deletions app/controllers/stuff_controller.rb
@@ -1,10 +1,6 @@
class StuffController < ApplicationController
load_and_authorize_resource
handles_sortable_columns
before_filter :no_sidebar
def no_sidebar
@skip_sidebar = true
end
# GET /stuff
# GET /stuff.xml
def index
Expand All @@ -30,7 +26,8 @@ def index
def log
@stuff = Stuff.find(:first, :conditions => [ 'lower(name) = ?', params[:stuff_name].strip.downcase ])
unless @stuff
@stuff = Stuff.create(:name => params[:stuff_name].strip)
@stuff = Stuff.new(:name => params[:stuff_name].strip)
@stuff.user = current_account
end
@location = current_account.get_location(params[:location_name])
@stuff.location = @location
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/time_controller.rb
Expand Up @@ -43,7 +43,7 @@ def graph
@width = 900
@time_bottom = @height
@start = (!params[:start].blank? ? Time.parse(params[:start]) : Date.new(Date.today.year, Date.today.month, 1)).midnight
@end = (!params[:end].blank? ? Time.parse(params[:end]) : Date.tomorrow).midnight
@end = (!params[:end].blank? ? Time.parse(params[:end]) : Time.zone.now).midnight
@height = (@day_height * (@end - @start) / 86400.0).to_i
entries = current_account.time_records.find(:all, :conditions => ["start_time >= ? AND start_time < ?", @start, @end], :order => "start_time")
total_time = (@end - @start).to_f
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/toronto_libraries_controller.rb
Expand Up @@ -41,7 +41,7 @@ def edit
# POST /toronto_libraries.xml
def create
@toronto_library = TorontoLibrary.new(params[:toronto_library])

@toronto_library.user = current_account
respond_to do |format|
if @toronto_library.save
format.html { redirect_to(@toronto_library, :notice => 'Toronto library was successfully created.') }
Expand Down
12 changes: 7 additions & 5 deletions app/models/time_tracker_log.rb
Expand Up @@ -28,10 +28,12 @@ def create_record(event_start, event_end, text)
# If the event starts before midnight
if (event_start < event_end.midnight) then
rec = TimeRecord.new(:name => text, :start_time => event_start, :end_time => event_end.midnight)
rec.user = @account
rec.save
event_start = event_end.midnight
end
rec = TimeRecord.new(:name => text, :start_time => event_start, :end_time => event_end)
rec.user = @account
rec.save
end

Expand Down Expand Up @@ -113,10 +115,10 @@ def refresh_from_csv(filename)
end

def entries(start_time, end_time)
start_time = Date.parse(start_time) unless start_time.is_a? Date or start_time.is_a? Time
end_time = Date.parse(end_time) unless end_time.is_a? Date or end_time.is_a? Time
start_time = Time.zone.parse(start_time) unless start_time.is_a? Date or start_time.is_a? Time
end_time = Time.zone.parse(end_time) unless end_time.is_a? Date or end_time.is_a? Time

@account.time_records.find(:all, :conditions => ["date(start_time, 'localtime') >= ? and date(end_time, 'localtime') <= ?", start_time, end_time])
@account.time_records.find(:all, :conditions => ["start_time >= ? and end_time <= ?", start_time, end_time])
end

def by_day(entries)
Expand All @@ -134,7 +136,7 @@ def by_day(entries)
end
# Go back and fill in sleep
days.each do |date,list|
days[date]['A - Sleep'] = 86400 - days_total[date]
days[date]['A - Sleep'] = 86400 - days_total[date].to_i
end
days
end
Expand All @@ -157,7 +159,7 @@ def summarize(start_time, end_time)
end
total += (x.end_time - x.start_time)
end
result["A - Sleep"] = (end_time - start_time + 1) * 86400
result["A - Sleep"] = (end_time - start_time)
result["A - Sleep"] -= (result['! Discretionary'] || 0) + (result['! Personal care'] || 0) + (result['! Unpaid work'] || 0) + (result['A - Work'] || 0)
result
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/home/index.html.haml
Expand Up @@ -27,7 +27,8 @@
- due = LibraryItem.current_items(current_account).minimum('due')
- if due
= " - first due: #{due.strftime('%a %b %e')}"
= link_to "(refresh)", library_refresh_path
- if can? :refresh_library, current_account
= link_to "(refresh)", library_refresh_path
.food.category
- remaining = (current_account.csa_foods.where('disposition = ""').sum(:quantity) / 1000.0)
- days = current_account.csa_foods.next_delivery - Date.today
Expand Down
1 change: 1 addition & 0 deletions app/views/partials/_sidebar.html.haml
Expand Up @@ -12,6 +12,7 @@
%li= link_to "Decision logs", decision_logs_path
%li= link_to "Time tracker", time_path
%li= link_to "Time tracker graph", "/time/graph"
%li= link_to "Time tracker clock", "/time/clock"

%a{:href => "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=zmw:00000.1.71265&bannertypeclick=wu_clean2day"}
%img{:src => "http://weathersticker.wunderground.com/weathersticker/cgi-bin/banner/ban/wxBanner?bannertype=wu_clean2day_metric_cond&airportcode=CYTZ&ForcedCity=Toronto&ForcedState=ON&wmo=71265&language=EN", :alt => "Click for Toronto, Ontario Forecast", :height => "100", :width => "300"}
4 changes: 2 additions & 2 deletions app/views/time/clock.html.erb
Expand Up @@ -19,9 +19,9 @@
var margin_top = <%= margin_top %>;
var separation = <%= separation %>;
// Draw the two circles
c = p.circle(radius, margin_top + radius, radius - 1);
c = p.circle(radius, margin_top + radius, radius - 2);
c.attr({fill: "#ccc"});
c = p.circle(radius * 3 + separation, margin_top + radius, radius - 1);
c = p.circle(radius * 3 + separation, margin_top + radius, radius - 2);
c.attr({fill: "#ccc"});
// Draw the curves
<% noon = 12 * 60
Expand Down
7 changes: 5 additions & 2 deletions config/initializers/session_store.rb
@@ -1,7 +1,10 @@
# Be sure to restart your server when you modify this file.

Home::Application.config.session_store :cookie_store, :key => 'quantifiedawesome', :domain => '.dev.quantifiedawesome.com'

if Rails.env.production?
Home::Application.config.session_store :cookie_store, :key => 'quantifiedawesome', :domain => '.quantifiedawesome.com'
else
Home::Application.config.session_store :cookie_store, :key => 'quantifiedawesome', :domain => '.dev.quantifiedawesome.com'
end
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
Expand Down
14 changes: 7 additions & 7 deletions db/schema.rb
Expand Up @@ -136,7 +136,7 @@
t.string "isbn"
t.boolean "public"
t.text "notes"
t.decimal "price"
t.decimal "price", :precision => 10, :scale => 0
t.integer "pages"
t.integer "user_id"
end
Expand Down Expand Up @@ -170,7 +170,7 @@
t.integer "measurement_id"
t.datetime "datetime"
t.text "notes"
t.decimal "value"
t.decimal "value", :precision => 10, :scale => 0
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
Expand All @@ -182,12 +182,12 @@
t.string "name"
t.text "notes"
t.string "unit"
t.decimal "average"
t.decimal "max"
t.decimal "min"
t.decimal "average", :precision => 10, :scale => 0
t.decimal "max", :precision => 10, :scale => 0
t.decimal "min", :precision => 10, :scale => 0
t.datetime "created_at"
t.datetime "updated_at"
t.decimal "sum"
t.decimal "sum", :precision => 10, :scale => 0
t.integer "user_id"
end

Expand All @@ -207,7 +207,7 @@
create_table "stuff", :force => true do |t|
t.string "name"
t.string "status"
t.decimal "price"
t.decimal "price", :precision => 10, :scale => 0
t.date "purchase_date"
t.text "notes"
t.string "long_name"
Expand Down

0 comments on commit e3b6b6d

Please sign in to comment.