From bd05d7639ff72e163bcb5260c44fafa4159b5844 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Tue, 5 Nov 2024 10:59:08 -0800 Subject: [PATCH] Refactor to use mixin for preview --- resources/js/common/reassignMixin.js | 71 +++++++++++++++++++ .../js/tasks/components/TasksPreview.vue | 67 +++-------------- resources/js/tasks/show.js | 2 + resources/views/tasks/edit.blade.php | 56 ++------------- 4 files changed, 87 insertions(+), 109 deletions(-) create mode 100644 resources/js/common/reassignMixin.js diff --git a/resources/js/common/reassignMixin.js b/resources/js/common/reassignMixin.js new file mode 100644 index 0000000000..5a9aef2fbe --- /dev/null +++ b/resources/js/common/reassignMixin.js @@ -0,0 +1,71 @@ +export default { + data() { + return { + selectedUser: null, + allowReassignment: false, + reassignUsers: [], + }; + }, + computed: { + currentTaskUserId() { + return this.task?.user_id ?? this.task?.user?.id; + } + }, + methods: { + setAllowReassignment() { + if (!this.task?.id) { + return; + } + window.ProcessMaker.apiClient.get('tasks/user-can-reassign?tasks=' + this.task.id) + .then((response) => { + this.allowReassignment = response.data[this.task.id]; + }); + }, + getReassignUsers(filter = null) { + const params = { }; + if (filter) { + params.filter = filter; + } + if (this.task?.id) { + params.assignable_for_task_id = this.task.id; + } + + ProcessMaker.apiClient.get('users_task_count', { params }).then(response => { + this.reassignUsers = []; + response.data.data.forEach((user) => { + if (this.currentTaskUserId === user.id) { + return; + } + this.reassignUsers.push({ + text: user.fullname, + value: user.id, + active_tasks_count: user.active_tasks_count + }); + }); + }); + }, + onReassignInput: _.debounce(function (filter) { + this.getReassignUsers(filter); + }, 300), + + reassignUser(redirect = false) { + if (this.selectedUser) { + ProcessMaker.apiClient + .put("tasks/" + this.task.id, { + user_id: this.selectedUser + }) + .then(response => { + this.$emit("on-reassign-user", this.selectedUser); + this.showReassignment = false; + this.selectedUser = null; + if (redirect) { + this.redirect('/tasks'); + } + if (this.showPreview) { + this.showPreview = false; + } + }); + } + }, + } +} \ No newline at end of file diff --git a/resources/js/tasks/components/TasksPreview.vue b/resources/js/tasks/components/TasksPreview.vue index 6a49434a8d..fd45f5817a 100644 --- a/resources/js/tasks/components/TasksPreview.vue +++ b/resources/js/tasks/components/TasksPreview.vue @@ -143,7 +143,7 @@ >
-