[Rt-commit] rt branch, 4.6/lifecycle-ui-dev, repushed
Craig Kaiser
craig at bestpractical.com
Sun Dec 8 09:48:24 EST 2019
The branch 4.6/lifecycle-ui-dev was deleted and repushed:
was a62f12eca6b3838acf3630e4992a14c19269b9d0
now 47f969304e8f3588cd666dd51e537743f2bc9bbc
1: a62f12eca6 ! 1: 47f969304e Core Lifecycle-UI
@@ -210,12 +210,6 @@
@_,
);
+ $args{'Type'} = $args{'Type'} // 'ticket';
-+
-+ my $needs_update = RT->System->LifecycleCacheNeedsUpdate;
-+ if ($needs_update > $lifecycle_cache_time) {
-+ $self->FillCache();
-+ $lifecycle_cache_time = $needs_update;
-+ }
- if (defined $args{Name} and exists $LIFECYCLES_CACHE{ $args{Name} }) {
- $self->{'name'} = $args{Name};
@@ -229,6 +223,12 @@
- $self->{'type'} = $args{Type};
- } else {
- return undef;
++ my $needs_update = RT->System->LifecycleCacheNeedsUpdate;
++ if ($needs_update > $lifecycle_cache_time) {
++ $self->FillCache();
++ $lifecycle_cache_time = $needs_update;
++ }
++
+ my $load_class = sub {
+ if (defined $args{Name} and exists $LIFECYCLES_CACHE{ $args{Name} }) {
+ $self->{'name'} = $args{Name};
@@ -414,17 +414,51 @@
+sub UpdateLifecycle {
+ my $class = shift;
+ my %args = (
-+ CurrentUser => undef,
-+ LifecycleObj => undef,
-+ NewConfig => undef,
++ CurrentUser => undef,
++ LifecycleObj => undef,
++ NewConfig => undef,
++ Attribute => undef,
+ @_,
+ );
++
++ if ( $args{'Attribute'} ) {
++ my $attribute = RT::Attribute->new( RT->SystemUser );
++
++ if ( $attribute->LoadByNameAndObject( Object => RT::System, Name => 'LifecycleAttribute-'.$args{'LifecycleObj'}->Name ) ) {
++ my ($ret, $msg) = $attribute->SetContent( $args{'Attribute'} );
++ if ( $ret ) {
++ RT::Logger->debug("Updating existing lifeycle attribute for " . $args{'LifecycleObj'}->Name);
++ }
++ else {
++ RT::Logger->debug("Could not update attribute for lifecycle ".$args{'LifecycleObj'}->Name.": $msg");
++ }
++ }
++ else {
++ my ($ret, $msg) = $attribute->Create(
++ Name => 'LifecycleAttribute-'.$args{'LifecycleObj'}->Name,
++ Description => 'LifecycleAttribute-'.$args{'LifecycleObj'}->Name,
++ Content => $args{'Attribute'},
++ Object => RT::System,
++ ContentType => 'storable',
++ ObjectType => 'RT::System'
++ );
++ if ( $ret ) {
++ RT::Logger->debug("Creating lifecycle attribute for: ".$args{'LifecycleObj'}->Name);
++ }
++ else {
++ RT::Logger->debug("Could not create lifecycle attribute for ".$args{'LifecycleObj'}->Name.": $msg");
++ }
++ }
++ }
+
+ my $CurrentUser = $args{CurrentUser};
+ my $name = $args{LifecycleObj}->Name;
+ my $lifecycles = RT->Config->Get('Lifecycles');
+
-+ $lifecycles->{$name} = $args{NewConfig};
++ %{$lifecycles->{$name}} = (
++ %{$lifecycles->{$name}},
++ %{$args{NewConfig}}
++ );
+
+ my ($ok, $msg) = $class->_SaveLifecycles($lifecycles, $CurrentUser);
+ return ($ok, $msg) if !$ok;
@@ -443,10 +477,11 @@
+ my $CurrentUser = $args{CurrentUser};
+ my $lifecycles = RT->Config->Get('Lifecycles');
+
-+ %{ $lifecycles->{__maps__} } = (
++ %{ $lifecycles->{__maps__} } = (
+ %{ $lifecycles->{__maps__} || {} },
+ %{ $args{Maps} },
+ );
++ %{ $lifecycles->{__maps__} } = %{ $args{Maps} };
+
+ my ($ok, $msg) = $class->_SaveLifecycles($lifecycles, $CurrentUser);
+ return ($ok, $msg) if !$ok;
@@ -859,10 +894,10 @@
+ <div class="form-row">
+ <input type="hidden" class="hidden" name="Name" value="<% $LifecycleObj->Name %>" />
+ <input type="hidden" class="hidden" name="Type" value="<% $LifecycleObj->Type %>" />
-+ <div class="col-md-12">
-+ <& /Elements/Submit, Label => loc('Save Changes') &>
-+ </div>
+ <& /Elements/Lifecycle/Graph, Lifecycle => $LifecycleObj->Name &>
++ <div class="col-md-12">
++ <& /Elements/Submit, Label => loc('Save Changes') &>
++ </div>
+ </div>
+</form>
+<%INIT>
@@ -883,7 +918,12 @@
+ NewConfig => JSON::from_json($Config),
+ Attribute => $LifecycleAttribute,
+ );
-+ #push @results, $msg;
++ if ( $ok ) {
++ push @results, "Lifecycle updated";
++ }
++ else {
++ push @results, "An error occured when attempting to update lifecycle, see RT log for more info.";
++ }
+}
+
+# This code does automatic redirection if any updates happen.
@@ -1092,7 +1132,7 @@
+ });
+ </script>
+ <div>
-+ <label class="switch">Disable Simulation
++ <label class="switch">Auto Layout
+ <input type="checkbox" name="enableSimulation" id="enableSimulation">
+ </label>
+ <p>
@@ -1123,7 +1163,7 @@
+my $attributes = RT::Attributes->new( RT->SystemUser );
+$attributes->Limit( FIELD => 'Description', VALUE => "LifecycleAttribute-$Lifecycle" );
+my $attribute = $attributes->First;
-+$attribute = $attribute ? JSON($attribute->Content) : "{}";
++$attribute = $attribute ? JSON($attribute->Content) : "{}";
+
+my $id = $Lifecycle . '-' . int(rand(2**31));
+</%INIT>
@@ -1544,16 +1584,20 @@
+ constructor(container, config, attribute) {
+ super("LifecycleModel");
+
-+ var self = this;
-+ self.width = 900;
-+ self.height = 350;
-+ self.node_radius = 35;
-+ self.attribute = attribute;
-+ self.initial = 1;
-+
-+ if ( self.attribute['checked'] ) {
++ var self = this;
++ self.width = 900;
++ self.height = 350;
++ self.node_radius = 35;
++ self.attribute = attribute;
++ self.initial = 1;
++ self.enableSimulation = 1;
++
++ if ( Object.keys(self.attribute).indexOf('checked') == -1 || self.attribute && self.attribute['checked'] ) {
+ jQuery('#enableSimulation').prop( "checked", true );
-+ self.checked = 1;
++ }
++ else {
++ self.enableSimulation = 0;
++ jQuery('#enableSimulation').prop( "checked", false );
+ }
+
+ jQuery("#SaveNode").click(function( event ) {
@@ -1601,7 +1645,7 @@
+ if(link) link.start = true;
+ else self.links.push({id: ++self.links_seq, source: source, target: target, start: false, end: true});
+ });
-+ if ( self.checked ) {
++ if ( !self.enableSimulation ) {
+ if (self.attribute[source.name][0]) source.x = parseFloat(self.attribute[source.name][0]);
+ if (self.attribute[source.name][1]) source.y = parseFloat(self.attribute[source.name][1]);
+ }
@@ -1609,14 +1653,12 @@
+
+ self.simulation = d3.forceSimulation();
+ const link_size = self.nodes.length > 10 ? 300 : self.nodes.length * 35;
-+ if ( self.checked ) {
++ if ( !self.enableSimulation ) {
+ self.simulation
-+ .force("link", d3.forceLink().distance(link_size < 100 ? 200 : link_size).strength(0))
-+ .force("charge", d3.forceManyBody().strength(0))
-+ .force("center", d3.forceCenter(self.width / 2, self.height / 2))
-+ .force('collision', d3.forceCollide().radius(function(d) {
-+ return null;
-+ }));
++ .force("link", null)
++ .force("charge", null)
++ .force("center", null)
++ .force('collision', null);
+ }
+ else {
+ self.simulation
@@ -1643,7 +1685,7 @@
+ if ( d.y + self.node_radius / 2 > self.height ) y = self.height - self.node_radius;
+ if ( d.y - self.node_radius / 2 <= 0 ) y = self.node_radius;
+
-+ if ( self.checked ) {
++ if ( !self.enableSimulation ) {
+ d.fx = x;
+ d.fy = y;
+ }
@@ -1684,10 +1726,7 @@
+ return 'M' + sourceX + ',' + sourceY + 'L' + targetX + ',' + targetY;
+ })
+ );
-+ }))
-+ .force("link")
-+ .links(self.links)
-+ .id(d => d.id);
++ }));
+
+ // Add our current config to the DOM
+ var form = jQuery('form[name="ModifyLifecycle"]');
@@ -1706,6 +1745,8 @@
+
+ self.initial = 0;
+ self.ExportAsConfiguration();
++
++ self.Refresh();
+ }
+
+ SetUp() {
@@ -1782,10 +1823,27 @@
+ self.Refresh();
+ });
+ }
-+ })
-+
-+ jQuery('#enableSimulation').click(function(){
-+ self.ToggleSimulation();
++ });
++
++ jQuery('#enableSimulation').click(function(e) {
++ if ( self.enableSimulation ) {
++ self.ToggleSimulation();
++ return true;
++ }
++
++ if (confirm("Enabling auto layout will remove all node positions") == true) {
++ self.ToggleSimulation();
++ return true;
++ } else {
++ return false;
++ }
++ });
++
++ jQuery('.submit').click(function(e) {
++ e.preventDefault();
++ self.ExportAsConfiguration();
++
++ document.ModifyLifecycle.submit();
+ });
+ }
+
@@ -1819,7 +1877,7 @@
+ }))
+ .on("end", (d => {
+ if (!d3.event.active) this.simulation.alphaTarget(0);
-+ if ( !self.checked ) {
++ if ( !self.enableSimulation ) {
+ d.fx = null, d.fy = null;
+ }
+ })));
@@ -1919,11 +1977,10 @@
+ }
+ else {
+ var name = document.getElementsByName('name')[0].value;
-+ if ( ( this.nodes.findIndex(x => x.name == name ) > 0 && this.nodes.findIndex(x => x.name == name ) <= 1 ) || name === '' ) {
-+ // FIXME
-+ // var form = jQuery('#lifeycycle-ui-edit-node');
-+ // var field = jQuery('<div class="alert alert-warning removing">Name invalid</div>');
-+ // form.append(field);
++ if ( self.nodes.findIndex(x => x.name == name ) >= 2 || name === '' ) {
++ var form = jQuery('#lifeycycle-ui-edit-node');
++ var field = jQuery('<div class="alert alert-warning removing">Name invalid</div>');
++ form.prepend(field);
+ return;
+ }
+
@@ -2075,17 +2132,17 @@
+
+ ToggleSimulation(){
+ var self = this;
-+ self.checked = jQuery('#enableSimulation').is(":checked");
++ self.enableSimulation = jQuery('#enableSimulation').is(":checked");
+
+ const link_size = self.nodes.length > 10 ? 300 : self.nodes.length * 35;
-+ if ( self.checked ) {
++ if ( !self.enableSimulation ) {
+ self.simulation
-+ .force("link", d3.forceLink().distance(link_size < 100 ? 200 : link_size).strength(0))
-+ .force("charge", d3.forceManyBody().strength(0))
-+ .force("center", d3.forceCenter(self.width / 2, self.height / 2))
-+ .force('collision', d3.forceCollide().radius(function(d) {
-+ return null;
-+ }));
++ .force("link", null)
++ .force("charge", null)
++ .force("center", null)
++ .force('collision', null);
++
++ self.ExportAsConfiguration();
+ }
+ else {
+ self.nodes.forEach(function(d) {
@@ -2098,7 +2155,10 @@
+ .force("center", d3.forceCenter(self.width / 2, self.height / 2))
+ .force('collision', d3.forceCollide().radius(function(d) {
+ return d.radius
-+ }));
++ }))
++ self.simulation.force("link")
++ .links(self.links)
++ .id(d => d.id);
+ }
+ self.ExportAsConfiguration();
+ }
@@ -2257,8 +2317,6 @@
+ initial: [],
+ active: [],
+ inactive: [],
-+ actions: [],
-+ starts: {},
+ transitions: {},
+ };
+
@@ -2297,15 +2355,15 @@
+
+ var pos = {};
+ if ( jQuery('#enableSimulation').is(":checked") ) {
++ pos = JSON.parse(jQuery('input[name="LifecycleAttribute"]').val())
+ pos["checked"] = 1;
++ }
++ else {
+ self.nodes.forEach( d => {
+ pos[d.name] = [d.fx, d.fy];
+ });
-+ }
-+ else {
-+ pos = JSON.parse(jQuery('input[name="LifecycleAttribute"]').val())
++
+ pos["checked"] = 0;
-+ console.log(pos);
+ }
+ var attribute = jQuery('input[name="LifecycleAttribute"]');
+ attribute.val(JSON.stringify(pos));
More information about the rt-commit
mailing list