From c9bd60f50ecd116494deed19fdc5cf34b11244c8 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Fri, 27 Jan 2017 23:14:37 +0100 Subject: [PATCH] [BUILD] Adds URLIndicator along with documentation Adds URLIndicator to the build, testable adding `openmct.install(new openmct.plugins.URLIndicatorPlugin({ url: 'http://localhost:8080/', icon: 'check', interval: 15000, label: 'Localhost' }))` to the openmct file. Also added Documentation about the plugin. --- API.md | 11 +++ .../URLIndicatorPlugin/URLIndicator.js | 97 +++++++++++++++++++ .../URLIndicatorPlugin/URLIndicatorPlugin.js | 20 ++++ src/plugins/plugins.js | 8 +- 4 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 src/plugins/URLIndicatorPlugin/URLIndicator.js create mode 100644 src/plugins/URLIndicatorPlugin/URLIndicatorPlugin.js diff --git a/API.md b/API.md index 537ef81322..e9147e1679 100644 --- a/API.md +++ b/API.md @@ -886,6 +886,17 @@ openmct.install(openmct.plugins.CouchDB('http://localhost:9200')) when the application is first started, providing a place for a user to store created items. * `openmct.plugins.UTCTimeSystem` provides a default time system for Open MCT. +* `openmct.plugins.URLIndicatorPlugin({ + url: 'http://google.com', + icon: 'check', + interval: 10000, + label: 'Google' + })` adds an indicator which shows the + availability of a URL with the following options: + - `url` : URL to indicate the status of + - `icon`: Icon to show in the status bar, defaults to `database` + - `interval`: Interval between checking the connection, defaults to `10000` + - `label` Name showing up as text in the status bar, defaults to url Generally, you will want to either install these plugins, or install different plugins that provide persistence and an initial folder diff --git a/src/plugins/URLIndicatorPlugin/URLIndicator.js b/src/plugins/URLIndicatorPlugin/URLIndicator.js new file mode 100644 index 0000000000..05d029f0b4 --- /dev/null +++ b/src/plugins/URLIndicatorPlugin/URLIndicator.js @@ -0,0 +1,97 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2016, 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. + *****************************************************************************/ + +define( + [], + function () { + + // Set of connection states; changing among these states will be + // reflected in the indicator's appearance. + // CONNECTED: Everything nominal, expect to be able to read/write. + // DISCONNECTED: HTTP failed; maybe misconfigured, disconnected. + // PENDING: Still trying to connect, and haven't failed yet. + var CONNECTED = { + glyphClass: "ok" + }, + PENDING = { + glyphClass: 'caution' + }, + DISCONNECTED = { + glyphClass: "err" + }; + function URLIndicator($http, $interval) { + var self = this; + this.icon = "icon-" + (this.options.icon ? this.options.icon : "database"); + this.URLpath = this.options.url; + this.label = this.options.label ? this.options.label : this.options.url; + this.interval = this.options.interval || 10000; + this.state = PENDING; + + function handleError(e) { + self.state = DISCONNECTED; + } + function handleResponse() { + self.state = CONNECTED; + } + function updateIndicator() { + $http.get(self.URLpath).then(handleResponse, handleError); + } + updateIndicator(); + $interval(updateIndicator, self.interval, 0, false); + } + + URLIndicator.prototype.getCssClass = function () { + return this.icon; + }; + URLIndicator.prototype.getGlyphClass = function () { + return this.state.glyphClass; + }; + URLIndicator.prototype.getText = function () { + switch (this.state) { + case CONNECTED: { + return this.label + " is connected"; + } + case PENDING: { + return "Checking status of " + this.label + " please stand by..."; + } + case DISCONNECTED: { + return this.label + " is offline"; + } + } + }; + URLIndicator.prototype.getDescription = function () { + switch (this.state) { + case CONNECTED: { + return this.label + " is online, checking status every " + + this.interval + " milliseconds."; + } + case PENDING: { + return "Checking status of " + this.label + " please stand by..."; + } + case DISCONNECTED: { + return this.label + " is offline, checking status every " + + this.interval + " milliseconds"; + } + } + }; + return URLIndicator; + }); diff --git a/src/plugins/URLIndicatorPlugin/URLIndicatorPlugin.js b/src/plugins/URLIndicatorPlugin/URLIndicatorPlugin.js new file mode 100644 index 0000000000..24a4394466 --- /dev/null +++ b/src/plugins/URLIndicatorPlugin/URLIndicatorPlugin.js @@ -0,0 +1,20 @@ +define( + [ + './URLIndicator' + ], + function URLIndicatorPlugin(URLIndicator) { + return function (opts) { + // Wrap the plugin in a function so we can apply the arguments. + function URLIndicatorWrapper() { + this.options = opts; + URLIndicator.apply(this, arguments); + } + URLIndicatorWrapper.prototype = Object.create(URLIndicator.prototype); + return function install(openmct) { + openmct.legacyExtension('indicators', { + "implementation": URLIndicatorWrapper, + "depends": ["$http", "$interval"] + }); + }; + }; +}); diff --git a/src/plugins/plugins.js b/src/plugins/plugins.js index b381a1cfc3..5633d2e1f0 100644 --- a/src/plugins/plugins.js +++ b/src/plugins/plugins.js @@ -27,7 +27,8 @@ define([ '../../platform/features/autoflow/plugin', './timeConductor/plugin', '../../example/imagery/plugin', - '../../platform/import-export/bundle' + '../../platform/import-export/bundle', + './URLIndicatorPlugin/URLIndicatorPlugin' ], function ( _, UTCTimeSystem, @@ -35,7 +36,8 @@ define([ AutoflowPlugin, TimeConductorPlugin, ExampleImagery, - ImportExport + ImportExport, + URLIndicatorPlugin ) { var bundleMap = { CouchDB: 'platform/persistence/couch', @@ -121,5 +123,7 @@ define([ plugins.ExampleImagery = ExampleImagery; + plugins.URLIndicatorPlugin = URLIndicatorPlugin; + return plugins; });