fix: display sla indicators at the top

This commit is contained in:
Himanshu Warekar 2019-05-05 12:19:08 +05:30
parent 898ab61dd4
commit b3070ca765
3 changed files with 43 additions and 32 deletions

View File

@ -1,12 +1,13 @@
frappe.ui.form.on("Issue", {
onload: function(frm) {
frm.email_field = "raised_by";
if (frm.doc.service_level_agreement) {
set_time_to_resolve_and_response(frm);
}
},
refresh: function (frm) {
if (frm.doc.service_level_agreement) {
set_time_to_resolve_and_response(frm);
}
if (frm.doc.status !== "Closed") {
frm.add_custom_button(__("Close"), function () {
frm.set_value("status", "Closed");
@ -27,6 +28,16 @@ frappe.ui.form.on("Issue", {
}
},
priority: function(frm) {
if (frm.doc.service_level_agreement) {
frm.call('change_sla_priority', {
"priority": frm.doc.priority
}).then(() => {
frm.refresh()
});
}
},
timeline_refresh: function(frm) {
// create button for "Help Article"
if(frappe.model.can_create('Help Article')) {
@ -81,36 +92,30 @@ frappe.ui.form.on("Issue", {
});
function set_time_to_resolve_and_response(frm) {
frm.dashboard.clear_headline();
const customer = frm.fields_dict['customer'].$wrapper;
const email_account = frm.fields_dict['email_account'].$wrapper;
var time_to_respond = get_time_left(frm.doc.response_by);
var time_to_resolve = get_time_left(frm.doc.resolution_by);
const time_to_respond = $(get_time_left_element(__('Time To Respond'), frm.doc.response_by));
const time_to_resolve = $(get_time_left_element(__('Time To Resolve'), frm.doc.resolution_by));
time_to_respond.insertAfter(customer);
time_to_resolve.insertAfter(email_account);
}
function get_time_left_element(label, timestamp) {
$('.'+ frappe.scrub(label) +'').remove();
return `
<div class="frappe-control input-max-width `+ frappe.scrub(label) +`" data-field_name="`+ frappe.scrub(label) +`">
<div class="form-group">
<div class="clearfix">
<label class="control-label" style="padding-right: 0px;">
${label}
</label>
</div>
<div class="control-input-wrapper">
<div class="control-value like-disabled-input">${get_time_left(timestamp)}</div>
</div>
</div>
</div>
`;
frm.dashboard.set_headline_alert(
'<div class="row">' +
'<div class="col-xs-6">' +
'<span class="indicator whitespace-nowrap '+ time_to_respond.indicator +'"><span class="hidden-xs">Time to Respond: '+ time_to_respond.diff_display +'</span></span> ' +
'</div>' +
'<div class="col-xs-6">' +
'<span class="indicator whitespace-nowrap '+ time_to_resolve.indicator +'"><span class="hidden-xs">Time to Resolve: '+ time_to_resolve.diff_display +'</span></span> ' +
'</div>' +
'</div>'
);
}
function get_time_left(timestamp) {
const diff = moment(timestamp).diff(moment());
return diff >= 44500 ? moment.duration(diff).humanize() : 0;
const diff_display = diff >= 44500 ? moment.duration(diff).humanize() : moment(0, 'seconds').format('HH:mm');
var indicator = "green";
if (diff_display == '00:00') {
indicator = "red";
}
return {"diff_display": diff_display,
"indicator": indicator};
}

View File

@ -150,6 +150,11 @@ class Issue(Document):
self.response_by = get_expected_time_for(parameter='response', service_level=priority, start_date_time=start_date_time)
self.resolution_by = get_expected_time_for(parameter='resolution', service_level=priority, start_date_time=start_date_time)
@frappe.whitelist()
def change_sla_priority(self, priority):
self.set_response_and_resolution_time(priority=priority)
self.save(ignore_permissions=True)
def get_expected_time_for(parameter, service_level, start_date_time):
current_date_time = start_date_time
expected_time = current_date_time

View File

@ -27,6 +27,7 @@
"depends_on": "eval: !doc.default_service_level_agreement",
"fieldname": "customer",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Customer",
"options": "Customer",
"set_only_once": 1
@ -35,6 +36,7 @@
"depends_on": "eval: !doc.customer",
"fieldname": "default_service_level_agreement",
"fieldtype": "Check",
"in_list_view": 1,
"label": "Default Service Level Agreement",
"set_only_once": 1
},
@ -121,8 +123,7 @@
"fieldname": "support_and_resolution",
"fieldtype": "Table",
"label": "Support and Resolution",
"options": "Service Day",
"read_only": 1
"options": "Service Day"
},
{
"fieldname": "service_level_agreement_name",
@ -132,7 +133,7 @@
"unique": 1
}
],
"modified": "2019-05-04 13:11:21.373147",
"modified": "2019-05-05 12:17:02.793287",
"modified_by": "Administrator",
"module": "Support",
"name": "Service Level Agreement",