view · edit · sidebar · attach · print · history

20110824-search-group-subgroup-migel-drb-client-oddb_org

<< | Index | >>


  1. Simplify Group, Subgroup search link
  2. Update Subgroup view
  3. Update Group view
  4. Fix Home link suspend
  5. Search with '-'
  6. Search Group and Subgroup
  7. Fix Limitation
  8. Simplify Limitation text link

Goal/Estimate/Evaluation
  • Migel drb client in oddb.org / 80% / 80%
Milestones
  1. Simplify Subgroup, Group search link
  2. Search Subgroup, Group, Product name (with '-') (by search button)
  3. Limitation, FB, Email links
Summary
Commits
Keep in Mind
  • How to check the class of DRbObject in drb server side
ToDo
  • Testcases oddb.org, migel

Simplify Group, Subgroup search link

Confirm

Note

  • There are two parts to be updated in the result view of product
    1. snapback link url
    2. links in the description
  • It is not good to update the link urls in ODDB::View::PointerSteps class, because this is a common class to be shared by many other view classes, not only migel product view vl
  • It is better to update src/view/migel/product.rb because the view class is only related to the migel product view
  • PointerSteps class is called from src/view/privatetemplate.rb (ODDB::View::PrivateTemplate) and PrivateTemplate view class is inherited by src/view/migel/product.rb (ODDB::View::Migel::Product class)

Experiment

  • src/view/migel/product.rb
class AccessoryOfList < AccessoryList
  def migel_code(model=@model, session=@session)
    if model.is_a?(DRbObject)
      # Actually, model is a Migel::Model::Product instance.
      model.pharmacode
    else
      super
    end
  end
class PointerSteps < ODDB::View::PointerSteps
  def pointer_descr(model, session=@session)
    event = :migel_search
    link = PointerLink.new(:pointer_descr, model, @session, self)
    if model.is_a?(DRbObject)
      # This is the case where Product instance comes from migel DRb server
      # DRbObject is acutally Migel::Model::Group, Subgroup class. see lib/migel/model/migelid.rb in migel project.
      key = if model.migel_code.length == 2
              :migel_group
            else
              :migel_subgroup
            end
    elsif model.is_a?(ODDB::Migel::Group)
      key = :migel_group
    elsif model.is_a?(ODDB::Migel::Subgroup)
      key = :migel_subgroup
    end
    link.href = @lookandfeel._event_url(event, {key => model.migel_code.delete('.')})
    link
  end
end
class Product < View::PrivateTemplate
  CONTENT = ProductComposite
  SNAPBACK_EVENT = :result
  def backtracking(model, session=@session)
    ODDB::View::Migel::PointerSteps.new(model, @session, self)
  end
end

Access

Result

Next

  • Group and Subgroup links in the description
  • src/view/migel/product.rb
class ProductInnerComposite < HtmlGrid::Composite
  def group(model) 
    pointer_link(model.group, :migel_group)
  end
  def subgroup(model) 
    pointer_link(model.subgroup, :migel_subgroup)
  end
  def pointer_link(model, key)
    link = PointerLink.new(:to_s, model, @session, self)
    link.value = model.send(@session.language)
    event = :migel_search
    link.href = @lookandfeel._event_url(event, {key => model.migel_code.delete('.')})
    link
  end

Access

Result

  • The Group and Subgroup links in the description area are updated as well

Update Subgroup view

  • src/util/oddbapp.rb
    def search_migel_subgroup(migel_code)
      code = migel_code.split(/(\d\d)/).select{|x| !x.empty?}.join('.')
      ret = MIGEL_SERVER.subgroup.find_by_migel_code(code)
      ret
    end
  • lib/migel/model/subgroup.rb
      def structural_ancestors(app)
        [group]
      end
  • src/view/migel/subgroup.rb
class ProductList < HtmlGrid::List
  def migel_code(model)
    unless model.items.empty?
      link = PointerLink.new(:migel_code, model, @session, self)
      event = :migel_search
      key = :migel_code
      link.href = @lookandfeel._event_url(event, {key => model.migel_code.delete('.')})
      link
    else
      model.migel_code
    end
  end

  def description(model)
    link = PointerLink.new(:to_s, model, @session, self)
    text = [
      model,
      (model.product_text if(model.respond_to?(:product_text))),
    ].compact.collect { |item|
      item.send(@session.language)
    }.join(': ').gsub("\n", ' ')
    if(text.size > 60)
      text = text[0,57] << '...'
    end
    link.value = text
    event = :migel_search
    key = :migel_product
    link.href = @lookandfeel._event_url(event, {key => model.migel_code.delete('.')})
    link
  end
class SubgroupInnerComposite < HtmlGrid::Composite
  def pointer_link(model)
    link = PointerLink.new(:to_s, model, @session, self)
    link.value = model.send(@session.language)
    event = :migel_search
    key = :migel_group
    link.href = @lookandfeel._event_url(event, {key => model.migel_code})
    link
  end
# Note: ODDB::View::Migel::PointerSteps is defined in src/view/migel/product.rb
class Subgroup < View::PrivateTemplate
  CONTENT = SubgroupComposite
  SNAPBACK_EVENT = :result
  def backtracking(model, session=@session)
    ODDB::View::Migel::PointerSteps.new(model, @session, self)
  end
end

Access

Result

  • Everything is fine

Next

  • Group view

Update Group view

  • src/view/migel/group.rb
class SubgroupList < HtmlGrid::List
  def migel_code(model=@model, session=@session)
    link = PointerLink.new(:migel_code, model, @session, self)
    event = :migel_search
    key = :migel_subgroup
    link.href = @lookandfeel._event_url(event, {key => model.migel_code.delete('.')})
    link
  end
end

Access

Result

Fix Home link

