Pflichtenhefte: Erste Version Baumansicht Textblöcke/Abschnitte/Funktionsblöcke
[kivitendo-erp.git] / SL / Presenter / RequirementSpec.pm
1 package SL::Presenter::RequirementSpec;
2
3 use strict;
4
5 use parent qw(Exporter);
6
7 use Exporter qw(import);
8 our @EXPORT = qw(requirement_spec_text_block_jstree_data
9                  requirement_spec_item_jstree_data);
10
11 use Carp;
12
13 use SL::JSON;
14
15 sub requirement_spec_text_block_jstree_data {
16   my ($self, $text_block, %params) = @_;
17
18   return {
19     data     => $text_block->title || '',
20     metadata => { id =>         $text_block->id, type => 'textblock' },
21     attr     => { id => "tb-" . $text_block->id, href => $params{href} || '#' },
22   };
23 }
24
25 sub requirement_spec_item_jstree_data {
26   my ($self, $item, %params) = @_;
27
28   my @children = map { $self->requirement_spec_item_jstree_data($_, %params) } @{ $item->sorted_children };
29   my $type     = !$item->parent_id ? 'section' : 'functionblock';
30
31   return {
32     data     => join(' ', map { $_ || '' } ($item->fb_number, $item->title)),
33     metadata => { id =>         $item->id, type => $type },
34     attr     => { id => "fb-" . $item->id, href => $params{href} || '#' },
35     children => \@children,
36   };
37 }
38
39 1;