Diff
Modified: trunk/app/controllers/relationships_controller.rb (2601 => 2602)
--- trunk/app/controllers/relationships_controller.rb 2011-06-03 16:56:27 UTC (rev 2601)
+++ trunk/app/controllers/relationships_controller.rb 2011-06-03 16:56:47 UTC (rev 2602)
@@ -13,13 +13,11 @@
# GET /:context_type/:context_id/edit_relationships
def edit_relationships
- @relationships = Relationship.find(:all, :conditions => ['pack_id = ?', @context.id])
+ @predicates = Ontology.find(:all).map do |o| o.predicates end.flatten
- @concepts = Vocabulary.find(:all).map do |v| v.concepts end.flatten
-
@pack_entries = @context.contributable_entries + @context.remote_entries
- @pack_entry_select_options = @pack_entries.map do |pe|
+ @select_options = @pack_entries.map do |pe|
if pe.class == PackContributableEntry
[pe.contributable.label, "contributable:#{pe.id}"]
else
@@ -34,17 +32,15 @@
subject = @context.find_pack_item(params[:subject])
objekt = @context.find_pack_item(params[:objekt])
- prefix, term = params[:predicate].split(":")
+ prefix, title = params[:predicate].split(":")
- label = Label.find(:first, :conditions =>
- ['label_type = ? AND vocabulary_id = ? AND text = ?',
- 'preferred',
- Vocabulary.find_by_prefix(prefix).id,
- term])
+ predicate = Predicate.find(:first, :conditions =>
+ [' AND title = ?',
+ Ontology.find_by_prefix(prefix).id, title])
- raise("Invalid form data") if subject.nil? || objekt.nil? || label.nil?
+ raise("Invalid form data") if subject.nil? || objekt.nil? || predicate.nil?
- @relationship = Relationship.new(:pack => @context, :concept => label.concept, :user => current_user)
+ @relationship = Relationship.new(:context => @context, :predicate => predicate, :user => current_user)
@relationship.subject = subject
@relationship.objekt = objekt
@@ -62,7 +58,7 @@
end
render :partial => "relationships/relationships",
- :locals => { :relationships => @context.relationships }
+ :locals => { :context => @context, :show_delete => true }
end
private
@@ -72,7 +68,7 @@
@context = extract_resource_context(params)
@relationship = Relationship.find_by_id(params[:id])
- return false if @relationship.nil? || @context.nil? || @relationship.pack != @context
+ return false if @relationship.nil? || @context.nil? || @relationship.context != @context
return false if Authorization.is_authorized?('view', nil, @context, current_user) == false
end
Modified: trunk/app/models/relationship.rb (2601 => 2602)
--- trunk/app/models/relationship.rb 2011-06-03 16:56:27 UTC (rev 2601)
+++ trunk/app/models/relationship.rb 2011-06-03 16:56:47 UTC (rev 2602)
@@ -7,7 +7,7 @@
acts_as_structured_data
- validates_uniqueness_of :concept_id, :scope => [:subject_id, :objekt_id]
+ validates_uniqueness_of :predicate_id, :scope => [:subject_id, :objekt_id]
end
Modified: trunk/app/views/relationships/_relationships.rhtml (2601 => 2602)
--- trunk/app/views/relationships/_relationships.rhtml 2011-06-03 16:56:27 UTC (rev 2601)
+++ trunk/app/views/relationships/_relationships.rhtml 2011-06-03 16:56:47 UTC (rev 2602)
@@ -1,9 +1,9 @@
-<% can_edit = Authorization.check(:action ="" 'edit', :object => pack, :user => current_user) %>
-<% relationships = pack.relationships %>
+<% can_edit = Authorization.check(:action ="" 'edit', :object => context, :user => current_user) %>
+<% relationships = context.relationships %>
<% if relationships.empty? %>
- <p><i>There are no relationships in this pack.</i></p>
+ <p><i>There are no relationships.</i></p>
<% else %>
@@ -12,10 +12,10 @@
<li>
<%= pack_entry_link(relationship.subject) -%>
- <% if relationship.concept.phrase %>
- <%=h relationship.concept.phrase -%>
+ <% if relationship.predicate.phrase %>
+ <%=h relationship.predicate.phrase -%>
<% else %>
- <%=h relationship.concept.preferred_label.text.underscore.humanize.downcase -%>
+ <%=h relationship.predicate.preferred_label.text.underscore.humanize.downcase -%>
<% end %>
<%= pack_entry_link(relationship.objekt) -%>.
@@ -23,7 +23,7 @@
<% if can_edit && defined?(show_delete) && show_delete %>
<%= link_to_remote("<img src='' />",
:update => "relationshipsElement",
- :url ="" pack_relationship_path(relationship.pack, relationship.id),
+ :url ="" pack_relationship_path(relationship.context, relationship.id),
:method => :delete,
:complete => "new Effect.Highlight('relationshipsElement', { duration: 1.5 });",
:confirm => "Are you sure you want to delete this relationship?" ) %>
Modified: trunk/app/views/relationships/edit_relationships.rhtml (2601 => 2602)
--- trunk/app/views/relationships/edit_relationships.rhtml 2011-06-03 16:56:27 UTC (rev 2601)
+++ trunk/app/views/relationships/edit_relationships.rhtml 2011-06-03 16:56:47 UTC (rev 2602)
@@ -8,20 +8,20 @@
<h2>Add new relationship</h2>
-<% if @pack_entry_select_options.length < 2 %>
+<% if @select_options.length < 2 %>
- <p><i>There must be at least two entries in a pack before you can add relationships.</i></p>
+ <p><i>There must be at least two entries before you can add relationships.</i></p>
<% else %>
<% form_tag("#{rest_resource_uri(@context)}/relationships") do -%>
<div class="edit_relationships">
- <%= select_tag("subject", options_for_select(@pack_entry_select_options)) -%>
+ <%= select_tag("subject", options_for_select(@select_options)) -%>
- <%= select_tag("predicate", options_for_select(@concepts.map do |c| [c.phrase, "#{c.vocabulary.prefix}:#{c.preferred_labels.first.text}"] end)) -%>
+ <%= select_tag("predicate", options_for_select(@predicates.map do |p| [p.phrase, "#{p.ontology.prefix}:#{p.title}"] end)) -%>
- <%= select_tag("objekt", options_for_select(@pack_entry_select_options)) -%>
+ <%= select_tag("objekt", options_for_select(@select_options)) -%>
<input type="submit" value="Add relationship"/>
@@ -34,12 +34,12 @@
<h2>Relationships</h2>
<div id="relationshipsElement">
- <%= render(:partial => "relationships", :locals => { :pack => @context, :show_delete => true }) -%>
+ <%= render(:partial => "relationships", :locals => { :context => @context, :show_delete => true }) -%>
</div>
<p style="text-align: center">
<form action="" pack_path(@context) -%>" method="get">
- <input type="submit" value="Back to pack" />
+ <input type="submit" value="Back" />
</form>
</p>
Modified: trunk/config/schema.d/packs.xml (2601 => 2602)
--- trunk/config/schema.d/packs.xml 2011-06-03 16:56:27 UTC (rev 2601)
+++ trunk/config/schema.d/packs.xml 2011-06-03 16:56:47 UTC (rev 2602)
@@ -11,7 +11,7 @@
<column type="datetime" name="created_at"/>
<column type="datetime" name="updated_at"/>
- <has-many target="relationships" dependent="destroy"/>
+ <has-many target="relationships" as="context" dependent="destroy"/>
</table>
@@ -43,22 +43,23 @@
<table name="relationships">
- <column type="integer" name="pack_id"/>
+ <column type="integer" name="context_id"/>
+ <column type="string" name="context_type"/>
<column type="integer" name="user_id"/>
- <column type="integer" name="concept_id"/>
+ <column type="integer" name="predicate_id"/>
<column type="string" name="subject_type"/>
<column type="integer" name="subject_id"/>
<column type="string" name="objekt_type"/>
<column type="integer" name="objekt_id"/>
<column type="datetime" name="created_at"/>
+ <belongs-to target="users"/>
+ <belongs-to target="contexts" polymorphic="true"/>
+
<belongs-to target="subjects" polymorphic="true"/>
+ <belongs-to target="predicates"/>
<belongs-to target="objekts" polymorphic="true"/>
- <belongs-to target="packs"/>
- <belongs-to target="users"/>
- <belongs-to target="concepts"/>
-
</table>
</schema>