diff --git a/example/notifications/src/NotificationLaunchController.js b/example/notifications/src/NotificationLaunchController.js index 17c448e598..ae07f3fa62 100644 --- a/example/notifications/src/NotificationLaunchController.js +++ b/example/notifications/src/NotificationLaunchController.js @@ -79,30 +79,34 @@ define( * periodically, tracking an ongoing process. */ $scope.newProgress = function () { + let progress = 0; var notificationModel = { title: "Progress notification example", severity: "info", - progress: 0, + progress: progress, actionText: getExampleActionText() }; + let notification; /** * Simulate an ongoing process and update the progress bar. * @param notification */ function incrementProgress() { - notificationModel.progress = Math.min(100, Math.floor(notificationModel.progress + Math.random() * 30)); - notificationModel.progressText = ["Estimated time" + + progress = Math.min(100, Math.floor(progress + Math.random() * 30)) + let progressText = ["Estimated time" + " remaining:" + - " about ", 60 - Math.floor((notificationModel.progress / 100) * 60), " seconds"].join(" "); - if (notificationModel.progress < 100) { + " about ", 60 - Math.floor((progress / 100) * 60), " seconds"].join(" "); + notification.progress(progress, progressText); + + if (progress < 100) { $timeout(function () { incrementProgress(notificationModel); }, 1000); } } - notificationService.notify(notificationModel); + notification = notificationService.notify(notificationModel); incrementProgress(); }; diff --git a/platform/commonUI/dialog/res/templates/message.html b/platform/commonUI/dialog/res/templates/message.html index 50124f8a71..4a41f43a69 100644 --- a/platform/commonUI/dialog/res/templates/message.html +++ b/platform/commonUI/dialog/res/templates/message.html @@ -2,31 +2,14 @@ ng-class="'message-severity-' + ngModel.severity">
-
{{ngModel.title}}
-
-
- {{ngModel.hint}} - [{{ngModel.timestamp}}] +
{{ngModel.message}}
-
- {{ngModel.actionText}} -
+ ng-show="ngModel.progressPerc !== undefined">
- - {{dialogOption.label}} - - - {{ngModel.primaryOption.label}} -
diff --git a/platform/commonUI/general/res/templates/progress-bar.html b/platform/commonUI/general/res/templates/progress-bar.html index fefaff22d3..69883ed7ec 100644 --- a/platform/commonUI/general/res/templates/progress-bar.html +++ b/platform/commonUI/general/res/templates/progress-bar.html @@ -1,10 +1,10 @@ + ng-class="{ indeterminate:ngModel.progressPerc === 'unknown' }"> - +
- {{ngModel.progress}}% complete. + {{ngModel.progressPerc}}% complete. {{ngModel.progressText}}
diff --git a/platform/commonUI/general/src/controllers/BannerController.js b/platform/commonUI/general/src/controllers/BannerController.js index 2e21c232f5..d994f31b58 100644 --- a/platform/commonUI/general/src/controllers/BannerController.js +++ b/platform/commonUI/general/src/controllers/BannerController.js @@ -50,7 +50,7 @@ define( }; $scope.dismiss = function (notification, $event) { $event.stopPropagation(); - notification.dismissOrMinimize(); + notification.dismiss(); }; $scope.maximize = function (notification) { if (notification.model.severity !== "info") { diff --git a/platform/commonUI/notification/bundle.js b/platform/commonUI/notification/bundle.js index 8d26855b38..7df0693071 100644 --- a/platform/commonUI/notification/bundle.js +++ b/platform/commonUI/notification/bundle.js @@ -23,11 +23,13 @@ define([ "./src/NotificationIndicatorController", "./src/NotificationIndicator", + "./src/NotificationService", "./res/notification-indicator.html", 'legacyRegistry' ], function ( NotificationIndicatorController, NotificationIndicator, + NotificationService, notificationIndicatorTemplate, legacyRegistry ) { @@ -46,7 +48,7 @@ define([ "implementation": NotificationIndicatorController, "depends": [ "$scope", - "notificationService", + "openmct", "dialogService" ] } @@ -61,7 +63,7 @@ define([ { "key": "notificationService", "implementation": function (openmct) { - return openmct.notifications; + return new NotificationService.default(openmct); }, "depends": [ "openmct" diff --git a/platform/commonUI/notification/src/NotificationIndicatorController.js b/platform/commonUI/notification/src/NotificationIndicatorController.js index 73ebbc51cc..9f695c1b6c 100644 --- a/platform/commonUI/notification/src/NotificationIndicatorController.js +++ b/platform/commonUI/notification/src/NotificationIndicatorController.js @@ -35,9 +35,9 @@ define( * @param dialogService * @constructor */ - function NotificationIndicatorController($scope, notificationService, dialogService) { - $scope.notifications = notificationService.notifications; - $scope.highest = notificationService.highest; + function NotificationIndicatorController($scope, openmct, dialogService) { + $scope.notifications = openmct.notifications.notifications; + $scope.highest = openmct.notifications.highest; /** * Launch a dialog showing a list of current notifications. @@ -48,7 +48,7 @@ define( title: "Messages", //Launch the message list dialog with the models // from the notifications - messages: notificationService.notifications + messages: openmct.notifications.notifications } }); diff --git a/platform/commonUI/notification/src/NotificationService.js b/platform/commonUI/notification/src/NotificationService.js new file mode 100644 index 0000000000..f914a15565 --- /dev/null +++ b/platform/commonUI/notification/src/NotificationService.js @@ -0,0 +1,64 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2018, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +export default class NotificationService { + constructor(openmct) { + this.openmct = openmct; + } + info(message) { + if (typeof message === 'string') { + return this.openmct.notifications.info(message); + } else { + if (message.hasOwnProperty('progress')) { + return this.openmct.notifications.progress(message.title, message.progress, message.progressText); + } else { + return this.openmct.notifications.info(message.title); + } + } + } + alert(message) { + if (typeof message === 'string') { + return this.openmct.notifications.alert(message); + } else { + return this.openmct.notifications.alert(message.title); + } + } + error(message) { + if (typeof message === 'string') { + return this.openmct.notifications.error(message); + } else { + return this.openmct.notifications.error(message.title); + } + } + notify(options) { + switch (options.severity) { + case 'info': + return this.info(options); + case 'alert': + return this.alert(options); + case 'error': + return this.error(options); + } + } + getAllNotifications() { + return this.openmct.notifications.notifications; + } +} diff --git a/src/api/notifications/MCTNotification.js b/src/api/notifications/MCTNotification.js deleted file mode 100644 index cff07d68b0..0000000000 --- a/src/api/notifications/MCTNotification.js +++ /dev/null @@ -1,48 +0,0 @@ -/***************************************************************************** - * Open MCT, Copyright (c) 2014-2018, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -import EventEmitter from 'EventEmitter'; -export default class MCTNotification extends EventEmitter { - - constructor(notificationModel, notificationAPI) { - super(); - this.notifications = notificationAPI; - this.model = notificationModel; - this.initializeModel(); - } - - minimize() { - this.notifications.minimize(this); - } - - dismiss() { - this.notifications.dismiss(this) - } - - dismissOrMinimize() { - this.notifications.dismissOrMinimize(this); - } - - initializeModel() { - this.model.minimized = this.model.minimized || false; - } -} diff --git a/src/api/notifications/NotificationApi.js b/src/api/notifications/NotificationApi.js index 182570f820..a579d31138 100644 --- a/src/api/notifications/NotificationApi.js +++ b/src/api/notifications/NotificationApi.js @@ -32,7 +32,6 @@ */ import moment from 'moment'; import EventEmitter from 'EventEmitter'; -import MCTNotification from './MCTNotification.js'; /** * A representation of a banner notification. Banner notifications @@ -42,20 +41,11 @@ import MCTNotification from './MCTNotification.js'; * and then minimized to a banner notification if needed, or vice-versa. * * @typedef {object} NotificationModel - * @property {string} title The title of the message - * @property {string} severity The importance of the message (one of - * 'info', 'alert', or 'error' where info < alert