Skip to content

Commit

Permalink
Reworked changelog list
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Nov 10, 2015
1 parent 80fe031 commit 8aacd16
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/custom/lookandfeelbase.rb
Expand Up @@ -1099,6 +1099,7 @@ def google_analytics_token
:name_descr => 'Beschreibung',
:name_first => 'Vorname',
:name_last => 'Nachname',
:name_list => 'Liste der Änderungen (ab November 2015) an der Fachinformation zu ',
:name => 'Name',
:name_sender => 'Absender-Name',
:narcotic => 'Betäubungsmittel',
Expand Down
79 changes: 40 additions & 39 deletions src/view/drugs/fachinfo_change_logs.rb
@@ -1,7 +1,5 @@
#!/usr/bin/env ruby
# encoding: utf-8
# ODDB::View::Drugs::Photo -- oddb.org -- 27.07.2012 -- yasaka@ywesee.com

require 'htmlgrid/div'
require 'htmlgrid/image'
require 'htmlgrid/link'
Expand All @@ -11,6 +9,7 @@ module ODDB
module View
module Drugs
class FachinfoDocumentChangelogItem < View::PublicTemplate
LEGACY_INTERFACE = false
include View::AdditionalInformation
COMPONENTS = {
[0,0] => :name,
Expand All @@ -25,61 +24,59 @@ class FachinfoDocumentChangelogItem < View::PublicTemplate
[4,0] => 'time list',
[0,1] => 'diff',
}
CSS_CLASS = 'composite'
COLSPAN_MAP = { [0,1] => 5, }
CSS_CLASS = 'composite '

DEFAULT_CLASS = HtmlGrid::Value
def diff(model, session)
def diff(model)
return model.diff.to_s(:html)
end
def nr_chunks(model, session)
def nr_chunks(model)
return unless model and @session.choosen_fachinfo_diff.size > 0
j = 0; model.diff.each_chunk{|x| j+= 1}
j
end
def name(model, session)
def name(model)
return unless model and @session.choosen_fachinfo_diff.size > 0
@session.choosen_fachinfo_diff[0].name_base
end
def time(model, session)
def time(model)
model.time.to_s
end
end
class FachinfoDocumentChangelogList < HtmlGrid::List
EMPTY_LIST_KEY = :choose_fachinfo_range
class FachinfoDocumentChangelogListItem < HtmlGrid::Composite
LEGACY_INTERFACE = false
COMPONENTS = {
[0,0] => :name,
[2,0] => :nr_chunks,
[4,0] => :time,
[6,0] => :change_log,
}
[1,0] => :nr_chunks,
[2,0] => :time,
}
DEFAULT_CLASS = HtmlGrid::Value
CSS_CLASS = 'composite'
CSS_MAP = {
[0,0] => 'name list',
[2,0] => 'nr_chunkslist',
[4,0] => 'timelist',
[6,0] => 'change_log',
}
SORT_DEFAULT = false
SORT_HEADER = false
def nr_chunks(model, session)
def nr_chunks(model)
return unless model and @session.choosen_fachinfo_diff.size > 0
j = 0; model.diff.each_chunk{|x| j+= 1}
j
end
def name(model, session)
def name(model)
return unless model and @session.choosen_fachinfo_diff.size > 0
@session.choosen_fachinfo_diff[0].name_base
end
def time(model, session)
model.time.to_s
end
def change_log(model, session=@session, key=:change_log)
return nil unless @session.choosen_fachinfo_diff.size > 0
end
class FachinfoDocumentChangelogList < HtmlGrid::List
CSS_CLASS = 'composite'
OMIT_HEADER = true
COMPONENTS = {
[0,0] => :list_item,
}
DEFAULT_CLASS = HtmlGrid::Value
SORT_DEFAULT = false
SORT_HEADER = false
def list_item(model, session=@session, key=:change_log)
return unless model and @session.choosen_fachinfo_diff.size > 0
link = HtmlGrid::Link.new(key, model, session, self)
# http://oddb-ci2.dyndns.org/de/gcc/show/fachinfo/51193/diff/2015-10-27
link.set_attribute('title', @lookandfeel.lookup(:change_log))
link.value = FachinfoDocumentChangelogListItem.new(model, session, self)
link.href = @lookandfeel._event_url(:show,
[:fachinfo,
@session.choosen_fachinfo_diff[0].iksnr,
Expand All @@ -90,30 +87,35 @@ def change_log(model, session=@session, key=:change_log)
end
end
class FachinfoDocumentChangelogsComposite < HtmlGrid::Composite
LEGACY_INTERFACE = false
CSS_CLASS = 'composite'
COMPONENTS = {
[0,1] => :change_log_list,
[0,0] => :heading,
[0,1] => FachinfoDocumentChangelogList,
}
CSS_MAP = {
[0,0] => 'change_log_list right',
[0,0] => 'th',
}
def initialize(model, session, container)
def initialize(model, session, container)
# latest changes must come first!
model.sort!{|x,y| y.time.to_s <=> x.time.to_s}
super
end
def change_log_list(model, session)
FachinfoDocumentChangelogList.new(model, session, self)
def heading(model)
title = @session.lookandfeel.lookup(:name_list)
return title unless @session.choosen_fachinfo_diff[0]
info = @session.choosen_fachinfo_diff[0]
"#{title} #{info.iksnr} #{info.name_base}"
end
end
class FachinfoDocumentChangelogs < View::PublicTemplate
CSS_CLASS = 'composite'
SNAPBACK_EVENT = :result
include View::AdditionalInformation
CONTENT = View::Drugs::FachinfoDocumentChangelogsComposite
def initialize(model, session)
super
end
end
class EmptyResultForm < HtmlGrid::Form
CSS_CLASS = 'composite'
COMPONENTS = {
[0,1] => :title_none_found,
[0,2] => 'e_empty_result',
Expand All @@ -122,9 +124,8 @@ class EmptyResultForm < HtmlGrid::Form
[0,0] => 'search',
[0,1] => 'th',
}
CSS_CLASS = 'composite'
def title_none_found(model, session)
@lookandfeel.lookup(:title_none_found, 'xng')
@lookandfeel.lookup(:title_none_found)
end
end
end
Expand Down
7 changes: 0 additions & 7 deletions test/test_view/drugs/fachinfo_change_logs.rb 100644 → 100755
Expand Up @@ -55,7 +55,6 @@ def setup
old_long = "eins\nzwei\ndrei\nvier\n\nfünf\nsechs\n\sieben\nacht\nNeun\nZehn\n"
@session.request_path = "de/gcc/show/fachinfo/51193/diff/#{@@one_year_ago.to_s}"
new_long = "eins\nzwei\ndrei\nvier\n\nFünfte Zeile geändert\nZeile eingefügt\nsechs\n\sieben\nacht\nNeun\nZehn\n"
# registration('51193').fachinfo.de.add_change_log_item($old_long, $new_long, { :context => 3, :include_plus_and_minus_in_html => true})
@text_item.add_change_log_item(old_long, new_long,
@@one_year_ago,
{ :context => 3, :include_plus_and_minus_in_html => true})
Expand All @@ -81,12 +80,6 @@ def setup
@result = @list.to_html(CGI.new)

end
def test_time
assert_kind_of(String, @result)
assert_match(@@one_year_ago.to_s, @result)
assert_match(@@two_years_ago.to_s, @result)
assert_nil(/#{@@today}/.match(@result))
end
def test_diff_single_item
@item = ODDB::View::Drugs::FachinfoDocumentChangelogItem.new(@text_item.change_log[1], @session)
@item.init
Expand Down

0 comments on commit 8aacd16

Please sign in to comment.