can now move workflow activities up and down within a workflow
This commit is contained in:
parent
a794fbd0d7
commit
70c501f8f2
3 changed files with 114 additions and 1 deletions
|
|
@ -129,6 +129,31 @@ sub deleteActivity {
|
|||
$activity->delete if ($activity);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 demoteActivity ( activityId )
|
||||
|
||||
Moves an activity down one position in the execution order.
|
||||
|
||||
=head3 activityId
|
||||
|
||||
The id of the activity to move.
|
||||
|
||||
=cut
|
||||
|
||||
sub demoteActivity {
|
||||
my $self = shift;
|
||||
my $thisId = shift;
|
||||
my ($thisSeq) = $self->session->db->quickArray("select sequenceNumber from WorkflowActivity where activityId=?",[$thisId]);
|
||||
my ($otherId) = $self->session->db->quickArray("select activityId from WorkflowActivity where workflowId=? and sequenceNumber=?",[$self->getId, $thisSeq+1]);
|
||||
if ($otherId ne "") {
|
||||
$self->session->db->write("update WorkflowActivity set sequenceNumber=sequenceNumber+1 where activityId=?", [$thisId]);
|
||||
$self->session->db->write("update WorkflowActivity set sequenceNumber=sequenceNumber-1 where activityId=?", [$otherId]);
|
||||
$self->reorderActivities;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 DESTROY ( )
|
||||
|
|
@ -286,6 +311,49 @@ sub new {
|
|||
bless {_session=>$session, _id=>$workflowId, _data=>$data}, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 promoteActivity ( activityId )
|
||||
|
||||
Moves an activity up one position in the execution order.
|
||||
|
||||
=head3 activityId
|
||||
|
||||
The id of the activity to move.
|
||||
|
||||
=cut
|
||||
|
||||
sub promoteActivity {
|
||||
my $self = shift;
|
||||
my $thisId = shift;
|
||||
my ($thisSeq) = $self->session->db->quickArray("select sequenceNumber from WorkflowActivity where activityId=?",[$thisId]);
|
||||
my ($otherId) = $self->session->db->quickArray("select activityId from WorkflowActivity where workflowId=? and sequenceNumber=?",[$self->getId, $thisSeq-1]);
|
||||
if ($otherId ne "") {
|
||||
$self->session->db->write("update WorkflowActivity set sequenceNumber=sequenceNumber-1 where activityId=?", [$thisId]);
|
||||
$self->session->db->write("update WorkflowActivity set sequenceNumber=sequenceNumber+1 where activityId=?", [$otherId]);
|
||||
$self->reorderActivities;
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head3 reorderActivities ( )
|
||||
|
||||
Reorders the acitivities to make sure they're consecutive.
|
||||
|
||||
=cut
|
||||
|
||||
sub reorderActivities {
|
||||
my $self = shift;
|
||||
my $sth = $self->session->db->read("select activityId from WorkflowActivity where workflowId=? order by sequenceNumber",[$self->getId]);
|
||||
my $i = 0;
|
||||
while (my ($id) = $sth->array) {
|
||||
$i++;
|
||||
$self->session->db->write("update WorkflowActivity set sequenceNumber=? where activityId=?",[$i, $id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue