view · edit · sidebar · attach · print · history

20110823-alphabetical_search-simplify_url-migel-drb-client-oddb_org

<< | Index | >>


  1. Replace A-Z search function of migel
  2. Product click search
  3. Simplify Product (Migelid) search link
  4. Fix snapback link of Group and Subgroup
  5. Simplify Group, Subgroup search link

Goal/Estimate/Evaluation
  • Migel drb client in oddb.org / 80% / 70%
Milestones
  1. A-Z alphabetical search
  2. show Subgroup, Group
  3. Search Subgroup, Group (by search button)
  4. Limitation, FB, Email link
Summary
Commits
Keep in Mind
  • ODDB::View::PointerSteps#pointer_descr should be updated for the case of DRbObject (Migel)
  • The links of Group and Subgroup in src/view/migel/product.rb also should be updated for DRbObject (Migel)
ToDo
  • Testcases oddb.org, migel

Replace A-Z search function of migel

Note

  • 'direct event' is used for the alphabetical search
  • It seems that the event directly call state class

Solution

  1. Find where the model data for the direct event is
  2. Replace Product class to the remote class
    • SimpleDelegator
    • Forwardable

Reference (Delegate, Forwardable)

Experiment

require 'delegate'

class Test1 < SimpleDelegator
  def initialize(obj)
    super(obj)
  end
  def hello
    #p 'hello'
    hello2
  end
end

class Test2
  def hello2
    p "byebye"
  end
end
test2 = Test2.new
test1 = Test1.new(test2)
test.hello

Result

"byebye"

Note

  • If I use SimpleDelegator class, I should rewrite the existing class, Product class, like hello method above.

Conclusion

  • We take the 1st solution, because we have found the model data for the state class is taken by search_migel_alphabetical method in oddbapp.rb
  • No, the model data is NOT coming from the search_migel_alphabetical method method
  • The model data is set int the load_model method of src/util/interval.rb
  • And the IndexedInterval module is included in src/state/migel/alphabetical.rb

Experiment

  • src/state/migel/alphabetical.rb
  def index_lookup(query)
    if(@session.language == 'en')
      lang = 'de'
    else
      lang = @session.language
    end
    @session.app.search_migel_alphabetical(query, lang)
  end
  • src/util/oddbapp.rb
    def search_migel_alphabetical(query, lang)
      MIGEL_SERVER.migelid.search_by_name(query)
    end

Result

  • Works

Product click search

Problem

  • The product name click search does not work

Note

Solution

  1. Add a new condition for migel product search in the resolve method
  2. Change URL first and create a new event (method) in Global state class

Note

  • The 1st solution directly updates the process, but the resolve method will be more complicated
  • The 2nd solution takes two steps, but the methods in Global state class becomes clear than the 1st solution. Also the URL becomes simpler.

Simplify Product (Migelid) search link

