Skip to content

Commit

Permalink
Show change_log of fachinfo. Fixed many unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Nov 5, 2015
1 parent 66a6b61 commit fb6a16b
Show file tree
Hide file tree
Showing 51 changed files with 1,647 additions and 1,100 deletions.
13 changes: 13 additions & 0 deletions doc/resources/gcc/oddb.css
Expand Up @@ -1070,3 +1070,16 @@ div#widget_interaction_chooser_searchbar {
background-color : #ccff99;
color : black;
}
.diff{overflow:auto;}
.diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
.diff del, .diff ins{display:block;text-decoration:none;}
.diff li{padding:0; display:table-row;margin: 0;height:1em;}
.diff li.ins{background:#dfd; color:#080}
.diff li.del{background:#fee; color:#b00}
.diff li:hover{background:#ffc}
/* try 'whitespace:pre;' if you don't want lines to wrap */
.diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;}
.diff del strong{font-weight:normal;background:#fcc;}
.diff ins strong{font-weight:normal;background:#9f9;}
.diff li.diff-comment { display: none; }
.diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
1 change: 0 additions & 1 deletion doc/resources/javascript/ywesee/widget/Editor.js

This file was deleted.

2 changes: 1 addition & 1 deletion fixtures/vcr_cassettes/oddb2xml.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/custom/lookandfeelbase.rb
Expand Up @@ -266,6 +266,10 @@ def google_analytics_token
#:change_flag_13 => 'Preiserhöhung',
:change_flag_14 => 'Löschung der Registration',
:change_flags => 'Change-Flags',
:change_log => 'Änderungen anzeigen',
:th_change_log => 'Link zu Details',
:th_diff => 'Änderungen',
:th_nr_chunks => 'Anzahl Änderungen',
:chapter => 'Kapitel',
:checkout => 'Bezahlen',
:checkout_invoice => 'Zu Rechnung hinzufügen',
Expand Down Expand Up @@ -311,7 +315,7 @@ def google_analytics_token
:complementary_type => "Komplementärprodukt",
:composition => "Zusammensetzung",
:composition_label => "Bezeichnung ",
:th_label => "th_Bezeichnung",
:th_label => "th_Bezeichnung",
:compositions => "Bestandteile",
:compositions0 => "",
:compositions1 => " Bestandteile",
Expand Down Expand Up @@ -1929,6 +1933,7 @@ def google_analytics_token
: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',
:change_log => 'liste des changements',
:chapter => 'Chapitre',
:checkout => 'Payer',
:checkout_invoice => 'Ajouter à la facture',
Expand Down
24 changes: 18 additions & 6 deletions src/model/fachinfo.rb
Expand Up @@ -15,13 +15,14 @@

module ODDB
class Fachinfo
class ChangeLogItem
class ChangeLogItem # we cannot remove this class or loading the ODBA cache will fail!
attr_accessor :email, :time, :chapter, :language
end
attr_accessor :links
attr_accessor :links
include Persistence
include Language
include RegistrationObserver
include RegistrationObserver
ODBA_SERIALIZABLE = ['@change_log']
def add_change_log_item(email, chapter, language)
item = ChangeLogItem.new
Expand Down Expand Up @@ -162,14 +163,25 @@ def photos(image_size="Thumbnail")
end
end
class FachinfoDocument
include Persistence
include Persistence
class ChangeLogItem
include Persistence
attr_accessor :time, :diff
def to_s
puts "ChangeLogItem: created #{time} diff: #{diff.to_s}"
end
end
def add_change_log_item(old_text, new_text)
Fachinfo_diff_options= {:diff => "-U 3",
:source => 'strings',
:include_plus_and_minus_in_html => true,
:include_diff_info => false,
:context => 0,
:allow_empty_diff => false,
}
def add_change_log_item(old_text, new_text, date = @@today, options = Fachinfo_diff_options)
item = ChangeLogItem.new
item.time = @@today
item.diff = Diffy::Diff.new(old_text, new_text)
item.time = date
item.diff = Diffy::Diff.new(old_text, new_text, options)
self.change_log.push(item)
self.odba_store
end
Expand Down
4 changes: 0 additions & 4 deletions src/plugin/text_info.rb
Expand Up @@ -132,9 +132,6 @@ def TextInfoPlugin::replace_textinfo(app, new_ti, container, type) # description
end
app.update(old_ti.pointer, {:descriptions => old_ti.descriptions})
else
require 'pry';
binding.pry if not container or not container.respond_to?(:pointer)
binding.pry if not new_ti or not new_ti.respond_to?(:pointer)
app.update(container.pointer, {type => new_ti.pointer})
end
end
Expand Down Expand Up @@ -261,7 +258,6 @@ def update_fachinfo name, iksnrs_from_xml, fis, fi_flags
## identification of Pseudo-Fachinfos happens at download-time.
# but because we still want to extract the iksnrs, we just mark them
# and defer inaction until here:
require 'pry'; binding.pry if fis.is_a?(ArgumentError)
unless fi_flags[:pseudo] || fis.empty?
LogFile.debug "update_fachinfo #{name} iksnr #{iksnr} store_fachinfo #{fi_flags} #{fis.keys} ATC #{fis.values.first.atc_code}"
fachinfo ||= TextInfoPlugin::store_fachinfo(@app, reg, fis)
Expand Down
26 changes: 17 additions & 9 deletions src/state/drugs/fachinfo.rb
Expand Up @@ -29,7 +29,7 @@ def init
@fachinfo.localized_name(@session.language))
@model.pointer_descr = descr
end
def allowed?
def allowed?(key = 'dummy')
@session.allowed?('edit', @fachinfo.registrations.first)
end
end
Expand All @@ -38,14 +38,22 @@ class FachinfoPreview < State::Drugs::Global
VOLATILE = true
end
class FachinfoPrint < State::Drugs::Global
VIEW = View::Drugs::FachinfoPrint
VOLATILE = true
def init
if(allowed?)
@default_view = ODDB::View::Drugs::CompanyFachinfoPrint
end
super
end
VIEW = View::Drugs::FachinfoPrint
VOLATILE = true
def init
if(allowed?)
@default_view = ODDB::View::Drugs::CompanyFachinfoPrint
end
super
end
end
class FachinfoDocumentChangelogs < State::Drugs::Global
VIEW = View::Drugs::FachinfoDocumentChangelogs
VOLATILE = true
end
class FachinfoDocumentChangelogItem < State::Drugs::Global
VIEW = View::Drugs::FachinfoDocumentChangelogItem
VOLATILE = true
end
class AjaxLinks < Global
VOLATILE = true
Expand Down
17 changes: 14 additions & 3 deletions src/state/global.rb
Expand Up @@ -170,6 +170,7 @@ def [](*args)
:preferences => State::User::Preferences,
:compare => State::Drugs::Compare,
:compare_search => State::Drugs::CompareSearch,
:diff => State::Drugs::FachinfoDocumentChangelogs,
:ddd => State::Drugs::DDD,
:ddd_chart => State::Ajax::DDDChart,
:ddd_price => State::Drugs::DDDPrice,
Expand Down Expand Up @@ -247,6 +248,9 @@ def [](*args)
[ :patinfo ] => State::Drugs::PatinfoPrint,
[ :rezept ] => State::Drugs::PrescriptionPrint,
}
CHANGELOGS_STATES = {
[ :fachinfo ] => State::Drugs::FachinfoDocumentChangelogs
}
REVERSE_MAP = {}
VIEW = View::Search
ZONE_NAVIGATION = []
Expand Down Expand Up @@ -775,7 +779,7 @@ def resolve_state(pointer, type=:standard)
state_map = {
:standard => self::class::RESOLVE_STATES,
:readonly => self::class::READONLY_STATES,
:print => self::class::PRINT_STATES,
:print => self::class::PRINT_STATES,
}
type = :standard unless(state_map.include?(type))
state_map[type][pointer.skeleton]
Expand Down Expand Up @@ -912,7 +916,14 @@ def _search_drugs_state(query, stype)
end
end
def show
if(@session.request_path == @request_path)
choosen = @session.choosen_fachinfo_diff
if choosen.size == 3
State::Drugs::FachinfoDocumentChangelogItem.new(@session, choosen[2])
elsif choosen.size == 2
State::Drugs::FachinfoDocumentChangelogs.new(@session, choosen[1])
elsif choosen.size == 1
State::Drugs::FachinfoDocumentChangelogs.new(@session, [])
elsif (@session.request_path == @request_path)
self
else
iksnr = @session.user_input(:reg)
Expand Down Expand Up @@ -992,7 +1003,7 @@ def suggest_address
addr.pointer = company.pointer + [:address, @session.user_input(:address)]
SuggestAddress.new(@session, addr)
else
$stdout.puts "globa suggest_address FAILED"
# $stdout.puts "global suggest_address FAILED"
end
end
def address_suggestion
Expand Down
16 changes: 16 additions & 0 deletions src/util/session.rb
Expand Up @@ -242,6 +242,22 @@ def set_persistent_user_input(key, val)
def sponsor
@app.sponsor(flavor)
end
DIFF_REGEXP = /show\/fachinfo\/(\d{5})\/diff(?:\/(\d{4}-\d{1,2}-\d{1,2}))*/
def choosen_fachinfo_diff
item = nil
m = DIFF_REGEXP.match(request_path)
if m
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])}
return [reg, log, item].compact
else
return [reg, log]
end
end
return []
end
ZsrAndEAN_Regexp = /(\/zsr_.+|)\/(ean|home_interactions)\/+([^\\?].+)/
def choosen_drugs
persistent = persistent_user_input(:drugs)
Expand Down
3 changes: 3 additions & 0 deletions src/util/validator.rb
Expand Up @@ -9,6 +9,7 @@
require 'model/ean13'
require 'iconv'
require 'cgi'
require 'mail'

