Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
447 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,30 @@ | ||
module StuffHelper | ||
def name_and_location(stuff) | ||
s = stuff.name | ||
if stuff.location | ||
s += ' < ' + stuff.hierarchy.map {|l| link_to h(l.name), l}.join(h(' < ')).html_safe | ||
end | ||
if managing? | ||
if stuff.stuff_type == 'stuff' and stuff.home_location and stuff.location != stuff.home_location | ||
s += ' ' + link_to("(return to #{stuff.home_location.name})", log_stuff_path(:stuff_name => stuff.name, :location_name => stuff.home_location.name), :method => :post) | ||
end | ||
end | ||
s | ||
end | ||
|
||
def move_link_to(stuff, location) | ||
if managing? | ||
s = link_to location.name, log_stuff_path(:stuff_name => stuff.name, :location_name => location.name), :method => :post | ||
s += ' (' | ||
s += link_to 'view', location | ||
s += ')' | ||
s | ||
else | ||
link_to location.name, location | ||
end | ||
end | ||
|
||
def location_list(stuff, list) | ||
list.map { |location| move_link_to(stuff, location) }.join(', ').html_safe | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,11 @@ | ||
class Context < ActiveRecord::Base | ||
belongs_to :user | ||
def rules_array | ||
self.rules.split /[\r\n]+/ | ||
end | ||
has_many :context_rules | ||
accepts_nested_attributes_for :context_rules, :allow_destroy => true | ||
validates_presence_of :name | ||
before_save :update_rules | ||
|
||
def stuff_rules | ||
rules = self.rules_array | ||
stuff = Hash.new { |h,k| h[k] = Hash.new } | ||
rules.each do |r| | ||
matches = r.match(/^stuff:[ \t]*([^,]+),[ \t]*(.*)/) | ||
if matches | ||
stuff[matches[1]][:destination] = matches[2] | ||
end | ||
end | ||
stuff_hash = self.user.stuff.includes(:location).where('name in (?)', stuff.keys) | ||
stuff_hash.each do |s| | ||
stuff[s.name][:stuff] = s | ||
stuff[s.name][:in_place] = (s.location and s.location.name == stuff[s.name][:destination]) | ||
end | ||
stuff | ||
def update_rules | ||
self.rules = self.context_rules.includes(:stuff).order('LOWER(stuff.name)').map { |x| x.stuff.name }.join(', ') | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class ContextRule < ActiveRecord::Base | ||
belongs_to :stuff | ||
belongs_to :location, :class_name => 'Stuff' | ||
belongs_to :context | ||
scope :out_of_place, includes(:stuff).where('(stuff.location_id IS NULL OR stuff.location_id != context_rules.location_id)') | ||
scope :in_place, includes(:stuff).where('stuff.location_id = context_rules.location_id') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class LocationHistory < ActiveRecord::Base | ||
belongs_to :user | ||
belongs_to :location, :polymorphic => true | ||
belongs_to :location, :class_name => 'Stuff' | ||
belongs_to :stuff | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.