[Rt-commit] rt branch, 5.0/sync-status-renaming-in-lifecycle-ui, created. rt-5.0.0beta1-24-ga6c12e6bbc

? sunnavy sunnavy at bestpractical.com
Thu Jun 11 14:18:26 EDT 2020


The branch, 5.0/sync-status-renaming-in-lifecycle-ui has been created
        at  a6c12e6bbc252546883fc93cacf747f13af7579a (commit)

- Log -----------------------------------------------------------------
commit fe23632cb7aab1b4a2670348581ca6f6c740cdd0
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jun 11 21:35:00 2020 +0800

    Drop UpdateChecks and rename methods it calls for better clarification
    
    These methods are used to delete passed node's related entries in
    "defaults", "actions" or "rights". The "Check..." names are a bit
    confusing.
    
    You can see that the original UpdateChecks was called not just on node
    deletion, but also on link deletion and node update, which is not quite
    right(quite obvious under the new names). We will fix it in the
    following commits.

diff --git a/share/static/js/lifecycleui-model.js b/share/static/js/lifecycleui-model.js
index bfeaf958e0..3bba64d490 100644
--- a/share/static/js/lifecycleui-model.js
+++ b/share/static/js/lifecycleui-model.js
@@ -78,8 +78,13 @@ class LifecycleModel {
         if ( link.start && link.end ) {
             self.links.splice(index, 1);
 
-            self.UpdateChecks(d.source);
-            self.UpdateChecks(d.target);
+            self.DeleteRights(d.source);
+            self.DeleteDefaults(d.source);
+            self.DeleteActions(d.source);
+
+            self.DeleteRights(d.target);
+            self.DeleteDefaults(d.target);
+            self.DeleteActions(d.target);
         }
         else if( link.start ) {
             link.end = true;
@@ -109,7 +114,9 @@ class LifecycleModel {
         var index = self.nodes.findIndex(function(x) { return x.id == d.id });
         self.DeleteLinksForNode(self.nodes[index]);
 
-        self.UpdateChecks(d);
+        self.DeleteRights(d);
+        self.DeleteDefaults(d);
+        self.DeleteActions(d);
 
         self.nodes.splice(index, 1);
     }
@@ -130,15 +137,7 @@ class LifecycleModel {
         });
     }
 
