Skip to content

Commit

Permalink
first draft of watched data objects
Browse files Browse the repository at this point in the history
  • Loading branch information
bensomers committed Jul 30, 2009
1 parent d8dd7c0 commit 4306d92
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/controllers/dashboard_controller.rb
Expand Up @@ -4,6 +4,8 @@ class DashboardController < ApplicationController
def index
@upcoming_shifts = current_user.shifts.select{|shift| !(shift.submitted?) and shift.scheduled? and shift.end > Time.now and @department.locations.include?(shift.location)}.sort_by(&:start)[0..3]
@most_recent_payform= current_user.payforms.sort_by(&:date).last
@watched_objects = current_user.user_config.watched_data_objects.split(", ").map{|id| DataObject.find(id)}.flatten

@dept_start_hour = current_department.department_config.schedule_start / 60
@dept_end_hour = current_department.department_config.schedule_end / 60
@hours_per_day = (@dept_end_hour - @dept_start_hour)
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/shifts_controller.rb
Expand Up @@ -7,7 +7,8 @@ class ShiftsController < ApplicationController
def index
@period_start = params[:date].blank? ? Date.parse("last Sunday") : Date.parse(params[:date])

# for lists of shifts
# For lists of shifts
# Should probably optimize by swapping out Ruby sorts & queries for SQL s-ben
unless current_department.locations.empty?
@active_shifts = Shift.all.select{|s| s.report and !s.submitted? and current_department.locations.include?(s.location)}.sort_by(&:start)
@upcoming_shifts = current_user.shifts.select{|shift| !(shift.submitted?) and shift.scheduled? and shift.end > Time.now and @department.locations.include?(shift.location)}.sort_by(&:start)[0..3]
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/user_configs_controller.rb
Expand Up @@ -4,10 +4,14 @@ class UserConfigsController < ApplicationController
def edit
@dept_select = current_user.departments.map{|d| [d.name, d.id]}
@loc_group_select = {}
@data_objects = []
current_user.departments.each do |dept|
@loc_group_select.store(dept.id, current_user.loc_groups(dept))
@data_objects << dept.data_objects
@data_objects.flatten!
end
@selected_loc_groups = @user_config.view_loc_groups.split(', ').map{|lg|LocGroup.find(lg).id}
@selected_data_objects = @user_config.watched_data_objects.split(', ').map{|obj|DataObject.find(obj).id}
end

def update
Expand Down
1 change: 1 addition & 0 deletions app/models/data_entry.rb
Expand Up @@ -40,6 +40,7 @@ def data_fields
self.content.split(';;').map{|str| str.split('::')}.map{|a| a.first}.sort
end

# Good candidate for refactoring *shudder* -ben
# Returns the data fields and user content in a set of {field => content} hashes
def data_fields_with_contents
content_arrays = self.content.split(';;').map{|str| str.split('::')}
Expand Down
6 changes: 6 additions & 0 deletions app/models/data_object.rb
Expand Up @@ -15,4 +15,10 @@ def self.by_location_group(loc_group)
loc_group.locations.map{|loc| loc.data_objects}.flatten.compact
end

### Virtual Attributes ###

def data_fields
self.data_type.data_fields
end

end
9 changes: 6 additions & 3 deletions app/models/shift.rb
Expand Up @@ -66,6 +66,10 @@ def self.delete_part_of_shift(shift, start_of_delete, end_of_delete)
# = Object methods =
# ==================

def duration
self.end - self.start
end

def css_class(current_user = nil)
if current_user and user == current_user
css_class = "user"
Expand All @@ -80,7 +84,6 @@ def css_class(current_user = nil)
css_class
end


def too_early?
self.start > 30.minutes.from_now
end
Expand All @@ -94,12 +97,12 @@ def late?
#seconds
end

#a shift has been signed in to if it has a report
# A shift has been signed in to if it has a report
def signed_in?
self.report
end

#a shift has been signed in to if its shift report has been submitted
# A shift has been signed in to if its shift report has been submitted
def submitted?
self.report and self.report.departed
end
Expand Down
16 changes: 13 additions & 3 deletions app/models/user_config.rb
Expand Up @@ -6,12 +6,22 @@ class UserConfig < ActiveRecord::Base

