Changeset 1103

Show
Ignore:
Timestamp:
2008-07-17 22:29:08 (6 months ago)
Author:
gaspard
Message:

Finished links/relation rewrite. Closes #196(4)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/links_controller.rb

    r1048 r1103  
    4747      @node.errors.add('base', 'you do not have the rights to do this') 
    4848    else 
    49       @link_id = params[:link_id] 
     49      @link_id = params.link_id 
    5050      @node.remove_link(@link_id) 
    5151      @node.save 
     
    5757   
    5858  def destroy 
    59     @node.remove_link(@link[:id]
     59    @node.remove_link(@link
    6060    @node.save 
    6161     
  • trunk/app/models/link.rb

    r1101 r1103  
    11class Link < ActiveRecord::Base 
    22  attr_reader :relation 
     3  attr_accessor :start, :side 
    34   
    45  class << self 
    56    def find_through(node, link_id) 
    67      return nil unless link = Link.find(:first, :conditions => ['(source_id = ? OR target_id = ?) AND id = ?', node[:id], node[:id], link_id]) 
    7       link.set_caller(node) 
     8      link.start = node 
     9      node.link  = link 
    810      link 
    911    end 
     
    1113   
    1214  def update_attributes_with_transformations(attrs) 
    13     attributes = attrs.dup 
    14     keys = attributes.keys 
    15     ['role', 'status', 'comment', 'other_zip'].each do |k| 
    16       if keys.include?(k) 
    17         self[k] = attributes[k] = attrs[k].blank? ? nil : attrs[k] 
     15    return false unless @node 
     16     
     17    if attrs['role'] 
     18      # TODO: destroy this link and create a new one ? 
     19    end 
     20     
     21    rel = @node.relation_proxy_from_link(self) 
     22    rel.other_link = self 
     23     
     24    ['status', 'comment'].each do |k| 
     25      rel.send("other_#{k}=", attrs[k]) if attrs.has_key?(k) 
     26      self[k] = attrs[k] 
     27    end 
     28     
     29    if attrs['other_zip'] 
     30      other_id = secure(Node) { Node.translate_pseudo_id(attrs['other_zip']) } 
     31      rel.other_id = other_id 
     32      if @side == :source 
     33        self[:target_id] = other_id 
     34        @target = nil 
    1835      else 
    19         attributes[k] = self[k] 
     36        self[:source_id] = other_id 
     37        @source = nil 
    2038      end 
    2139    end 
    22     debugger 
    23     if attributes['other_zip'] 
    24       other_id = secure(Node) { Node.translate_pseudo_id(attributes['other_zip']) } 
    25     else 
    26       other_id = @other[:id] 
    27     end 
    2840     
    29     # ALL THIS IS BAD. Bad design lead to bad hacky code. PLEASE rewrite links ! 
    30     @node.update_link(attributes['role'], :id => other_id, :status => attributes['status'], :comment => attributes['comment']) 
    3141    @node.save 
    32     if @other == @target 
    33       self[:target_id] = other_id 
    34       self[:id] = Link.find(:first, :conditions => ['target_id = ? AND relation_id = ?', other_id, relation_id])[:id]  
    35       @target = nil 
    36     else 
    37       self[:source_id] = other_id 
    38       self[:id] = Link.find(:first, :conditions => ['source_id = ? AND relation_id = ?', other_id, relation_id])[:id] 
    39       @source = nil 
    40     end 
    41     sync_node 
     42    @node.link = self 
    4243    @errors = @node.errors 
     44    return errors.empty? 
    4345  end 
    4446   
    4547  def target 
    46     @target ||= secure!(Node) { Node.find(target_id) } 
     48    @target ||= begin 
     49      node = secure!(Node) { Node.find(target_id) } 
     50      node.link = self 
     51      node 
     52    end 
    4753  end 
    4854   
    4955  def source 
    50     @source ||= secure!(Node) { Node.find(source_id) } 
     56    @source ||= begin 
     57      node = secure!(Node) { Node.find(source_id) } 
     58      node.link = self 
     59      node 
     60    end 
    5161  end 
    5262   
    53   def set_caller(node) 
     63  def start=(node) 
    5464    @node = node 
    55     @relation    = @node.relation_proxy(:link => self) 
    56     self['role'] = @relation.other_role 
    57     sync_node 
     65    if @node[:id] == self[:source_id] 
     66      @side = :source 
     67      @source = @node 
     68    else 
     69      @side = :target 
     70      @target = @node 
     71    end 
    5872  end 
    5973   
    6074  def other 
    61     @other 
     75    @side == :source ? target : source 
     76  end 
     77   
     78  def this 
     79    @side == :source ? source : target 
    6280  end 
    6381   
    6482  def other_zip 
    65     self['other_zip'
     83    other[:zip
    6684  end 
    6785   
    68   def node_zip 
    69     self['node_zip'
     86  def this_zip 
     87    this[:zip
    7088  end 
    7189   
    72   private 
    73     def sync_node 
    74       if source_id == @node[:id] 
    75         @other = target 
     90  def relation_proxy(node=nil) 
     91    return @relation_proxy if defined?(@relation_proxy) 
     92    rel = RelationProxy.find(self[:relation_id]) 
     93    @node = node if node 
     94    if @node 
     95      if self[:source_id] == @node[:id] 
     96        rel.side = :source 
    7697      else 
    77         @other = source 
     98        rel.side = :target 
    7899      end 
    79       self['node_zip']  = @node[:zip] 
    80       self['other_zip'] = @other.zip 
    81       @other.link  = self # used to get l_status, l_comment after save 
    82       @node.link   = self 
     100      rel.start = @node 
    83101    end 
     102    @relation_proxy = rel 
     103  end 
     104   
     105  def role 
     106    relation_proxy.other_role 
     107  end 
    84108end 
  • trunk/app/models/node.rb

    r1096 r1103  
    603603        false 
    604604      else 
    605         relation = Relation.find_by_role(rel.singularize) 
     605        relation = RelationProxy.find_by_role(rel.singularize) 
    606606        return rel =~ /s$/ unless relation 
    607607        relation.target_role == rel.singularize ? !relation.target_unique : !relation.source_unique 
  • trunk/app/models/relation_proxy.rb

    r1102 r1103  
    11class RelationProxy < Relation 
    2   attr_accessor   :side, :link_errors, :start, :link 
     2  attr_accessor   :side, :link_errors, :start, :other_link 
    33   
    44  class << self 
     
    7171  end 
    7272   
     73  # When a ...-to-many node is loaded and we modify it, focus on this specific node. For example: 
     74  # calendar_status does not make sense (there can be many calendars). But if we focus on a specific 
     75  # calendar, we then get the status for this particular link. 
     76  def other_link=(link) 
     77    return unless link[:relation_id] == self[:id] 
     78    @other_link = link 
     79  end 
     80   
    7381  # get 
    7482   
     
    121129  def other_ids=(v) 
    122130    self.other_id = v 
     131  end 
     132   
     133  def remove_link(link) 
     134    @links_to_delete ||= [] 
     135    @links_to_delete << link 
    123136  end 
    124137   
     
    148161  # 2. can write in new target 
    149162  def attributes_to_update_valid? 
    150     return true unless @attributes_to_update 
    151      
    152     unless @attributes_to_update[:id] 
    153       # try to find current id/ids 
    154       if unique? 
    155         if other_id 
    156           @attributes_to_update[:id] = other_id 
    157         else 
    158           @link_errors = ["Cannot set attributes #{@attributes_to_update.keys.join(', ')} without a target (missing id)."] 
    159         end 
    160       else 
    161         # error: cannot set other attributes (status/comment) on multiple nodes 
    162         @link_errors = ["Cannot set attributes #{@attributes_to_update.keys.join(', ')} in #{as_unique? ? 'one' : 'many'}-to-many relation '#{this_role}'."] 
    163       end 
    164     end 
    165      
    166     if @attributes_to_update[:id].kind_of?(Array)  
    167       if unique? 
    168         @link_errors = ["Cannot set multiple targets on #{as_unique? ? 'one' : 'many'}-to-one relation '#{this_role}'."] 
    169       elsif @attributes_to_update.keys.include?(:status) || @attributes_to_update.keys.include?(:comment) 
    170         keys = @attributes_to_update.keys 
    171         keys.delete(:id) 
    172         @link_errors = ["Cannot set attributes #{keys.join(', ')} on multiple targets."] 
    173       end 
    174     end 
    175      
    176     return false if @link_errors 
     163    debugger if $debbbb 
     164    return true unless @attributes_to_update || @links_to_delete 
     165     
    177166    @link_errors  = [] 
    178167    @add_links    = [] 
     
    180169    @update_links = [] 
    181170     
    182     # 1. find what changed 
    183     if @attributes_to_update[:id].kind_of?(Array) 
    184       # ..-to-many 
    185       # define all links 
     171    if @links_to_delete 
     172      # only removing links 
     173      @del_links = @links_to_delete 
     174      @attributes_to_update = {} 
     175    else 
     176      # check if we have an update/create 
     177      unless @attributes_to_update[:id] 
     178        # try to find current id/ids 
     179        if @other_link 
     180          @attributes_to_update[:id] = @other_link[other_side] 
     181        elsif link_id = @start.link_id 
     182          @other_link = Link.find(link_id) 
     183          @attributes_to_update[:id] = @other_link[other_side] 
     184        elsif unique? 
     185          if other_id 
     186            @attributes_to_update[:id] = other_id 
     187          else 
     188            @link_errors << "invalid target" 
     189          end 
     190        else 
     191          # error: cannot set other attributes (status/comment) on multiple nodes 
     192          @link_errors << "invalid target" 
     193        end 
     194      end 
     195     
     196      if @attributes_to_update[:id].kind_of?(Array)  
     197        if unique? 
     198          @link_errors << "Cannot set multiple targets on #{as_unique? ? 'one' : 'many'}-to-one relation '#{this_role}'." 
     199        elsif @attributes_to_update.has_key?(:status) || @attributes_to_update.has_key?(:comment) 
     200          keys = @attributes_to_update.keys 
     201          keys.delete(:id) 
     202          @link_errors << "Cannot set attributes #{keys.join(', ')} on multiple targets." 
     203        end 
     204      end 
     205     
     206      return false if @link_errors != [] 
     207     
     208      # 1. find what changed 
     209      if @attributes_to_update[:id].kind_of?(Array) 
     210        # ..-to-many 
     211        # define all links 
    186212       
    187       # list of link ids set 
    188       add_link_ids = @attributes_to_update[:id] 
     213        # list of link ids set 
     214        add_link_ids = @attributes_to_update[:id] 
    189215 
    190       # find all current links 
    191       other_links.each do |link| 
    192         obj_id = link[other_side] 
    193         if add_link_ids.include?(obj_id) 
    194           # ignore existing links 
    195           add_link_ids.delete(obj_id) 
     216        # find all current links 
     217        other_links.each do |link| 
     218          obj_id = link[other_side] 
     219          if add_link_ids.include?(obj_id) 
     220            # ignore existing links 
     221            add_link_ids.delete(obj_id) 
     222          else 
     223            # remove unused links 
     224            @del_links << link 
     225          end 
     226        end   
     227        @add_links = add_link_ids.map {|obj_id| Hash[:id,obj_id] } 
     228      elsif unique? 
     229        # ..-to-one 
     230        # define/update link 
     231        if other_id == @attributes_to_update[:id] 
     232          # same target: update 
     233          @update_links << changed_link(other_link, @attributes_to_update) 
    196234        else 
    197           # remove unused links 
    198           @del_links << link 
    199         end 
    200       end   
    201       @add_links = add_link_ids.map {|obj_id| Hash[:id,obj_id] } 
    202     elsif unique? 
    203       # ..-to-one 
    204       # define/update link 
    205       if other_id == @attributes_to_update[:id] 
    206         # same target: update 
    207         @update_links << changed_link(other_link, @attributes_to_update) 
    208       else 
    209         # other target: replace 
    210         @del_links = [other_link] 
    211         @add_links << @attributes_to_update 
    212       end 
    213     else 
    214       # ..-to-many 
    215       # add/update a link 
    216       if other_ids.include?(@attributes_to_update[:id]) 
    217         # update 
    218         if @attributes_to_update.keys.include?(:status) || @attributes_to_update.keys.include?(:comment) 
    219           other_links.each do |link| 
    220             if link[other_side] == @attributes_to_update[:id] 
    221               @update_links << changed_link(link, @attributes_to_update) 
    222               break 
     235          # other target: replace 
     236          @del_links = [other_link] if other_link 
     237          @add_links << @attributes_to_update 
     238        end 
     239      else 
     240        # ..-to-many 
     241        # add/update a link 
     242        if other_ids.include?(@attributes_to_update[:id]) 
     243          # update 
     244          if @attributes_to_update.has_key?(:status) || @attributes_to_update.has_key?(:comment) 
     245            other_links.each do |link| 
     246              if link[other_side] == @attributes_to_update[:id] 
     247                @update_links << changed_link(link, @attributes_to_update) 
     248                break 
     249              end 
    223250            end 
    224251          end 
    225         end 
    226       else 
    227         # add 
    228         @add_links << @attributes_to_update 
    229       end 
    230     end   
     252        else 
     253          # add 
     254          @add_links << @attributes_to_update 
     255        end 
     256      end   
     257    end 
    231258     
    232259    # 2. can write in new target ? (and remove targets previous link) 
     
    243270      end 
    244271    end 
    245      
     272 
    246273    # 1. can remove old link ? 
    247274    @del_links.each do |link| 
     
    255282  end 
    256283   
     284  # Return updated link if changed or nil when nothing changed 
    257285  def changed_link(link, attrs) 
    258286    changed = false 
    259287    [:status, :comment].each do |sym| 
    260       next unless attrs.keys.include?(sym) 
     288      next unless attrs.has_key?(sym) 
    261289      if attrs[sym] != link[sym] 
    262290        changed = true 
     
    280308    end 
    281309    Link.connection.execute "INSERT INTO links (`relation_id`,`#{link_side}`,`#{other_side}`,`status`,`comment`) VALUES #{list.join(',')}" 
    282     remove_instance_variable(:@attributes_to_update) 
     310    @attributes_to_update = nil 
     311    @links_to_delete      = nil 
    283312    remove_instance_variable(:@records)     if defined?(@records) 
    284313    remove_instance_variable(:@record)      if defined?(@record) 
  • trunk/app/views/links/_form.rhtml

    r1048 r1103  
    11<td class='inline_form' colspan='5'> 
    22  <% if @link %> 
    3   <%= form_remote_tag(:url=> node_link_path(:node_id => @link['node_zip'], :id => @link[:id])) %> 
     3  <%= form_remote_tag(:url=> node_link_path(:node_id => @link.this_zip, :id => @link[:id])) %> 
    44  <input type='hidden' name='_method' value ='put'/> 
    55  <% else %> 
     
    1010  <div class='add'> 
    1111    <%=  if @link 
    12       link_to_remote _('btn_x'), :url => node_link_path(:node_id => @link['node_zip'], :id => @link[:id]), :method => :get 
     12      link_to_remote _('btn_x'), :url => node_link_path(:node_id => @link.this_zip, :id => @link[:id]), :method => :get 
    1313    else 
    1414      link_to_function _('btn_x'), "['add_link', 'add_link_form'].each(Element.toggle);" 
     
    2121      roles.unshift ['tag', 'tags'] 
    2222    end -%> 
     23    <% if !@link || @link.new_record? -%> 
    2324    <li> 
    24       <% if !@link || @link.new_record? -%> 
    25       <%= select('link', 'role',  roles, :selected => @link ? @link['role'] : '') %> 
    26       <% else -%> 
    27       <input type='hidden' name='link[role]' value='<%= @link['role'] %>'/> 
    28       <b><%= @link['role'] %></b> 
    29       <% end -%> 
     25      <%= select('link', 'role',  roles, :selected => @link ? @link.role : '') %> 
    3026      <%= select_id('link', 'other_zip') %> 
    3127    </li> 
    32     <li><label for='link_comment'><%= _('status')%></label><%= text_field('link', 'status', :size=>15 ) %></li> 
     28    <% else -%> 
     29    <li> 
     30      <label for='link_role'><%= @link.role %></label> 
     31      <%= select_id('link', 'other_zip') %> 
     32    </li> 
     33    <% end -%> 
     34    <li><label for='link_status'><%= _('status')%></label><%= text_field('link', 'status', :size=>15 ) %></li> 
    3335    <li><label for='link_comment'><%= _('comment')%></label><%= text_field('link', 'comment', :size=>15 ) %></li> 
    3436    <li><input type="submit" class="btn_validate" value='<%= _('set') %>'/></li> 
  • trunk/app/views/links/_li.rhtml

    r980 r1103  
    1 <tr id='link<%= li[:link_id] %>'> 
    2   <td class="box"><%= link_to_remote( relation.other_icon.blank? ? _('img_link') : relation.other_icon, :update=>"link#{li[:link_id]}", :url=>node_edit_link_path(:node_id => @node[:zip], :id => li[:link_id]), :method=>:get) %></td> 
     1<tr id='link<%= li.link_id %>'> 
     2  <td class="box"><%= link_to_remote( relation.other_icon.blank? ? _('img_link') : relation.other_icon, :update=>"link#{li.link_id}", :url=>node_edit_link_path(:node_id => @node[:zip], :id => li.link_id), :method=>:get) %></td> 
    33  <td class="path" ><%= link_to( li.rootpath, zen_path(li), :popup=>true ) %></td> 
    44  <td class="status" ><%= li.l_status %></td> 
    55  <td class="comment" ><%= li.l_comment %></td> 
    6   <td class="actions"> <%= link_to_remote(_('btn_tiny_del'), :url => node_link_path(:node_id => @node[:zip],:id => li[:link_id]), :method => :delete) %> </td> 
     6  <td class="actions"> <%= link_to_remote(_('btn_tiny_del'), :url => node_link_path(:node_id => @node[:zip],:id => li.link_id), :method => :delete) %> </td> 
    77</tr> 
  • trunk/app/views/links/show.rjs

    r1048 r1103  
    11if @node.errors.empty? 
    2   page.replace "link#{params[:id]}", :partial=>'links/li', :collection=>[@link.other], :locals => {:relation => @link.relation
     2  page.replace "link#{params[:id]}", :partial=>'links/li', :collection=>[@link.other], :locals => {:relation => @link.relation_proxy
    33else 
    44  page.replace_html 'link_errors', :inline=> @errors ? render_errors : error_messages_for(@node) 
  • trunk/config/awstats.conf.rhtml

    r1098 r1103  
    554554# Default: "" 
    555555# 
    556 OnlyFiles="REGEX[^\/([^o][^o]\/|[^o].\/|.[^o]\/)]" 
     556OnlyFiles="REGEX[^\/([^o].(\/|$)|.[^o](\/|$))]" 
     557 
    557558 
    558559 
  • trunk/lib/has_relations.rb

    r1102 r1103  
    4747    module InstanceMethods 
    4848       
     49      # status defined through loading link 
     50      def l_status 
     51        val = @link ? @link[:status] : self['l_status'] 
     52        val ? val.to_i : nil 
     53      end 
     54       
     55      # comment defined through loading link 
     56      def l_comment 
     57        @link ? @link[:comment] : self['l_comment'] 
     58      end 
     59       
     60      def link_id 
     61        @link ? @link[:id] : self[:link_id] 
     62      end 
     63       
     64      def link_id=(v) 
     65        if @link && @link[:id].to_i != v.to_i 
     66          @link = nil 
     67        end 
     68        self[:link_id] = v.to_i 
     69        if @link_attributes_to_update 
     70          if rel = relation_proxy_from_link 
     71            @link_attributes_to_update.each do |k,v| 
     72              rel.send("other_#{k}=",v) 
     73            end 
     74          end 
     75        end  
     76      end 
     77       
     78      def add_link(role, hash) 
     79        if rel = relation_proxy(role) 
     80          [:status, :comment, :id].each do |k| 
     81            rel.send("other_#{k}=", hash[k]) if hash.has_key?(k) 
     82          end 
     83        else 
     84          errors.add(role, 'invalid relation') 
     85        end 
     86      end 
     87       
     88      def remove_link(link) 
     89        if link[:source_id] != self[:id] && link[:target_id] != self[:id] 
     90          errors.add('link', "not related to this node") 
     91          return false 
     92        end 
     93        # find proxy 
     94        if rel = relation_proxy_from_link(link) 
     95          rel.remove_link(link) 
     96        else 
     97          errors.add('link', "cannot remove (relation proxy not found).") 
     98        end 
     99      end 
     100       
     101      def l_comment=(v) 
     102        if rel = relation_proxy_from_link 
     103          rel.other_comment = v.blank? ? nil : v 
     104        else 
     105          @l_comment = v.blank? ? nil : v 
     106        end 
     107      end 
     108       
     109      def l_status=(v) 
     110        if rel = relation_proxy_from_link 
     111          rel.other_status = v.blank? ? nil : v 
     112        else 
     113          @l_status = v.blank? ? nil : v 
     114        end 
     115      end 
     116       
    49117      def all_relations 
    50118        @all_relations ||= self.vclass.all_relations(self) 
     
    73141        return @relation_proxies[role] if @relation_proxies.has_key?(role) 
    74142        @relation_proxies[role] = RelationProxy.get_proxy(self, role.singularize.underscore) 
     143      end 
     144       
     145      def relation_proxy_from_link(link = nil) 
     146        unless link 
     147          if @link 
     148            link = @link 
     149          elsif self.link_id 
     150            link = @link = Link.find_through(self, self.link_id) 
     151          end 
     152          return nil unless link 
     153        end 
     154        @relation_proxies ||= {} 
     155        return @relation_proxies[link.role] if @relation_proxies.has_key?(link.role) 
     156        @relation_proxies[link.role] = link.relation_proxy(self) 
     157      end 
     158       
     159      def remove_link(link) 
     160        if link[:source_id] != self[:id] && link[:target_id] != self[:id] 
     161          errors.add('link', "not related to this node") 
     162          return false 
     163        end 
     164        # find proxy 
     165        if rel = relation_proxy_from_link(link) 
     166          rel.remove_link(link) 
     167        else 
     168          errors.add('link', "cannot remove (relation proxy not found).") 
     169        end 
    75170      end 
    76171       
     
    107202                  # not used to set relations (must use 'translate_attributes' to chagen zip into id before call) 
    108203                  raise err 
    109                 when 'id', 'ids', 'zip', 'zips' 
    110                   if field[-1..-1] == 's' 
    111                     # plural 
    112                     raise err if rel.unique? 
    113                   else 
    114                     # singular 
    115                     raise err if !rel.unique? 
    116                   end 
    117                 else 
    118                   # comment, status: must be singular 
    119                   raise err if !rel.unique? 
    120204                end 
    121205                # set value 
     
    123207              else 
    124208                # get 
    125                 case field 
    126                 when 'id', 'ids', 'zip', 'zips' 
    127                   if field[-1..-1] == 's' 
    128                     # plural 
    129                     raise err if rel.unique? 
     209                if field != 'ids' && field != 'zips' && !rel.unique? 
     210                  # ask for a single value in a ..-to-many relation 
     211                  # 1. try to use focus 
     212                  if @link 
     213                    rel.other_link = @link 
     214                  elsif self.link_id 
     215                    @link = Link.find_through(self, self.link_id) 
     216                    rel.other_link = @link 
    130217                  else 
    131                     # singular 
    132                     raise err if !rel.unique? 
     218                    return nil 
    133219                  end 
    134                 else 
    135                   # comment, status: must be singular 
    136                   raise err if !rel.unique? 
    137220                end 
    138221                rel.send("other_#{field}") 
     
    292375      alias update_link set_relation 
    293376       
    294       def remove_link(link_id) 
    295         @relations_to_update ||= [] 
    296         @relations_to_update << [:remove, link_id] 
    297       end 
    298        
    299       def add_link(role, value) 
    300         @relations_to_update ||= [] 
    301         @relations_to_update << [:add, [role, value]] 
    302       end 
     377       
    303378       
    304379      def all_relations 
     
    331406        if role = opts[:role] 
    332407          if opts[:ignore_source] 
    333             rel = Relation.find_by_role(role.singularize.underscore) 
     408            rel = RelationProxy.find_by_role(role.singularize.underscore) 
    334409          else 
    335410            rel = Relation.get_proxy(self, role.singularize.underscore) 
     
    352427      end 
    353428       
    354       # status defined through loading link 
    355       def l_status 
    356         val = @link ? @link[:status] : self['l_status'] 
    357         val ? val.to_i : nil 
    358       end 
    359        
    360       # comment defined through loading link 
    361       def l_comment 
    362         @link ? @link[:comment] : self['l_comment'] 
    363       end 
    364        
    365429      # ALL THIS IS HORRIBLE CODE. NEED MORE TIME TO REWRITE THIS BIG MESS... 
    366       def l_status=(v) 
    367         self[:l_status] = v 
    368         @link_to_update ||= {} 
    369         @link_to_update[:status] = v 
    370       end 
    371        
    372       def l_comment=(v) 
    373         self[:l_comment] = v 
    374         @link_to_update ||= {} 
    375         @link_to_update[:comment] = v 
    376       end 
    377        
    378       def link_id 
    379         @link ? @link[:id] : self[:link_id] 
    380       end 
    381        
    382       def link_id=(v) 
    383         if @link && @link[:id].to_i != v.to_i 
    384           @link = nil 
    385         end 
    386         self[:link_id] = v.to_i 
    387         @link_to_update ||= {} 
    388         @link_to_update[:id] = v.to_i 
    389       end 
     430       
    390431       
    391432      private 
  • trunk/lib/multiversion.rb

    r1097 r1103  
    335335              next 
    336336            end 
    337             current_value = self.send(k) rescue nil # remove rescue when link is fixed 
     337            current_value = self.send(k) rescue nil 
    338338            case current_value.class.to_s 
    339339            when 'NilClass' 
  • trunk/lib/node_query.rb

    r1102 r1103  
    258258        if type == 'RELATION_ID' 
    259259          role = value 
    260           if rel = Relation.find_by_role(role.singularize) 
     260          if rel = RelationProxy.find_by_role(role.singularize) 
    261261            rel[:id] 
    262262          else 
  • trunk/lib/parser/lib/rules/zena.rb

    r1102 r1103  
    101101    def self.zafu_readable?(sym) 
    102102      if sym.to_s =~ /(.*)_zips?$/ 
    103         return true if self.ancestors.include?(Node) && Relation.find_by_role($1.singularize) 
     103        return true if self.ancestors.include?(Node) && RelationProxy.find_by_role($1.singularize) 
    104104      end 
    105105      self.zafu_readable_attributes.include?(sym.to_s) 
     
    18381838          # plural 
    18391839          do_list( build_finder_for(count, method, @params) ) 
     1840        # elsif count == :count 
     1841        #   "<%= #{build_finder_for(count, method, @params)} %>" 
    18401842        else 
    18411843          # singular 
  • trunk/public/stylesheets/popup.css

    r1094 r1103  
    168168 
    169169.inline_form ul { list-style:none; text-align:left;} 
    170 #add_link_form label, #add_link_form select {float:left; width:70px; margin-right:5px;} 
     170#links label, #links select {float:left; width:70px; margin-right:5px;} 
    171171 
    172172 
  • trunk/test/functional/links_controller_test.rb

    r970 r1103  
    1515  def test_create 
    1616    login(:lion) 
    17     node = secure!(Node) { nodes(:people) } 
    18     assert_nil node.find(:first, 'icon') 
    19     post 'create', 'node_id' => nodes_zip(:people), 'link' => {'other_zip' => 'bird', 'role' => 'icon', 'comment' => 'super icon'} 
     17    node = secure!(Node) { nodes(:letter) } 
     18    assert_nil node.find(:first, 'calendar') 
     19    post 'create', 'node_id' => nodes_zip(:letter), 'link' => {'other_zip' => nodes_zip(:zena).to_s, 'role' => 'calendar', 'comment' => 'super icon'} 
    2020    assert_response :success 
    21     node = secure!(Node) { nodes(:people) } 
    22     assert icon = node.find(:first, 'icon') 
    23     assert_equal nodes_id(:bird_jpg), icon[:id] 
    24     assert_equal 'super icon', icon.l_comment 
    25     assert_nil icon.l_status 
     21    node = assigns(:node) 
     22    puts node.errors.inspect 
     23    node = secure!(Node) { nodes(:letter) } 
     24    assert calendar = node.find(:first, 'calendar') 
     25    assert_equal nodes_id(:zena), calendar[:id] 
     26    assert_equal 'super icon', calendar.l_comment 
     27    assert_nil calendar.l_status 
     28  end 
     29   
     30  def test_show 
     31    login(:lion) 
     32    get 'show', 'id'=>links_id(:opening_in_art), 'node_id'=>nodes_zip(:art) 
     33    assert_response :success 
    2634  end 
    2735end 
  • trunk/test/helpers/node_query_test.rb

    r1042 r1103  
    4444     
    4545  end 
     46   
     47  def test_find_new_record 
     48    login(:tiger) 
     49    node = secure!(Node) { Node.new } 
     50    assert_equal nil, node.find(:all,'set_tags') 
     51    node = secure!(Node) { Node.get_class('Tag').new_instance } 
     52    assert_equal nil, node.find(:all,'tagged') 
     53  end 
     54   
     55  def test_do_find_in_new_node 
     56    login(:tiger) 
     57    assert var1_new = secure!(Node) { Node.get_class("Post").new } 
     58    assert_nil var1_new.do_find(:all, eval("\"#{Node.build_find(:all, 'posts in site', :node_name => 'self')}\"")) 
     59  end 
     60   
     61  def test_link_id 
     62    login(:tiger) 
     63    page = secure!(Node) { nodes(:cleanWater) } 
     64    pages = page.find(:all, 'pages') 
     65    assert_nil pages[0].link_id 
     66    tags  = page.find(:all, 'set_tags') 
     67    assert_equal [links_id(:cleanWater_in_art).to_s], tags.map{|r| r.link_id} 
     68  end 
     69   
     70  def test_do_find_bad_relation 
     71    login(:lion) 
     72    node = secure!(Node) { nodes(:status) } 
     73    assert_nil node.find(:first, 'blah') 
     74  end 
     75   
     76  def test_l_status 
     77    login(:lion) 
     78    node = secure!(Node) { nodes(:art) } 
     79    tagged = node.find(:all, 'tagged') 
     80    # cleanWater, opening 
     81    assert_equal [10, 5], tagged.map{|t| t.l_status} 
     82  end 
     83   
     84  def test_l_comment 
     85    login(:lion) 
     86    node = secure!(Node) { nodes(:opening) } 
     87    tagged = node.find(:all, 'set_tags') 
     88    # art, news 
     89    assert_equal ["cold", "hot"], tagged.map{|t| t.l_comment} 
     90  end 
     91   
     92  def test_l_comment_empty 
     93    login(:lion) 
     94    node = secure!(Node) { nodes(:art) } 
     95    tagged = node.find(:all, 'tagged') 
     96    # cleanWater, opening 
     97    assert_equal [nil, "cold"], tagged.map{|t| t.l_comment} 
     98  end 
    4699 
    47100  make_tests 
  • trunk/test/unit/link_test.rb

    r1048 r1103  
    66    node = secure!(Node) { nodes(:cleanWater) } 
    77    link = Link.find_through(node, links_id(:status_hot_for_cleanWater)) 
    8     assert_equal 'hot', link['role'] 
     8    assert_equal 'hot', link.role 
    99  end 
    1010   
     
    1515    link = Link.find_through(node, links_id(:status_hot_for_cleanWater)) 
    1616    link.update_attributes_with_transformations('role' => 'hot', 'other_zip' => nodes_zip(:lake), 'comment' => 'pop') 
    17     assert_equal 'hot', link['role'] 
    18     assert_equal nodes_zip(:lake), link['other_zip'] 
    19     # change propagated to caller node. Yes, this is ugly, please rewrite... 
     17    assert_equal 'hot', link.role 
     18    assert_equal nodes_zip(:lake), link.other_zip 
     19    # change propagated to caller node. 
    2020    assert_equal 'pop', node.l_comment 
    2121    node = secure!(Node) { nodes(:cleanWater) } 
     
    2727    node = secure!(Node) { nodes(:zena) } 
    2828    assert link = Link.find_through(node, links_id(:opening_in_zena)) 
    29     assert_equal nodes_zip(:zena), link['node_zip'] 
    30     assert_equal nodes_zip(:opening), link['other_zip'] 
     29    assert_equal nodes_zip(:zena), link.this_zip 
     30    assert_equal nodes_zip(:opening), link.other_zip 
    3131  end 
    3232end 
  • trunk/test/unit/node_test.rb

    r1094 r1103  
    13011301  end 
    13021302   
     1303  def test_translate_pseudo_id 
     1304    login(:lion) 
     1305    { '11'                        => nodes_id(:zena),  
     1306      'bird'                      => nodes_id(:bird_jpg),  
     1307      nodes_zip(:cleanWater).to_i => nodes_id(:cleanWater), 
     1308      nodes_zip(:status)          => nodes_id(:status), 
     1309      'statu'                     => nodes_id(:status), 
     1310    }.each do |k,v| 
     1311      assert_equal v, secure(Node) { Node.translate_pseudo_id(k) }, "'#{k}' should translate to '#{v}'" 
     1312    end 
     1313  end 
     1314   
    13031315  # FIXME: write test 
    13041316  def test_assets 
  • trunk/test/unit/relation_proxy_test.rb

    r1102 r1103  
    123123  end 
    124124   
    125   def test_destroy_links 
     125  def test_remove_link 
    126126    login(:tiger) 
    127127    node = secure!(Node) { nodes(:cleanWater) } 
    128128    assert_equal nodes_id(:art), node.find(:first, 'set_tags')[:id] 
    129     assert node.remove_link(links_id(:cleanWater_in_art)) 
     129    assert node.remove_link(links(:cleanWater_in_art)) 
    130130    assert node.save 
    131131    assert_nil node.find(:first, 'set_tags') 
    132132  end 
    133133   
    134   def test_relation_new_record 
    135     login(:tiger) 
    136     node = secure!(Node) { Node.new } 
    137     assert_equal nil, node.find(:all,'set_tags') 
    138     node = secure!(Node) { Node.get_class('Tag').new_instance } 
    139     assert_equal nil, node.find(:all,'tagged') 
    140   end 
    141  
    142   def test_link_id 
    143     login(:tiger) 
    144     page = secure!(Node) { nodes(:cleanWater) } 
    145     pages = page.find(:all, 'pages') 
    146     assert_nil pages[0][:link_id] 
    147     tags  = page.find(:all, 'set_tags') 
    148     assert_equal [links_id(:cleanWater_in_art).to_s], tags.map{|r| r[:link_id]} 
    149   end 
    150    
    151   def test_do_find_in_new_node 
    152     login(:tiger) 
    153     assert var1_new = secure!(Node) { Node.get_class("Post").new } 
    154     assert_nil var1_new.do_find(:all, eval("\"#{Node.build_find(:all, 'posts in site', :node_name => 'self')}\"")) 
    155   end 
    156    
    157134  def test_update_attributes_empty_value 
    158135    login(:lion) 
     
    161138  end 
    162139   
    163   def test_do_find_bad_relation 
    164     login(:lion) 
    165     node = secure!(Node) { nodes(:status) } 
    166     assert_nil node.find(:first, 'blah') 
    167   end 
    168    
    169   def test_l_status 
    170     login(:lion) 
    171     node = secure!(Node) { nodes(:art) } 
    172     tagged = node.find(:all, 'tagged') 
    173     # cleanWater, opening 
    174     assert_equal [10, 5], tagged.map{|t| t.l_status} 
    175   end 
    176    
    177   def test_l