[Bps-public-commit] rt-extension-lifecycleui branch, master, updated. 047863eca3a63978a3d0312bc935ddaf124c5f2e
Shawn Moore
shawn at bestpractical.com
Thu Aug 17 13:05:26 EDT 2017
The branch, master has been updated
via 047863eca3a63978a3d0312bc935ddaf124c5f2e (commit)
via 1e8fc0c142624d20ce4082d3c7b980e995ab1b51 (commit)
via a839a604803f222056e84a9e48d47f81e62cbe80 (commit)
via 0752102a38edff7e1306ac8292004db5a0fe4d09 (commit)
via 18a2dd81d06d38ed8e8f436d937ba2f1c470dee8 (commit)
via 5d40fd6f91dd39b87a097e21e19ca0bd41a5939b (commit)
from 288769402d55fb404e8ef6f27bdd88f7e0ad4934 (commit)
Summary of changes:
html/Admin/Lifecycles/Create.html | 28 +++++------
lib/RT/Extension/LifecycleUI.pm | 103 ++++++++++++++++++++++++++++++++++++++
2 files changed, 115 insertions(+), 16 deletions(-)
- Log -----------------------------------------------------------------
commit 5d40fd6f91dd39b87a097e21e19ca0bd41a5939b
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Wed Aug 16 18:34:44 2017 +0000
Link from ConfigInDatabase to lifecycles admin UI
diff --git a/lib/RT/Extension/LifecycleUI.pm b/lib/RT/Extension/LifecycleUI.pm
index dff33dd..881d9f9 100644
--- a/lib/RT/Extension/LifecycleUI.pm
+++ b/lib/RT/Extension/LifecycleUI.pm
@@ -6,6 +6,9 @@ our $VERSION = '0.01';
RT->AddStyleSheets("lifecycleui.css");
+$RT::Config::META{Lifecycles}{EditLink} = RT->Config->Get('WebURL') . 'Admin/Lifecycles/';
+$RT::Config::META{Lifecycles}{EditLinkLabel} = "lifecycles administration";
+
=head1 NAME
RT-Extension-LifecycleUI - manage lifecycles via admin UI
commit 18a2dd81d06d38ed8e8f436d937ba2f1c470dee8
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Wed Aug 16 18:39:06 2017 +0000
Fix check for empty Name
diff --git a/html/Admin/Lifecycles/Create.html b/html/Admin/Lifecycles/Create.html
index a1b1ad1..d31951b 100644
--- a/html/Admin/Lifecycles/Create.html
+++ b/html/Admin/Lifecycles/Create.html
@@ -36,7 +36,7 @@ if (defined($Clone) || defined($Blank)) {
my ($type, $clone_of);
Abort("New lifecycle name required")
- unless defined $Name;
+ unless length $Name;
if (defined($Clone)) {
($type, $clone_of) = split '--', $Clone;
commit 0752102a38edff7e1306ac8292004db5a0fe4d09
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Aug 17 16:03:38 2017 +0000
Move lifecycle create code into CreateLifecycle sub
diff --git a/html/Admin/Lifecycles/Create.html b/html/Admin/Lifecycles/Create.html
index d31951b..179ccc0 100644
--- a/html/Admin/Lifecycles/Create.html
+++ b/html/Admin/Lifecycles/Create.html
@@ -35,24 +35,21 @@ for my $type (@types) {
if (defined($Clone) || defined($Blank)) {
my ($type, $clone_of);
- Abort("New lifecycle name required")
- unless length $Name;
-
if (defined($Clone)) {
($type, $clone_of) = split '--', $Clone;
- Abort("Invalid $type lifecycle $clone_of")
- unless grep { $_ eq $clone_of } RT::Lifecycle->ListAll($type);
}
else {
$type = $Blank;
- Abort("Invalid lifecycle type $type")
- unless $RT::Lifecycle::LIFECYCLES_TYPES{$type};
}
- Abort("$type lifecycle $Name already exists")
- if grep { $_ eq $Name } RT::Lifecycle->ListAll($type);
+ my ($ok, $msg) = RT::Extension::LifecycleUI->CreateLifecycle(
+ CurrentUser => $session{CurrentUser},
+ Name => $Name,
+ Type => $type,
+ Clone => $clone_of,
+ );
- # XXX create blank or clone
+ Abort($msg) if !$ok;
my $type_uri = $type;
my $Name_uri = $Name;
diff --git a/lib/RT/Extension/LifecycleUI.pm b/lib/RT/Extension/LifecycleUI.pm
index 881d9f9..03fd097 100644
--- a/lib/RT/Extension/LifecycleUI.pm
+++ b/lib/RT/Extension/LifecycleUI.pm
@@ -9,6 +9,41 @@ RT->AddStyleSheets("lifecycleui.css");
$RT::Config::META{Lifecycles}{EditLink} = RT->Config->Get('WebURL') . 'Admin/Lifecycles/';
$RT::Config::META{Lifecycles}{EditLinkLabel} = "lifecycles administration";
+sub CreateLifecycle {
+ my $class = shift;
+ my %args = (
+ CurrentUser => undef,
+ Name => undef,
+ Type => undef,
+ Clone => undef,
+ @_,
+ );
+
+ my $CurrentUser = $args{CurrentUser};
+ my $Name = $args{Name};
+ my $Type = $args{Type};
+ my $Clone = $args{Clone};
+
+ return (0, $CurrentUser->loc("Lifecycle Name required"))
+ unless length $Name;
+
+ return (0, $CurrentUser->loc("Lifecycle Type required"))
+ unless length $Type;
+
+ return (0, $CurrentUser->loc("Invalid lifecycle type '[_1]'", $Type))
+ unless $RT::Lifecycle::LIFECYCLES_TYPES{$Type};
+
+ if (length $Clone) {
+ return (0, $CurrentUser->loc("Invalid '[_1]' lifecycle '[_2]'", $Type, $Clone))
+ unless grep { $_ eq $Clone } RT::Lifecycle->ListAll($Type);
+ }
+
+ return (0, $CurrentUser->loc("'[_1]' lifecycle '[_2]' already exists", $Type, $Name))
+ if grep { $_ eq $Name } RT::Lifecycle->ListAll($Type);
+
+ return (1, $CurrentUser->loc("Lifecycle created"));
+}
+
=head1 NAME
RT-Extension-LifecycleUI - manage lifecycles via admin UI
commit a839a604803f222056e84a9e48d47f81e62cbe80
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Aug 17 16:20:22 2017 +0000
Implement create/clone lifecycle by saving as database setting
diff --git a/lib/RT/Extension/LifecycleUI.pm b/lib/RT/Extension/LifecycleUI.pm
index 03fd097..a3215ea 100644
--- a/lib/RT/Extension/LifecycleUI.pm
+++ b/lib/RT/Extension/LifecycleUI.pm
@@ -1,6 +1,7 @@
package RT::Extension::LifecycleUI;
use strict;
use warnings;
+use Storable;
our $VERSION = '0.01';
@@ -9,6 +10,42 @@ RT->AddStyleSheets("lifecycleui.css");
$RT::Config::META{Lifecycles}{EditLink} = RT->Config->Get('WebURL') . 'Admin/Lifecycles/';
$RT::Config::META{Lifecycles}{EditLinkLabel} = "lifecycles administration";
+sub _CreateLifecycle {
+ my $class = shift;
+ my %args = @_;
+ my $CurrentUser = $args{CurrentUser};
+
+ my $lifecycles = RT->Config->Get('Lifecycles');
+ my $lifecycle;
+
+ if ($args{Clone}) {
+ $lifecycle = Storable::dclone($lifecycles->{ $args{Clone} });
+ }
+ else {
+ $lifecycle = { type => $args{Type} };
+ }
+
+ $lifecycles->{$args{Name}} = $lifecycle;
+
+ my $setting = RT::DatabaseSetting->new($CurrentUser);
+ $setting->Load('Lifecycles');
+ if ($setting->Id) {
+ my ($ok, $msg) = $setting->SetContent($lifecycles);
+ return ($ok, $msg) if !$ok;
+ }
+ else {
+ my ($ok, $msg) = $setting->Create(
+ Name => 'Lifecycles',
+ Content => $lifecycles,
+ );
+ return ($ok, $msg) if !$ok;
+ }
+
+ RT::Lifecycle->FillCache;
+
+ return (1, $CurrentUser->loc("Lifecycle created"));
+}
+
sub CreateLifecycle {
my $class = shift;
my %args = (
@@ -41,7 +78,7 @@ sub CreateLifecycle {
return (0, $CurrentUser->loc("'[_1]' lifecycle '[_2]' already exists", $Type, $Name))
if grep { $_ eq $Name } RT::Lifecycle->ListAll($Type);
- return (1, $CurrentUser->loc("Lifecycle created"));
+ return $class->_CreateLifecycle(%args);
}
=head1 NAME
commit 1e8fc0c142624d20ce4082d3c7b980e995ab1b51
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Aug 17 16:29:49 2017 +0000
Improve create flow
This uses a pattern similar to RT's /Admin/Actions/Create.html
diff --git a/html/Admin/Lifecycles/Create.html b/html/Admin/Lifecycles/Create.html
index 179ccc0..097abcd 100644
--- a/html/Admin/Lifecycles/Create.html
+++ b/html/Admin/Lifecycles/Create.html
@@ -51,12 +51,11 @@ if (defined($Clone) || defined($Blank)) {
Abort($msg) if !$ok;
- my $type_uri = $type;
- my $Name_uri = $Name;
- RT::Interface::Web::EscapeURI(\$type_uri);
- RT::Interface::Web::EscapeURI(\$Name_uri);
-
- RT::Interface::Web::Redirect( RT->Config->Get('WebURL') ."Admin/Lifecycles/Modify.html?Type=". $type_uri."&Name=".$Name_uri);
+ MaybeRedirectForResults(
+ Actions => [ $msg ],
+ Path => 'Admin/Lifecycles/Modify.html',
+ Arguments => { Type => $type, Name => $Name },
+ );
}
</%INIT>
<%ARGS>
commit 047863eca3a63978a3d0312bc935ddaf124c5f2e
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Aug 17 16:52:59 2017 +0000
On clone, clone all status maps too
diff --git a/lib/RT/Extension/LifecycleUI.pm b/lib/RT/Extension/LifecycleUI.pm
index a3215ea..c187541 100644
--- a/lib/RT/Extension/LifecycleUI.pm
+++ b/lib/RT/Extension/LifecycleUI.pm
@@ -10,6 +10,29 @@ RT->AddStyleSheets("lifecycleui.css");
$RT::Config::META{Lifecycles}{EditLink} = RT->Config->Get('WebURL') . 'Admin/Lifecycles/';
$RT::Config::META{Lifecycles}{EditLinkLabel} = "lifecycles administration";
+sub _CloneLifecycleMaps {
+ my $class = shift;
+ my $maps = shift;
+ my $name = shift;
+ my $clone = shift;
+
+ for my $key (keys %$maps) {
+ my $map = $maps->{$key};
+
+ next unless $key =~ s/^ \Q$clone\E \s+ -> \s+/$name -> /x
+ || $key =~ s/\s+ -> \s+ \Q$clone\E $/ -> $name/x;
+
+ $maps->{$key} = Storable::dclone($map);
+ }
+
+ my $CloneObj = RT::Lifecycle->new;
+ $CloneObj->Load($clone);
+
+ my %map = map { $_ => $_ } $CloneObj->Valid;
+ $maps->{"$name -> $clone"} = { %map };
+ $maps->{"$clone -> $name"} = { %map };
+}
+
sub _CreateLifecycle {
my $class = shift;
my %args = @_;
@@ -20,6 +43,11 @@ sub _CreateLifecycle {
if ($args{Clone}) {
$lifecycle = Storable::dclone($lifecycles->{ $args{Clone} });
+ $class->_CloneLifecycleMaps(
+ $lifecycles->{__maps__},
+ $args{Name},
+ $args{Clone},
+ );
}
else {
$lifecycle = { type => $args{Type} };
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list