VIEW_WEEK_OPTIONS = [
# Displayed stored in db
["Whole week", "whole_period"],
["Remainder of week", "remainder"],
["Whole week", "whole_period"],
["Remainder of week", "remainder"],
["Just the current day", "current_day"]
]

# Custom accessor, so you can assign loc groups by passing in either an array
### CUSTOM ACCESSORS ###
# Incidentally, these two are identical, but I don't know where I could refactor
# them out to. So they're not DRY for now. We can improve it later, once we
# come up with a good place to do so. -ben

def watched_data_objects=(data_objects)
data_objects = data_objects.split(',') if data_objects.class == String
write_attribute(:watched_data_objects, data_objects.uniq.remove_blank.join(", "))
end

# Loc Groups can be assigned either by passing in an array
# of ids or a comma-separated string.
def view_loc_groups=(loc_groups)
loc_groups = loc_groups.split(', ') if loc_groups.class == String
Expand Down
1 change: 1 addition & 0 deletions app/models/user_observer.rb
Expand Up @@ -6,6 +6,7 @@ def after_create(user)
UserConfig.create!({:user_id => user.id,
:view_loc_groups => (user.departments.collect{|d| d.loc_groups}.flatten.collect{|l| l.id} * ", "),
:view_week => "",
:watched_data_objects => "",
:default_dept => user.departments.first.id
})
end
Expand Down
8 changes: 8 additions & 0 deletions app/views/dashboard/index.html.erb
Expand Up @@ -37,6 +37,14 @@
</fieldset><br />
<% end %>
<% unless @watched_objects.empty? %>
<br />
<fieldset class="index">
<legend>Recent updates for your watched data objects</legend>
<%= render :partial => 'data_objects/watched_object', :collection => @watched_objects %>
</fieldset><br />
<% end %>
<% unless current_user.user_config.view_loc_groups.empty? %>
<fieldset class="index">
<legend>Today's schedule</legend>
Expand Down
1 change: 1 addition & 0 deletions app/views/data_objects/_data_objects_table.html.erb
@@ -1,3 +1,4 @@
<%# This can be refactored with the data_object.data_entries virtual attribute %>
<div>
<h2><%= link_to data_objects_table.first.name.pluralize, data_objects_table.first %></h2>
<table id=<%= "data_objects_table_#{data_objects_table.first.id}" %> class="data_table">
Expand Down
23 changes: 23 additions & 0 deletions app/views/data_objects/_watched_object.html.erb
@@ -0,0 +1,23 @@
<div>
<table id=<%= "watched_objects_#{watched_object.id}" %> class="data_table">
<thead>
<tr>
<th>Name</th>
<% watched_object.data_fields.each do |df| %>
<th><%= df.name %></th>
<% end %>
</tr>
</thead>
<tbody>
<% entry = watched_object.data_entries.last.data_fields_with_contents unless watched_object.data_entries.empty? %>
<tr>
<td><%= link_to watched_object.name, watched_object %></td>
<% watched_object.data_fields.each do |df| %>
<td>
<%= entry[df.id.to_s] if entry %>
</td>
<% end %>
</tr>
</tbody>
</table>
</div>
15 changes: 13 additions & 2 deletions app/views/user_configs/_form.html.erb
Expand Up @@ -23,10 +23,21 @@
</p>
<p>
<%= f.label :view_week %><br />
<small>This controls what portion of the shift schedule you see, relative to
your pay period. Your pay period is defined by your administrator.</small><br />
<small>This controls what portion of the shift schedule you see.</small><br />
<%= f.select :view_week, UserConfig::VIEW_WEEK_OPTIONS %>
</p>
<p>
<%= f.label :watched_data_objects %><br />
<small>This controls which data objects you will see updates for on your
dashboard.</small><br />
<%= collection_multiple_select( :user_config, :watched_data_objects,
@data_objects, :id, :name,
:selected_items => @selected_data_objects) %>
<%#= tree_multiple_select( :user_config, :watched_data_objects,
:data_fields, :id, :name,
:child_method => :data_fields) %>


