Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOUR-15854 on task completed - override behavior #6875

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 89 additions & 10 deletions ProcessMaker/Models/ProcessRequestToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use DB;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Notification;
Expand Down Expand Up @@ -135,6 +136,7 @@ class ProcessRequestToken extends ProcessMakerModel implements TokenInterface
*/
protected $appends = [
'advanceStatus',
'elementDestination'
];

/**
Expand Down Expand Up @@ -286,29 +288,46 @@ public function assignableUsers()
return new TokenAssignableUsers($query, $this);
}

/**
* Get the BPMN definition of the element where the token is.
*
* @return array|\ProcessMaker\Nayra\Contracts\Bpmn\EntityInterface
*/
public function getDefinition($asObject = false, $par = null)
private function getDefinitionFromOwner($asObject)
devmiguelangel marked this conversation as resolved.
Show resolved Hide resolved
{
if ($this->getOwner() && $this->getOwnerElement()) {
$element = $this->getOwnerElement();
$element = $this->getOwnerElement();

return $asObject ? $element : $element->getProperties();
}
return $asObject ? $element : $element->getProperties();
}

private function getDefinitionFromRequest($asObject)
devmiguelangel marked this conversation as resolved.
Show resolved Hide resolved
{
$request = $this->processRequest ?: $this->getInstance();

if (!$request) {
return [];
}

$process = $request->processVersion ?: $request->process;
$definitions = $process->getDefinitions();
$element = $definitions->findElementById($this->element_id);

if (!$element) {
return [];
}

return $asObject ? $element->getBpmnElementInstance() : $element->getBpmnElementInstance()->getProperties();
}

/**
* Get the BPMN definition of the element where the token is.
*
* @return array|\ProcessMaker\Nayra\Contracts\Bpmn\EntityInterface
*/
public function getDefinition($asObject = false, $par = null)
{
if ($this->getOwner() && $this->getOwnerElement()) {
return $this->getDefinitionFromOwner($asObject);
}

return $this->getDefinitionFromRequest($asObject);
}

/**
* Get the BPMN element node where the token is currently located.
*
Expand Down Expand Up @@ -1152,4 +1171,64 @@ public function reassign($toUserId, User $requestingUser)
$this->user->notify($notification);
event(new ActivityAssigned($this));
}

/**
* Determines the destination URL based on the element destination type specified in the definition.
*
* @return string|null
*/
public function getElementDestinationAttribute(): ?string
{
$definition = $this->getDefinition();
$elementDestinationProp = $definition['elementDestination'] ?? null;
$elementDestination = null;
$elementDestinationType = null;

try {
$elementDestinationProp = json_decode($elementDestinationProp, true);
if (is_array($elementDestinationProp) && array_key_exists('type', $elementDestinationProp)) {
$elementDestinationType = $elementDestinationProp['type'];
}
} catch (Exception $e) {
return null;
}

switch ($elementDestinationType) {
devmiguelangel marked this conversation as resolved.
Show resolved Hide resolved
case 'customDashboard':
case 'externalURL':
if (array_key_exists('value', $elementDestinationProp)) {
if (is_string($elementDestinationProp['value'])) {
$elementDestination = $elementDestinationProp['value'];
} else {
$elementDestination = $elementDestinationProp['value']['url'] ?? null;
}
}
break;
case 'taskList':
$elementDestination = route('tasks.index');
break;
case 'homepageDashboard':
if (hasPackage('package-dynamic-ui')) {
devmiguelangel marked this conversation as resolved.
Show resolved Hide resolved
$user = auth()->user();
$elementDestination = \ProcessMaker\Package\PackageDynamicUI\Models\DynamicUI::getHomePage($user);
} else {
$elementDestination = route('home');
}
break;
case 'processLaunchpad':
$elementDestination = route('process.browser.index', [
'process' => $this->process_id,
'categorySelected' => -1
]);
break;
case 'taskSource':
$elementDestination = $elementDestinationType;
break;
default:
$elementDestination = null;
break;
}

return $elementDestination;
}
}
4 changes: 4 additions & 0 deletions resources/js/processes-catalogue/components/ProcessTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<script>
import RequestTab from "./RequestTab.vue";
import TaskTab from "./TaskTab.vue";

export default {
components: {
RequestTab,
Expand All @@ -42,6 +43,9 @@ export default {
type: Object,
},
},
mounted() {
sessionStorage.setItem("elementDestinationURL", window.location.href);
},
};
</script>
<style>
Expand Down
10 changes: 8 additions & 2 deletions resources/views/tasks/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,17 @@ class="multiselect__tag-icon"></i>
redirectToTask(task, force = false) {
this.redirect(`/tasks/${task}/edit`, force);
},
closed(taskId) {
closed(taskId, elementDestination = null) {
// avoid redirection if using a customized renderer
if (this.task.component && this.task.component === 'AdvancedScreenFrame') {
return;
}

if (elementDestination) {
this.redirect(elementDestination);
return;
}

this.redirect("/tasks");
},
claimTask() {
Expand Down Expand Up @@ -677,7 +683,7 @@ class="multiselect__tag-icon"></i>
screenFields.forEach((field) => {
_.set(draftData, field, _.get(this.formData, field));
});

return ProcessMaker.apiClient
.put("drafts/" + this.task.id, draftData)
.then((response) => {
Expand Down
2 changes: 2 additions & 0 deletions resources/views/tasks/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class="ml-md-2"
window.ProcessMaker.taskDraftsEnabled = @json($taskDraftsEnabled);
window.ProcessMaker.advanced_filter = @json($userFilter);
window.Processmaker.defaultColumns = @json($defaultColumns);

window.sessionStorage.setItem('elementDestinationURL', window.location.href);
</script>
<script src="{{mix('js/tasks/index.js')}}"></script>
@endsection
Expand Down
Loading