Skip to content

Commit

Permalink
Merge pull request #418 from ruzz311/optional-alert-levels
Browse files Browse the repository at this point in the history
Fix #406 - Settings for notify by a given level
  • Loading branch information
ruzz311 committed May 3, 2016
2 parents a0c45c7 + ba3cccb commit d4c757a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 25 deletions.
30 changes: 29 additions & 1 deletion web/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<hr class="clear">


<div class="expandable settings">
<div class="expandable settings settings-general">
<div class="container">
<div class="setting">
<div class="setting-meta">
Expand Down Expand Up @@ -119,6 +119,34 @@
</script>
</div>

<div class="expandable settings settings-notification">
<div class="container">
<div class="setting">
<div class="setting-meta">
Notifications
</div>
<div class="setting-val">
<ol class="enum" id="notification">
<li data-notification="true">On</li>
<li data-notification="false">Off</li>
</ol>
</div>
</div>
<div class="setting">
<div class="setting-meta">
Level
</div>
<div class="setting-val">
<ol class="enum" id="notification-level">
<li data-notification-level=".*">Always</li>
<li data-notification-level="fail|panic">Fail or Panic</li>
<li data-notification-level="ok">Success Only</li>
</ol>
</div>
</div>
</div>
</div>


</div>
</header>
Expand Down
82 changes: 58 additions & 24 deletions web/client/resources/js/goconvey.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,40 @@ function wireup()
});
// End settings wireup

//wireup the notification-settings switches
$('.enum#notification').on('click', 'li:not(.sel)', function()
{
var enabled = $(this).data('notification');
log("Turning notifications " + enabled ? 'on' : 'off');
save('notifications', enabled);

if (notif() && 'Notification' in window)
{
if (Notification.permission !== 'denied')
{
Notification.requestPermission(function(per)
{
if (!('permission' in Notification))
{
Notification.permission = per;
}
});
}
else
log("Permission denied to show desktop notification");
}

setNotifUI()
});

$('.enum#notification-level').on('click', 'li:not(.sel)', function()
{
var level = $(this).data('notification-level');
convey.notificationLevel = level;
save('notification-level', level);
});
// End notification-settings

convey.layout.header = $('header').first();
convey.layout.frame = $('.frame').first();
convey.layout.footer = $('footer').last();
Expand Down Expand Up @@ -222,23 +256,7 @@ function wireup()

$('#toggle-notif').click(function()
{
log("Turning notifications " + (notif() ? "off" : "on"));
$(this).toggleClass("fa-bell-o fa-bell " + convey.layout.selClass);
save('notifications', !notif());

if (notif() && 'Notification' in window)
{
if (Notification.permission !== 'denied')
{
Notification.requestPermission(function(per)
{
if (!('permission' in Notification))
Notification.permission = per;
});
}
else
log("Permission denied to show desktop notification");
}
toggle($('.settings-notification'), $(this));
});

$('#show-history').click(function()
Expand All @@ -248,7 +266,7 @@ function wireup()

$('#show-settings').click(function()
{
toggle($('.settings'), $(this));
toggle($('.settings-general'), $(this));
});

$('#show-gen').click(function() {
Expand Down Expand Up @@ -394,12 +412,13 @@ function wireup()
$(window).resize(reframe);
}

function setTooltips(){
function setTooltips()
{
var tips = {
'#path': { delayIn: 500 },
'#logo': { gravity: 'w' },
'.controls li, .pkg-cover-name': { live: false },
'footer .replay':{ live: false, gravity: 'e' },
'footer .replay': { live: false, gravity: 'e' },
'.ignore': { live: false, gravity: $.fn.tipsy.autoNS },
'.disabled': { live: false, gravity: $.fn.tipsy.autoNS }
};
Expand All @@ -414,6 +433,12 @@ function setTooltips(){
}
}

function setNotifUI()
{
var $toggleNotif = $('#toggle-notif').addClass(notif() ? "fa-bell" : "fa-bell-o");
$toggleNotif.removeClass(!notif() ? "fa-bell" : "fa-bell-o");
}

function expandAll()
{
$('.story-pkg').each(function() { expandPackage($(this).data('pkg')); });
Expand Down Expand Up @@ -491,8 +516,16 @@ function loadSettingsFromStorage()
convey.uiEffects = uiEffects === "true";
enumSel("ui-effects", uiEffects);

if (notif())
$('#toggle-notif').toggleClass("fa-bell-o fa-bell " + convey.layout.selClass);
enumSel("notification", ""+notif());
var notifLevel = get("notification-level");
if (notifLevel === null)
{
notifLevel = '.*';
}
convey.notificationLevel = notifLevel;
enumSel("notification-level", notifLevel);

setNotifUI();
}


Expand Down Expand Up @@ -783,7 +816,8 @@ function process(data, status, jqxhr)
convey.intervalFuncs.momentjs();

// Show notification, if enabled
if (notif())
var levelRegex = new RegExp("("+convey.notificationLevel+")", "i");
if (notif() && current().overall.status.class.match(levelRegex))
{
log("Showing notification");
if (convey.notif)
Expand All @@ -792,7 +826,7 @@ function process(data, status, jqxhr)
convey.notif.close();
}

var notifText = notifSummary(current())
var notifText = notifSummary(current());

convey.notif = new Notification(notifText.title, {
body: notifText.body,
Expand Down

0 comments on commit d4c757a

Please sign in to comment.