Skip to content

Commit d4c757a

Browse files
committed
Merge pull request #418 from ruzz311/optional-alert-levels
Fix #406 - Settings for notify by a given level
2 parents a0c45c7 + ba3cccb commit d4c757a

File tree

2 files changed

+87
-25
lines changed

2 files changed

+87
-25
lines changed

web/client/index.html

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<hr class="clear">
6161

6262

63-
<div class="expandable settings">
63+
<div class="expandable settings settings-general">
6464
<div class="container">
6565
<div class="setting">
6666
<div class="setting-meta">
@@ -119,6 +119,34 @@
119119
</script>
120120
</div>
121121

122+
<div class="expandable settings settings-notification">
123+
<div class="container">
124+
<div class="setting">
125+
<div class="setting-meta">
126+
Notifications
127+
</div>
128+
<div class="setting-val">
129+
<ol class="enum" id="notification">
130+
<li data-notification="true">On</li>
131+
<li data-notification="false">Off</li>
132+
</ol>
133+
</div>
134+
</div>
135+
<div class="setting">
136+
<div class="setting-meta">
137+
Level
138+
</div>
139+
<div class="setting-val">
140+
<ol class="enum" id="notification-level">
141+
<li data-notification-level=".*">Always</li>
142+
<li data-notification-level="fail|panic">Fail or Panic</li>
143+
<li data-notification-level="ok">Success Only</li>
144+
</ol>
145+
</div>
146+
</div>
147+
</div>
148+
</div>
149+
122150

123151
</div>
124152
</header>

web/client/resources/js/goconvey.js

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,40 @@ function wireup()
171171
});
172172
// End settings wireup
173173

174+
//wireup the notification-settings switches
175+
$('.enum#notification').on('click', 'li:not(.sel)', function()
176+
{
177+
var enabled = $(this).data('notification');
178+
log("Turning notifications " + enabled ? 'on' : 'off');
179+
save('notifications', enabled);
180+
181+
if (notif() && 'Notification' in window)
182+
{
183+
if (Notification.permission !== 'denied')
184+
{
185+
Notification.requestPermission(function(per)
186+
{
187+
if (!('permission' in Notification))
188+
{
189+
Notification.permission = per;
190+
}
191+
});
192+
}
193+
else
194+
log("Permission denied to show desktop notification");
195+
}
196+
197+
setNotifUI()
198+
});
199+
200+
$('.enum#notification-level').on('click', 'li:not(.sel)', function()
201+
{
202+
var level = $(this).data('notification-level');
203+
convey.notificationLevel = level;
204+
save('notification-level', level);
205+
});
206+
// End notification-settings
207+
174208
convey.layout.header = $('header').first();
175209
convey.layout.frame = $('.frame').first();
176210
convey.layout.footer = $('footer').last();
@@ -222,23 +256,7 @@ function wireup()
222256

223257
$('#toggle-notif').click(function()
224258
{
225-
log("Turning notifications " + (notif() ? "off" : "on"));
226-
$(this).toggleClass("fa-bell-o fa-bell " + convey.layout.selClass);
227-
save('notifications', !notif());
228-
229-
if (notif() && 'Notification' in window)
230-
{
231-
if (Notification.permission !== 'denied')
232-
{
233-
Notification.requestPermission(function(per)
234-
{
235-
if (!('permission' in Notification))
236-
Notification.permission = per;
237-
});
238-
}
239-
else
240-
log("Permission denied to show desktop notification");
241-
}
259+
toggle($('.settings-notification'), $(this));
242260
});
243261

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

249267
$('#show-settings').click(function()
250268
{
251-
toggle($('.settings'), $(this));
269+
toggle($('.settings-general'), $(this));
252270
});
253271

254272
$('#show-gen').click(function() {
@@ -394,12 +412,13 @@ function wireup()
394412
$(window).resize(reframe);
395413
}
396414

397-
function setTooltips(){
415+
function setTooltips()
416+
{
398417
var tips = {
399418
'#path': { delayIn: 500 },
400419
'#logo': { gravity: 'w' },
401420
'.controls li, .pkg-cover-name': { live: false },
402-
'footer .replay':{ live: false, gravity: 'e' },
421+
'footer .replay': { live: false, gravity: 'e' },
403422
'.ignore': { live: false, gravity: $.fn.tipsy.autoNS },
404423
'.disabled': { live: false, gravity: $.fn.tipsy.autoNS }
405424
};
@@ -414,6 +433,12 @@ function setTooltips(){
414433
}
415434
}
416435

436+
function setNotifUI()
437+
{
438+
var $toggleNotif = $('#toggle-notif').addClass(notif() ? "fa-bell" : "fa-bell-o");
439+
$toggleNotif.removeClass(!notif() ? "fa-bell" : "fa-bell-o");
440+
}
441+
417442
function expandAll()
418443
{
419444
$('.story-pkg').each(function() { expandPackage($(this).data('pkg')); });
@@ -491,8 +516,16 @@ function loadSettingsFromStorage()
491516
convey.uiEffects = uiEffects === "true";
492517
enumSel("ui-effects", uiEffects);
493518

494-
if (notif())
495-
$('#toggle-notif').toggleClass("fa-bell-o fa-bell " + convey.layout.selClass);
519+
enumSel("notification", ""+notif());
520+
var notifLevel = get("notification-level");
521+
if (notifLevel === null)
522+
{
523+
notifLevel = '.*';
524+
}
525+
convey.notificationLevel = notifLevel;
526+
enumSel("notification-level", notifLevel);
527+
528+
setNotifUI();
496529
}
497530

498531

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

785818
// Show notification, if enabled
786-
if (notif())
819+
var levelRegex = new RegExp("("+convey.notificationLevel+")", "i");
820+
if (notif() && current().overall.status.class.match(levelRegex))
787821
{
788822
log("Showing notification");
789823
if (convey.notif)
@@ -792,7 +826,7 @@ function process(data, status, jqxhr)
792826
convey.notif.close();
793827
}
794828

795-
var notifText = notifSummary(current())
829+
var notifText = notifSummary(current());
796830

797831
convey.notif = new Notification(notifText.title, {
798832
body: notifText.body,

0 commit comments

Comments
 (0)