diff --git a/platform/commonUI/dialog/bundle.json b/platform/commonUI/dialog/bundle.json index 9a2d541419..eab8fb000a 100644 --- a/platform/commonUI/dialog/bundle.json +++ b/platform/commonUI/dialog/bundle.json @@ -1,5 +1,15 @@ { "extensions": { + "constants": [ + { + "key": "messageSeverity", + "value": { + "ERROR": "error", + "INFO": "info", + "SUCCESS": "success" + } + } + ], "services": [ { "key": "dialogService", @@ -24,6 +34,10 @@ { "key": "form-dialog", "templateUrl": "templates/dialog.html" + }, + { + "key": "blocking-message", + "templateUrl": "templates/blocking-message.html" } ], "containers": [ diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index d71bb3a393..3a52c92d03 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -96,6 +96,11 @@ "key": "SelectorController", "implementation": "controllers/SelectorController.js", "depends": [ "objectService", "$scope" ] + }, + { + "key": "BannerController", + "implementation": "controllers/BannerController.js", + "depends": ["$scope", "notificationService"] } ], "directives": [ diff --git a/platform/commonUI/general/res/templates/message-banner.html b/platform/commonUI/general/res/templates/message-banner.html index c5386311c6..8d3a95e0cc 100644 --- a/platform/commonUI/general/res/templates/message-banner.html +++ b/platform/commonUI/general/res/templates/message-banner.html @@ -1,9 +1,9 @@
Objects not saved - + x
\ No newline at end of file diff --git a/platform/commonUI/general/src/controllers/BannerController.js b/platform/commonUI/general/src/controllers/BannerController.js new file mode 100644 index 0000000000..1c6193e061 --- /dev/null +++ b/platform/commonUI/general/src/controllers/BannerController.js @@ -0,0 +1,31 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web 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 Web 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. + *****************************************************************************/ +/*global define*/ + +define( + [], + function () { + "use strict"; + function BannerController($scope, notificationService){ + $scope.activeNotification = notificationService.active.Notification; + } + }); \ No newline at end of file diff --git a/platform/commonUI/notification/bundle.json b/platform/commonUI/notification/bundle.json new file mode 100644 index 0000000000..56087d9094 --- /dev/null +++ b/platform/commonUI/notification/bundle.json @@ -0,0 +1,18 @@ +{ + "extensions": { + "constants": [ + { + "key": "DEFAULT_AUTO_DISMISS", + "value": 2000 + } + ], + "services": [ + { + "key": "notificationService", + "implementation": "NotificationService.js", + "depends": [ "$log", "$timeout", "messageSeverity", + "DEFAULT_AUTO_DISMISS" ] + } + ] + } +} \ No newline at end of file diff --git a/platform/commonUI/notification/src/NotificationService.js b/platform/commonUI/notification/src/NotificationService.js new file mode 100644 index 0000000000..07aea14da4 --- /dev/null +++ b/platform/commonUI/notification/src/NotificationService.js @@ -0,0 +1,142 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web 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 Web 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. + *****************************************************************************/ +/*global define*/ + +/** + * This bundle implements the notification service, which can be used to + * show banner notifications to the user. + * @namespace platform/commonUI/dialog + */ +define( + [], + function () { + "use strict"; + /** + * The notification service is responsible for informing the user of + * events via the use of banner notifications. + * @memberof platform/commonUI/notification + * @constructor + */ + function NotificationService($log, $timeout, messageSeverity, DEFAULT_AUTO_DISMISS) { + //maintain an array of notifications. + //expose a method for adding notifications. + //expose a method for dismissing notifications. + //expose a method for minimizing notifications. + //expose a method for getting the 'current' notification. How + //this is determined could be a little nuanced. + //Allow for auto-dismissal of success messages + // + // + // + // Questions: + // 1) What happens when a newer, but lower priority + // message arrives (eg. success). Just show it? It will + // auto-dismissed, and the existing error message will be + // exposed. + // + + this.notifications = []; + this.$log = $log; + this.$timeout = $timeout; + this.messageSeverity = messageSeverity; + this.DEFAULT_AUTO_DISMISS = DEFAULT_AUTO_DISMISS; + + /** + * Exposes the current "active" notification. This is a + * notification that is of current highest importance that has + * not been dismissed. The deinition of what is of highest + * importance might be a little nuanced and require tweaking. + * For example, if an important error message is visible and a + * success message is triggered, it may be desirable to + * temporarily show the success message and then auto-dismiss it. + * @type {{notification: undefined}} + */ + this.active = { + notification: undefined + }; + } + /** + var model = { + title: string, + progress: number, + severity: MessageSeverity, + unknownProgress: boolean, + minimized: boolean, + autoDismiss: boolean | number, + actions: { + label: string, + action: function + } + } + */ + + /** + * Possibly refactor this out to a provider? + * @constructor + */ + function Notification (model) { + this.model = model; + } + + Notification.prototype.minimize = function () { + if (typeof setValue !== undefined){ + model.minimized = setValue; + } else { + return model.minimized; + } + }; + + /** + * model = { + * + * } + * @param model + */ + NotificationService.prototype.notify = function (model) { + var notification = new Notification(model); + this.notifications.push(notification); + this.setActiveNotification(notification); + }; + + + + NotificationService.prototype.setActiveNotification = function () { + //If there is a message active, time it out, and then chain a + // new message to appear. + if (this.active.timeout){ + this.active.timeout = this.active.timeout.then(function (){ + this.active.timeout = $timeout(function(){ + this.dismiss(this.active.notification); + }); + }); + } + }; + + NotificationService.prototype.dismiss = function (notification) { + var index = this.notifications.indexOf(notification); + if (index >= 0) { + this.notifications = this.notifications.splice(index, 1); + delete this.active.notification; + } + } + return NotificationService; + }); \ No newline at end of file