From 77d082914b43807bbb0aadf7312d5e4ac40e9541 Mon Sep 17 00:00:00 2001 From: Niklaus Giger Date: Tue, 10 Nov 2015 15:49:01 +0100 Subject: [PATCH] Don't add duplicated changelog entries. Take 2 Signed-off-by: Niklaus Giger --- src/custom/lookandfeelbase.rb | 8 +++- src/model/fachinfo.rb | 12 +++-- src/plugin/text_info.rb | 7 +-- src/util/session.rb | 5 ++- src/view/drugs/fachinfo_change_logs.rb | 10 ++--- test/stub/session.rb | 5 ++- test/test_model/fachinfo.rb | 66 +++++++++++++++++++--------- test/test_util/session.rb | 2 +- test/test_view/drugs/fachinfo_change_logs.rb | 18 +++++--- 9 files changed, 90 insertions(+), 43 deletions(-) mode change 100644 => 100755 test/test_model/fachinfo.rb mode change 100644 => 100755 test/test_util/session.rb diff --git a/src/custom/lookandfeelbase.rb b/src/custom/lookandfeelbase.rb index 065e721..3c3745a 100644 --- a/src/custom/lookandfeelbase.rb +++ b/src/custom/lookandfeelbase.rb @@ -267,10 +267,12 @@ Zeno Davatz #:change_flag_13 => 'Preiserhöhung', :change_flag_14 => 'Löschung der Registration', :change_flags => 'Change-Flags', - :th_change_log => 'Änderungen an Fachfinfo', + :th_change_log => 'Änderungen an Fachinfo', :th_change_log_heading => 'Liste der Änderungen (ab November 2015) an der Fachinformation zu ', :th_change_log_time => 'vom', :th_nr_chunks => 'Änderungen', + :change_log_item => 'Liste der Änderungen an der Fachinformation zu .. vom ..', + :change_logs => 'Liste der Änderungen an der Fachinformation zu ..', :chapter => 'Kapitel', :checkout => 'Bezahlen', :checkout_invoice => 'Zu Rechnung hinzufügen', @@ -1934,6 +1936,10 @@ Zeno Davatz :category_c => 'Liste des stupéfiants pouvant être obtenus en petite quantité sans ordonnance médi-cale et soustraits partiellement au contrôle (art. 3, 2e al., LStup)', :category_d => 'Liste des stupéfiants prohibés (art. 8, 1er et 3e al., LStup)', :certificate_number => 'CCP-no', + :th_change_log => "Changements de l'information professionelle", + :th_change_log_heading => "Liste des changements(à partir de novembre 2015) de l'information professionelle", + :th_change_log_time => 'du', + :th_nr_chunks => 'changements', :chapter => 'Chapitre', :checkout => 'Payer', :checkout_invoice => 'Ajouter à la facture', diff --git a/src/model/fachinfo.rb b/src/model/fachinfo.rb index 5e51cfa..7c5d4c7 100644 --- a/src/model/fachinfo.rb +++ b/src/model/fachinfo.rb @@ -167,8 +167,9 @@ module ODDB class ChangeLogItem include Persistence attr_accessor :time, :diff - def to_s - puts "ChangeLogItem: created #{time} diff: #{diff.to_s}" + def <=>(anOther) + # [diff.to_s, time] <=> [anOther.diff.to_s, anOther.time] + diff.to_s <=> anOther.diff.to_s end end Fachinfo_diff_options= {:diff => "-U 3", @@ -179,9 +180,14 @@ module ODDB :allow_empty_diff => false, } def add_change_log_item(old_text, new_text, date = @@today, options = Fachinfo_diff_options) + @change_log ||= [] item = ChangeLogItem.new item.time = date - item.diff = Diffy::Diff.new(old_text, new_text, options) + item.diff = Diffy::Diff.new(old_text ? old_text : '', new_text, options) + if @change_log and @change_log.find { |x| x.diff.to_s.eql?(item.diff.to_s) } + puts "FachinfoDocument::ChangeLogItem: Don't adding duplicates entry #{old_text ? old_text[0..150] : ''}" + return + end self.change_log.push(item) self.odba_store end diff --git a/src/plugin/text_info.rb b/src/plugin/text_info.rb index 08d7c7e..1f3295f 100644 --- a/src/plugin/text_info.rb +++ b/src/plugin/text_info.rb @@ -136,13 +136,14 @@ module ODDB end end def TextInfoPlugin::add_change_log_item(text_item, old_text, new_text, lang) - $stdout.puts("add_change_log_item: update #{text_item.class} lang #{lang} #{text_item.class} #{old_text[-30..-1]} -> #{new_text[-30..-1]}") + msg = "add_change_log_item: update #{text_item.class} lang #{lang} #{text_item.class} #{old_text[-30..-1]} -> #{new_text[-30..-1]}" + LogFile.debug msg + $stdout.puts(msg); $stdout.sync text_item.add_change_log_item(old_text, new_text) text_item.odba_isolated_store end def TextInfoPlugin::store_fachinfo(app, reg, fis) existing = reg.fachinfo - $stdout.puts("store_fachinfo: #{reg.iksnr} existing #{existing.class}") ptr = Persistence::Pointer.new(:fachinfo).creator if existing old_text_de = existing.de.text @@ -1192,7 +1193,7 @@ module ODDB unless infos.empty? _infos = {} [:de, :fr].map do |lang| - LogFile.debug "_infos #{lang} #{infos[lang]} #{infos[lang].class}" + LogFile.debug "_infos #{lang} #{infos[lang].to_s[0..150] } #{infos[lang].class}" unless strange?(infos[lang]) _infos[lang] = infos[lang] end diff --git a/src/util/session.rb b/src/util/session.rb index a44b031..328ad18 100644 --- a/src/util/session.rb +++ b/src/util/session.rb @@ -242,7 +242,8 @@ module ODDB def sponsor @app.sponsor(flavor) end - DIFF_REGEXP = /show\/fachinfo\/(\d{5})\/diff(?:\/(\d{4}-\d{1,2}-\d{1,2}))*/ + # we expect a european date in the format tt.dd.yyyy + DIFF_REGEXP = /show\/fachinfo\/(\d{5})\/diff(?:\/(\d{2}\.\d{1,2}\.\d{1,4}))*/ def choosen_fachinfo_diff item = nil m = DIFF_REGEXP.match(request_path) @@ -250,7 +251,7 @@ module ODDB reg = @app.registration(m[1]) log = reg.fachinfo.send(self.language).change_log.sort!{|x,y| y.time.to_s <=> x.time.to_s} if reg and m[2] - item = log.find{|item| item.time.to_s.eql?(m[2])} + item = log.find{|item| item.time.strftime('%d.%m.%Y').eql?(m[2])} return [reg, log, item].compact else return [reg, log] diff --git a/src/view/drugs/fachinfo_change_logs.rb b/src/view/drugs/fachinfo_change_logs.rb index 0b311a4..328a637 100644 --- a/src/view/drugs/fachinfo_change_logs.rb +++ b/src/view/drugs/fachinfo_change_logs.rb @@ -28,7 +28,7 @@ module ODDB [0,0] => 'th', } CSS_CLASS = 'composite ' - COLSPAN_MAP = { [0,1] => 6 } + COLSPAN_MAP = { [0,1] => 7 } DEFAULT_CLASS = HtmlGrid::Value def diff(model) @@ -44,12 +44,12 @@ module ODDB @session.choosen_fachinfo_diff[0].name_base end def time(model) - model.time.to_s + model.time.strftime('%d.%m.%Y') end end class FachinfoDocumentChangelogItem < PrivateTemplate CONTENT = View::Drugs::FachinfoDocumentChangelogItemComposite - SNAPBACK_EVENT = :result + SNAPBACK_EVENT = :change_log_item end class FachinfoDocumentChangelogListItem < HtmlGrid::Composite @@ -90,7 +90,7 @@ module ODDB [:fachinfo, @session.choosen_fachinfo_diff[0].iksnr, :diff, - model.time.to_s + model.time.strftime('%d.%m.%Y') ] ) link end @@ -118,7 +118,7 @@ module ODDB end end class FachinfoDocumentChangelogs < View::PrivateTemplate - SNAPBACK_EVENT = :result + SNAPBACK_EVENT = :change_logs CONTENT = View::Drugs::FachinfoDocumentChangelogsComposite end class EmptyResultForm < HtmlGrid::Form diff --git a/test/stub/session.rb b/test/stub/session.rb index 45a8c93..7305704 100644 --- a/test/stub/session.rb +++ b/test/stub/session.rb @@ -9,7 +9,7 @@ module ODDB attr_accessor :last_update, :currency, :unknown_user, :sponsor, :registrations end class StubSession < SBSM::Session - attr_accessor :lookandfeel, :app, :flavor, :language, :request_path, :diff_info + attr_accessor :lookandfeel, :app, :flavor, :language, :request_path, :diff_info, :state def choosen_fachinfo_diff return @diff_info || [] end @@ -22,6 +22,9 @@ module ODDB def enabled? true end + def allowed?(param1, param2) + true + end def http_protocol 'http' end diff --git a/test/test_model/fachinfo.rb b/test/test_model/fachinfo.rb old mode 100644 new mode 100755 index d491b9e..4ad0397 --- a/test/test_model/fachinfo.rb +++ b/test/test_model/fachinfo.rb @@ -183,6 +183,12 @@ ATC-Code: L01XE31 class TestFachinfoDocument fi) @app.should_receive(:registration).with(reg_nr).and_return(reg) text_info.add_change_log_item('alt','neu') - @session.instance_eval("@request_path = '/de/gcc/show/fachinfo/#{reg_nr}/diff/#{@@today.to_s}'") + @session.instance_eval("@request_path = '/de/gcc/show/fachinfo/#{reg_nr}/diff/#{@@today.strftime('%d.%m.%Y')}'") assert_equal(3, @session.choosen_fachinfo_diff.size) assert_equal(reg_nr, @session.choosen_fachinfo_diff[0].iksnr) assert_equal(1, @session.choosen_fachinfo_diff[1].size) diff --git a/test/test_view/drugs/fachinfo_change_logs.rb b/test/test_view/drugs/fachinfo_change_logs.rb index 26e275e..49bb94e 100755 --- a/test/test_view/drugs/fachinfo_change_logs.rb +++ b/test/test_view/drugs/fachinfo_change_logs.rb @@ -20,7 +20,11 @@ module ODDB class Session DEFAULT_FLAVOR = 'gcc' end - + module State + class Global < SBSM::State + attr_accessor :snapback_model + end + end module View class TestFachinfoChangelog {}, ) @zone = flexmock('zone', :zone => 'zone') + @snapback_model = flexmock('snapback_model', :pointer => 'pointer') @state = flexmock('state', :direct_event => 'direct_event', :zone => @zone, + :snapback_model => @snapback_model, ) @app = flexmock('app', StubApp.new) @app.unknown_user = @user @session = StubSession.new('key', @app) @session.lookandfeel = LookandfeelBase.new(@session) @session.language = 'de' + @session.state = @state @text_item = FachinfoDocument.new @text_item.name = 'name_of_fi' @old_string = '1234_old' @@ -59,7 +66,6 @@ module ODDB @@one_year_ago, { :context => 3, :include_plus_and_minus_in_html => true}) @list = ODDB::View::Drugs::FachinfoDocumentChangelogs.new(@text_item.change_log, @session) - @reg_nr = '51193' text_info = flexmock('text_info', ODDB::FachinfoDocument2001.new, :odba_store => nil) fi = flexmock('fachinfo', ODDB::Fachinfo.new, :de => text_info) @@ -86,7 +92,7 @@ module ODDB result = @item.to_html(CGI.new) # puts @result.split(' @result.index(@@one_year_ago.to_s), 'Newer entries must come first') # Do we have the correct links? needed_part = changelog_request_path.sub('de/gcc/', '') - assert_match(needed_part + '/' + @@two_years_ago.to_s, @result, 'Must find link for two years old entry') - assert_match(needed_part + '/' + @@one_year_ago.to_s, @result, 'Must find link for one year old entry') - assert_match(needed_part + '/' + @@today.to_s, @result, 'Must find link for todays entry') + assert_match(needed_part + '/' + @@two_years_ago.strftime('%d.%m.%Y'), @result, 'Must find link for two years old entry') + assert_match(needed_part + '/' + @@one_year_ago.strftime('%d.%m.%Y'), @result, 'Must find link for one year old entry') + assert_match(needed_part + '/' + @@today.strftime('%d.%m.%Y'), @result, 'Must find link for todays entry') end end end -- 2.1.4