aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-05-08 11:46:47 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-05-08 11:46:47 +0100
commitdeb14e7bc1979343188a0130d34bef16256e17ca (patch)
treec6015ab576ecca6b9b8d8fff90990f04a8455617
parent5c34efb1c21fc75c38024a0c802d448eef6527ba (diff)
Web interface now uses an ajax call to work out ack times, falling back to
javascript if that takes too long. Default working hours are now 9.30 - 5.30 as per SLA.
-rw-r--r--lib/mauve/configuration.rb2
-rw-r--r--lib/mauve/mauve_time.rb5
-rw-r--r--lib/mauve/web_interface.rb25
-rw-r--r--static/javascript/mauve_utils.js30
4 files changed, 36 insertions, 26 deletions
diff --git a/lib/mauve/configuration.rb b/lib/mauve/configuration.rb
index 4ee71dd..2acbc42 100644
--- a/lib/mauve/configuration.rb
+++ b/lib/mauve/configuration.rb
@@ -79,7 +79,7 @@ module Mauve
#
self.dead_zone = 3...6
self.daytime_hours = 8...20
- self.working_hours = 9...17
+ self.working_hours = 9.5..17.5
end
# Set the calendar URL.
diff --git a/lib/mauve/mauve_time.rb b/lib/mauve/mauve_time.rb
index d3fc039..c12fba3 100644
--- a/lib/mauve/mauve_time.rb
+++ b/lib/mauve/mauve_time.rb
@@ -119,7 +119,10 @@ class Time
if defined? Mauve::Configuration and Mauve::Configuration.current
Mauve::Configuration.current.working_hours
else
- [9.0...17.0]
+ # From our SLA:
+ # "Working hours" means 9.30am to 5.30pm, Monday to Friday, excluding
+ # English bank holidays.
+ [9.5..17.5]
end
end
diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb
index 5919bb6..9a46403 100644
--- a/lib/mauve/web_interface.rb
+++ b/lib/mauve/web_interface.rb
@@ -267,29 +267,30 @@ EOF
#
get '/ajax/time_in_x_hours/:n_hours/:type_hours' do
- content_type :text
+ content_type "application/json"
n_hours = params[:n_hours].to_f
type_hours = params[:type_hours].to_s
- #
- # Sanitise parameters
- #
- n_hours = ( n_hours > 300 ? 300 : n_hours )
- type_hours = "daytime" unless %w(daytime working wallclock).include?(type_hours)
now = Time.now
- ack_until = now.in_x_hours(n_hours, type_hours)
+ max_ack = (Time.now + Configuration.current.max_acknowledgement_time)
#
- # Make sure we can't ack longer than a week.
+ # Make sure we can't ack longer than the configuration allows.
#
- max_ack = (Time.now + Configuration.current.max_acknowledgement_time)
- ack_until = max_ack if ack_until > max_ack
-
+ if (n_hours * 3600.0).to_i > Configuration.current.max_acknowledgement_time
+ ack_until = max_ack
+ else
+ type_hours = "daytime" unless %w(daytime working wallclock).include?(type_hours)
+ ack_until = now.in_x_hours(n_hours, type_hours)
+ pp ack_until
+ ack_until = max_ack if ack_until > max_ack
+ end
+
#
# Return answer as unix seconds.
#
- ack_until.to_f.round.to_s
+ "{ \"time\" : #{ack_until.to_f.round}, \"string\" : \"#{ack_until.to_s_human}\" }"
end
get '/ajax/time_to_s_human/:seconds' do
diff --git a/static/javascript/mauve_utils.js b/static/javascript/mauve_utils.js
index 1918006..1330635 100644
--- a/static/javascript/mauve_utils.js
+++ b/static/javascript/mauve_utils.js
@@ -1,20 +1,25 @@
function updateDate() {
- //
- // Date.getTime() returns *milliseconds*
- //
- var this_date = workoutDate( $( '#n_hours' ).val(), $( '#type_hours' ).val() );
- $( '#ack_until' ).val( this_date.getTime()/1000 );
//
// Use a asynchronous ajax convert a date to a human string. NB Date.getTime()
// returns *milliseconds*
//
$.ajax( {
- url: '/ajax/time_to_s_human/'+this_date.getTime()/1000,
- timeout: 1000,
- success: function( data ) { $( '#ack_until_text' ).html( "( until "+data+" )" ); },
- error: function( a,b,c ) { $( '#ack_until_text' ).html( "( until "+this_date.toString()+" )" ); }
+ url: '/ajax/time_in_x_hours/'+$( '#n_hours' ).val()+'/'+$( '#type_hours' ).val(),
+ timeout: 2000,
+ success: function( data ) {
+ $( '#ack_until' ).val( data['time'] );
+ $( '#ack_until_text' ).html( "( until "+data['string']+" )" );
+ },
+ error: function( a,b,c ) {
+ //
+ // Date.getTime() returns *milliseconds*
+ //
+ var this_date = workoutDate( $( '#n_hours' ).val(), $( '#type_hours' ).val() );
+ $( '#ack_until' ).val( this_date.getTime()/1000 );
+ $( '#ack_until_text' ).html( "( until "+this_date.toString()+" )" );
+ }
} );
return false;
@@ -110,13 +115,14 @@ function doTimeTest( t, type ) {
switch ( type ) {
case "working":
r = ( d.getDay() > 0 && d.getDay() < 6 &&
- ( ( d.getHours() >= 9 && d.getHours() <= 16 ) ||
- ( d.getHours() == 8 && d.getMinutes() >= 30 )
+ ( ( d.getHours() >= 10 && d.getHours() <= 16 ) ||
+ ( d.getHours() == 9 && d.getMinutes() >= 30 ) ||
+ ( d.getHours() == 17 && d.getMinutes() < 30 )
) );
break;
case "daytime":
- r = ( d.getHours() >= 8 && d.getHours() <= 21 );
+ r = ( d.getHours() >= 8 && d.getHours() < 22 );
break;
default: