wontomedia 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +661 -0
- data/COPYING.DOCUMENTATION +450 -0
- data/LICENSE +661 -0
- data/README.markdown +56 -0
- data/Rakefile +185 -0
- data/VERSION.yml +4 -0
- data/app/controllers/admin_controller.rb +144 -0
- data/app/controllers/application_controller.rb +29 -0
- data/app/controllers/connections_controller.rb +150 -0
- data/app/controllers/items_controller.rb +365 -0
- data/app/helpers/connections_helper.rb +67 -0
- data/app/helpers/format_helper.rb +154 -0
- data/app/helpers/items_helper.rb +105 -0
- data/app/models/category_item.rb +23 -0
- data/app/models/connection.rb +210 -0
- data/app/models/individual_item.rb +23 -0
- data/app/models/item.rb +86 -0
- data/app/models/property_item.rb +23 -0
- data/app/models/qualified_item.rb +23 -0
- data/app/views/admin/index.html.erb +74 -0
- data/app/views/connections/_index_outbound_links.html.erb +48 -0
- data/app/views/connections/_spo_select_controls.html.erb +151 -0
- data/app/views/connections/edit.html.erb +70 -0
- data/app/views/connections/index.html.erb +84 -0
- data/app/views/connections/new.html.erb +61 -0
- data/app/views/connections/show.html.erb +110 -0
- data/app/views/items/_active_content.html.erb +26 -0
- data/app/views/items/_content_examples.html.erb +55 -0
- data/app/views/items/_core_tasks.html.erb +23 -0
- data/app/views/items/_form_fields.html.erb +69 -0
- data/app/views/items/_list_outbound_links.html.erb +58 -0
- data/app/views/items/_screen_select.html.erb +24 -0
- data/app/views/items/_show_outbound_links.html.erb +70 -0
- data/app/views/items/_topic_list.html.erb +26 -0
- data/app/views/items/_type_select.html.erb +47 -0
- data/app/views/items/edit.html.erb +63 -0
- data/app/views/items/index.html.erb +74 -0
- data/app/views/items/new.html.erb +124 -0
- data/app/views/items/newpop.html.erb +58 -0
- data/app/views/items/show.html.erb +209 -0
- data/app/views/layouts/_amazon_ads.html.erb +55 -0
- data/app/views/layouts/_glossary_help_box.html.erb +43 -0
- data/app/views/layouts/_google_ads.html.erb +40 -0
- data/app/views/layouts/_language_select.html.erb +24 -0
- data/app/views/layouts/_login_controls.html.erb +24 -0
- data/app/views/layouts/_master_help.html.erb +24 -0
- data/app/views/layouts/_navigation_menu.html.erb +39 -0
- data/app/views/layouts/_search_box.html.erb +27 -0
- data/app/views/layouts/_status_msgs.html.erb +25 -0
- data/app/views/layouts/application.html.erb +67 -0
- data/app/views/layouts/base.html.erb +93 -0
- data/app/views/layouts/home.html.erb +67 -0
- data/app/views/layouts/popup.html.erb +23 -0
- data/assets/wontomedia-sample.rb +47 -0
- data/config/asset_packages.yml +44 -0
- data/config/boot.rb +110 -0
- data/config/cucumber.yml +65 -0
- data/config/database-mysql-development.yml +47 -0
- data/config/database-mysql.yml +26 -0
- data/config/environment.rb +94 -0
- data/config/environments/cucumber.rb +29 -0
- data/config/environments/development.rb +26 -0
- data/config/environments/production.rb +33 -0
- data/config/environments/test.rb +31 -0
- data/config/initializers/inflections.rb +19 -0
- data/config/initializers/mime_types.rb +14 -0
- data/config/initializers/new_rails_defaults.rb +26 -0
- data/config/locales/en.yml +14 -0
- data/config/routes.rb +37 -0
- data/db/fixtures/connections.yml +96 -0
- data/db/fixtures/items.yml +277 -0
- data/db/migrate/20090312212805_create_items.rb +31 -0
- data/db/migrate/20090406221320_create_connections.rb +32 -0
- data/db/migrate/20090411014503_add_type_for_item_subclasses.rb +29 -0
- data/db/migrate/20090415142152_rename_item_type.rb +31 -0
- data/db/migrate/20090518022918_rename_object_and_self.rb +33 -0
- data/db/migrate/20090529171442_add_flags_to_items.rb +27 -0
- data/db/migrate/20090529171508_add_flags_to_connections.rb +27 -0
- data/db/migrate/20090605213800_flags_columns_not_null.rb +29 -0
- data/db/migrate/20090605215028_flags_columns_default_zero.rb +29 -0
- data/db/schema.rb +30 -0
- data/default-custom/app/views/items/_home_extern_list.html.erb +32 -0
- data/default-custom/app/views/items/_home_introductory_text.html.erb +70 -0
- data/default-custom/app/views/items/home.html.erb +77 -0
- data/default-custom/public/images/logo.png +0 -0
- data/default-custom/public/images/logo.svg +74 -0
- data/default-custom/public/stylesheets/wm.css +301 -0
- data/doc/README.markdown +44 -0
- data/doc/README_FOR_APP +82 -0
- data/doc/customization.markdown +93 -0
- data/doc/scripts/rake-customize.markdown +83 -0
- data/lib/helpers/connection_helper.rb +41 -0
- data/lib/helpers/item_helper.rb +141 -0
- data/lib/helpers/tripple_navigation.rb +158 -0
- data/lib/tasks/cucumber.rake +83 -0
- data/lib/tasks/customize.rake +70 -0
- data/lib/tasks/db.rake +65 -0
- data/lib/tasks/javascript_testing_tasks.rake +176 -0
- data/public/404.html +50 -0
- data/public/422.html +50 -0
- data/public/500.html +53 -0
- data/public/dispatch.cgi +20 -0
- data/public/dispatch.fcgi +34 -0
- data/public/dispatch.rb +20 -0
- data/public/favicon.ico +0 -0
- data/public/images/blank_error_icon.png +0 -0
- data/public/images/blank_status_icon.png +0 -0
- data/public/images/error_error_icon.png +0 -0
- data/public/images/error_status_icon.png +0 -0
- data/public/images/good_status_icon.png +0 -0
- data/public/images/help_icon.png +0 -0
- data/public/images/twitter_icon.png +0 -0
- data/public/images/warn_error_icon.png +0 -0
- data/public/images/working_status_icon.gif +0 -0
- data/public/javascripts/application.js +56 -0
- data/public/javascripts/controls.js +963 -0
- data/public/javascripts/dragdrop.js +973 -0
- data/public/javascripts/effects.js +1128 -0
- data/public/javascripts/event.simulate.js +64 -0
- data/public/javascripts/fancybox.js +43 -0
- data/public/javascripts/forConnectionsForms.js +218 -0
- data/public/javascripts/forItemsForms.js +511 -0
- data/public/javascripts/itemCreatePopup.js +115 -0
- data/public/javascripts/itemTitleToName.js +119 -0
- data/public/javascripts/jquery.js +4376 -0
- data/public/javascripts/modalbox.js +502 -0
- data/public/javascripts/prototype.js +4320 -0
- data/public/javascripts/reconcileJQueryAndPrototype.js +19 -0
- data/public/robots.txt +7 -0
- data/public/stylesheets/blank.gif +0 -0
- data/public/stylesheets/fancy_close.png +0 -0
- data/public/stylesheets/fancy_loading.png +0 -0
- data/public/stylesheets/fancy_nav_left.png +0 -0
- data/public/stylesheets/fancy_nav_right.png +0 -0
- data/public/stylesheets/fancy_shadow_e.png +0 -0
- data/public/stylesheets/fancy_shadow_n.png +0 -0
- data/public/stylesheets/fancy_shadow_ne.png +0 -0
- data/public/stylesheets/fancy_shadow_nw.png +0 -0
- data/public/stylesheets/fancy_shadow_s.png +0 -0
- data/public/stylesheets/fancy_shadow_se.png +0 -0
- data/public/stylesheets/fancy_shadow_sw.png +0 -0
- data/public/stylesheets/fancy_shadow_w.png +0 -0
- data/public/stylesheets/fancy_title_left.png +0 -0
- data/public/stylesheets/fancy_title_main.png +0 -0
- data/public/stylesheets/fancy_title_over.png +0 -0
- data/public/stylesheets/fancy_title_right.png +0 -0
- data/public/stylesheets/fancybox.css +333 -0
- data/public/stylesheets/modalbox.css +110 -0
- data/public/stylesheets/scaffold.css +36 -0
- data/public/stylesheets/spinner.gif +0 -0
- data/script/about +4 -0
- data/script/console +3 -0
- data/script/cucumber +10 -0
- data/script/dbconsole +3 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/performance/request +3 -0
- data/script/plugin +3 -0
- data/script/process/inspector +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/vendor/plugins/asset_packager/CHANGELOG +122 -0
- data/vendor/plugins/asset_packager/README +178 -0
- data/vendor/plugins/asset_packager/Rakefile +22 -0
- data/vendor/plugins/asset_packager/about.yml +8 -0
- data/vendor/plugins/asset_packager/init.rb +2 -0
- data/vendor/plugins/asset_packager/install.rb +1 -0
- data/vendor/plugins/asset_packager/lib/jsmin.rb +205 -0
- data/vendor/plugins/asset_packager/lib/synthesis/asset_package.rb +212 -0
- data/vendor/plugins/asset_packager/lib/synthesis/asset_package_helper.rb +39 -0
- data/vendor/plugins/asset_packager/tasks/asset_packager_tasks.rake +23 -0
- data/vendor/plugins/asset_packager/test/asset_package_helper_development_test.rb +100 -0
- data/vendor/plugins/asset_packager/test/asset_package_helper_production_test.rb +140 -0
- data/vendor/plugins/asset_packager/test/asset_packager_test.rb +92 -0
- data/vendor/plugins/asset_packager/test/asset_packages.yml +20 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/application.js +2 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/bar.js +4 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/controls.js +815 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/dragdrop.js +913 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/effects.js +958 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/foo.js +4 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/prototype.js +2006 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/bar.css +16 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/foo.css +16 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/header.css +16 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/screen.css +16 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/subdir/bar.css +16 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/subdir/foo.css +16 -0
- metadata +265 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
#--
|
2
|
+
# WontoMedia - a wontology web application
|
3
|
+
# Copyright (C) 2010 - Glen E. Ivey
|
4
|
+
# www.wontology.com
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License version
|
8
|
+
# 3 as published by the Free Software Foundation.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Affero General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
16
|
+
# along with this program in the file COPYING and/or LICENSE. If not,
|
17
|
+
# see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
|
21
|
+
require Rails.root.join( 'app', 'helpers', 'format_helper' )
|
22
|
+
include(FormatHelper)
|
23
|
+
|
24
|
+
# Helpers for app/views/items/* pages
|
25
|
+
module ItemsHelper
|
26
|
+
|
27
|
+
# This method is called with the _ID_ of an Item and returns markup
|
28
|
+
# showing the +title+ string for that item which will show a
|
29
|
+
# 'tooltip' with the Item's +name+ string on mouse-over. If the
|
30
|
+
# argument Item is the same as the Item for which the current view
|
31
|
+
# is being generated (the output page's "self", <tt>@item</tt>),
|
32
|
+
# then the +title+ will be displayed as simple text. If the
|
33
|
+
# argument Item is different from the page's item, then the +title+
|
34
|
+
# will be displayed as a link to _that_ Item's +show+ page.
|
35
|
+
def self_string_or_other_link(item_id)
|
36
|
+
n = @item_hash[item_id]
|
37
|
+
title = h filter_parenthetical n.title
|
38
|
+
if item_id == @item.id # self
|
39
|
+
text_with_tooltip title, h( n.name )
|
40
|
+
else # other
|
41
|
+
link_with_tooltip title, h( n.name ), item_path(n)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# When called, this helper adds to the current page the
|
46
|
+
# open-<tt><table></tt> tag and table-heading cells for the table of
|
47
|
+
# connection subject-predicate-object Items within the
|
48
|
+
# <tt>app/views/items/show</tt> view.
|
49
|
+
def output_table_open
|
50
|
+
header_style = 'display: block; position: relative;'
|
51
|
+
concat(tag 'table', nil, true) # generate an "open" table tag
|
52
|
+
concat(content_tag( 'thead',
|
53
|
+
content_tag( 'tr',
|
54
|
+
content_tag( 'th', '' ) +
|
55
|
+
content_tag( 'th',
|
56
|
+
content_tag( 'span', '<em>is</em> or <em>has</em>',
|
57
|
+
:style => "#{header_style} left: -3em;" )) +
|
58
|
+
content_tag( 'th',
|
59
|
+
content_tag( 'span', '<em>to</em> or <em>with</em>',
|
60
|
+
:style => "#{header_style} left: -1em;" ))
|
61
|
+
)
|
62
|
+
))
|
63
|
+
end
|
64
|
+
|
65
|
+
# When called, this helper adds to the current page the closing
|
66
|
+
# <tt></table></tt> tag for the table of connection
|
67
|
+
# subject-predicate-object Items within the
|
68
|
+
# <tt>app/views/items/show</tt> view.
|
69
|
+
def output_table_close
|
70
|
+
concat('</table>')
|
71
|
+
end
|
72
|
+
|
73
|
+
# When called, this helper adds to the current page "Edit..." and
|
74
|
+
# "Delete" links if they are appropriate for the Item instance
|
75
|
+
# passed in. Neither link is "appropriate" for Items flagged in the
|
76
|
+
# database as <tt>Item::DATA_IS_UNALTERABLE</tt>. In addition, the
|
77
|
+
# "Delete" link will be output only if there are no existing
|
78
|
+
# connections in the database which reference the +item+ (as
|
79
|
+
# determined by the ItemsController and passed to the view in the
|
80
|
+
# <tt>@not_in_use_hash</tt>).
|
81
|
+
def generate_item_links(item)
|
82
|
+
if (item.flags & Item::DATA_IS_UNALTERABLE) == 0
|
83
|
+
concat(
|
84
|
+
link_with_help_icon({
|
85
|
+
:destination => link_to( 'Edit…', edit_item_path(item),
|
86
|
+
:rel => 'nofollow'),
|
87
|
+
:already_generated => @edit_help_icon_used,
|
88
|
+
:help_alt => 'Help edit item',
|
89
|
+
:which_help => 'ItemEdit' }) )
|
90
|
+
@edit_help_icon_used = true
|
91
|
+
|
92
|
+
if @not_in_use_hash[item.id]
|
93
|
+
concat(
|
94
|
+
link_with_help_icon({
|
95
|
+
:destination => link_to( 'Delete', item_path(item),
|
96
|
+
:rel => 'nofollow', :method => :delete,
|
97
|
+
:confirm => 'Are you sure?'),
|
98
|
+
:already_generated => @delete_help_icon_used,
|
99
|
+
:help_alt => 'Help delete item',
|
100
|
+
:which_help => 'ItemDelete' }) )
|
101
|
+
@delete_help_icon_used = true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#--
|
2
|
+
# WontoMedia - a wontology web application
|
3
|
+
# Copyright (C) 2010 - Glen E. Ivey
|
4
|
+
# www.wontology.com
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License version
|
8
|
+
# 3 as published by the Free Software Foundation.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Affero General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
16
|
+
# along with this program in the file COPYING and/or LICENSE. If not,
|
17
|
+
# see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
|
21
|
+
# This model class is a child of Item using Rails' single-table inheritance.
|
22
|
+
class CategoryItem < Item
|
23
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
#--
|
2
|
+
# WontoMedia - a wontology web application
|
3
|
+
# Copyright (C) 2010 - Glen E. Ivey
|
4
|
+
# www.wontology.com
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License version
|
8
|
+
# 3 as published by the Free Software Foundation.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Affero General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
16
|
+
# along with this program in the file COPYING and/or LICENSE. If not,
|
17
|
+
# see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
|
21
|
+
require Rails.root.join( 'lib', 'helpers', 'item_helper')
|
22
|
+
require Rails.root.join( 'lib', 'helpers', 'tripple_navigation')
|
23
|
+
|
24
|
+
# Model for the representation of "connections" (which are used to
|
25
|
+
# make statements about the relationships between "item") in
|
26
|
+
# WontoMedia's database. The schema listing the data fields for a
|
27
|
+
# Connection is, of course, in db/schema.rb. And Rails'
|
28
|
+
# automatically-provided model methods are based on the field names
|
29
|
+
# there.
|
30
|
+
#
|
31
|
+
# A great deal of this model's behavior is provided by Rails
|
32
|
+
# <tt>belongs_to</tt> relations between Connection object fields and
|
33
|
+
# Item objects (see source).
|
34
|
+
class Connection < ActiveRecord::Base
|
35
|
+
|
36
|
+
# This constant is a bit mask for Item.flags. A non-zero value
|
37
|
+
# indicates that the Item instance should not be user-modifiable.
|
38
|
+
DATA_IS_UNALTERABLE = 1
|
39
|
+
|
40
|
+
|
41
|
+
before_validation :complex_validations
|
42
|
+
# validates_presence_of :subject, :predicate, :obj
|
43
|
+
#explicitly do the equivalent of the above in complex_validations because
|
44
|
+
#c_v has to be a "before" callback (so it's return value is checked), which
|
45
|
+
#means other validations aren't run yet, so can't count on these IDs to
|
46
|
+
#be present/valid. Ugh.
|
47
|
+
# validates_uniqueness_of :subject_id, :scope => [:predicate_id, :obj_id]
|
48
|
+
#this works, but is subsumed by checks in c_v, so eliminated duplication
|
49
|
+
|
50
|
+
belongs_to :subject, :class_name => "Item"
|
51
|
+
belongs_to :predicate, :class_name => "Item"
|
52
|
+
belongs_to :obj, :class_name => "Item"
|
53
|
+
belongs_to :connection_desc, :class_name => "Item"
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# This method is a hack to provide a legitimate default value for
|
58
|
+
# the +flags+ field of an Item that hasn't been initialized yet.
|
59
|
+
# Alternative at http://blog.phusion.nl/2008/10/03/47/
|
60
|
+
def flags #:nodoc:
|
61
|
+
# Note that the default value returned here must/does match the
|
62
|
+
# column default specified in the database schema
|
63
|
+
self[:flags] or 0
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
# This method performs checks to determine whether an individual
|
70
|
+
# Connection, if placed in the context of the rest of WontoMedia's
|
71
|
+
# database, would violate any rules about the structure of the
|
72
|
+
# relationship network. It is automatically invoked using Rails'
|
73
|
+
# <tt>before_validation</tt> hook. In the event that one or more
|
74
|
+
# checks fail, this method returns +false+ and places the
|
75
|
+
# appropriate message(s) in the +errors+ flash.
|
76
|
+
def complex_validations() #:doc:
|
77
|
+
[ [subject_id, :subject], [predicate_id, :predicate],
|
78
|
+
[obj_id, :obj] ].each do |tocheck|
|
79
|
+
field, symbol = *tocheck
|
80
|
+
if field.nil?
|
81
|
+
errors.add symbol, "can't be blank."
|
82
|
+
return false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# is there an existing connection with a predicate that is a
|
87
|
+
# sub-property or super-property of the current predicate?
|
88
|
+
# check for duplicate connection and all super-properties
|
89
|
+
TrippleNavigation.relation_and_all_superproperties(
|
90
|
+
predicate_id) do |super_prop|
|
91
|
+
unless (Connection.all( :conditions => [
|
92
|
+
"subject_id = ? AND predicate_id = ? AND obj_id = ?",
|
93
|
+
subject_id, super_prop, obj_id ] ).empty? )
|
94
|
+
errors.add :subject, 'relationship (or equivalent) already exists.'
|
95
|
+
return false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# check for sub-properties
|
100
|
+
TrippleNavigation.relation_and_all_subproperties(
|
101
|
+
predicate_id) do |sub_prop|
|
102
|
+
unless (Connection.all( :conditions => [
|
103
|
+
"subject_id = ? AND predicate_id = ? AND obj_id = ?",
|
104
|
+
subject_id, sub_prop, obj_id ] ).empty? )
|
105
|
+
errors.add :subject, 'equivalent relationship already exists.'
|
106
|
+
return false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# is there an existing implied opposing connection?
|
112
|
+
# find all connections back-connecting our subject and object, determine
|
113
|
+
# if any of their predicates has an (inherited)
|
114
|
+
# inverse_relationship to current predicate
|
115
|
+
if connections = Connection.all( :conditions => [
|
116
|
+
"subject_id = ? AND obj_id = ?", obj_id, subject_id ] )
|
117
|
+
|
118
|
+
inverse_id = Item.find_by_name("inverse_relationship").id
|
119
|
+
|
120
|
+
connections.each do |e|
|
121
|
+
TrippleNavigation.relation_and_all_superproperties(
|
122
|
+
predicate_id) do |proposed_rel|
|
123
|
+
TrippleNavigation.relation_and_all_superproperties(
|
124
|
+
e.predicate_id) do |existing_rel|
|
125
|
+
if Connection.all( :conditions => [
|
126
|
+
"subject_id = ? AND predicate_id = ? AND obj_id = ?",
|
127
|
+
proposed_rel, inverse_id, existing_rel ] ).length > 0
|
128
|
+
errors.add :subject, 'already has this relationship implied.'
|
129
|
+
return false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
#used in many subsequent tests
|
138
|
+
spo_id = Item.find_by_name("sub_property_of").id
|
139
|
+
|
140
|
+
|
141
|
+
# would this create an "individual parent_of category" relationship?
|
142
|
+
subItem = Item.find(subject_id)
|
143
|
+
objItem = Item.find(obj_id)
|
144
|
+
# check for "individual parent_of category"
|
145
|
+
if subItem.sti_type == ItemHelper::ITEM_INDIVIDUAL_CLASS_NAME &&
|
146
|
+
objItem.sti_type == ItemHelper::ITEM_CATEGORY_CLASS_NAME
|
147
|
+
if TrippleNavigation.check_properties(
|
148
|
+
:does => predicate_id,
|
149
|
+
:inherit_from => Item.find_by_name("parent_of").id,
|
150
|
+
:via => spo_id)
|
151
|
+
errors.add :predicate,
|
152
|
+
'an individual cannot be the parent of a category.'
|
153
|
+
return false
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# check for "category child_of individual"
|
158
|
+
if subItem.sti_type == ItemHelper::ITEM_CATEGORY_CLASS_NAME &&
|
159
|
+
objItem.sti_type == ItemHelper::ITEM_INDIVIDUAL_CLASS_NAME
|
160
|
+
if TrippleNavigation.check_properties(
|
161
|
+
:does => predicate_id,
|
162
|
+
:inherit_from => Item.find_by_name("child_of").id,
|
163
|
+
:via => spo_id)
|
164
|
+
errors.add :predicate,
|
165
|
+
'a category cannot be the child of an individual.'
|
166
|
+
return false
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
# would this create a loop (including connection-to-self) of
|
172
|
+
# hierarchical or ordered relationships?
|
173
|
+
# if this is the kind of property we have to worry about?
|
174
|
+
[
|
175
|
+
Item.find_by_name("parent_of").id,
|
176
|
+
Item.find_by_name("child_of").id,
|
177
|
+
Item.find_by_name("sub_property_of").id,
|
178
|
+
Item.find_by_name("predecessor_of").id,
|
179
|
+
Item.find_by_name("successor_of").id
|
180
|
+
].each do |prop_id|
|
181
|
+
if TrippleNavigation.check_properties(
|
182
|
+
:does => predicate_id, :inherit_from => prop_id, :via => spo_id)
|
183
|
+
if TrippleNavigation.check_properties(
|
184
|
+
:does => obj_id, :link_to => subject_id,
|
185
|
+
:through_children_of => prop_id )
|
186
|
+
errors.add :subject, 'this relationship would create a loop.'
|
187
|
+
return false
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# is this a "bad" connection-to-self?
|
193
|
+
if subject_id == obj_id
|
194
|
+
[ "inverse_relationship", "hierarchical_relationship",
|
195
|
+
"ordered_relationship" ].each do |relation_name|
|
196
|
+
if TrippleNavigation.check_properties(
|
197
|
+
:does => predicate_id,
|
198
|
+
:inherit_from => Item.find_by_name(relation_name).id,
|
199
|
+
:via => spo_id )
|
200
|
+
errors.add :subject,
|
201
|
+
'cannot create an ordered/hierarchical relationship from an item to itself'
|
202
|
+
return false
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
true
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#--
|
2
|
+
# WontoMedia - a wontology web application
|
3
|
+
# Copyright (C) 2010 - Glen E. Ivey
|
4
|
+
# www.wontology.com
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License version
|
8
|
+
# 3 as published by the Free Software Foundation.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Affero General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
16
|
+
# along with this program in the file COPYING and/or LICENSE. If not,
|
17
|
+
# see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
|
21
|
+
# This model class is a child of Item using Rails' single-table inheritance.
|
22
|
+
class IndividualItem < Item
|
23
|
+
end
|
data/app/models/item.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
#--
|
2
|
+
# WontoMedia - a wontology web application
|
3
|
+
# Copyright (C) 2010 - Glen E. Ivey
|
4
|
+
# www.wontology.com
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License version
|
8
|
+
# 3 as published by the Free Software Foundation.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Affero General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
16
|
+
# along with this program in the file COPYING and/or LICENSE. If not,
|
17
|
+
# see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
|
21
|
+
# Model for the representation of "items" (things that can be related
|
22
|
+
# to each other through "connections") in WontoMedia's database. The
|
23
|
+
# schema listing the data fields for an Item is, of course, in
|
24
|
+
# db/schema.rb. And Rails' automatically-provided model methods are
|
25
|
+
# based on the field names there.
|
26
|
+
#
|
27
|
+
# WontoMedia uses Rails' "single-table inheritance" to create several
|
28
|
+
# specialized types of Item objects, all of which are stored in the
|
29
|
+
# same database table together. The type of object a particular table
|
30
|
+
# row represents is determined by that object's <tt>sti_type</tt>
|
31
|
+
# field. There are a number of constants and methods in the module
|
32
|
+
# ItemHelper that can be used load or evaluate +sti_type+ and to
|
33
|
+
# perform generic operations on Item instances that correctly preserve
|
34
|
+
# their child class.
|
35
|
+
#
|
36
|
+
# A great deal of this model's behavior is provided through Rails
|
37
|
+
# validation methods (<tt>validates_...</tt>), see the source for
|
38
|
+
# details.
|
39
|
+
class Item < ActiveRecord::Base
|
40
|
+
|
41
|
+
# This constant is a bit mask for Item.flags. A non-zero value
|
42
|
+
# indicates that the Item instance should not be user-modifiable.
|
43
|
+
DATA_IS_UNALTERABLE = 1
|
44
|
+
|
45
|
+
|
46
|
+
self.inheritance_column = "sti_type"
|
47
|
+
|
48
|
+
# name
|
49
|
+
validates_presence_of :name, :message => "Item's name cannot be blank."
|
50
|
+
validates_length_of :name, :maximum => 80,
|
51
|
+
:message => "Item name must be 80 characters or less."
|
52
|
+
validates_each :name do |record, attr, value|
|
53
|
+
if !(value =~ /^[a-zA-Z][a-zA-Z0-9._:-]*$/m) ||
|
54
|
+
(value =~ /\n/m)
|
55
|
+
record.errors.add attr, "must start with a letter, and can contain only"\
|
56
|
+
"letters, numbers, and/or the period, colon, dash, and underscore."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
validates_uniqueness_of :name, :message =>
|
60
|
+
"There is already a item with the same name."
|
61
|
+
|
62
|
+
# title
|
63
|
+
validates_presence_of :title, :message => "Item's title cannot be blank."
|
64
|
+
validates_length_of :title, :maximum => 255,
|
65
|
+
:message => "Item title must be 255 characters or less."
|
66
|
+
validates_each :title do |record, attr, value|
|
67
|
+
if value =~ /[\n\t]/m
|
68
|
+
record.errors.add attr, "should not be multiple lines."
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
validates_length_of :description, :maximum => 65000,
|
73
|
+
:allow_nil => true, :allow_blank => true,
|
74
|
+
:message => "Item description must be 65,000 characters or less."
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
# This method is a hack to provide a legitimate default value for
|
79
|
+
# the +flags+ field of an Item that hasn't been initialized yet.
|
80
|
+
# Alternative at http://blog.phusion.nl/2008/10/03/47/
|
81
|
+
def flags #:nodoc:
|
82
|
+
# Note that the default value returned here must/does match the
|
83
|
+
# column default specified in the database schema
|
84
|
+
self[:flags] or 0
|
85
|
+
end
|
86
|
+
end
|