diff --git a/lib/WebGUI/Operation.pm b/lib/WebGUI/Operation.pm index ad4ff7cd2..9e414b824 100644 --- a/lib/WebGUI/Operation.pm +++ b/lib/WebGUI/Operation.pm @@ -87,6 +87,8 @@ sub getOperations { 'manageRevisionsInTag' => 'WebGUI::Operation::VersionTag', 'rollbackVersionTag' => 'WebGUI::Operation::VersionTag', 'setWorkingVersionTag' => 'WebGUI::Operation::VersionTag', + 'promoteWorkflowActivity' => 'WebGUI::Operation::Workflow', + 'demoteWorkflowActivity' => 'WebGUI::Operation::Workflow', 'addWorkflow' => 'WebGUI::Operation::Workflow', 'deleteWorkflow' => 'WebGUI::Operation::Workflow', 'runWorkflow' => 'WebGUI::Operation::Workflow', diff --git a/lib/WebGUI/Operation/Workflow.pm b/lib/WebGUI/Operation/Workflow.pm index e15e7ae49..66852392f 100644 --- a/lib/WebGUI/Operation/Workflow.pm +++ b/lib/WebGUI/Operation/Workflow.pm @@ -118,6 +118,26 @@ sub www_deleteWorkflowActivity { return www_editWorkflow($session); } +#------------------------------------------------------------------ + +=head2 www_demoteWorkflowActivity ( session ) + +Moves a workflow activity down one position in the execution order. + +=head3 session + +A reference to the current session. + +=cut + +sub www_demoteWorkflowActivity { + my $session = shift; + return $session->privilege->insufficient() unless ($session->user->isInGroup("pbgroup000000000000015")); + my $workflow = WebGUI::Workflow->new($session, $session->form->param("workflowId")); + $workflow->demoteActivity($session->form->param("activityId")); + return www_editWorkflow($session); +} + #------------------------------------------------------------------- =head2 www_editWorkflow ( session, workflow ) @@ -184,11 +204,13 @@ sub www_editWorkflow { ); $f->submit; my $steps = ''; - my $rs = $session->db->read("select activityId, title from workflowActivity where workflowId=?",[$workflow->getId]); + my $rs = $session->db->read("select activityId, title from workflowActivity where workflowId=? order by sequenceNumber",[$workflow->getId]); while (my ($id, $title) = $rs->array) { $steps .= ''; } $steps .= '
' .$session->icon->delete("op=deleteWorkflowActivity;workflowId=".$workflow->getId.";activityId=".$id, undef, $i18n->get("confirm delete activity")) .$session->icon->edit("op=editWorkflowActivity;workflowId=".$workflow->getId.";activityId=".$id) + .$session->icon->moveDown("op=demoteWorkflowActivity;workflowId=".$workflow->getId.";activityId=".$id) + .$session->icon->moveUp("op=promoteWorkflowActivity;workflowId=".$workflow->getId.";activityId=".$id) .''.$title.'
'; @@ -302,6 +324,27 @@ sub www_manageWorkflows { return $ac->render($output); } + +#------------------------------------------------------------------ + +=head2 www_promoteWorkflowActivity ( session ) + +Moves a workflow activity up one position in the execution order. + +=head3 session + +A reference to the current session. + +=cut + +sub www_promoteWorkflowActivity { + my $session = shift; + return $session->privilege->insufficient() unless ($session->user->isInGroup("pbgroup000000000000015")); + my $workflow = WebGUI::Workflow->new($session, $session->form->param("workflowId")); + $workflow->promoteActivity($session->form->param("activityId")); + return www_editWorkflow($session); +} + #------------------------------------------------------------------- =head2 www_runWorkflow ( ) diff --git a/lib/WebGUI/Workflow.pm b/lib/WebGUI/Workflow.pm index db25b0fda..1d7d5d0f0 100644 --- a/lib/WebGUI/Workflow.pm +++ b/lib/WebGUI/Workflow.pm @@ -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 ( )