<p><%= f.submit "Submit" %></p>
<% end %>

2 changes: 1 addition & 1 deletion db/migrate/20090605194714_create_data_fields.rb
Expand Up @@ -5,7 +5,7 @@ def self.up
t.string :name
t.string :display_type
t.string :values
t.string :validations
t.string :alerts
t.timestamps
end
end
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20090626190626_create_user_configs.rb
Expand Up @@ -5,6 +5,7 @@ def self.up
t.integer :default_dept
t.string :view_loc_groups
t.string :view_week
t.string :watched_data_objects
t.timestamps
end
end
Expand Down
8 changes: 4 additions & 4 deletions preload_data/data_fields.yml
Expand Up @@ -6,7 +6,7 @@ data_fields_001:
id: "1"
name: Orientation
updated_at: 2009-07-02 22:11:53
validations:
alerts:
values: Good, Evil
data_fields_002:
created_at: 2009-07-02 22:11:53
Expand All @@ -15,7 +15,7 @@ data_fields_002:
id: "2"
name: Model
updated_at: 2009-07-02 22:11:53
validations:
alerts:
values: YT-1300 light freighter, Death Star, Firefly
data_fields_003:
created_at: 2009-07-02 22:11:53
Expand All @@ -24,7 +24,7 @@ data_fields_003:
id: "3"
name: fur color
updated_at: 2009-07-02 22:11:53
validations:
alerts:
values: tabby, brown, orange, white
data_fields_004:
created_at: 2009-07-02 22:11:53
Expand All @@ -33,5 +33,5 @@ data_fields_004:
id: "4"
name: number of lives
updated_at: 2009-07-02 22:11:53
validations:
alerts:
values: integer
18 changes: 18 additions & 0 deletions preload_data/user_configs.yml
Expand Up @@ -7,6 +7,7 @@ user_configs_001:
user_id: "13"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_002:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -15,6 +16,7 @@ user_configs_002:
user_id: "14"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_003:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -23,6 +25,7 @@ user_configs_003:
user_id: "15"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_004:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -31,6 +34,7 @@ user_configs_004:
user_id: "16"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_005:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -39,6 +43,7 @@ user_configs_005:
user_id: "17"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_006:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -47,6 +52,7 @@ user_configs_006:
user_id: "18"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_007:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -55,6 +61,7 @@ user_configs_007:
user_id: "20"
view_loc_groups: 2, 3, 4
view_week: whole_period
watched_data_objects: ""
user_configs_008:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -63,6 +70,7 @@ user_configs_008:
user_id: "21"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_009:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -71,6 +79,7 @@ user_configs_009:
user_id: "22"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_010:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -79,6 +88,7 @@ user_configs_010:
user_id: "23"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_011:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -87,6 +97,7 @@ user_configs_011:
user_id: "24"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_012:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -95,6 +106,7 @@ user_configs_012:
user_id: "26"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_013:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -103,6 +115,7 @@ user_configs_013:
user_id: "27"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_014:
created_at: 2009-06-22 17:42:57
default_dept: "1"
Expand All @@ -111,6 +124,7 @@ user_configs_014:
user_id: "28"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_015:
created_at: 2009-06-30 19:58:09
default_dept:
Expand All @@ -119,6 +133,7 @@ user_configs_015:
user_id: "49"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_016:
created_at: 2009-06-30 19:58:26
default_dept:
Expand All @@ -127,6 +142,7 @@ user_configs_016:
user_id: "50"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_017:
created_at: 2009-06-30 20:23:05
default_dept:
Expand All @@ -135,6 +151,7 @@ user_configs_017:
user_id: "51"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""
user_configs_018:
created_at: 2009-07-10 12:59:25
default_dept:
Expand All @@ -143,3 +160,4 @@ user_configs_018:
user_id: "52"
view_loc_groups: ""
view_week: ""
watched_data_objects: ""

0 comments on commit 4306d92

Please sign in to comment.