[Rt-commit] r15703 - in rt/3.8/trunk: . share/html/Dashboards

sartak at bestpractical.com sartak at bestpractical.com
Tue Sep 2 22:13:11 EDT 2008


Author: sartak
Date: Tue Sep  2 22:13:11 2008
New Revision: 15703

Modified:
   rt/3.8/trunk/   (props changed)
   rt/3.8/trunk/lib/RT/Dashboard.pm
   rt/3.8/trunk/share/html/Dashboards/Queries.html

Log:
 r70874 at onn:  sartak | 2008-09-02 21:28:18 -0400
 Begin rejiggering the API to support different things in a dashboard


Modified: rt/3.8/trunk/lib/RT/Dashboard.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Dashboard.pm	(original)
+++ rt/3.8/trunk/lib/RT/Dashboard.pm	Tue Sep  2 22:13:11 2008
@@ -108,7 +108,7 @@
     return $object->AddAttribute(
         'Name'        => 'Dashboard',
         'Description' => $args->{'Name'},
-        'Content'     => {Searches => $args->{'Searches'}},
+        'Content'     => {Portlets => $args->{'Portlets'}},
     );
 }
 
@@ -117,9 +117,9 @@
     my $args = shift;
 
     my ($status, $msg) = (1, undef);
-    if (defined $args->{'Searches'}) {
+    if (defined $args->{'Portlets'}) {
         ($status, $msg) = $self->{'Attribute'}->SetSubValues(
-            Searches => $args->{'Searches'},
+            Portlets => $args->{'Portlets'},
         );
     }
 
@@ -145,6 +145,19 @@
     return ($status, $msg);
 }
 
+=head2 Portlets
+
+Returns the list of this dashboard's portlets, each a hashref with key
+C<portlet_type> being C<search> or C<component>.
+
+=cut
+
+sub Portlets {
+    my $self = shift;
+    return unless ref($self->{'Attribute'}) eq 'RT::Attribute';
+    return @{ $self->{'Attribute'}->SubValue('Portlets') || [] };
+}
+
 =head2 Searches
 
 Returns a list of loaded saved searches
@@ -154,23 +167,21 @@
 sub Searches {
     my $self = shift;
     return map {
-               my $search = RT::SavedSearch->new($self->CurrentUser);
-               $search->Load($_->[0], $_->[1]);
-               $search
-           } $self->SearchIds;
+        my $search = RT::SavedSearch->new($self->CurrentUser);
+        $search->Load($_->{privacy}, $_->{id});
+        $search
+    } $self->SearchIds;
 }
 
 =head2 SearchIds
 
-Returns a list of array references, each being a saved-search privacy, ID, and
-description
+Returns a list of hash references
 
 =cut
 
 sub SearchIds {
     my $self = shift;
-    return unless ref($self->{'Attribute'}) eq 'RT::Attribute';
-    return @{ $self->{'Attribute'}->SubValue('Searches') || [] };
+    return grep { $_->{portlet_type} eq 'search' } $self->Portlets;
 }
 
 =head2 SearchPrivacies
@@ -185,7 +196,7 @@
     return map { [$self->SearchPrivacy(@$_)] } $self->SearchIds;
 }
 
-=head2 SearchPrivacy TYPE, ID, DESC
+=head2 SearchPrivacy Portlet
 
 Returns an array for one saved search, suitable for passing to
 /Elements/ShowSearch.
@@ -194,6 +205,8 @@
 
 sub SearchPrivacy {
     my $self = shift;
+    my $portlet = shift;
+
     my ($type, $id, $desc) = @_;
     if ($type eq 'RT::System') {
         return Name => $desc;

Modified: rt/3.8/trunk/share/html/Dashboards/Queries.html
==============================================================================
--- rt/3.8/trunk/share/html/Dashboards/Queries.html	(original)
+++ rt/3.8/trunk/share/html/Dashboards/Queries.html	Tue Sep  2 22:13:11 2008
@@ -96,9 +96,18 @@
 my @selected;
 
 # Get the list of queries already in use
-for ($Dashboard->SearchIds) {
-    my ($privacy, $id, $desc) = @$_;
-    my $name = "search-$id-$privacy";
+for my $portlet ($Dashboard->Portlets) {
+    my ($name, $desc);
+
+    if ($portlet->{portlet_type} eq 'search') {
+        $name = join '-', 'search', $portlet->{id}, $portlet->{privacy};
+        $desc = $portlet->{description};
+    }
+    else {
+        $name = join '-', 'component', $portlet->{component};
+        $desc = $portlet->{component};
+    }
+
     push @selected, $name;
     $desc_of{$name} = $desc;
 }
@@ -141,20 +150,30 @@
     OnSubmit  => sub {
         my $self = shift;
 
-        my @searches;
-        # transform list of "SearchID-PrivacyObjType-PrivacyObjID"s to
-        # list of [Privacy, SearchID, Description]s
+        my @portlets;
         for (@{ $self->{Current} }) {
             my $item = $_;
             my $desc = $desc_of{$item};
-            my $type = $1 if $item =~ s/^(\w+)-//;
+            my $portlet_type = $1 if $item =~ s/^(\w+)-//;
 
-            if ($type eq 'search') {
-                push @searches, [ reverse(split /-/, $item, 2), $desc ];
+            if ($portlet_type eq 'search') {
+                my ($search_id, $privacy) = split '-', $item, 2;
+                push @portlets, {
+                    portlet_type => $portlet_type,
+                    privacy      => $privacy,
+                    id           => $search_id,
+                    description  => $desc,
+                };
+            }
+            elsif ($portlet_type eq 'component') {
+                push @portlets, {
+                    portlet_type => $portlet_type,
+                    component    => $item,
+                };
             }
         }
 
-        my ($ok, $msg) = $Dashboard->Update(Searches => \@searches);
+        my ($ok, $msg) = $Dashboard->Update(Portlets => \@portlets);
 
         if ($ok) {
             push @results, loc("Dashboard updated");


More information about the Rt-commit mailing list