-    UpdateChecks(d) {
-        var self = this;
-
-        self.CheckRights(d);
-        self.CheckDefaults(d);
-        self.CheckActions(d);
-    }
-
-    CheckDefaults(d) {
+    DeleteDefaults(d) {
         var self = this;
 
         jQuery.each(self.config.defaults, function (key, value) {
@@ -148,7 +147,7 @@ class LifecycleModel {
         });
     }
 
-    CheckRights(d) {
+    DeleteRights(d) {
         var self = this;
 
         jQuery.each(self.config.rights, function(key, value) {
@@ -160,7 +159,7 @@ class LifecycleModel {
         });
     }
 
-    CheckActions(d) {
+    DeleteActions(d) {
         var self = this;
 
         var actions = [];
@@ -194,13 +193,17 @@ class LifecycleModel {
             }
             return true;
         });
-        self.UpdateChecks(node);
+        self.DeleteRights(node);
+        self.DeleteDefaults(node);
+        self.DeleteActions(node);
     }
 
     UpdateNodeModel(node, args) {
         var self = this;
 
-        self.UpdateChecks(node);
+        self.DeleteRights(node);
+        self.DeleteDefaults(node);
+        self.DeleteActions(node);
 
         var nodeIndex = self.nodes.findIndex(function(x) { return x.id == node.id });
 

commit aa4629b440b29a4551506d24672fca8b28da84ed
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jun 11 22:02:15 2020 +0800

    Only delete the link related entries in rights/actions on link deletion
    
    Previously on link deletion, we deleted all *node* related entries,
    which was too much. e.g. to delete "new -> open"/"open -> new" links, we
    just want to delete "new -> open"/"open -> new" entries in
    actions/rights, instead of entries including "new -> stalled", "open ->
    resolved", etc.
    
    Note that as DeleteLinksForNode is only called in DeleteNode, which
    already calls DeleteRights/DeleteActions, so no need to call them in
    DeleteLinksForNode itself.
    
    Related regex is tweaked a little bit too.

diff --git a/share/static/js/lifecycleui-model.js b/share/static/js/lifecycleui-model.js
index 3bba64d490..8753a11835 100644
--- a/share/static/js/lifecycleui-model.js
+++ b/share/static/js/lifecycleui-model.js
@@ -77,14 +77,11 @@ class LifecycleModel {
         // delete link if we have both transitions already
         if ( link.start && link.end ) {
             self.links.splice(index, 1);
-
-            self.DeleteRights(d.source);
-            self.DeleteDefaults(d.source);
-            self.DeleteActions(d.source);
-
-            self.DeleteRights(d.target);
-            self.DeleteDefaults(d.target);
-            self.DeleteActions(d.target);
+            var from = d.source.name.toLowerCase();
+            var to = d.target.name.toLowerCase();
+            var pattern = from + ' *-> *' + to + '|' + to + ' *-> *' + from;
+            self.DeleteRights(null, pattern);
+            self.DeleteActions(null, pattern);
         }
         else if( link.start ) {
             link.end = true;
@@ -147,21 +144,27 @@ class LifecycleModel {
         });
     }
 
-    DeleteRights(d) {
+    DeleteRights(d, pattern) {
         var self = this;
+        if ( !pattern ) {
+            pattern = d.name.toLowerCase() + " *->|-> *" + d.name.toLowerCase();
+        }
 
+        var re = new RegExp(pattern);
         jQuery.each(self.config.rights, function(key, value) {
-            var pattern = d.name.toLowerCase()+" ->|-> "+d.name.toLowerCase();
-            var re = new RegExp(pattern,"g");
             if ( re.test(key.toLowerCase()) ) {
                 delete self.config.rights[key];
             }
         });
     }
 
-    DeleteActions(d) {
+    DeleteActions(d, pattern) {
         var self = this;
+        if ( !pattern ) {
+            pattern = d.name.toLowerCase() + " *->|-> *" + d.name.toLowerCase();
+        }
 
+        var re = new RegExp(pattern);
         var actions = [];
         var tempArr = self.config.actions || [];
 
@@ -171,7 +174,6 @@ class LifecycleModel {
             [action, info] = tempArr.splice(0, 2);
             if (!action) continue;
 
-            var re = new RegExp(d.name.toLowerCase()+" *->|-> *"+d.name.toLowerCase(),"g");
             if ( ! re.test(action) ) {
                 actions.push(action);
                 actions.push(info);
@@ -193,9 +195,6 @@ class LifecycleModel {
             }
             return true;
         });
-        self.DeleteRights(node);
-        self.DeleteDefaults(node);
-        self.DeleteActions(node);
     }
 
     UpdateNodeModel(node, args) {

commit 4e0ebf89ce99035baceeb270d2de90e806ba1c3d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jun 11 23:10:20 2020 +0800

    Update names in defaults/actions/rights instead of delete them on node update

diff --git a/share/static/js/lifecycleui-model.js b/share/static/js/lifecycleui-model.js
index 8753a11835..fdabdac1d2 100644
--- a/share/static/js/lifecycleui-model.js
+++ b/share/static/js/lifecycleui-model.js
@@ -200,10 +200,6 @@ class LifecycleModel {
     UpdateNodeModel(node, args) {
         var self = this;
 
-        self.DeleteRights(node);
-        self.DeleteDefaults(node);
-        self.DeleteActions(node);
-
         var nodeIndex = self.nodes.findIndex(function(x) { return x.id == node.id });
 
         var oldValue =  self.nodes[nodeIndex];
@@ -228,6 +224,9 @@ class LifecycleModel {
             var index = self.links.findIndex(function(x) { return x.id == link.id });
             self.links[index] = {...link, target: nodeUpdated}
         });
+
+        if ( oldValue.name === nodeUpdated.name ) return;
+
         // Only need to check for target
         var tempArr = [];
         self.create_nodes.forEach(function(target) {
@@ -239,6 +238,33 @@ class LifecycleModel {
             }
         });
         self.create_nodes = tempArr;
+
+        for (let type in self.config.defaults) {
+            if ( self.config.defaults[type] === oldValue.name ) {
+                self.config.defaults[type] = nodeUpdated.name;
+            }
+        }
+
+        let re_from = new RegExp(oldValue.name + ' *->');
+        let re_to = new RegExp('-> *' + oldValue.name);
+
+        for (let action in self.config.rights) {
+            let updated = action.replace(re_from, nodeUpdated.name + ' ->').replace(re_to, '-> ' + nodeUpdated.name);
+            if ( action != updated ) {
+                self.config.rights[updated] = self.config.rights[action];
+                delete self.config.rights[action];
+            }
+        }
+
+        let actions = [];
+        for ( let i = 0; i < self.config.actions.length; i += 2 ) {
+            let action = self.config.actions[i];
+            let info = self.config.actions[i+1];
+            let updated = action.replace(re_from, nodeUpdated.name + ' ->').replace(re_to, '-> ' + nodeUpdated.name);
+            actions.push(updated);
+            actions.push(info);
+        }
+        self.config.actions = actions;
     }
 
     ExportAsConfiguration () {

commit 3c2775a654c2f9a0f75ad1d155ec4230dcf80406
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jun 12 00:10:36 2020 +0800

    Restrict inputs to ModifyLifecycle from to avoid possible conflicts
    
    This is just in case customization adds some forms in header(e.g. top
    actions).

diff --git a/share/static/js/lifecycleui-model.js b/share/static/js/lifecycleui-model.js
index fdabdac1d2..89a7afd928 100644
--- a/share/static/js/lifecycleui-model.js
+++ b/share/static/js/lifecycleui-model.js
@@ -309,7 +309,7 @@ class LifecycleModel {
 
         self.config = {...self.config, ...config};
 
-        var field = jQuery('input[name=Config]');
+        var field = jQuery('form[name=ModifyLifecycle] input[name=Config]');
         field.val(JSON.stringify(self.config));
 
         var pos;
@@ -319,7 +319,7 @@ class LifecycleModel {
                 pos[d.name] = [Math.round(d.x), Math.round(d.y)];
             });
         }
-        var layout = jQuery('input[name=Layout]');
+        var layout = jQuery('form[name=ModifyLifecycle] input[name=Layout]');
         layout.val(pos ? JSON.stringify(pos) : '');
     };
 }

commit 44dcefb6a607c7db5797098c6189b6e3e53d9b21
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jun 12 00:13:11 2020 +0800

    Update maps for status renaming on lifecycle modify page

diff --git a/lib/RT/Lifecycle.pm b/lib/RT/Lifecycle.pm
index 9cdf420c29..7f39bd7d97 100644
--- a/lib/RT/Lifecycle.pm
+++ b/lib/RT/Lifecycle.pm
@@ -889,7 +889,7 @@ sub CreateLifecycle {
     return $class->_CreateLifecycle(%args);
 }
 
-=head2 UpdateLifecycle( CurrentUser => undef, LifecycleObj => undef, NewConfig => undef )
+=head2 UpdateLifecycle( CurrentUser => undef, LifecycleObj => undef, NewConfig => undef, Maps => undef )
 
 Update passed lifecycle to the new configuration.
 
@@ -903,6 +903,7 @@ sub UpdateLifecycle {
         CurrentUser  => undef,
         LifecycleObj => undef,
         NewConfig    => undef,
+        Maps         => undef,
         @_,
     );
 
@@ -912,6 +913,10 @@ sub UpdateLifecycle {
 
     $lifecycles->{$name} = $args{NewConfig};
 
+    if ( $args{Maps} ) {
+        %{ $lifecycles->{__maps__} } = ( %{ $lifecycles->{__maps__} || {} }, %{ $args{Maps} }, );
+    }
+
     my ($ok, $msg) = $class->_SaveLifecycles($lifecycles, $CurrentUser);
     return ($ok, $msg) if !$ok;
 
diff --git a/share/html/Admin/Lifecycles/Modify.html b/share/html/Admin/Lifecycles/Modify.html
index 8ad3a50182..c764d0e969 100644
--- a/share/html/Admin/Lifecycles/Modify.html
+++ b/share/html/Admin/Lifecycles/Modify.html
@@ -64,8 +64,9 @@
   <input type="hidden" class="hidden" name="Update" value="1" />
   <input type="hidden" class="hidden" name="Config" />
   <input type="hidden" class="hidden" name="Layout" />
+  <input type="hidden" class="hidden" name="Maps" />
 
-  <& /Elements/Lifecycle/Graph, Name => $Name, Config => $Config, Layout => $Layout &>
+  <& /Elements/Lifecycle/Graph, Name => $Name, Config => $Config, Layout => $Layout, Maps => $Maps &>
   <div class="form-row">
     <div class="col-12">
       <& /Elements/Submit, Name => 'Update', Label => loc('Save Changes') &>
@@ -117,6 +118,7 @@ if ( $Update ) {
             CurrentUser  => $session{CurrentUser},
             LifecycleObj => $LifecycleObj,
             NewConfig    => $lifecycle,
+            Maps         => JSON::from_json($Maps),
         );
         if ($ok) {
             push @results, loc('Lifecycle updated');
@@ -131,6 +133,7 @@ if ( $Update ) {
 }
 else {
     $Config ||= JSON( RT->Config->Get('Lifecycles')->{$Name} );
+    $Maps ||= JSON( RT->Config->Get('Lifecycles')->{__maps__} || {} );
 
     unless ($Layout) {
         my $conf = RT::Configuration->new( $session{CurrentUser} );
@@ -150,5 +153,6 @@ $Name   => undef
 $Type   => undef
 $Config => undef
 $Layout => undef
+$Maps   => undef
 $Update => undef
 </%ARGS>
diff --git a/share/html/Elements/Lifecycle/Graph b/share/html/Elements/Lifecycle/Graph
index e9d9905c50..5fecc2caa7 100644
--- a/share/html/Elements/Lifecycle/Graph
+++ b/share/html/Elements/Lifecycle/Graph
@@ -86,7 +86,7 @@
 
   <script type="text/javascript">
     jQuery(function () {
-        new RT.NewLifecycleEditor( document.getElementById('lifecycle-<% $id %>'), <% $Config |n %> <% $Layout ? ", $Layout" : () |n %> );
+        new RT.NewLifecycleEditor( document.getElementById('lifecycle-<% $id %>'), <% $Config |n %>, <% $Maps |n %> <% $Layout ? ", $Layout" : () |n %> );
     });
   </script>
   <div class="row">
@@ -122,5 +122,6 @@ my $id = $Name . '-' . int(rand(2**31));
 <%ARGS>
 $Config
 $Name
+$Maps
 $Layout => ''
 </%ARGS>
diff --git a/share/static/js/lifecycleui-editor.js b/share/static/js/lifecycleui-editor.js
index 095fdacfd0..14d209dba2 100644
--- a/share/static/js/lifecycleui-editor.js
+++ b/share/static/js/lifecycleui-editor.js
@@ -1,12 +1,13 @@
 jQuery(function () {
     RT.NewLifecycleEditor = class LifecycleEditorNew extends LifecycleModel {
-        constructor(container, config, layout) {
+        constructor(container, config, maps, layout) {
             super("LifecycleModel");
 
             var self              = this;
             self.width            = 900;
             self.height           = 350;
             self.node_radius      = 35;
+            self.maps             = maps;
             self.layout           = layout;
             self.enableSimulation = 1;
 
diff --git a/share/static/js/lifecycleui-model.js b/share/static/js/lifecycleui-model.js
index 89a7afd928..9b3df7885f 100644
--- a/share/static/js/lifecycleui-model.js
+++ b/share/static/js/lifecycleui-model.js
@@ -265,6 +265,27 @@ class LifecycleModel {
             actions.push(info);
         }
         self.config.actions = actions;
+
+        let config_name = jQuery('form[name=ModifyLifecycle] input[name=Name]').val();
+        for (let item in self.maps) {
+            if ( item.match(config_name + ' *->')) {
+                let maps = self.maps[item];
+                for ( let from in maps ) {
+                    if ( from === oldValue.name ) {
+                        maps[nodeUpdated.name] = maps[from];
+                        delete maps[from];
+                    }
+                }
+            }
+            else if ( item.match('-> *' + config_name) ) {
+                let maps = self.maps[item];
+                for ( let from in maps ) {
+                    if ( maps[from] === oldValue.name ) {
+                        maps[from] = nodeUpdated.name;
+                    }
+                }
+            }
+        }
     }
 
     ExportAsConfiguration () {
@@ -321,5 +342,8 @@ class LifecycleModel {
         }
         var layout = jQuery('form[name=ModifyLifecycle] input[name=Layout]');
         layout.val(pos ? JSON.stringify(pos) : '');
+
+        var maps = jQuery('form[name=ModifyLifecycle] input[name=Maps]');
+        maps.val(JSON.stringify(self.maps));
     };
 }

commit a6c12e6bbc252546883fc93cacf747f13af7579a
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jun 12 00:48:58 2020 +0800

    Drop unused submit trigger in lifecycle UI

diff --git a/share/static/js/lifecycleui-editor.js b/share/static/js/lifecycleui-editor.js
index 14d209dba2..e31757a458 100644
--- a/share/static/js/lifecycleui-editor.js
+++ b/share/static/js/lifecycleui-editor.js
@@ -242,13 +242,6 @@ jQuery(function () {
                 self.ToggleSimulation();
                 return true;
             });
-
-            jQuery('.submit').click(function(e) {
-                e.preventDefault();
-                self.ExportAsConfiguration();
-
-                document.ModifyLifecycle.submit();
-            });
         }
 
         RenderNode() {

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


More information about the rt-commit mailing list