diff --git a/ui/js/components/auth.js b/ui/js/components/auth.js index 862315627..1bee2573d 100644 --- a/ui/js/components/auth.js +++ b/ui/js/components/auth.js @@ -115,7 +115,7 @@ treeherder.component("login", { .then(function () { ctrl.setLoggedOut(); }, function (data) { - thNotify.send(`Logout failed: ${data.data}`, "danger", true); + thNotify.send(`Logout failed: ${data.data}`, "danger", { sticky: true }); }); }; diff --git a/ui/js/controllers/bugfiler.js b/ui/js/controllers/bugfiler.js index 724289feb..1892a6c20 100644 --- a/ui/js/controllers/bugfiler.js +++ b/ui/js/controllers/bugfiler.js @@ -395,7 +395,7 @@ treeherder.controller('BugFilerCtrl', [ var data = response.data; if (data.failure) { var error = JSON.parse(data.failure.join("")); - thNotify.send("Bugzilla error: " + error.message, "danger", true); + thNotify.send("Bugzilla error: " + error.message, "danger", { sticky: true }); $scope.toggleForm(false); } else { successCallback(data); diff --git a/ui/js/controllers/failureviewer.js b/ui/js/controllers/failureviewer.js index 3654d5ec1..b89f342d1 100644 --- a/ui/js/controllers/failureviewer.js +++ b/ui/js/controllers/failureviewer.js @@ -14,7 +14,7 @@ failureViewerApp.controller('FailureViewerCtrl', [ if (query_string.classified_failure_id) { $scope.classifiedFailureId = query_string.classified_failure_id; } else { - thNotify.send("No classified_failure_id specified", "danger", true); + thNotify.send("No classified_failure_id specified", "danger", { sticky: true }); } $scope.init = function () { if ($scope.classifiedFailureId) { diff --git a/ui/js/controllers/jobs.js b/ui/js/controllers/jobs.js index 6fa0cdd3f..0cf94654d 100644 --- a/ui/js/controllers/jobs.js +++ b/ui/js/controllers/jobs.js @@ -253,7 +253,7 @@ treeherderApp.controller('ResultSetCtrl', [ ).then(function (msg) { thNotify.send(msg, "success"); }, function (e) { - thNotify.send(ThTaskclusterErrors.format(e), 'danger', true); + thNotify.send(ThTaskclusterErrors.format(e), 'danger', { sticky: true }); }); }); }; @@ -275,7 +275,7 @@ treeherderApp.controller('ResultSetCtrl', [ thNotify.send(results[1], "success"); ThResultSetStore.deleteRunnableJobs($scope.repoName, $scope.resultset); }, function (e) { - thNotify.send(ThTaskclusterErrors.format(e), 'danger', true); + thNotify.send(ThTaskclusterErrors.format(e), 'danger', { sticky: true }); }); }); } else { diff --git a/ui/js/controllers/logviewer.js b/ui/js/controllers/logviewer.js index e03b9c100..311155df2 100644 --- a/ui/js/controllers/logviewer.js +++ b/ui/js/controllers/logviewer.js @@ -159,7 +159,7 @@ logViewerApp.controller('LogviewerCtrl', [ }, () => { $scope.loading = false; $scope.jobExists = false; - thNotify.send('The job does not exist or has expired', 'danger', true); + thNotify.send('The job does not exist or has expired', 'danger', { sticky: true }); }); }); }; diff --git a/ui/js/controllers/tcjobactions.js b/ui/js/controllers/tcjobactions.js index 69f276a30..2405473a0 100644 --- a/ui/js/controllers/tcjobactions.js +++ b/ui/js/controllers/tcjobactions.js @@ -76,10 +76,13 @@ treeherder.controller('TCJobActionsCtrl', [ message = 'Visit Taskcluster Tools site to access loaner:'; url = `${url}/connect`; } - $scope.$apply(thNotify.send(message, 'success', true, 'Open in Taskcluster', url)); + $scope.$apply(thNotify.send(message, 'success', { + linkText: 'Open in Taskcluster', + url, + })); $uibModalInstance.close('request sent'); }, function (e) { - $scope.$apply(thNotify.send(ThTaskclusterErrors.format(e), 'danger', true)); + $scope.$apply(thNotify.send(ThTaskclusterErrors.format(e), 'danger', { sticky: true })); $scope.triggering = false; $uibModalInstance.close('error'); }); diff --git a/ui/js/models/resultsets_store.js b/ui/js/models/resultsets_store.js index 704ca8e28..e7982f323 100644 --- a/ui/js/models/resultsets_store.js +++ b/ui/js/models/resultsets_store.js @@ -1021,7 +1021,7 @@ treeherder.factory('ThResultSetStore', [ return $q.all([loadRepositories, loadResultsets]) .then(() => appendResultSets(repoName, resultsets), (data) => { - thNotify.send("Error retrieving resultset data!", "danger", true); + thNotify.send("Error retrieving resultset data!", "danger", { sticky: true }); $log.error(data); appendResultSets(repoName, { results: [] }); }) @@ -1116,7 +1116,7 @@ treeherder.factory('ThResultSetStore', [ }, function () { // the job wasn't found in the db. Either never existed, // or was expired and deleted. - thNotify.send("Unable to find job with id " + selectedJobId, "danger", true); + thNotify.send("Unable to find job with id " + selectedJobId, "danger", { sticky: true }); }); } } diff --git a/ui/js/services/buildapi.js b/ui/js/services/buildapi.js index 485ec3d6a..877bfa19d 100644 --- a/ui/js/services/buildapi.js +++ b/ui/js/services/buildapi.js @@ -18,7 +18,7 @@ treeherder.factory('thBuildApi', [ } else if (status === 202 || status === 200) { thNotify.send(action + " SUCCESS"); } else { - thNotify.send(action + " FAILED " + status, "danger", true); + thNotify.send(action + " FAILED " + status, "danger", { sticky: true }); } diff --git a/ui/js/services/main.js b/ui/js/services/main.js index e65d7e64f..22c06d60b 100755 --- a/ui/js/services/main.js +++ b/ui/js/services/main.js @@ -125,20 +125,24 @@ treeherder.factory('thNotify', [ /* * send a message to the notification queue * @severity can be one of success|info|warning|danger - * @sticky is a boolean indicating if you want the message to disappear - * after a while or not + * @opts is an object with up to three entries: + * sticky -- Keeps notification visible until cleared if true + * linkText -- Text to display as a link if exists + * url -- Location the link should point to if exists */ - send: function (message, severity, sticky, linkText, url) { + send: function (message, severity, opts) { + if (!_.isPlainObject(opts)) { + throw new Error('Must pass an object as last argument to thNotify.send!'); + } $log.debug("received message", message); + opts = opts || {}; severity = severity || 'info'; - sticky = sticky || false; + var maxNsNotifications = 5; var notification = { - message: message, - severity: severity, - sticky: sticky, - linkText: linkText, - url: url, + ...opts, + message, + severity, created: Date.now() }; thNotify.notifications.unshift(notification); @@ -146,7 +150,7 @@ treeherder.factory('thNotify', [ thNotify.storedNotifications.splice(40); localStorageService.set('notifications', thNotify.storedNotifications); - if (!sticky) { + if (!opts.sticky) { if (thNotify.notifications.length > maxNsNotifications) { $timeout(thNotify.shift); return; diff --git a/ui/js/services/tcactions.js b/ui/js/services/tcactions.js index 487603508..410d9aa10 100644 --- a/ui/js/services/tcactions.js +++ b/ui/js/services/tcactions.js @@ -30,7 +30,7 @@ treeherder.factory('tcactions', [ }, load: (decisionTaskID, job) => { if (!decisionTaskID) { - thNotify.send("No decision task, can't find taskcluster actions", "danger", true); + thNotify.send("No decision task, can't find taskcluster actions", "danger", { sticky: true }); return; } @@ -65,7 +65,7 @@ treeherder.factory('tcactions', [ return null; } if (response.data.version !== 1) { - thNotify.send("Wrong version of actions.json, can't continue", "danger", true); + thNotify.send("Wrong version of actions.json, can't continue", "danger", { sticky: true }); return; } diff --git a/ui/plugins/annotations/controller.js b/ui/plugins/annotations/controller.js index 011bc8fe8..86be7e2b2 100644 --- a/ui/plugins/annotations/controller.js +++ b/ui/plugins/annotations/controller.js @@ -42,7 +42,7 @@ treeherder.controller('AnnotationsPluginCtrl', [ classification.delete() .then( function () { - thNotify.send("Classification successfully deleted", "success", false); + thNotify.send("Classification successfully deleted", "success"); var jobs = {}; jobs[$scope.selectedJob.id] = $scope.selectedJob; @@ -53,7 +53,7 @@ treeherder.controller('AnnotationsPluginCtrl', [ $rootScope.$emit(thEvents.jobsClassified, { jobs: jobs }); }, function () { - thNotify.send("Classification deletion failed", "danger", true); + thNotify.send("Classification deletion failed", "danger", { sticky: true }); } ); }; @@ -62,14 +62,14 @@ treeherder.controller('AnnotationsPluginCtrl', [ bug.delete() .then( function () { - thNotify.send("Association to bug " + bug.bug_id + " successfully deleted", "success", false); + thNotify.send("Association to bug " + bug.bug_id + " successfully deleted", "success"); var jobs = {}; jobs[$scope.selectedJob.id] = $scope.selectedJob; $rootScope.$emit(thEvents.bugsAssociated, { jobs: jobs }); }, function () { - thNotify.send("Association to bug " + bug.bug_id + " deletion failed", "danger", true); + thNotify.send("Association to bug " + bug.bug_id + " deletion failed", "danger", { sticky: true }); } ); }; diff --git a/ui/plugins/controller.js b/ui/plugins/controller.js index 5c502905b..a770823f1 100644 --- a/ui/plugins/controller.js +++ b/ui/plugins/controller.js @@ -410,7 +410,7 @@ treeherder.controller('PluginCtrl', [ }, function (e) { // The full message is too large to fit in a Treeherder // notification box. - $scope.$apply(thNotify.send(ThTaskclusterErrors.format(e), 'danger', true)); + $scope.$apply(thNotify.send(ThTaskclusterErrors.format(e), 'danger', { sticky: true })); }); } } @@ -443,7 +443,7 @@ treeherder.controller('PluginCtrl', [ }, function (e) { // The full message is too large to fit in a Treeherder // notification box. - $scope.$apply(thNotify.send(ThTaskclusterErrors.format(e), 'danger', true)); + $scope.$apply(thNotify.send(ThTaskclusterErrors.format(e), 'danger', { sticky: true })); }); }); });