Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 21 additions & 1 deletion ProcessMaker/Repositories/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Mustache_Engine;
use ProcessMaker\Models\ProcessCollaboration;
use ProcessMaker\Models\ProcessRequest as Instance;
use ProcessMaker\Models\ProcessRequestToken;
Expand Down Expand Up @@ -145,7 +146,7 @@ public function persistActivityActivated(ActivityInterface $activity, TokenInter
}

//Default 3 days of due date
$due = $activity->getProperty('dueIn', '72');
$due = $this->getDueVariable($activity, $token);
$token->due_at = $due ? Carbon::now()->addHours($due) : null;
$token->initiated_at = null;
$token->riskchanges_at = $due ? Carbon::now()->addHours($due * 0.7) : null;
Expand All @@ -158,6 +159,25 @@ public function persistActivityActivated(ActivityInterface $activity, TokenInter
$this->instanceRepository->persistInstanceUpdated($token->getInstance());
}

/**
* Get due Variable
*
* @param Instance $instance
* @param User $user
*/
private function getDueVariable(ActivityInterface $activity, TokenInterface $token)
{
$isDueVariable = $activity->getProperty('isDueInVariable', false);
$dueVariable = $activity->getProperty('dueInVariable');
if ($isDueVariable && !empty($dueVariable)) {
$instanceData= $token->getInstance()->getDataStore()->getData();
$mustache = new Mustache_Engine();
$mustacheDueVariable = $mustache->render($dueVariable, $instanceData);
return is_numeric($mustacheDueVariable) ? $mustacheDueVariable : '72';
}
return $activity->getProperty('dueIn', '72');
}

/**
* Persists tokens that triggered a Start Event
*
Expand Down
2 changes: 2 additions & 0 deletions public/definitions/ProcessMaker.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<xsd:attribute name="interstitialScreenRef" type="xsd:string"/>
<xsd:attribute name="screenVersion" type="xsd:string" use="optional"/>
<xsd:attribute name="dueIn" type="xsd:decimal"/>
<xsd:attribute name="dueInVariable" type="xsd:string" use="optional"/>
<xsd:attribute name="isDueInVariable" type="xsd:boolean" default="false"/>
<xsd:attribute name="notifyAfterRouting" type="xsd:boolean" default="false"/>
<xsd:attribute name="notifyToRequestCreator" type="xsd:boolean" default="false"/>
<xsd:attribute name="assignment" type="xsd:string" default="requestor"/>
Expand Down
118 changes: 78 additions & 40 deletions resources/js/processes/modeler/components/inspector/TaskDueIn.vue
Original file line number Diff line number Diff line change
@@ -1,52 +1,90 @@
<template>
<div class="form-group">
<label>{{ $t("Due In") }}</label>
<input class="form-control" :aria-label="$t('Enter the hours until this Task is overdue')"
type="number"
:placeholder="$t('72 hours')"
:value="dueInGetter"
@input="dueInSetter"
min="0"
v-on:keydown="dueInValidate">
<small class="form-text text-muted">{{ $t("Enter the hours until this Task is overdue") }}</small>
</div>
<div class="form-group">
<label>{{ $t("Due In") }}</label>
<b-form-checkbox
v-model="isCheckDueIn"
name="checkDueInVariable"
>
{{ $t("Use request Variable") }}
</b-form-checkbox>
<template v-if="!isCheckDueIn">
<input
class="form-control"
:aria-label="$t('Enter the hours until this Task is overdue')"
type="number"
:placeholder="$t('72 hours')"
:value="dueInGetter"
min="0"
@input="dueInSetter"
@keydown="dueInValidate"
>
<small class="form-text text-muted">{{ $t("Enter the hours until this Task is overdue") }}</small>
</template>
<template v-else>
<input
class="form-control"
type="text"
:placeholder="$t('Type')"
:value="dueInVariableGetter"
@input="dueInVariableSetter"
@keydown="dueInValidate"
>
<small class="form-text text-muted">{{ $t("This field supports mustache syntax to send requests variables.") }}</small>
</template>
</div>
</template>

<script>
export default {
props: ["value", "label", "helper", "property"],
computed: {
dueInGetter() {
return _.get(this.node, "dueIn");
export default {
props: ["value", "label", "helper", "property"],
computed: {
dueInGetter() {
return _.get(this.node, "dueIn");
},
node() {
return this.$root.$children[0].$refs.modeler.highlightedNode.definition;
},
isCheckDueIn: {
get() {
return _.get(this.node, "isDueInVariable");
},
node() {
return this.$root.$children[0].$refs.modeler.highlightedNode.definition;
set(val) {
this.$set(this.node, "isDueInVariable", val);
},
},
methods: {
dueInValidate(event) {
if (event.key === "-") {
event.preventDefault();
return;
}
},
/**
dueInVariableGetter() {
return _.get(this.node, "dueInVariable");
},
},
methods: {
dueInValidate(event) {
if (event.key === "-") {
event.preventDefault();
}
},
/**
* Update due in property
*/
dueInSetter(event) {
const validValue = Math.abs(event.target.value * 1) || "";
if (!validValue) {
this.$delete(this.node, "dueIn");
} else {
this.$set(this.node, "dueIn", validValue);
}
this.$emit("input", this.value);
String(validValue) !== event.target.value
? (event.target.value = validValue)
: null;
},
}
};
dueInSetter(event) {
const validValue = Math.abs(event.target.value * 1) || "";
if (!validValue) {
this.$delete(this.node, "dueIn");
} else {
this.$set(this.node, "dueIn", validValue);
}
this.$emit("input", this.value);
String(validValue) !== event.target.value
? (event.target.value = validValue)
: null;
},
/**
* Updte due in with variable
*/
dueInVariableSetter(event) {
this.$set(this.node, "dueInVariable", event.target.value);
},
},
};
</script>

<style lang="scss" scoped>
Expand Down