Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Saving progress working fine
  • Loading branch information
CarliPinell committed May 22, 2024
commit a3e8f9e22528ec1d8fdd9442b18575d63a0e678c
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
82 changes: 72 additions & 10 deletions resources/js/tasks/components/QuickFillPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,78 @@ export default {
this.$emit("close");
},
buttonThisDataFromFullTask(data) {
return ProcessMaker.apiClient
.put("drafts/" + this.task.id, data)
.then((response) => {
this.task.draft = _.merge({}, this.task.draft, response.data);
window.location.href = `/tasks/${this.task.id}/edit`;
ProcessMaker.alert(this.$t("Task Filled successfully."), "success");
})
.catch((error) => {
console.error("Error", error);
});
// return ProcessMaker.apiClient
// .put("drafts/" + this.task.id, data)
// .then((response) => {
// this.task.draft = _.merge({}, this.task.draft, response.data);
// window.location.href = `/tasks/${this.task.id}/edit`;
// ProcessMaker.alert(this.$t("Task Filled successfully."), "success");
// })
// .catch((error) => {
// console.error("Error", error);
// });

if (this.propFromButton === "fullTask") {
return new Promise((resolve, reject) => {
ProcessMaker.apiClient.get("drafts/" + this.task.id)
.then(responseGet => {
const dataFromGet = responseGet.data;
if (Array.isArray(dataFromGet) && dataFromGet.length === 0) {
console.log("devuelve array vacio: ", dataFromGet);
// Si dataFromGet es un array vacío, mantén la variable data original
resolve(data);
} else {
console.log("devuelve objeto");
// Si dataFromGet no es un array vacío, asigna su valor a data
//const newData = dataFromGet;
const newData = _.mergeWith(
_.cloneDeep(dataFromGet),
data,
(objValue, srcValue) => {
// If object value is falsy returns value from source(event.detail)
if (!objValue) {
return srcValue;
}
// Otherwise, keeps object value(this.formData)
return objValue;
}
);
resolve(newData);
}
})
.catch(errorGet => {
reject(errorGet);
});
})
.then(dataToUse => {
return ProcessMaker.apiClient.put("drafts/" + this.task.id, dataToUse)
.then(responsePut => {
this.task.draft = _.merge({}, this.task.draft, responsePut.data);
window.location.href = `/tasks/${this.task.id}/edit`;
ProcessMaker.alert(this.$t("Task Filled successfully."), "success");
})
.catch(errorPut => {
console.error("Error", errorPut);
});
})
.catch(error => {
console.error("Error", error);
});
} else {
return ProcessMaker.apiClient
.put("drafts/" + this.task.id, data)
.then((response) => {
this.task.draft = _.merge({}, this.task.draft, response.data);
window.location.href = `/tasks/${this.task.id}/edit`;
ProcessMaker.alert(this.$t("Task Filled successfully."), "success");
})
.catch((error) => {
console.error("Error", error);
});

}


},
/*
* To do: There's a global-search-bar class with a large z-index. We added a class
Expand Down
13 changes: 12 additions & 1 deletion resources/views/tasks/preview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,18 @@ class="card border-0"
});

window.addEventListener('fillData', event => {
this.formData = _.merge(_.cloneDeep(this.formData), event.detail);
this.formData = _.mergeWith(
_.cloneDeep(this.formData),
event.detail,
(objValue, srcValue) => {
// If object value is falsy returns value from source(event.detail)
if (!objValue) {
return srcValue;
}
// Otherwise, keeps object value(this.formData)
return objValue;
}
);
});

window.addEventListener('eraseData', event => {
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
Route::put('tasks/{task}/setPriority', [TaskController::class, 'setPriority'])->name('tasks.priority');

// TaskDrafts
Route::get('drafts/{task}', [TaskDraftController::class, 'index'])->name('taskdraft.index');
Route::put('drafts/{task}', [TaskDraftController::class, 'update'])->name('taskdraft.update');
Route::delete('drafts/{task}', [TaskDraftController::class, 'delete'])->name('taskdraft.delete');

Expand Down