-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extension.pm
85 lines (69 loc) · 2.52 KB
/
Extension.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2012 Jolla Ltd.
# Contact: Pami Ketolainen <[email protected]>
package Bugzilla::Extension::TreeViewPlus;
use strict;
use base qw(Bugzilla::Extension);
# This code for this is in ./extensions/TreeViewPlus/lib/Util.pm
use Bugzilla::Extension::TreeViewPlus::Util;
use MIME::Base64;
use Bugzilla::Bug;
use JSON qw(encode_json);
our $VERSION = '0.01';
use constant COL_MAP => {
# columns which are not in the FIELD_MAP
assigned_to_realname => 'assigned_to',
changeddate => 'last_change_time',
opendate => 'creation_time',
qa_contact_realname => 'qa_contact',
reporter_realname => 'creator',
short_short_desc => 'summary',
map { Bugzilla::Bug::FIELD_MAP->{$_} => $_ } keys %{ Bugzilla::Bug::FIELD_MAP() }
};
sub template_before_process {
my ($self, $params) = @_;
return unless ($params->{file} eq 'list/list-tvp.html.tmpl');
my $vars = $params->{vars};
my @bug_ids;
my %buginfo;
for my $bug (@{$vars->{bugs}}) {
$buginfo{$bug->{bug_id}} = $bug;
push(@bug_ids, $bug->{bug_id});
}
my $dir = Bugzilla->cgi->param('tvp_dir') || '';
$vars->{tvp_dir} = $dir;
# bas64 encoding for the initial data so that possible script or other html
# tags in the content don't break the page
$vars->{tree_json} = encode_base64(encode_json(
_dynatree(\%buginfo, $vars->{displaycolumns},
get_tree(\@bug_ids, $dir))
), "");
$vars->{displaycolumns_json} = encode_json($vars->{displaycolumns});
$vars->{field_map_json} = encode_json(COL_MAP);
$vars->{tvp_to} = $dir eq 'blocked' ? 'blocks' : 'depends_on';
$vars->{tvp_from} = $dir eq 'blocked' ? 'depends_on' : 'blocks';
}
## Generates the data sturcture suitable for jQuery dynatree
sub _dynatree {
my ($buginfo, $columns, $node, $id) = @_;
my %result;
if (defined $id ) {
$result{bug_id} = $id;
$result{href} = "show_bug.cgi?id=$id";
$result{title} = $id;
my $bug = $buginfo->{$id};
if (defined $bug) {
$result{in_results} = 1;
$result{columns} = $bug;
}
}
my @children = map {_dynatree($buginfo, $columns, $node->{$_}, $_)} keys %$node;
$result{children} = \@children;
return \%result;
}
__PACKAGE__->NAME;