From 13c75e73812927359ca8a1d606ed33bd6a75eea5 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 15 Jun 2011 21:12:26 +0100 Subject: Rejigged column names.. and javascript location. --HG-- rename : static/mauve_utils.js => static/javascript/mauve_utils.js --- lib/mauve/alert.rb | 2 +- static/javascript | 1 - static/javascript/mauve_utils.js | 56 +++++++++ static/mauve.js | 211 --------------------------------- static/mauve_utils.js | 56 --------- views/_alerts_table.haml | 2 +- views/_alerts_table_alert_summary.haml | 5 +- views/_alerts_table_group.haml | 2 +- views/_head.haml | 2 +- 9 files changed, 64 insertions(+), 273 deletions(-) delete mode 120000 static/javascript create mode 100644 static/javascript/mauve_utils.js delete mode 100644 static/mauve.js delete mode 100644 static/mauve_utils.js diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index 9cb2521..6694fca 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -395,7 +395,7 @@ module Mauve alert_db = first(:alert_id => alert.id, :source => update.source) || new(:alert_id => alert.id, :source => update.source) - + # # Work out what state the alert was in before receiving this update. # diff --git a/static/javascript b/static/javascript deleted file mode 120000 index e3b95b4..0000000 --- a/static/javascript +++ /dev/null @@ -1 +0,0 @@ -/usr/share/javascript \ No newline at end of file diff --git a/static/javascript/mauve_utils.js b/static/javascript/mauve_utils.js new file mode 100644 index 0000000..3012ca3 --- /dev/null +++ b/static/javascript/mauve_utils.js @@ -0,0 +1,56 @@ + +function updateDate() { + // + // Date.getTime() returns *milliseconds* + // + var this_date = workoutDate( $('#n_hours').val(), $('#type_hours').val() ); + $('#ack_until_text').html("(until "+humanDate(this_date)+")"); + $('#ack_until').val(this_date.getTime()/1000); + + return false; +} + +function workoutDate(h, t) { + var new_date = null; + + // + // Use a synchronous ajax request to fetch the date. Note that + // Date.getTime() returns milliseconds.. + // + $.ajax({ + url: '/ajax/time_in_x_hours/'+h+"/"+t, + async: false, + success: function(data) { new_date = new Date ( new Number(data) * 1000 ); } + }); + + return new_date; +} + + +function humanDate(d) { + var new_date = null; + // + // Use a synchronous ajax convert a date to a human string. NB Date.getTime() + // returns *milliseconds* + // + $.ajax({ + url: '/ajax/time_to_s_human/'+d.getTime()/1000, + async: false, + success: function(data) { new_date = data; } + }); + + return new_date; +} + +function fetchDetail(a) { + // Use a synchronous ajax request to fetch the date. + $.get('/ajax/alerts_table_alert_detail/'+a, + function(data) { + $('#tr_summary_'+a).after(data); + // Only fetch the data once. + $('#a_detail_'+a).attr("onclick",null).click(function() { $('#tr_detail_'+a).toggle(); return false; }); + }); + + return false; +} + diff --git a/static/mauve.js b/static/mauve.js deleted file mode 100644 index 0cc32ec..0000000 --- a/static/mauve.js +++ /dev/null @@ -1,211 +0,0 @@ -/* - * This contains all the 'clever' javascript used on the page. - */ -var mouse_is_inside = false; - -/* -try { - $("#myselector").click (function () {}); //my jQuery code here -} catch (e) { - //this executes if jQuery isn't loaded - alert(e.message - + "\nCould be a network error leading to jquery not being loaded!\n" - + "Reloading the page."); - window.location.reload(true); -} -*/ - -//////////////////////////////////////////////////////////////////////////////// -// Treeview data. -$(document).ready(function(){ - $("#blackAck").treeview({ - control: "#treecontrolAck", - persist: "cookie", - cookieId: "treeview-black" - }); - -}); -$(document).ready(function(){ - $("#blackNew").treeview({ - control: "#treecontrolNew", - persist: "cookie", - cookieId: "treeview-black" - }); -}); - -$(document).ready(function(){ - - //////////////////////////////////////////////////////////////////////////////// - // This allows pop! to do its thing, used for details. - $.pop(); - - //////////////////////////////////////////////////////////////////////////////// - // Countdown code. - - /* - // This binds to the timer that reloads the page every 300 seconds via callback. - $('#reloadPage').countdown({until: +300, onExpiry: liftOff, format: 'MS'}); - - // This is the callback that reloads the page. - function liftOff() { - window.location.reload(true); - } - */ - - - //////////////////////////////////////////////////////////////////////////////// - // Mouse outside of changeStatus form. - // See url http://stackoverflow.com/questions/1403615/use-jquery-to-hide-div-when-click-outside-it - $('.updateAlertStatus').hover(function(){ - mouse_is_inside=true; - }, function(){ - mouse_is_inside=false; - }); - $('body').mouseup(function(){ - if(! mouse_is_inside) - { - //$(".updateAlertStatus").fadeOut(1000); - //$('.darkMask').fadeOut(1000); - $(".updateAlertStatus").hide(); - $('.darkMask').hide(); - } - }); -}); - -//////////////////////////////////////////////////////////////////////////////// -// Acknowledge status functions. - - -//////////////////////////////////////////////////////////////////////////////// -// Standards are there to be violated... -function mouseX(evt) { - if (evt.pageX) return evt.pageX; - else if (evt.clientX) - return evt.clientX + (document.documentElement.scrollLeft ? - document.documentElement.scrollLeft : - document.body.scrollLeft); - else return null; -} - -//////////////////////////////////////////////////////////////////////////////// -// Standards are there to be violated... -function mouseY(evt) { - if (evt.pageY) return evt.pageY; - else if (evt.clientY) - return evt.clientY + (document.documentElement.scrollTop ? - document.documentElement.scrollTop : - document.body.scrollTop); - else return null; -} - -//////////////////////////////////////////////////////////////////////////////// -// Shows the updateAlertStatus div where the mouse clicked and mask the rest of -// page. -function showAcknowledgeStatus (e, id, ackTime) { - - // Build the form. - document.changeAlertStatusForm.AlertID.value = id; - document.changeAlertStatusForm.AlertDefaultAcknowledgeTime.value = ackTime; - var myselect=document.getElementById("sample"); - myselect.remove(0); - str = returnTimeString(ackTime); - myselect.add(new Option(str, ackTime, true, true), myselect.options[0]) - - // Show the form. - //leftVal = mouseX(e); - leftVal = 2 - topVal = mouseY(e); - $('.updateAlertStatus').css({left:leftVal,top:topVal}).fadeIn(500); - $('.darkMask').css({height:$(document).height()}).show(); -} - -// Returns the default time. -function returnTimeString (time) { - hrs = time / 3600 - if (1 == hrs) - { - str = "1 hour" - } - else if (24 > hrs && 1 > hrs) - { - str = hrs + " hours" - } - else if (24 == hrs) - { - str = "1 day" - } - else if (24 < hrs && 168 > hrs) - { - str = hrs / 24 + " days" - } - else if (168 == hrs) - { - str = "1 week" - } - else - { - str = hrs / 168 + " weeks" - } - return str + ", default." -} - -//////////////////////////////////////////////////////////////////////////////// -// Shows the updateAlertSatus div for group of alerts. -function showBulkAcknowledgeStatus(e, ids, ackTime) -{ - for (i in ids) - { - changeAcknowledgeStatusCall(ids[i], ackTime); - } - //window.location.reload(true); - tmp = $('#firstAlert'+ids[0]); - tmp.remove() -} - -function changeAcknowledgeStatusCall (id, acknowledgedUntil) { - $.post('/alert/acknowledge/'+id+'/'+acknowledgedUntil); - tmp = $('#alert'+id) - tmp.remove(); - tmp.appendTo('#blackAck'); -} - -//////////////////////////////////////////////////////////////////////////////// -// Actually gets the alert updated and moves it to the right list. -// Note that id is a numberical ID of the alert. -// Note that acknowledgedUntil is a number of seconds. -function changeAcknowledgeStatus (id, acknowledgedUntil) { - if (-1 != id) - { - changeAcknowledgeStatusCall(id, acknowledgedUntil); - } - $(".updateAlertStatus").hide(); - $('.darkMask').hide(); -} - -//////////////////////////////////////////////////////////////////////////////// -// Clears (aka trash aka delete) an alert. -// THIS IS NOT WHAT YOU WANT -// url http://stackoverflow.com/questions/95600/jquery-error-option-in-ajax-utility -// url http://stackoverflow.com/questions/377644/jquery-ajax-error-handling-show-custom-exception-messages -function clearAlert (id) { - $.post('/alert/'+id+'/clear'); - $(".updateAlertStatus").hide(); - $('.darkMask').hide(); - tmp = $('#alert'+id) - tmp.remove(); -} - -//////////////////////////////////////////////////////////////////////////////// -// Raises (aka unacknowledge) an alert. -function raiseAlert (id) { - $.post('/alert/'+id+'/raise'); - $(".updateAlertStatus").hide(); - $('.darkMask').hide(); - tmp = $('#alert'+id) - tmp.remove(); - tmp.appendTo('#blackNew'); -} - - -//////////////////////////////////////////////////////////////////////////////// -// EOF diff --git a/static/mauve_utils.js b/static/mauve_utils.js deleted file mode 100644 index 3012ca3..0000000 --- a/static/mauve_utils.js +++ /dev/null @@ -1,56 +0,0 @@ - -function updateDate() { - // - // Date.getTime() returns *milliseconds* - // - var this_date = workoutDate( $('#n_hours').val(), $('#type_hours').val() ); - $('#ack_until_text').html("(until "+humanDate(this_date)+")"); - $('#ack_until').val(this_date.getTime()/1000); - - return false; -} - -function workoutDate(h, t) { - var new_date = null; - - // - // Use a synchronous ajax request to fetch the date. Note that - // Date.getTime() returns milliseconds.. - // - $.ajax({ - url: '/ajax/time_in_x_hours/'+h+"/"+t, - async: false, - success: function(data) { new_date = new Date ( new Number(data) * 1000 ); } - }); - - return new_date; -} - - -function humanDate(d) { - var new_date = null; - // - // Use a synchronous ajax convert a date to a human string. NB Date.getTime() - // returns *milliseconds* - // - $.ajax({ - url: '/ajax/time_to_s_human/'+d.getTime()/1000, - async: false, - success: function(data) { new_date = data; } - }); - - return new_date; -} - -function fetchDetail(a) { - // Use a synchronous ajax request to fetch the date. - $.get('/ajax/alerts_table_alert_detail/'+a, - function(data) { - $('#tr_summary_'+a).after(data); - // Only fetch the data once. - $('#a_detail_'+a).attr("onclick",null).click(function() { $('#tr_detail_'+a).toggle(); return false; }); - }); - - return false; -} - diff --git a/views/_alerts_table.haml b/views/_alerts_table.haml index aa0c437..f413c30 100644 --- a/views/_alerts_table.haml +++ b/views/_alerts_table.haml @@ -10,8 +10,8 @@ this.checked = !this.checked; }); }); - %th#time At %th#summary Summary + %th#time At = partial("alerts_table_group", :collection => @grouped_alerts) %tr %td   diff --git a/views/_alerts_table_alert_summary.haml b/views/_alerts_table_alert_summary.haml index 06f1dc2..a06ccb8 100644 --- a/views/_alerts_table_alert_summary.haml +++ b/views/_alerts_table_alert_summary.haml @@ -6,5 +6,8 @@ %label{ :for => "alerts[#{alert.id}]" } %strong= alert.subject = alert.summary - %a{ :id => ["a","detail", alert.id], :href => "/alert/#{alert.id}", :onclick => "fetchDetail('#{alert.id}'); return false;"} Details ↓ + %a{ :id => ["a","detail", alert.id], | + :href => "/alert/#{alert.id}", | + :onclick => "fetchDetail('#{alert.id}'); return false;"} + Details ↓ %td= alert.raised_at.to_s_relative diff --git a/views/_alerts_table_group.haml b/views/_alerts_table_group.haml index f3af4b2..8bc73b4 100644 --- a/views/_alerts_table_group.haml +++ b/views/_alerts_table_group.haml @@ -2,7 +2,7 @@ - group, alerts = alerts_table_group unless alerts_table_group.nil? - hilight = cycle(nil,"hilight") - row_class = [ hilight, alerts.first.raised? && "triggered", alerts.first.acknowledged? && "acknowledged", alerts.first.level] -=partial("alerts_table_alert_summary", :locals => {:alert => alerts.first, :row_class => row_class }) +=partial("alerts_table_alert_summary", :locals => {:alert => alerts.pop, :row_class => row_class }) - if alerts.length > 1 %tr{ :class => [ hilight, alerts.first.raised? && "triggered", alerts.first.acknowledged? && "acknowledged"]} %td   diff --git a/views/_head.haml b/views/_head.haml index 276680d..981aaf1 100644 --- a/views/_head.haml +++ b/views/_head.haml @@ -5,4 +5,4 @@ %link{:rel => "stylesheet", :href => "/stylesheets/mauve.css", :media => "all", :type => "text/css"}/ %link{:rel => "stylesheet", :href => "/stylesheets/mauve-handheld.css", :media => "handheld, only screen and (max-width: 1000px), only screen and (max-device-width: 1000px)", :type => "text/css" }/ %script{:src => '/javascript/jquery/jquery.min.js', :type => 'text/javascript'} - %script{:src => '/mauve_utils.js', :type => 'text/javascript'} + %script{:src => '/javascript/mauve_utils.js', :type => 'text/javascript'} -- cgit v1.2.1