Skip to content

Commit bd05d76

Browse files
committed
Refactor to use mixin for preview
1 parent eaf7ad7 commit bd05d76

File tree

4 files changed

+87
-109
lines changed

4 files changed

+87
-109
lines changed

resources/js/common/reassignMixin.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
export default {
2+
data() {
3+
return {
4+
selectedUser: null,
5+
allowReassignment: false,
6+
reassignUsers: [],
7+
};
8+
},
9+
computed: {
10+
currentTaskUserId() {
11+
return this.task?.user_id ?? this.task?.user?.id;
12+
}
13+
},
14+
methods: {
15+
setAllowReassignment() {
16+
if (!this.task?.id) {
17+
return;
18+
}
19+
window.ProcessMaker.apiClient.get('tasks/user-can-reassign?tasks=' + this.task.id)
20+
.then((response) => {
21+
this.allowReassignment = response.data[this.task.id];
22+
});
23+
},
24+
getReassignUsers(filter = null) {
25+
const params = { };
26+
if (filter) {
27+
params.filter = filter;
28+
}
29+
if (this.task?.id) {
30+
params.assignable_for_task_id = this.task.id;
31+
}
32+
33+
ProcessMaker.apiClient.get('users_task_count', { params }).then(response => {
34+
this.reassignUsers = [];
35+
response.data.data.forEach((user) => {
36+
if (this.currentTaskUserId === user.id) {
37+
return;
38+
}
39+
this.reassignUsers.push({
40+
text: user.fullname,
41+
value: user.id,
42+
active_tasks_count: user.active_tasks_count
43+
});
44+
});
45+
});
46+
},
47+
onReassignInput: _.debounce(function (filter) {
48+
this.getReassignUsers(filter);
49+
}, 300),
50+
51+
reassignUser(redirect = false) {
52+
if (this.selectedUser) {
53+
ProcessMaker.apiClient
54+
.put("tasks/" + this.task.id, {
55+
user_id: this.selectedUser
56+
})
57+
.then(response => {
58+
this.$emit("on-reassign-user", this.selectedUser);
59+
this.showReassignment = false;
60+
this.selectedUser = null;
61+
if (redirect) {
62+
this.redirect('/tasks');
63+
}
64+
if (this.showPreview) {
65+
this.showPreview = false;
66+
}
67+
});
68+
}
69+
},
70+
}
71+
}

