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
14 changes: 13 additions & 1 deletion ProcessMaker/Http/Controllers/Api/TaskDraftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@

class TaskDraftController extends Controller
{
public function index(Request $request, ProcessRequestToken $task)
{
$search = ['task_id' => $task->id];
$draft = TaskDraft::where($search)->first();

if ($draft) {
$draftData = $draft->data;
return new ApiResource($draftData);
}

return new ApiResource(null);
}

public function update(Request $request, ProcessRequestToken $task)
{
$search = ['task_id' => $task->id];
Expand All @@ -24,7 +37,6 @@ public function update(Request $request, ProcessRequestToken $task)
}
$draft->data = $data;
$draft->saveOrFail();

return new ApiResource($draft);
}

Expand Down
4 changes: 4 additions & 0 deletions ProcessMaker/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ public function edit(ProcessRequestToken $task, string $preview = '')

public function quickFillEdit(ProcessRequestToken $task)
{
$screenVersion = $task->getScreenVersion();
$screenFields = $screenVersion ? $screenVersion->screenFilteredFields() : [];

return view('tasks.editQuickFill', [
'task' => $task,
'screenFields' => $screenFields,
]);
}
}
2 changes: 1 addition & 1 deletion resources/js/inbox-rules/components/InboxRuleFillData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
this.$emit("submit", data);
});
this.receiveEvent('taskReady', () => {
this.sendEvent("fillData", this.inboxRuleData);
this.sendEvent("fillDataOverwriteExistingFields", this.inboxRuleData);
});
},
methods: {
Expand Down
24 changes: 21 additions & 3 deletions resources/js/tasks/components/QuickFillPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
</template>
<script>
export default {
props: ["task", "propColumns", "propFilters", "propFromButton"],
props: ["task", "propColumns", "propFilters", "propFromButton", "screenFields"],
data() {
return {
processName: "",
Expand Down Expand Up @@ -269,9 +269,27 @@ export default {
}
this.$emit("close");
},
buttonThisDataFromFullTask(data) {
buttonThisDataFromFullTask(quickFillData) {
// If the task does not have a draft yet, use the task data
const dataToUse = this.task.draft?.data ?? this.task.data;

const draftData = {};
this.screenFields.forEach((field) => {
const existingValue = _.get(dataToUse, field, null);
let quickFillValue;
if (existingValue) {
// If the value exists in the task data (or task draft data), don't overwrite it
quickFillValue = existingValue;
} else {
// use the value from the quick fill
quickFillValue = _.get(quickFillData, field, null);
}
// Set the value. This handles nested values using dot notation in 'field' string
_.set(draftData, field, quickFillValue);
});

return ProcessMaker.apiClient
.put("drafts/" + this.task.id, data)
.put("drafts/" + this.task.id, draftData)
.then((response) => {
this.task.draft = _.merge({}, this.task.draft, response.data);
window.location.href = `/tasks/${this.task.id}/edit`;
Expand Down
8 changes: 7 additions & 1 deletion resources/views/tasks/editQuickFill.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function() use ($task) {
<div v-cloak id="quickfill" class="container-fluid px-3">
<quick-fill-preview
class="quick-fill-preview"
:task="{{ $task }}"
:task="task"
:screen-fields="screenFields"
:prop-from-button ="'fullTask'"
:prop-columns="columns"
:prop-filters="filters"
Expand All @@ -43,13 +44,18 @@ class="quick-fill-preview"
<script src="{{mix('js/tasks/show.js')}}"></script>
<script>
let task = @json($task);
task.draft = @json($task->draft);
task.data = @json($task->processRequest->data);
const screenFields = @json($screenFields);
const store = new Vuex.Store();
const main = new Vue({
store: store,
el: "#quickfill",
data: {
isDisabled: true,
data: {},
task,
screenFields,
filters: {
order: { by: "created_at", direction: "desc" },
filters:[
Expand Down
24 changes: 24 additions & 0 deletions resources/views/tasks/preview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,30 @@ class="card border-0"
});

window.addEventListener('fillData', event => {
const newData = {};
screenFields.forEach((field) => {

const existingValue = _.get(this.formData, field, null);
let quickFillValue;

if (existingValue) {
// If the value exists in the task data, don't overwrite it
quickFillValue = existingValue;
} else {
// use the value from the quick fill(event.detail)
quickFillValue = _.get(event.detail, field, null);
}
// Set the value. This handles nested values using dot notation in 'field' string
_.set(newData, field, quickFillValue);
});

this.formData = newData;
});

// Used by inbox rules new/edit interface. With inbox rules, we always
// want to use all data saved in the inbox rule db record, regardless
// if the field exists or not.
window.addEventListener('fillDataOverwriteExistingFields', event => {
this.formData = _.merge(_.cloneDeep(this.formData), event.detail);
});

Expand Down