Problem

Note

  • This 'Home' link appears when oddbd restarts, otherwise it never comes

suspend

Search with '-'

Problem

Experiment

migel> Migel::Model::Migelid.search_by_name('Wegwerf').length
-> 1
migel> Migel::Model::Migelid.search_by_name('Wegwerf-Scheidenpessar').length
-> 1
migel> Migel::Model::Migelid.search_by_name('Wegwerf-Scheidenp').length
-> 1
migel> Migel::Model::Migelid.search_by_name('Scheidenpessar').length
-> 1
migel> Migel::Model::Migelid.search_by_name('Scheidenpes').length
-> 1
migel> Migel::Model::Migelid.search_by_name('WegwerfScheidenpessar').length
-> 0

Experiment

  • src/util/oddbapp.rb
    def search_migel_products(query, lang)
      migel_code = if query =~ /(\d){9}/
                     query.split(/(\d\d)/).select{|x| !x.empty?}.join('.')
                   elsif query =~ /(\d\d\.){4}\d/
                     query
                   end
      if migel_code
         MIGEL_SERVER.migelid.search_by_migel_code(migel_code)
      else
p query.class
p query
         MIGEL_SERVER.migelid.search_by_name(query).concat(
           MIGEL_SERVER.subgroup.search_by_name(query).concat(
             MIGEL_SERVER.group.search_by_name(query)
           )
         )
      end
    end

Access

Result

String
"WegwerfScheidenpessar"

Note

  • ODDB.search_term(query) remove the '-' from the query

Solution

  1. Update server side, z.B. Migel::Model::Migelid.search_by_name
  2. Update client side before calling Migel::Model::Migelid.search_by_name

Experiment (This is a temporary solution)

  • src/state/global.rb
      def search
        zone = @session.zone
        query = @session.persistent_user_input(:search_query)
        if(query.is_a? RuntimeError)
          State::Exception.new(@session, query)
        elsif(!query.nil?)
          if zone == :migel
            query = query.to_s.gsub(//u,'')
          else
            query = ODDB.search_term(query)
          end

Access

Result

  • works

Search Group and Subgroup

  • src/util/oddbapp.rb
    def search_migel_products(query, lang)
      migel_code = if query =~ /(\d){9}/
                     query.split(/(\d\d)/).select{|x| !x.empty?}.join('.')
                   elsif query =~ /(\d\d\.){4}\d/
                     query
                   end
      if migel_code
         MIGEL_SERVER.migelid.search_by_migel_code(migel_code)
      else
         MIGEL_SERVER.subgroup.search_by_name(query)
      end
    end

Access

Result

Log

error in SBSM::Session#process: /de/gcc/search/zone/migel/search_query/Urin-Bettbeutel
NoMethodError
undefined method `subgroup' for #<Migel::Model::Subgroup:0x7fbf84ae5e98>
(druby://localhost:10000) /home/masa/ywesee/oddb.org/src/state/migel/result.rb:33:in `init'
(druby://localhost:10000) /usr/lib64/ruby/1.8/drb/drb.rb:1555:in `call'
(druby://localhost:33000) /usr/lib64/ruby/1.8/drb/invokemethod.rb:10:in `block_yield'
(druby://localhost:33000) /usr/lib64/ruby/1.8/drb/invokemethod.rb:17:in `perform_with_block'
(druby://localhost:33000) /usr/lib64/ruby/1.8/drb/invokemethod.rb:14:in `each'

Note

Experiment

  • src/util/oddbapp.rb
    def search_migel_products(query, lang)
      migel_code = if query =~ /(\d){9}/
                     query.split(/(\d\d)/).select{|x| !x.empty?}.join('.')
                   elsif query =~ /(\d\d\.){4}\d/
                     query
                   end
      if migel_code
         MIGEL_SERVER.migelid.search_by_migel_code(migel_code)
      else
        if group = MIGEL_SERVER.group.search_by_name(query).first
          group.subgroups.collect{|sg| sg.migelids}.flatten
        elsif subgroup = MIGEL_SERVER.subgroup.search_by_name(query).first
          subgroup.migelids
        else
          MIGEL_SERVER.migelid.search_by_name(query)
        end
      end
    end

Access

Result

  • works and looks good
  • But stil Group and Subgroup link is wrong

Experiment

  • src/view/migel/result.rb class List < HtmlGrid::List def product_description(model)
    link = PointerLink.new(:to_s, model, @session, self)
    text = [
      model,
      (model.product_text if(model.respond_to?(:product_text))),
    ].compact.collect { |item|
      item.send(@session.language)
    }.join(': ').gsub("\n", ' ')
    if(text.size > 60)
      text = text[0,57] << '...'
    end
    key = if model.migel_code.length == 2
            :migel_group
          elsif model.migel_code.length == 5
            :migel_subgroup
          else
            :migel_product
          end
    link.href = @lookandfeel._event_url(:migel_search, {key => model.migel_code.gsub(/\./, '')})
    link.value = text
    link
end

Result

  • Everything is fine

Fix Limitation

Problem

  • Now, all the product have 'L' link

Experiment

  • src/view/migel/result.rb
  def limitation_text(model)
    if(sltxt = model.limitation_text and !sltxt.to_s.empty?)
      limitation_link(sltxt)
    else
      ''
    end
  end
  • src/view/additional_information.rb

Result

  • Looks good
  • But I need to simplify the link to limitation text state and view
  • Also I have to update limitaion_link method in src/view/additional_information.rb

Note

  • The cause is Multilingual class
  • The limitation_text of server side object is an instance of Multilingual
  • That is why the condition, sltxt = model.limitation_text, is always true

Simplify Limitation text link

view · edit · sidebar · attach · print · history
Page last modified on August 24, 2011, at 04:47 PM