From d5e48b2b1f549a5dba879761e7303cc0e7b57ce6 Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Wed, 10 Oct 2018 17:35:11 -0700 Subject: [PATCH] Vue status bar (#2188) * Implemented indicators * WIP * Fixed templates from notifications example * Message bar implemented * Implemented notifications * Fixed bug with destruction of notifications * Renamed MessageBanner to NotificationBanner * Add save success message * Removed NotificationServiceSpec * Removed legacy constants from bundle --- example/notifications/bundle.js | 8 +- .../src/NotificationLaunchController.js | 79 +--- .../src/controllers/BannerController.js | 2 +- platform/commonUI/notification/bundle.js | 25 +- .../notification/src/NotificationService.js | 437 ------------------ .../test/NotificationServiceSpec.js | 275 ----------- src/MCT.js | 2 + src/api/api.js | 3 + src/api/indicators/IndicatorAPI.js | 9 +- src/api/notifications/MCTNotification.js | 48 ++ src/api/notifications/NotificationApi.js | 353 ++++++++++++++ src/ui/components/layout/BrowseBar.vue | 7 +- src/ui/components/layout/Layout.vue | 6 +- src/ui/components/layout/MctStatus.vue | 14 - .../layout/status-bar/Indicators.vue | 41 ++ .../layout/status-bar/NotificationBanner.vue | 98 ++++ .../layout/status-bar/StatusBar.vue | 42 ++ 17 files changed, 623 insertions(+), 826 deletions(-) delete mode 100644 platform/commonUI/notification/src/NotificationService.js delete mode 100644 platform/commonUI/notification/test/NotificationServiceSpec.js create mode 100644 src/api/notifications/MCTNotification.js create mode 100644 src/api/notifications/NotificationApi.js delete mode 100644 src/ui/components/layout/MctStatus.vue create mode 100644 src/ui/components/layout/status-bar/Indicators.vue create mode 100644 src/ui/components/layout/status-bar/NotificationBanner.vue create mode 100644 src/ui/components/layout/status-bar/StatusBar.vue diff --git a/example/notifications/bundle.js b/example/notifications/bundle.js index 77a2fb54a9..46ab95978d 100644 --- a/example/notifications/bundle.js +++ b/example/notifications/bundle.js @@ -26,12 +26,16 @@ define([ "./src/NotificationLaunchController", "./src/DialogLaunchIndicator", "./src/NotificationLaunchIndicator", + "./res/dialog-launch.html", + "./res/notification-launch.html", 'legacyRegistry' ], function ( DialogLaunchController, NotificationLaunchController, DialogLaunchIndicator, NotificationLaunchIndicator, + DialogLaunch, + NotificationLaunch, legacyRegistry ) { "use strict"; @@ -41,11 +45,11 @@ define([ "templates": [ { "key": "dialogLaunchTemplate", - "templateUrl": "dialog-launch.html" + "template": DialogLaunch }, { "key": "notificationLaunchTemplate", - "templateUrl": "notification-launch.html" + "template": NotificationLaunch } ], "controllers": [ diff --git a/example/notifications/src/NotificationLaunchController.js b/example/notifications/src/NotificationLaunchController.js index 711ac3dd71..17c448e598 100644 --- a/example/notifications/src/NotificationLaunchController.js +++ b/example/notifications/src/NotificationLaunchController.js @@ -51,76 +51,26 @@ define( return actionTexts[Math.floor(Math.random()*3)]; } - function getExampleActions() { - var actions = [ - { - label: "Try Again", - callback: function () { - $log.debug("Try Again pressed"); - } - }, - { - label: "Remove", - callback: function () { - $log.debug("Remove pressed"); - } - }, - { - label: "Cancel", - callback: function () { - $log.debug("Cancel pressed"); - } - } - ]; - - // Randomly remove some actions off the top; leave at least one - actions.splice(0,Math.floor(Math.random() * actions.length)); - - return actions; - } - - function getExampleSeverity() { - var severities = [ - "info", - "alert", - "error" - ]; - return severities[Math.floor(Math.random() * severities.length)]; - } - /** * Launch a new notification with a severity level of 'Error'. */ - $scope.newError = function(){ - + $scope.newError = function () { notificationService.notify({ title: "Example error notification " + messageCounter++, hint: "An error has occurred", - severity: "error", - primaryOption: { - label: 'Retry', - callback: function() { - $log.info('Retry clicked'); - } - }, - options: getExampleActions()}); + severity: "error" + }); }; /** * Launch a new notification with a severity of 'Alert'. */ - $scope.newAlert = function(){ - + $scope.newAlert = function () { notificationService.notify({ title: "Alert notification " + (messageCounter++), hint: "This is an alert message", severity: "alert", - primaryOption: { - label: 'Retry', - callback: function() { - $log.info('Retry clicked'); - } - }, - options: getExampleActions()}); + autoDismiss: true + }); }; @@ -128,39 +78,38 @@ define( * Launch a new notification with a progress bar that is updated * periodically, tracking an ongoing process. */ - $scope.newProgress = function(){ - + $scope.newProgress = function () { var notificationModel = { title: "Progress notification example", severity: "info", progress: 0, - actionText: getExampleActionText(), - unknownProgress: false + actionText: getExampleActionText() }; /** * Simulate an ongoing process and update the progress bar. * @param notification */ - function incrementProgress(notificationModel) { + function incrementProgress() { notificationModel.progress = Math.min(100, Math.floor(notificationModel.progress + Math.random() * 30)); notificationModel.progressText = ["Estimated time" + " remaining:" + " about ", 60 - Math.floor((notificationModel.progress / 100) * 60), " seconds"].join(" "); if (notificationModel.progress < 100) { - $timeout(function(){incrementProgress(notificationModel);}, 1000); + $timeout(function () { + incrementProgress(notificationModel); + }, 1000); } } notificationService.notify(notificationModel); - incrementProgress(notificationModel); + incrementProgress(); }; /** * Launch a new notification with severity level of INFO. */ - $scope.newInfo = function(){ - + $scope.newInfo = function () { notificationService.info({ title: "Example Info notification " + messageCounter++ }); diff --git a/platform/commonUI/general/src/controllers/BannerController.js b/platform/commonUI/general/src/controllers/BannerController.js index 9a85729840..2e21c232f5 100644 --- a/platform/commonUI/general/src/controllers/BannerController.js +++ b/platform/commonUI/general/src/controllers/BannerController.js @@ -60,7 +60,7 @@ define( }; //If the notification is dismissed by the user, close // the dialog. - notification.onDismiss(function () { + notification.on('dismiss', function () { dialog.dismiss(); }); diff --git a/platform/commonUI/notification/bundle.js b/platform/commonUI/notification/bundle.js index 4eb4a1e396..8d26855b38 100644 --- a/platform/commonUI/notification/bundle.js +++ b/platform/commonUI/notification/bundle.js @@ -23,33 +23,17 @@ define([ "./src/NotificationIndicatorController", "./src/NotificationIndicator", - "./src/NotificationService", "./res/notification-indicator.html", 'legacyRegistry' ], function ( NotificationIndicatorController, NotificationIndicator, - NotificationService, notificationIndicatorTemplate, legacyRegistry ) { legacyRegistry.register("platform/commonUI/notification", { "extensions": { - "constants": [ - { - "key": "DEFAULT_AUTO_DISMISS", - "value": 3000 - }, - { - "key": "FORCE_AUTO_DISMISS", - "value": 1000 - }, - { - "key": "MINIMIZE_TIMEOUT", - "value": 300 - } - ], "templates": [ { "key": "notificationIndicatorTemplate", @@ -76,12 +60,11 @@ define([ "services": [ { "key": "notificationService", - "implementation": NotificationService, + "implementation": function (openmct) { + return openmct.notifications; + }, "depends": [ - "$timeout", - "topic", - "DEFAULT_AUTO_DISMISS", - "MINIMIZE_TIMEOUT" + "openmct" ] } ] diff --git a/platform/commonUI/notification/src/NotificationService.js b/platform/commonUI/notification/src/NotificationService.js deleted file mode 100644 index 0823482e7f..0000000000 --- a/platform/commonUI/notification/src/NotificationService.js +++ /dev/null @@ -1,437 +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. - *****************************************************************************/ - -/** - * This bundle implements the notification service, which can be used to - * show banner notifications to the user. Banner notifications - * are used to inform users of events in a non-intrusive way. As - * much as possible, notifications share a model with blocking - * dialogs so that the same information can be provided in a dialog - * and then minimized to a banner notification if needed. - * - * @namespace platform/commonUI/notification - */ -define( - ['moment'], - function (moment) { - - /** - * A representation of a user action. Options are provided to - * dialogs and notifications and are shown as buttons. - * - * @typedef {object} NotificationOption - * @property {string} label the label to appear on the button for - * this action - * @property {function} callback a callback function to be invoked - * when the button is clicked - */ - - /** - * A representation of a banner notification. Banner notifications - * are used to inform users of events in a non-intrusive way. As - * much as possible, notifications share a model with blocking - * dialogs so that the same information can be provided in a dialog - * 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