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/app/views/tests/view_helpers.html.erb b/app/views/tests/view_helpers.html.erb new file mode 100644 index 000000000..080d04cfc --- /dev/null +++ b/app/views/tests/view_helpers.html.erb @@ -0,0 +1,13 @@ + +<%= javascript_include_tag "/assets/tests/qunit-1.21.0.js", "/assets/tests/view_helpers.js", nonce: true %> + + + +<%= javascript_tag nonce: true do -%> +<% end -%> + +
diff --git a/config/routes/test.rb b/config/routes/test.rb index eebd02eac..c0e71e57a 100644 --- a/config/routes/test.rb +++ b/config/routes/test.rb @@ -37,6 +37,7 @@ Zammad::Application.routes.draw do match '/tests_text_module', to: 'tests#text_module', via: :get match '/tests_color_object', to: 'tests#color_object', via: :get match '/tests_kb_video_embeding', to: 'tests#kb_video_embeding', via: :get + match '/tests_view_helpers', to: 'tests#view_helpers', via: :get match '/tests/wait/:sec', to: 'tests#wait', via: :get match '/tests/raised_exception', to: 'tests#error_raised_exception', via: :get diff --git a/public/assets/tests/view_helpers.js b/public/assets/tests/view_helpers.js new file mode 100644 index 000000000..9ebf4385c --- /dev/null +++ b/public/assets/tests/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') +}) diff --git a/spec/system/js/q_unit_spec.rb b/spec/system/js/q_unit_spec.rb index ffa1fe604..63b392edc 100644 --- a/spec/system/js/q_unit_spec.rb +++ b/spec/system/js/q_unit_spec.rb @@ -68,6 +68,10 @@ RSpec.describe 'QUnit', type: :system, authenticated_as: false, set_up: true, we it 'Image Service' do q_unit_tests('image_service') end + + it 'View helpers' do + q_unit_tests('view_helpers') + end end context 'Form' do