|
From: <fu...@us...> - 2003-12-23 14:59:16
|
Update of /cvsroot/neelix/neelix/model
In directory sc8-pr-cvs1:/tmp/cvs-serv18551/model
Modified Files:
model.rb
Log Message:
presenter - only whitespace.
model - mucked around with Replicator
view - Added a menu. The Add Cookbook option in the Action menu works, the other Action menu items need to be done. Then we need to add delete cookbook/category/recipe menu items.
Index: model.rb
===================================================================
RCS file: /cvsroot/neelix/neelix/model/model.rb,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- model.rb 23 Dec 2003 02:45:53 -0000 1.8
+++ model.rb 23 Dec 2003 14:59:12 -0000 1.9
@@ -388,12 +388,12 @@
class Replicator
include Singleton
- attr_accessor :shelf
+ attr_reader :cookbooks, :measures, :foods
def initialize()
@dbh = nil
@hash = Hash.new
- @shelf = Array.new
+
end
def check_dbh
@@ -403,6 +403,21 @@
def attach(dbh)
@dbh = dbh
@hash = Hash.new
+
+ @cookbooks = ObservableArray.new
+ @dbh.select_all('select cookbook_id from cookbook').each do |row|
+ @cookbooks << get('cookbook', row['cookbook_id'])
+ end
+
+ @measures = ObservableArray.new
+ @dbh.select_all("select measure_id from measure").each do |row|
+ @measures << get('measure', row['measure_id'])
+ end
+
+ @foods = ObservableArray.new
+ @dbh.select_all("select food_id from food").each do |row|
+ @foods << get('food', row['food_id'])
+ end
end
def get(type,id)
@@ -449,53 +464,42 @@
end
end
- def measure_list
- measures = Array.new
- @dbh.select_all("select measure_id from measure").each do |row|
- measures << get('measure', row['measure_id'])
- end
- measures
- end
-
+ # should this be a presenter function? If it were, we couldn't make use of SQL...
def find_food(name)
row = @dbh.select_one("select food_id from food where name=?", name)
return get('food', row['food_id']) unless row.nil?
nil
end
- def shelf
- check_dbh
-
- cookbooks = Array.new
- @dbh.select_all('select cookbook_id from cookbook').each do |row|
- cookbooks << get('cookbook', row['cookbook_id'])
- end
- return cookbooks
- end
-
def create(type,values)
check_dbh
case type
when 'cookbook'
- @dbh.do('insert into cookbook (cookbook_id) values (NULL)')
+ @dbh.do('insert into cookbook (cookbook_id,name) values (NULL,?)',
+ values['name'])
@dbh.commit
id = @dbh.select_one('select max(cookbook_id) from cookbook')[0].to_i
@hash['cookbook'] = Hash.new if @hash['cookbook'].nil?
- return @hash['cookbook'][id] = Cookbook.new(@dbh, id)
+ @hash['cookbook'][id] = Cookbook.new(@dbh, id)
+ @cookbooks << @hash['cookbook'][id]
+ return @hash['cookbook'][id]
when 'category'
- @dbh.do('insert into category (cookbook_id) values (?)',
- values['cookbook_id'])
+ @dbh.do('insert into category (cookbook_id,name) values (?,?)',
+ values['cookbook_id'], values['name'])
@dbh.commit
id = @dbh.select_one('select max(category_id) from category')[0].to_i
@hash['category'] = Hash.new if @hash['category'].nil?
- return @hash['category'][id] = Category.new(@dbh, id)
+ c = @hash['category'][id] = Category.new(@dbh, id)
+ @hash['cookbook'][values['cookbook_id']].categories << c
+ return c
when 'recipe'
- @dbh.do('insert into recipe (recipe_id) values (NULL)')
+ @dbh.do('insert into recipe (recipe_id,name) values (NULL,?)',
+ values['name'])
@dbh.commit
id = @dbh.select_one('select max(recipe_id) from recipe')[0].to_i
@@ -517,7 +521,9 @@
id = @dbh.select_one('select max(ingredient_id) from ingredient')[0].to_i
@hash['ingredient'] = Hash.new if @hash['ingredient'].nil?
- return @hash['ingredient'][id] = Ingredient.new(@dbh, id)
+ i = @hash['ingredient'][id] = Ingredient.new(@dbh, id)
+ @hash['recipe'][values['recipe_id']].ingredients << i
+ return i
when 'food'
@dbh.do('insert into food (name) values (?)', values['name'])
@@ -525,7 +531,9 @@
id = @dbh.select_one('select max(food_id) from food')[0].to_i
@hash['food'] = Hash.new if @hash['food'].nil?
- return @hash['food'][id] = Food.new(@dbh, id)
+ f = @hash['food'][id] = Food.new(@dbh, id)
+ @foods << f
+ return f
when 'measure'
@dbh.do('insert into measure (measure_id) values (NULL)')
@@ -533,7 +541,9 @@
id = @dbh.select_one('select max(measure_id) from measure')[0].to_i
@hash['measure'] = Hash.new if @hash['measure'].nil?
- return @hash['measure'][id] = Measure.new(@dbh, id)
+ m = @hash['measure'][id] = Measure.new(@dbh, id)
+ @measures << m
+ return m
else raise "Invalid Record Type"
end
|