resources/js/tasks/components/TasksPreview.vue

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
>
144144
</b-button>
145145
<b-button
146-
v-if="isAllowReassignment || isUserAdmin || isProcessManager"
146+
v-if="allowReassignment"
147147
class="btn text-secondary icon-button"
148148
variant="light"
149149
:aria-label="$t('Reassign')"
@@ -187,16 +187,15 @@
187187
</div>
188188
<div class="flex-grow-1">
189189
<PMDropdownSuggest v-model="selectedUser"
190-
:options="users"
191-
@onInput="onInput"
192-
@onSelectedOption="onSelectedOption"
190+
:options="reassignUsers"
191+
@onInput="onReassignInput"
193192
:placeholder="$t('Type here to search')">
194193
<template v-slot:pre-text="{ option }">
195-
<b-badge variant="secondary" class="mr-2 custom-badges pl-2 pr-2 rounded-lg">{{ option.count }}</b-badge>
194+
<b-badge variant="secondary" class="mr-2 custom-badges pl-2 pr-2 rounded-lg">{{ option.active_tasks_count }}</b-badge>
196195
</template>
197196
</PMDropdownSuggest>
198197
</div>
199-
<button type="button" class="btn btn-primary btn-sm ml-2" @click="reassignUser" :disabled="disabled">
198+
<button type="button" class="btn btn-primary btn-sm ml-2" @click="reassignUser(false)" :disabled="disabled">
200199
{{ $t('Assign') }}
201200
</button>
202201
<button type="button" class="btn btn-outline-secondary btn-sm ml-2" @click="cancelReassign">
@@ -263,15 +262,14 @@ import QuickFillPreview from "./QuickFillPreview.vue";
263262
import PreviewMixin from "./PreviewMixin";
264263
import autosaveMixins from "../../modules/autosave/autosaveMixin.js"
265264
import PMDropdownSuggest from "../../components/PMDropdownSuggest.vue";
265+
import reassignMixin from "../../common/reassignMixin";
266266
267267
export default {
268268
components: { SplitpaneContainer, TaskLoading, QuickFillPreview, TaskSaveNotification, EllipsisMenu, PMDropdownSuggest },
269-
mixins: [PreviewMixin, autosaveMixins],
269+
mixins: [PreviewMixin, autosaveMixins, reassignMixin],
270270
props: ["tooltipButton", "propPreview"],
271271
data(){
272272
return {
273-
selectedUser: null,
274-
users: []
275273
};
276274
},
277275
watch: {
@@ -294,6 +292,7 @@ export default {
294292
295293
if (task?.id !== previousTask?.id) {
296294
this.userHasInteracted = false;
295+
this.setAllowReassignment();
297296
}
298297
},
299298
},
@@ -328,24 +327,12 @@ export default {
328327
this.screenWidthPx = window.innerWidth;
329328
window.addEventListener('resize', this.updateScreenWidthPx);
330329
this.getUser();
331-
this.getUsers("");
330+
this.setAllowReassignment();
332331
},
333332
computed: {
334333
disabled() {
335334
return this.selectedUser ? false : true;
336335
},
337-
isAllowReassignment() {
338-
if (this.taskDefinition.definition) {
339-
return this.taskDefinition.definition.allowReassignment === "true";
340-
}
341-
return false;
342-
},
343-
isUserAdmin() {
344-
return this.user.is_administrator;
345-
},
346-
isProcessManager() {
347-
return this.task.process_obj.properties.manager_id === ProcessMaker.user.id;
348-
},
349336
},
350337
methods: {
351338
fillWithQuickFillData(data) {
@@ -416,26 +403,13 @@ export default {
416403
this.userHasInteracted = false;
417404
});
418405
},
419-
reassignUser() {
420-
if (this.selectedUser) {
421-
ProcessMaker.apiClient
422-
.put("tasks/" + this.task.id, {
423-
user_id: this.selectedUser
424-
})
425-
.then(response => {
426-
this.$emit("on-reassign-user", this.selectedUser);
427-
this.showReassignment = false;
428-
this.selectedUser = null;
429-
this.getUsers("");
430-
});
431-
}
432-
},
433406
cancelReassign() {
434407
this.showReassignment = false;
435408
this.selectedUser = null;
436409
},
437410
openReassignment() {
438411
this.showReassignment = !this.showReassignment;
412+
this.getReassignUsers();
439413
},
440414
getTaskDefinitionForReassignmentPermission() {
441415
ProcessMaker.apiClient
@@ -451,27 +425,6 @@ export default {
451425
this.user = response.data;
452426
});
453427
},
454-
getUsers(filter) {
455-
ProcessMaker.apiClient.get(this.getUrlUsersTaskCount(filter)).then(response => {
456-
this.users = [];
457-
for (let i in response.data.data) {
458-
this.users.push({
459-
text: response.data.data[i].fullname,
460-
value: response.data.data[i].id,
461-
count: response.data.data[i].count
462-
});
463-
}
464-
});
465-
},
466-
getUrlUsersTaskCount(filter) {
467-
let url = "users_task_count?filter=" + filter;
468-
return url;
469-
},
470-
onInput(filter) {
471-
this.getUsers(filter);
472-
},
473-
onSelectedOption(item) {
474-
}
475428
}
476429
};
477430
</script>

resources/js/tasks/show.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import autosaveMixins from "../modules/autosave/autosaveMixin";
1515
import draftFileUploadMixin from "../modules/autosave/draftFileUploadMixin";
1616
import Mustache from "mustache";
1717
import TaskSaveNotification from "./components/TaskSaveNotification.vue";
18+
import reassignMixin from "../common/reassignMixin";
1819

1920
Vue.use(Vuex);
2021
Vue.use("task", Task);
@@ -32,6 +33,7 @@ Vue.component("PMDropdownSuggest", PMDropdownSuggest);
3233

3334
Vue.mixin(autosaveMixins);
3435
Vue.mixin(draftFileUploadMixin);
36+
Vue.mixin(reassignMixin);
3537

3638
window.debounce = debounce;
3739
window.Vuex = Vuex;