module ODDB
class Validator < SBSM::Validator
Expand Down Expand Up @@ -163,6 +164,7 @@ class Validator < SBSM::Validator
:address_send,
:back,
:calculate_offer,
:diff,
:checkout,
:choice,
:clear_interaction_basket,
Expand Down Expand Up @@ -371,6 +373,7 @@ class Validator < SBSM::Validator
:captcha,
:certificate_number,
:challenge,
:diff,
:chapter,
:chemical_substance,
:city,
Expand Down
52 changes: 0 additions & 52 deletions src/view/chapter.rb
Expand Up @@ -200,58 +200,6 @@ class PrintChapter < Chapter
PAR_STYLE = 'padding-bottom: 4px; white-space: normal; line-height: 1.5em'
SEC_STYLE = 'font-size: 13px; margin-top: 4px; line-height: 1.5em'
end
class ChapterEditor < HtmlGrid::Textarea
include ChapterMethods
def init
super
@attributes.update({
'data-dojo-type' => 'dijit.Editor',
})
end
def _to_html(context, value=@value)
if(value)
sections(context, value.sections)
end
end
end
class EditChapterForm < Form
COMPONENTS = {
[0,0] => :heading,
[0,1,1]=> :edit_chapter,
[1,2] => :submit,
}
LABELS = true
LEGACY_INTERFACE = false
SYMBOL_MAP = { }
CSS_CLASS = 'composite tundra'
CSS_MAP = {
[0,0] => 'list',
[0,1] => 'list top',
}
COMPONENT_CSS_MAP = {
#[0,0,1] => 'standard',
}
def initialize(name, *args)
@name = name
super(*args)
end
def edit_chapter(model)
editor = ChapterEditor.new(:html_chapter, model, @session, self)
editor.value = model.send(@name)
editor.label = true
editor.css_id = "html-chapter"
self.onsubmit = "this.html_chapter.value = dijit.byId('html-chapter').getValue();"
editor
end
def heading(model)
HtmlGrid::InputText.new(:heading, model.send(@name),
@session, self)
end
def hidden_fields(context)
chapter = {'name' => 'chapter', 'value' => @name}
super << context.hidden(chapter)
end
end
class Links < HtmlGrid::List
COMPONENTS = {
[0,0] => :delete,
Expand Down

0 comments on commit fb6a16b

Please sign in to comment.