[Rt-commit] rt branch, 4.4/dashboard-language, created. rt-4.2.12-505-g45be79a

Shawn Moore shawn at bestpractical.com
Tue Nov 10 13:11:22 EST 2015


The branch, 4.4/dashboard-language has been created
        at  45be79ac09927c299d8910d024a1987ce70a944e (commit)

- Log -----------------------------------------------------------------
commit 45be79ac09927c299d8910d024a1987ce70a944e
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Nov 10 18:00:53 2015 +0000

    Add language selector for dashboard subscriptions

diff --git a/share/html/Dashboards/Render.html b/share/html/Dashboards/Render.html
index 0306077..37ee4fc 100644
--- a/share/html/Dashboards/Render.html
+++ b/share/html/Dashboards/Render.html
@@ -55,6 +55,15 @@
 <& /Elements/Tabs &>
 % }
 
+% # honor the chosen language for just the dashboard content
+% my $original_handle;
+% if ($SubscriptionObj->id) {
+%     if (my $lang = $SubscriptionObj->SubValue('Language')) {
+%         $original_handle = $session{'CurrentUser'}->{'LangHandle'};
+%         $session{'CurrentUser'}->{'LangHandle'} = RT::I18N->get_handle($lang);
+%     }
+% }
+
 % $m->callback(CallbackName => 'BeforeTable', Dashboard => $Dashboard, show_cb => $show_cb);
 
 <table class="dashboard" id="dashboard-<%$id%>">
@@ -91,6 +100,10 @@
 </html>
 % }
 
+% # restore the original language for anything else on the page
+% if ($original_handle) {
+%     $session{'CurrentUser'}->{'LangHandle'} = $original_handle;
+% }
 <%INIT>
 
 
diff --git a/share/html/Dashboards/Subscription.html b/share/html/Dashboards/Subscription.html
index d55076d..aae84ea 100644
--- a/share/html/Dashboards/Subscription.html
+++ b/share/html/Dashboards/Subscription.html
@@ -165,6 +165,15 @@
 (<%$timezone%>)
 </td></tr>
 <tr><td class="label">
+<&|/l&>Language</&>:
+</td><td class="value">
+<& /Elements/SelectLang,
+    Name => 'Language',
+    Default => $fields{'Language'},
+    ShowNullOption => 1,
+ &>
+</td></tr>
+<tr><td class="label">
 <&|/l&>Rows</&>:
 </td><td class="value">
 <select name="Rows">
@@ -225,6 +234,7 @@ my %fields = (
     Recipient   => '',
     Fow         => 1,
     Counter     => 0,
+    Language    => '',
 );
 
 # update any fields with the values from the subscription object
@@ -306,5 +316,6 @@ $Dow         => undef
 $Dom         => undef
 $Rows        => undef
 $Recipient   => undef
+$Language    => undef
 </%ARGS>
 
diff --git a/t/mail/dashboards.t b/t/mail/dashboards.t
index 3d004ae..3970324 100644
--- a/t/mail/dashboards.t
+++ b/t/mail/dashboards.t
@@ -91,6 +91,8 @@ my ($dashboard_id, $subscription_id) = get_dash_sub_ids();
 sub produces_dashboard_mail_ok { # {{{
     my %args = @_;
     my $subject = delete $args{Subject};
+    my $body_like = delete $args{BodyLike};
+    my $body_unlike = delete $args{BodyUnlike};
 
     local $Test::Builder::Level = $Test::Builder::Level + 1;
 
@@ -107,8 +109,20 @@ sub produces_dashboard_mail_ok { # {{{
     is($mail->head->get('X-RT-Dashboard-Subscription-Id'), "$subscription_id\n");
 
     my $body = $mail->bodyhandle->as_string;
-    like($body, qr{My dashboards});
+    like($body, qr{My dashboards}) if !$body_like && !$body_unlike;
     like($body, qr{<a href="http://[^/]+/Dashboards/\d+/Testing!">Testing!</a>});
+
+    if ($body_like) {
+        for my $re (ref($body_like) eq 'ARRAY' ? @$body_like : $body_like) {
+            ok($body =~ $re, "body should match $re");
+        }
+    }
+
+    if ($body_unlike) {
+        for my $re (ref($body_unlike) eq 'ARRAY' ? @$body_unlike : $body_unlike) {
+            ok($body !~ $re, "body should not match $re");
+        }
+    }
 } # }}}
 
 sub produces_no_dashboard_mail_ok { # {{{
@@ -318,6 +332,7 @@ create_dashboard($baseurl, $m);
 create_subscription($baseurl, $m,
     Frequency => 'monthly',
     Hour => '06:00',
+    Language => 'fr',
 );
 
 ($dashboard_id, $subscription_id) = get_dash_sub_ids();
@@ -326,8 +341,10 @@ $good_time = 1291201200;        # dec 1
 $bad_time = $good_time - 86400; # day before (i.e. different month)
 
 produces_dashboard_mail_ok(
-    Time    => $good_time,
-    Subject =>  "[example.com] a Monthly b Testing! c\n",
+    Time       => $good_time,
+    Subject    => "[example.com] a Monthly b Testing! c\n",
+    BodyLike   => qr/Mes tableaux de bord/,
+    BodyUnlike => qr/My dashboards/,
 );
 
 produces_no_dashboard_mail_ok(

-----------------------------------------------------------------------


More information about the rt-commit mailing list