From d41162bc35f9555f6bb40f45b18e52ed8824b2fc Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 9 Aug 2013 13:05:38 +0200 Subject: [PATCH] =?utf8?q?Pflichnhefttextbl=C3=B6cke:=20Kopieren/Einf?= =?utf8?q?=C3=BCgen=20mit=20Bildern=20gefixt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Clipboard/Base.pm | 13 ++++ SL/Clipboard/RequirementSpecPicture.pm | 84 ++++++++++++++++++++++++ SL/Clipboard/RequirementSpecTextBlock.pm | 24 ++++++- locale/de/all | 1 + 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 SL/Clipboard/RequirementSpecPicture.pm diff --git a/SL/Clipboard/Base.pm b/SL/Clipboard/Base.pm index 8b7f92a64..47ccc2413 100644 --- a/SL/Clipboard/Base.pm +++ b/SL/Clipboard/Base.pm @@ -69,6 +69,13 @@ sub _fix_tree { } } +sub _binary_column_names { + my ($self, $class) = @_; + return map { $_->name } + grep { ref($_) =~ m/Pg::Bytea$/i } + @{ $class->meta->columns }; +} + 1; __END__ @@ -187,6 +194,12 @@ the newly created object before handing it back to the caller. Returns the actual clipped type (e.g. C). This is derived from the actual class name of C<$self>. +=item C<_binary_column_names $class> + +Returns an array of column names that have a binary type. Useful for +sub-classes which need to encode binary content in Base64 during +C. + =item C<_fix_object $object> This function is called by L before the object is passed diff --git a/SL/Clipboard/RequirementSpecPicture.pm b/SL/Clipboard/RequirementSpecPicture.pm new file mode 100644 index 000000000..7a3757f82 --- /dev/null +++ b/SL/Clipboard/RequirementSpecPicture.pm @@ -0,0 +1,84 @@ +package SL::Clipboard::RequirementSpecPicture; + +use strict; + +use parent qw(SL::Clipboard::Base); + +use SL::Common; +use SL::Locale::String; +use MIME::Base64; + +sub dump { + my ($self, $object) = @_; + + $self->reload_object($object); + + my $tree = $self->as_tree($object, exclude => sub { ref($_[0]) !~ m/::RequirementSpecPicture$/ }); + $tree->{$_} = encode_base64($tree->{$_}, '') for $self->_binary_column_names('SL::DB::RequirementSpecPicture'); + + return $tree; +} + +sub describe { + my ($self) = @_; + + return t8('Requirement spec picture "#1"', $self->content->{description} ? $self->content->{description} . ' (' . $self->content->{picture_file_name} . ')' : $self->content->{picture_file_name}); +} + +sub _fix_object { + my ($self, $object) = @_; + + $object->$_(undef) for qw(number); + $object->$_(decode_base64($object->$_)) for $self->_binary_column_names('SL::DB::RequirementSpecPicture'); + + return $object; +} + +1; +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::Clipboard::RequirementSpecPicture - Clipboard specialization for +SL::DB::RequirementSpecPicture + +=head1 NOTES + +The underlying RDBO model contains binary columns, but binary data +cannot be dumped as YAML. Therefore the binary content is encoded in +Base64 in L and decoded back to binary form in L. + +=head1 FUNCTIONS + +=over 4 + +=item C + +Returns a human-readable description including the title and an +excerpt of its content. + +=item C + +This specialization reloads C<$object> from the database, and dumps +it. Binary columns are dumped encoded in Base64. + +=item C<_fix_object $object> + +Fixes C<$object> by clearing certain columns like the number. Also +decodes binary columns from Base64 back to binary. + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut diff --git a/SL/Clipboard/RequirementSpecTextBlock.pm b/SL/Clipboard/RequirementSpecTextBlock.pm index 53333c56a..4b40a8e8c 100644 --- a/SL/Clipboard/RequirementSpecTextBlock.pm +++ b/SL/Clipboard/RequirementSpecTextBlock.pm @@ -4,9 +4,21 @@ use strict; use parent qw(SL::Clipboard::Base); +use SL::Clipboard::RequirementSpecPicture; use SL::Common; use SL::Locale::String; +sub dump { + my ($self, $object) = @_; + + $self->reload_object($object); + + my $tree = $self->as_tree($object, exclude => sub { ref($_[0]) !~ m/::RequirementSpecTextBlock$/ }); + $tree->{pictures} = [ map { SL::Clipboard::RequirementSpecPicture->new->dump($_) } @{ $object->pictures } ]; + + return $tree; +} + sub describe { my ($self) = @_; @@ -18,6 +30,8 @@ sub _fix_object { $object->$_(undef) for qw(output_position position requirement_spec_id); + SL::Clipboard::RequirementSpecPicture->new->_fix_object($_) for @{ $object->pictures || [] }; + return $object; } @@ -42,9 +56,17 @@ SL::DB::RequirementSpecTextBlock Returns a human-readable description including the title and an excerpt of its content. +=item C + +This specialization reloads C<$object> from the database, loads all of +its pictures and dumps it. The pictures are dumped using the clipboard +specialization for it, L. + =item C<_fix_object $object> -Fixes C<$object> by clearing certain columns like the position. +Fixes C<$object> by clearing certain columns like the position. Lets +pictures be fixed by the clipboard specialization for it, +L. =back diff --git a/locale/de/all b/locale/de/all index eacf655be..a8fdb7015 100755 --- a/locale/de/all +++ b/locale/de/all @@ -1918,6 +1918,7 @@ $self->{texts} = { 'Requirement Specs' => 'Pflichtenhefte', 'Requirement spec actions' => 'Pflichtenheftaktionen', 'Requirement spec function block #1 with #2 sub function blocks; description: "#3"' => 'Pflichtenheft-Funktionsblock #1 mit #2 Unterfunktionsblöcken; Beschreibung: "#3"', + 'Requirement spec picture "#1"' => 'Pflichtenheftbild "#1"', 'Requirement spec section #1 "#2" with #3 function blocks and a total of #4 sub function blocks; preamble: "#5"' => 'Pflichtenheftabschnitt #1 "#2" mit #3 Funktionsblöcken und insgesamt #4 Unterfunktionsblöcken; Einleitung: "#5"', 'Requirement spec sub function block #1; description: "#2"' => 'Pflichtenheft-Unterfunktionsblock #1; Beschreibung: "#2"', 'Requirement spec template \'#1\'' => 'Pflichtenheftvorlage \'#1\'', -- 2.20.1