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
3 changes: 3 additions & 0 deletions src/assets/priority-header.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
254 changes: 203 additions & 51 deletions src/components/renderer/form-tasks.vue
Original file line number Diff line number Diff line change
@@ -1,48 +1,111 @@
<template>
<div v-if="showTable">
<vuetable
ref="vuetable"
:data-manager="dataManager"
:sort-order="sortOrder"
:api-mode="false"
:fields="fields"
<filter-table
:headers="tableHeaders"
:data="tableData"
:css="css"
data-path="data"
pagination-path="meta"
:unread="unreadColumnName"
:loading="shouldShowLoader"
>
<template slot="name" slot-scope="props">
<b-link
v-uni-id="props.rowData.id.toString()"
:href="onAction('edit', props.rowData, props.rowIndex)"
<template
v-for="(column, index) in tableHeaders"
v-slot:[column.field]
>
<div
:key="index"
style="display: inline-block"
>
{{ props.rowData.element_name }}
</b-link>
<img
v-if="column.field === 'is_priority'"
src="../../assets/priority-header.svg"
alt="priority-header"
width="20"
height="20"
/>
<span v-else>{{ $t(column.label) }}</span>
</div>
</template>
<template slot="requestName" slot-scope="props">
<b-link
:href="onAction('showRequestSummary', props.rowData, props.rowIndex)"
<template
v-for="(row, rowIndex) in tableData.data"
v-slot:[`row-${rowIndex}`]
>
<td v-for="(header, colIndex) in tableHeaders"
:key="`${rowIndex}-${colIndex}`"
>
#{{ props.rowData.process_request.id }}
{{ props.rowData.process_request.name }}
</b-link>
<template v-if="containsHTML(getNestedPropertyValue(row, header))">
<div
:id="`element-${rowIndex}-${colIndex}`"
:class="{ 'pm-table-truncate': header.truncate }"
:style="{ maxWidth: header.width + 'px' }"
>
<span v-html="sanitize(getNestedPropertyValue(row, header))"></span>
</div>
<b-tooltip
v-if="header.truncate"
:target="`element-${rowIndex}-${colIndex}`"
custom-class="pm-table-tooltip"
@show="checkIfTooltipIsNeeded"
>
{{ sanitizeTooltip(getNestedPropertyValue(row, header)) }}
</b-tooltip>
</template>
<template v-else>
<template v-if="isComponent(row[header.field])">
<component
:is="row[header.field].component"
v-bind="row[header.field].props"
>
</component>
</template>
<template v-else>
<template v-if="header.field === 'due_at'">
<span
:class="[
'badge',
'badge-' + row['color_badge'],
'due-' + row['color_badge'],
]"
>
{{ formatRemainingTime(row.due_at) }}
</span>
<span>{{ getNestedPropertyValue(row, header) }}</span>
</template>
<template v-else-if="header.field === 'is_priority'">
<span>
<img
:src="
row[header.field]
? '/img/priority.svg'
: '/img/no-priority.svg'
"
:alt="row[header.field] ? 'priority' : 'no-priority'"
width="20"
height="20"
@click.prevent="togglePriority(row.id, !row[header.field])"
/>
</span>
</template>
<template v-else>
<div
:id="`element-${rowIndex}-${colIndex}`"
:class="{ 'pm-table-truncate': header.truncate }"
:style="{ maxWidth: header.width + 'px' }"
>
{{ getNestedPropertyValue(row, header) }}
<b-tooltip
v-if="header.truncate"
:target="`element-${rowIndex}-${colIndex}`"
custom-class="pm-table-tooltip"
@show="checkIfTooltipIsNeeded"
>
{{ getNestedPropertyValue(row, header) }}
</b-tooltip>
</div>
</template>
</template>
</template>
</td>
</template>
<template slot="dueDate" slot-scope="props">
<span :class="classDueDate(props.rowData.due_at)">
{{ formatDate(props.rowData.due_at) }}
</span>
</template>
<template slot="completedDate" slot-scope="props">
<span class="text-dark">
{{ formatDate(props.rowData.completed_at) }}
</span>
</template>
<template slot="preview" slot-scope="props">
<span>
<i class="fa fa-eye" @click="previewTasks(props.rowData)" />
</span>
</template>
</vuetable>
</filter-table>
<component :is="tasksPreview" ref="preview-sidebar" />
</div>
<div v-else>
Expand Down Expand Up @@ -71,6 +134,7 @@ export default {
order_direction: "DESC",
status: "",
showTable: true,
tableHeaders: [],
sortOrder: [
{
field: "ID",
Expand All @@ -88,7 +152,7 @@ export default {
}
},
mounted() {
this.setFields();
this.setupColumns();
this.pmql = `(user_id = ${ProcessMaker.user.id}) AND (status = "In Progress")`;
this.fetch();
this.$root.$on("dropdownSelectionTask", this.fetchData);
Expand Down Expand Up @@ -151,6 +215,11 @@ export default {
)
.then((response) => {
this.showTable = response.data.data.length !== 0;
for (const record of response.data.data) {
record["case_title"] = this.formatCaseTitle(record.process_request, record);
record["color_badge"] = this.formatColorBadge(record["due_at"]);
record["element_name"] = this.formatActiveTask(record);
}
this.tableData = response.data;
this.countResponse = this.tableData.meta.total;
this.countOverdue = `${this.tableData.meta.in_overdue}`;
Expand All @@ -174,40 +243,79 @@ export default {
});
});
},
formatActiveTask(row) {
return `
<a href="${this.openTask(row)}"
data-cy="active-task-data"
class="text-nowrap">
${row.element_name}
</a>`;
},
formatColorBadge(date) {
const days = this.remainingTime(date);
return days >= 0 ? "primary" : "danger";
},
formatCaseTitle(processRequest, record) {
return `
<a href="${this.openTask(processRequest, 1)}"
class="text-nowrap">
${
processRequest.case_title_formatted ||
processRequest.case_title ||
record.case_title ||
""
}
</a>`;
},
openTask() {},
getColumns() {
const columns = [
{
label: "Task",
field: "task",
field: "element_name",
sortable: true,
default: true
default: true,
width: 153,
},
{
label: "Request",
field: "request",
label: "Priority",
field: "is_priority",
sortable: false,
default: true,
width: 48,
},
{
label: "Case title",
field: "case_title",
name: "__slot:case_number",
sortable: true,
default: true
}
default: true,
width: 314,
truncate: true,
},
];

if (this.status === "CLOSED") {
columns.push({
label: "Completed",
field: "completed_at",
sortable: true,
default: true
default: true,
width: 220,
});
} else {
columns.push({
label: "Due",
field: "due_at",
sortable: true,
default: true
default: true,
width: 220,
});
}
return columns;
},
setFields() {
setupColumns() {
this.tableHeaders = this.getColumns();
const columns = this.getColumns();

columns.forEach((column) => {
Expand All @@ -221,6 +329,10 @@ export default {
field.field = "element_name";
field.sortField = "element_name";
break;
case "is_priority":
field.name = "__slot:is_priority";
field.field = "is_priority";
break;
case "request":
field.name = "__slot:requestName";
field.sortField = "process_requests.id,process_requests.name";
Expand Down Expand Up @@ -254,10 +366,6 @@ export default {
name: "__slot:preview",
title: ""
});

this.$nextTick(() => {
this.$refs.vuetable.normalizeFields();
});
},
formatDate(value, format) {
format = format || "";
Expand Down Expand Up @@ -311,7 +419,51 @@ export default {
this.pmql = "";
this.pmql = searchData;
this.fetch();
},
formatRemainingTime(date) {
const millisecondsPerDay = 1000 * 60 * 60 * 24;
const remaining = this.remainingTime(date);
const daysRemaining = Math.ceil(remaining / millisecondsPerDay);
if (daysRemaining <= 1 && daysRemaining >= -1) {
const hoursRemaining = Math.ceil(remaining / (1000 * 60 * 60));
return `${hoursRemaining}H`;
}

return `${daysRemaining}D`;
},
remainingTime(date) {
date = moment(date);
if (!date.isValid()) {
return 0;
}
return date.diff(this.now);
},
sanitizeTooltip(html) {
let cleanHtml = html.replace(/<script(.*?)>[\s\S]*?<\/script>/gi, "");
cleanHtml = cleanHtml.replace(/<style(.*?)>[\s\S]*?<\/style>/gi, "");
cleanHtml = cleanHtml.replace(
/<(?!img|input|meta|time|button|select|textarea|datalist|progress|meter)[^>]*>/gi,
""
);
cleanHtml = cleanHtml.replace(/\s+/g, " ");

return cleanHtml;
}
}
};
</script>

<style scoped>
.due-danger {
background-color: rgba(237, 72, 88, 0.2);
color: rgba(237, 72, 88, 1);
font-weight: 600;
border-radius: 5px;
}
.due-primary {
background: rgba(205, 221, 238, 1);
color: rgba(86, 104, 119, 1);
font-weight: 600;
border-radius: 5px;
}
</style>
Loading