diff --git a/app/assets/javascripts/app/lib/mixins/view_helpers.coffee b/app/assets/javascripts/app/lib/mixins/view_helpers.coffee index 1ef955244..fd4a0db12 100644 --- a/app/assets/javascripts/app/lib/mixins/view_helpers.coffee +++ b/app/assets/javascripts/app/lib/mixins/view_helpers.coffee @@ -36,22 +36,38 @@ App.ViewHelpers = App.Utils.decimal(data, positions) # define time_duration / mm:ss / hh:mm:ss format helper - time_duration: (time, show_seconds = true) -> + time_duration: (time) -> return '' if !time return '' if isNaN(parseInt(time)) # Hours, minutes and seconds - hrs = ~~parseInt((time / 3600)) + hrs = ~~parseInt((time / 3600)) mins = ~~parseInt(((time % 3600) / 60)) secs = parseInt(time % 60) # Output like "1:01" or "4:03:59" or "123:03:59" mins = "0#{mins}" if mins < 10 secs = "0#{secs}" if secs < 10 - if hrs > 0 && show_seconds + + if hrs > 0 return "#{hrs}:#{mins}:#{secs}" + "#{mins}:#{secs}" + # define time_duration / hh:mm + time_duration_hh_mm: (time_in_minutes) -> + return '' if !time_in_minutes + return '' if isNaN(parseInt(time_in_minutes)) + + # Hours, minutes and seconds + hrs = ~~parseInt((time_in_minutes / 60)) + mins = ~~parseInt((time_in_minutes % 60)) + + hrs = "0#{hrs}" if hrs < 10 + mins = "0#{mins}" if mins < 10 + + "#{hrs}:#{mins}" + # define mask helper # mask an value like 'a***********yz' M: (item, start = 1, end = 2) -> diff --git a/app/assets/javascripts/app/views/sla/index.jst.eco b/app/assets/javascripts/app/views/sla/index.jst.eco index 8e0ee1bdf..0aab1d7c5 100644 --- a/app/assets/javascripts/app/views/sla/index.jst.eco +++ b/app/assets/javascripts/app/views/sla/index.jst.eco @@ -34,19 +34,19 @@
<%- @T('Escalation Times') %>
<% if sla.first_response_time: %> - <%- @time_duration(sla.first_response_time, false) %> <%- @T('hours') %> - <%- @T('First Response Time') %> + <%- @time_duration_hh_mm(sla.first_response_time) %> <%- @T('hours') %> - <%- @T('First Response Time') %> <% end %> <% if sla.response_time: %>
- <%- @time_duration(sla.response_time, false) %> <%- @T('hours') %> - <%- @T('Response Time') %> + <%- @time_duration_hh_mm(sla.response_time) %> <%- @T('hours') %> - <%- @T('Response Time') %> <% end %> <% if sla.update_time: %>
- <%- @time_duration(sla.update_time, false) %> <%- @T('hours') %> - <%- @T('Update Time') %> + <%- @time_duration_hh_mm(sla.update_time) %> <%- @T('hours') %> - <%- @T('Update Time') %> <% end %> <% if sla.solution_time: %>
- <%- @time_duration(sla.solution_time, false) %> <%- @T('hours') %> - <%- @T('Solution Time') %> + <%- @time_duration_hh_mm(sla.solution_time) %> <%- @T('hours') %> - <%- @T('Solution Time') %> <% end %>
diff --git a/public/assets/tests/qunit/view_helpers.js b/public/assets/tests/qunit/view_helpers.js new file mode 100644 index 000000000..9ebf4385c --- /dev/null +++ b/public/assets/tests/qunit/view_helpers.js @@ -0,0 +1,25 @@ +QUnit.test("time_duration_hh_mm", assert => { + let func = App.ViewHelpers.time_duration_hh_mm + assert.equal(func(1), '00:01') + + assert.equal(func(61), '01:01') + + assert.equal(func(3600), '60:00') + + assert.equal(func(7200), '120:00') +}) + +QUnit.test("time_duration", assert => { + let func = App.ViewHelpers.time_duration + assert.equal(func(1), '00:01') + + assert.equal(func(61), '01:01') + + assert.equal(func(3600), '1:00:00') + + assert.equal(func(7200), '2:00:00') + + assert.equal(func(36000), '10:00:00') + + assert.equal(func(360101), '100:01:41') +})