view · edit · sidebar · attach · print · history

20110805-url-format-oddb_org

<< | Index | >>


  1. Replace all the link URL format, registration, sequence, and package
  2. Update testcases for new link format

Goal/Estimate/Evaluation
  • Change URL format oddb.org / 100% / 90%
Milestones
Summary
Commits

Replace all the link URL format, registration, sequence, and package

Task

Experiment

      def compositions(model, session=@session)
        link = HtmlGrid::Link.new(:show, model, session, self)
        #link.href = @lookandfeel._event_url(:show, {:pointer => model.pointer})
        list = model.pointer.to_s.gsub(/\./,'').split(/!/).delete_if{|v| v == ":"}.map{|i| i.split(",")}.flatten
        nrs  = Hash[*list]
        iksnr = nrs['registration']
        seqnr = nrs['sequence']
        ikscd = nrs['package']
        smart_link = if iksnr && seqnr && ikscd
                       ['reg', iksnr, 'seq', seqnr, 'pack', ikscd]
                     elsif iksnr && seqnr
                       ['reg', iksnr, 'seq', seqnr]
                     elsif iksnr
                       ['reg', iksnr]
                     end
        if smart_link
          link.href = @lookandfeel._event_url(:show, smart_link)
        else     
          link.href = @lookandfeel._event_url(:show, {:pointer => model.pointer})
        end

Run

  • bin/currencyd
  • bin/yusd
  • bin/oddbd

Result

  • success

Note

  • It is no problem even if the second argument of _event_url method is Array, not Hash
  • It would be nice rather than Hash, because the order of (key, value) sets can be specified
  • The URL format in the sequence view from the show result is still in the old format

Refactoring

  • src/util/persistence.rb#to_csv
    class Pointer
      def to_csv
        @directions.collect { |orig|
          step = orig.collect { |arg|
            if(arg.is_a? Pointer)
              arg
            else
              arg.to_s.gsub('%','%%').gsub(/[:!,.]/u, '%\0')
            end
          }
          step.join(',')
        }.join(',')
      end
    end
      def compositions(model, session=@session)
        link = HtmlGrid::Link.new(:show, model, session, self)
        link.href = @lookandfeel._event_url(:show, {:pointer => model.pointer})
        smart_link = model.pointer.to_csv.gsub(/registration/, 'reg').gsub(/sequence/, 'seq').gsub(/package/, 'pack').split(/,/)
        if smart_link.include?('reg')
          link.href = @lookandfeel._event_url(:show, smart_link)
        else # This is an old format by using the default pointer format
          link.href = @lookandfeel._event_url(:show, {:pointer => model.pointer})
        end

Result

  • success

Next

  • The URL link from the registration and sequence views

Experiment

    if(@session.allowed?('edit', 'org.oddb.drugs'))
      PointerLink.new(:ikscd, model, @session, self)
    else
      evt = @session.state.respond_to?(:suggest_choose) ? :suggest_choose : :show
      link = HtmlGrid::Link.new(:ikscd, model, @session, self)
      link.value = model.ikscd
      #args = {:pointer => model.pointer}
      #link.href = @lookandfeel.event_url(evt, args)
      smart_link = model.pointer.to_csv.gsub(/registration/, 'reg').gsub(/sequence/, 'seq').gsub(/package/, 'pack').split(/,/)
      if evt == :show and smart_link.include?('reg')
        link.href = @lookandfeel.event_url(evt, smart_link)
      else
        link.href = @lookandfeel.event_url(evt, {:pointer => model.pointer})
      end
      link
    end
   end

Result

  • success
  • but the URL format from the registration view is still in old format

Note

  • This is the admin view but the method is used when I am not logged-in
  • '@lookandfeel.event_url' inserts 'state_id'

Experiment

  • src/view/admin/registration.rb#seqnr def seqnr(model, session=@session)
    if(@session.allowed?('edit', model))
      PointerLink.new(:seqnr, model, @session, self)
    else
      evt = @session.state.respond_to?(:suggest_choose) ? :suggest_choose : :show
      link = HtmlGrid::Link.new(:seqnr, model, @session, self)
      #args = {:pointer => model.pointer}
      #link.href = @lookandfeel.event_url(evt, args)
      smart_link_format = model.pointer.to_csv.gsub(/registration/, 'reg').gsub(/sequence/, 'seq').gsub(/package/, 'pack').split(/,/)
      if evt == :show and smart_link_format.include?('reg')
        link.href = @lookandfeel.event_url(evt, smart_link_format)
      else
        old_link_format = {:pointer => model.pointer}
        link.href = @lookandfeel.event_url(evt, old_link_format)
      end
      link.value = model.seqnr
      link
    end
   end

Result

  • success

Next

  • Testcases

Update testcases for new link format

git status

#       modified:   src/state/global.rb
#       modified:   src/util/persistence.rb
#       modified:   src/util/validator.rb
#       modified:   src/view/additional_information.rb
#       modified:   src/view/admin/registration.rb
#       modified:   src/view/admin/sequence.rb
#       modified:   src/view/pointersteps.rb
#       modified:   src/view/pointervalue.rb

One by one

  1. src/state/global.rb (coverage: 99.74%, 110 tests, 114 assertions, 0 failures, 0 errors)
  2. src/util/persistence.rb (coverage: 85.13%, 40 tests, 72 assertions, 0 failures, 0 errors)
  3. src/util/validator.rb (coverage: 99.10%, 39 tests, 65 assertions, 0 failures, 0 errors)
  4. src/view/pointersteps.rb (coverage: 100%, 9 tests, 9 assertions, 0 failures, 0 errors)
  5. src/view/pointervalue.rb (coverage: 100%, 7 tests, 7 assertions, 0 failures, 0 errors)
  6. src/view/admin/registration.rb (coverage: 99.55%, 21 tests, 21 assertions, 0 failures, 0 errors)
  7. src/view/additional_information.rb (There is no testcase file for this module)
  8. src/view/admin/sequence.rb (the testcases for additional_information.rb are also defined) (coverage: 100%, 52 tests, 61 assertions, 0 failures, 0 errors)

Note

  • test/suite.rb returns 15 errors (this is due to the new method of Pointer#to_csv)
masa@masa ~/ywesee/oddb.org $ ruby test/suite.rb 
4116 tests, 6570 assertions, 0 failures, 15 errors

Commit

server git pull (error!)

$ git pull
remote: Counting objects: 46, done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 26 (delta 20), reused 0 (delta 0)
Unpacking objects: 100% (26/26), done.
From /home/ywesee/git/oddb.org
   81ca738..d8a4e48  master     -> origin
Updating 81ca738..d8a4e48
error: Your local changes to the following files would be overwritten by merge:
        src/util/persistence.rb
Please, commit your changes or stash them before you can merge.
Aborting
view · edit · sidebar · attach · print · history
Page last modified on August 08, 2011, at 07:34 AM