forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes zammad#864 - Added relative pending_time to Macro/Trigger/Sched…
…uler functionality. Based on the Pull Request zammad#2862 by @fleverest – huge thanks ❤️
- Loading branch information
1 parent
e48f49a
commit 22fe0a2
Showing
12 changed files
with
363 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Ensures pending time is always zero-seconds | ||
class Observer::Ticket::PendingTime < ActiveRecord::Observer | ||
observe 'ticket' | ||
|
||
def before_create(record) | ||
_check(record) | ||
end | ||
|
||
def before_update(record) | ||
_check(record) | ||
end | ||
|
||
private | ||
|
||
def _check(record) | ||
return true if record.pending_time.blank? | ||
return true if !record.pending_time_changed? | ||
return true if record.pending_time.sec.zero? | ||
|
||
record.pending_time = record.pending_time.change sec: 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
<link rel="stylesheet" href="/assets/tests/qunit-1.21.0.css"> | ||
<%= javascript_include_tag "/assets/tests/qunit-1.21.0.js", "/assets/tests/ticket_macro.js", nonce: true %> | ||
|
||
<style type="text/css"> | ||
body { | ||
padding-top: 0px; | ||
} | ||
</style> | ||
|
||
<script type="text/javascript"> | ||
</script> | ||
|
||
<div id="qunit" class="u-dontfold"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
test( "ticket macro pending time check", function() { | ||
var test_relative = function(rules, target, description){ | ||
var ticket = new App.Ticket() | ||
|
||
App.Ticket.macro({ | ||
ticket: ticket, | ||
macro: { | ||
"ticket.pending_time": rules | ||
} | ||
}) | ||
|
||
var compare_against = new Date() | ||
var travel = Math.abs( new Date(ticket.pending_time) - compare_against) | ||
|
||
var diff = Math.abs(target - travel) | ||
|
||
ok(diff < 1000, description) | ||
} | ||
|
||
var rules = { | ||
operator: "relative", | ||
range: "day", | ||
value: 5 | ||
} | ||
|
||
test_relative(rules, 60 * 60 * 24 * 5 * 1000, '5 days') | ||
|
||
var rules = { | ||
operator: "relative", | ||
range: "minute", | ||
value: 3 | ||
} | ||
|
||
test_relative(rules, 60 * 3 * 1000, '5 minutes') | ||
|
||
var rules = { | ||
operator: "relative", | ||
range: "hour", | ||
value: 10 | ||
} | ||
|
||
test_relative(rules, 60 * 60 * 10 * 1000, '10 hours') | ||
}) |
Oops, something went wrong.