Task

      def migel_search
        if migel_code = @session.user_input(:migel_code) and product = @session.search_migel_products(migel_code).first
          ODDB::State::Migel::Items.new(@session, ODDB::Migel::Items.new(product))
        elsif migel_code = @session.user_input(:migel_product) and product = @session.search_migel_products(migel_code).first
          ODDB::State::Migel::Product.new(@session, product)
        else
          self
        end
      end
  • src/util/validator.rb
  STRINGS = [
...
      :migel_product,
  • lib/migel/model/migelid.rb
    class Migelid < Migel::ModelSuper
      belongs_to :subgroup, delegates(:group)
...
      alias :product_text :migelid_text

Access

Result

Note

  • There is not shown snapback link of Group and Subgroup

Next

  • Change the alphabetical result view for the URL
  • src/view/migel/result.rb#product_description
  def product_description(model)
...
    link.href = @lookandfeel._event_url(:migel_search, {:migel_product => model.migel_code.gsub(/\./, '')})
...
  end

Result

  • Works

Next

  • snapback link

Fix snapback link of Group and Subgroup

Problem

  • The snapback links of Group and Subgroup are not shown

Note

  • The snapback links are created in _compose method of the ODDB::Voew::PointerSteps#compose_list method
  • _compose method is an alias of SBSM::Composite#compose method
  • Actually, compose_component method creates (add) components in the field of snapback link
  • The important part is the part before the compose_list mehthod calling in ODDB::View::PointerSteps#compose_list method
        model = if(model.respond_to? :structural_ancestors)
                  model.structural_ancestors(@session.app)
                elsif(sbm = @session.state.snapback_model)
                  [sbm]
                end || []
        offset = compose_list(model, offset)
  • The model is ODDB::Migel::Product but in the case of connecting to the migel server, this becomes DRbObject(Migel::Model::Migelid)
  • and Migelid instance does not have structural_ancestors method

Experiment

  • lib/migel/model/migelid.rb
      def structural_ancestors(app)
        [group, subgroup]
      end
  • lib/migel/model/group.rb
      def pointer
        'pointer'
      end
  • lib/migel/model/subgroup.rb
      def pointer
        'pointer'
      end
  • lib/migel/model/migelid.rb
      def pointer
        'pointer'
      end
  • src/view/pointersteps.rb#pointer_descr
      def pointer_descr(model, session=@session)
        link = PointerLink.new(:pointer_descr, model, @session, self)
        unless(@session.allowed?('edit', model))
          link.href = if model.pointer.respond_to?(:to_csv) and
                         smart_link_format = model.pointer.to_csv.gsub(/registration/, 'reg').gsub(/sequence/, 'seq').gsub(/package/, 'pack').split(/,/) and
                         smart_link_format.include?('reg')
                        @lookandfeel._event_url(:show, smart_link_format) 
                      else 
                        old_link_format = {:pointer => model.pointer}
                        @lookandfeel._event_url(:show, old_link_format)
                      end
        end
        link
      end

Key Point

  • The :pointer_descr method is used for the snapback link value
  • and :pointer is used for the snapback link url that is described in the pointer_descr method in a view class.
  • In more detail, the link is created ODDB::View::PointerStep#compose method (-> compose_list method -> pointer_descr method)
    • The pointer method of class is used in the pointer_descr method of PointerSteps class

Access

Result

Note

  • But the link still does not work,
  • because the search function of Subgroup and Group is not replaced, yet.

Simplify Group, Subgroup search link

Current (z.B.)

Goal

Experiment

  • src/util/validator.rb
  STRINGS = [
...
      :migel_subgroup,
  • src/state/global.rb#migel_search
      def migel_search
        if migel_code = @session.user_input(:migel_code) and product = @session.search_migel_products(migel_code).first
          ODDB::State::Migel::Items.new(@session, ODDB::Migel::Items.new(product))
        elsif migel_code = @session.user_input(:migel_product) and product = @session.search_migel_products(migel_code).first
          ODDB::State::Migel::Product.new(@session, product)
        elsif migel_code = @session.user_input(:migel_subgroup)
          code = migel_code.split(/(\d\d)/).select{|x| !x.empty?}
          groupcd = code[0]
          subgroupcd = code[1]
          subgroup = @session.app.migel_group(groupcd).subgroup(subgroupcd)
          ODDB::State::Migel::Subgroup.new(@session, subgroup)
        else
          self
        end
      end

Access

Result

Experiment

  • src/util/validator.rb
  STRINGS = [
...
      :migel_group,
  • src/state/global.rb#migel_search
      def migel_search
        if migel_code = @session.user_input(:migel_code) and product = @session.search_migel_products(migel_code).first
          ODDB::State::Migel::Items.new(@session, ODDB::Migel::Items.new(product))
        elsif migel_code = @session.user_input(:migel_product) and product = @session.search_migel_products(migel_code).first
          ODDB::State::Migel::Product.new(@session, product)
        elsif migel_code = @session.user_input(:migel_subgroup)
          code = migel_code.split(/(\d\d)/).select{|x| !x.empty?}
          groupcd = code[0]
          subgroupcd = code[1]
          subgroup = @session.app.migel_group(groupcd).subgroup(subgroupcd)
          ODDB::State::Migel::Subgroup.new(@session, subgroup)
        elsif migel_code = @session.user_input(:migel_group) and group = @session.app.migel_group(migel_code)
          ODDB::State::Migel::Group.new(@session, group)
        else
          self
        end
      end

Access

Result

Refactoring (for Migel DRbObject)

  • src/state/global.rb
      def migel_search
        if migel_code = @session.user_input(:migel_code) and product = @session.search_migel_products(migel_code).first
          ODDB::State::Migel::Items.new(@session, ODDB::Migel::Items.new(product))
        elsif migel_code = @session.user_input(:migel_product) and product = @session.search_migel_products(migel_code).first
          ODDB::State::Migel::Product.new(@session, product)
        elsif migel_code = @session.user_input(:migel_subgroup) and subgroup = @session.app.search_migel_subgroup(migel_code)
          ODDB::State::Migel::Subgroup.new(@session, subgroup)
        elsif migel_code = @session.user_input(:migel_group) and group = @session.app.search_migel_group(migel_code)
          ODDB::State::Migel::Group.new(@session, group)
        else
          self
        end
      end
  • src/util/oddbapp.rb
  def search_migel_subgroup(migel_code)
    if code = migel_code.split(/(\d\d)/).select{|x| !x.empty?} and
       groupcd = code[0] and subgroupcd = code[1]
       migel_group(groupcd).subgroup(subgroupcd)
    end
  end
  def search_migel_group(migel_code)
    migel_group(migel_code)
  end

Access

Result

  • works

Next

  • Update the link of Group and Subgroup
    • ODDB::View::PointerSteps#pointer_descr
    • src/view/migel/product.rb
view · edit · sidebar · attach · print · history
Page last modified on August 24, 2011, at 07:30 AM