resources/views/tasks/edit.blade.php

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ class="d-inline-flex pull-left align-items-center"
339339
<div class="form-group">
340340
{!!Form::label('user', __('User'))!!}
341341
<p-m-dropdown-suggest v-model="selectedUser"
342-
:options="users"
343-
@pmds-input="onInput"
342+
:options="reassignUsers"
343+
@pmds-input="onReassignInput"
344344
:placeholder="$t('Type here to search')">
345345
<template v-slot:pre-text="{ option }">
346346
<b-badge variant="secondary"
@@ -354,7 +354,7 @@ class="mr-2 custom-badges pl-2 pr-2 rounded-lg">
354354
<button type="button" class="btn btn-outline-secondary" @click="cancelReassign">
355355
{{__('Cancel')}}
356356
</button>
357-
<button type="button" class="btn btn-secondary" @click="reassignUser" :disabled="disabled">
357+
<button type="button" class="btn btn-secondary" @click="reassignUser(true)" :disabled="disabled">
358358
{{__('Reassign')}}
359359
</button>
360360
</div>
@@ -427,7 +427,6 @@ class="mr-2 custom-badges pl-2 pr-2 rounded-lg">
427427
task,
428428
draftTask,
429429
userHasAccessToTask,
430-
selectedUser: null,
431430
hasErrors: false,
432431
redirectInProcess: false,
433432
formData: {},
@@ -451,9 +450,7 @@ class="mr-2 custom-badges pl-2 pr-2 rounded-lg">
451450
showMenu: true,
452451
userConfiguration: @json($userConfiguration),
453452
urlConfiguration:'users/configuration',
454-
users: [],
455453
showTabs: true,
456-
allowReassignment: false,
457454
},
458455
watch: {
459456
task: {
@@ -542,17 +539,8 @@ class="mr-2 custom-badges pl-2 pr-2 rounded-lg">
542539
const status = (this.task.advanceStatus || '').toUpperCase();
543540
return "card-header text-status " + header[status];
544541
},
545-
currentTaskUserId() {
546-
return this.task?.user_id ?? this.task?.user?.id;
547-
}
548542
},
549543
methods: {
550-
setAllowReassignment() {
551-
window.ProcessMaker.apiClient.get('tasks/user-can-reassign?tasks=' + this.task.id)
552-
.then((response) => {
553-
this.allowReassignment = response.data[this.task.id];
554-
});
555-
},
556544
defineUserConfiguration() {
557545
this.userConfiguration = JSON.parse(this.userConfiguration.ui_configuration);
558546
this.showMenu = this.userConfiguration.tasks.isMenuCollapse;
@@ -641,7 +629,7 @@ class="mr-2 custom-badges pl-2 pr-2 rounded-lg">
641629
show () {
642630
this.selectedUser = null;
643631
this.showReassignment = true;
644-
this.getUsers("");
632+
this.getReassignUsers();
645633
},
646634
showQuickFill () {
647635
this.redirect(`/tasks/${this.task.id}/edit/quickfill`);
@@ -650,19 +638,6 @@ class="mr-2 custom-badges pl-2 pr-2 rounded-lg">
650638
this.selectedUser = null;
651639
this.showReassignment = false;
652640
},
653-
reassignUser () {
654-
if (this.selectedUser) {
655-
ProcessMaker.apiClient
656-
.put("tasks/" + this.task.id, {
657-
user_id: this.selectedUser
658-
})
659-
.then(response => {
660-
this.showReassignment = false;
661-
this.selectedUser = null;
662-
this.redirect('/tasks');
663-
});
664-
}
665-
},
666641
redirect(to, forceRedirect = false) {
667642
if (this.redirectInProcess && !forceRedirect) {
668643
return;
@@ -875,29 +850,6 @@ class="mr-2 custom-badges pl-2 pr-2 rounded-lg">
875850
caseTitleField(task) {
876851
this.caseTitle = task.process_request.case_title;
877852
},
878-
getUsers(filter) {
879-
const params = { filter };
880-
if (this.task?.id) {
881-
params.assignable_for_task_id = this.task.id;
882-
}
883-
884-
ProcessMaker.apiClient.get('users_task_count', { params }).then(response => {
885-
this.users = [];
886-
response.data.data.forEach((user) => {
887-
if (this.currentTaskUserId === user.id) {
888-
return;
889-
}
890-
this.users.push({
891-
text: user.fullname,
892-
value: user.id,
893-
active_tasks_count: user.active_tasks_count
894-
});
895-
});
896-
});
897-
},
898-
onInput: _.debounce(function (filter) {
899-
this.getUsers(filter);
900-
}, 300),
901853
getCommentsData: async () => {
902854
const response = await ProcessMaker.apiClient.get("comments-by-case", {
903855
params: {

0 commit comments

Comments
 (0)