openmct/example/imagery/plugin.js

176 lines
7.2 KiB
JavaScript
Raw Normal View History

/*****************************************************************************
* Open MCT, Copyright (c) 2014-2021, 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.
*****************************************************************************/
2017-05-22 21:40:35 +00:00
define([
], function (
2017-05-22 21:40:35 +00:00
) {
function ImageryPlugin() {
Imagery Age to be displayed for realtime mode in Imagery View (#3308) * fix linting errors * removing testing units * WIP: stubbe in age in template, adding getAge function * WIP: stubbed in age in template, dummy function to start * added image age for realtime mode, ready for styling * reverting unnecesarry telemetryview file changes, not needed for this issue * checking for age tracking conditions on mount * Image age styling and changes - Cleaned up code in ImageryPlugin to use const instead of var, changed image delay time into a const * Image age styling and changes - WIP! - Layout changes for Imagery control-bar; - New animation effect, WIP; * Image age styling and changes - Markup and CSS updates for Imagery view; - Final layout for age indicator; * parsing image timestamp in case it is a string * using moment for human readable durations above 8 hours * UTC based timesystem check * reset "new" css class on image age when "time" updates * WIP: debuggin weird imagery plugin issue for first selection of image in thumbnails * fixing pause overwriting clicked images selection * making isImageNew a computed value * WIP: pr updates * WIP: tabling PR edits to focus on lower hanging PR edits for testathon * WIP * overhaul of imagery plugin logic for optimization PLUS imagery age * adding next/prev functionality to refactored plugin * added arrow left and right keys to navigate next and previous * added arrow key scrolling and scrolling thumbnail into view and hold down scrolling * adding in missing class * component based key listening, PR updates * refactor to use just imageIndex to track focused image, utilized more caching, PR comment edits Co-authored-by: David Tsay <david.e.tsay@nasa.gov> Co-authored-by: charlesh88 <charlesh88@gmail.com>
2020-10-06 23:01:47 +00:00
const IMAGE_SAMPLES = [
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18731.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18732.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18733.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18734.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18735.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18736.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18737.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18738.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18739.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18740.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18741.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18742.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18743.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18744.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18745.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18746.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18747.jpg",
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18748.jpg"
];
Imagery Age to be displayed for realtime mode in Imagery View (#3308) * fix linting errors * removing testing units * WIP: stubbe in age in template, adding getAge function * WIP: stubbed in age in template, dummy function to start * added image age for realtime mode, ready for styling * reverting unnecesarry telemetryview file changes, not needed for this issue * checking for age tracking conditions on mount * Image age styling and changes - Cleaned up code in ImageryPlugin to use const instead of var, changed image delay time into a const * Image age styling and changes - WIP! - Layout changes for Imagery control-bar; - New animation effect, WIP; * Image age styling and changes - Markup and CSS updates for Imagery view; - Final layout for age indicator; * parsing image timestamp in case it is a string * using moment for human readable durations above 8 hours * UTC based timesystem check * reset "new" css class on image age when "time" updates * WIP: debuggin weird imagery plugin issue for first selection of image in thumbnails * fixing pause overwriting clicked images selection * making isImageNew a computed value * WIP: pr updates * WIP: tabling PR edits to focus on lower hanging PR edits for testathon * WIP * overhaul of imagery plugin logic for optimization PLUS imagery age * adding next/prev functionality to refactored plugin * added arrow left and right keys to navigate next and previous * added arrow key scrolling and scrolling thumbnail into view and hold down scrolling * adding in missing class * component based key listening, PR updates * refactor to use just imageIndex to track focused image, utilized more caching, PR comment edits Co-authored-by: David Tsay <david.e.tsay@nasa.gov> Co-authored-by: charlesh88 <charlesh88@gmail.com>
2020-10-06 23:01:47 +00:00
const IMAGE_DELAY = 20000;
function getCompassValues(min, max) {
return min + Math.random() * (max - min);
}
function pointForTimestamp(timestamp, name) {
const url = IMAGE_SAMPLES[Math.floor(timestamp / IMAGE_DELAY) % IMAGE_SAMPLES.length];
const urlItems = url.split('/');
const imageDownloadName = `example.imagery.${urlItems[urlItems.length - 1]}`;
return {
name,
Imagery Age to be displayed for realtime mode in Imagery View (#3308) * fix linting errors * removing testing units * WIP: stubbe in age in template, adding getAge function * WIP: stubbed in age in template, dummy function to start * added image age for realtime mode, ready for styling * reverting unnecesarry telemetryview file changes, not needed for this issue * checking for age tracking conditions on mount * Image age styling and changes - Cleaned up code in ImageryPlugin to use const instead of var, changed image delay time into a const * Image age styling and changes - WIP! - Layout changes for Imagery control-bar; - New animation effect, WIP; * Image age styling and changes - Markup and CSS updates for Imagery view; - Final layout for age indicator; * parsing image timestamp in case it is a string * using moment for human readable durations above 8 hours * UTC based timesystem check * reset "new" css class on image age when "time" updates * WIP: debuggin weird imagery plugin issue for first selection of image in thumbnails * fixing pause overwriting clicked images selection * making isImageNew a computed value * WIP: pr updates * WIP: tabling PR edits to focus on lower hanging PR edits for testathon * WIP * overhaul of imagery plugin logic for optimization PLUS imagery age * adding next/prev functionality to refactored plugin * added arrow left and right keys to navigate next and previous * added arrow key scrolling and scrolling thumbnail into view and hold down scrolling * adding in missing class * component based key listening, PR updates * refactor to use just imageIndex to track focused image, utilized more caching, PR comment edits Co-authored-by: David Tsay <david.e.tsay@nasa.gov> Co-authored-by: charlesh88 <charlesh88@gmail.com>
2020-10-06 23:01:47 +00:00
utc: Math.floor(timestamp / IMAGE_DELAY) * IMAGE_DELAY,
local: Math.floor(timestamp / IMAGE_DELAY) * IMAGE_DELAY,
url,
sunOrientation: getCompassValues(0, 360),
cameraPan: getCompassValues(0, 360),
heading: getCompassValues(0, 360),
imageDownloadName
};
}
var realtimeProvider = {
supportsSubscribe: function (domainObject) {
return domainObject.type === 'example.imagery';
},
subscribe: function (domainObject, callback) {
var interval = setInterval(function () {
callback(pointForTimestamp(Date.now(), domainObject.name));
Imagery Age to be displayed for realtime mode in Imagery View (#3308) * fix linting errors * removing testing units * WIP: stubbe in age in template, adding getAge function * WIP: stubbed in age in template, dummy function to start * added image age for realtime mode, ready for styling * reverting unnecesarry telemetryview file changes, not needed for this issue * checking for age tracking conditions on mount * Image age styling and changes - Cleaned up code in ImageryPlugin to use const instead of var, changed image delay time into a const * Image age styling and changes - WIP! - Layout changes for Imagery control-bar; - New animation effect, WIP; * Image age styling and changes - Markup and CSS updates for Imagery view; - Final layout for age indicator; * parsing image timestamp in case it is a string * using moment for human readable durations above 8 hours * UTC based timesystem check * reset "new" css class on image age when "time" updates * WIP: debuggin weird imagery plugin issue for first selection of image in thumbnails * fixing pause overwriting clicked images selection * making isImageNew a computed value * WIP: pr updates * WIP: tabling PR edits to focus on lower hanging PR edits for testathon * WIP * overhaul of imagery plugin logic for optimization PLUS imagery age * adding next/prev functionality to refactored plugin * added arrow left and right keys to navigate next and previous * added arrow key scrolling and scrolling thumbnail into view and hold down scrolling * adding in missing class * component based key listening, PR updates * refactor to use just imageIndex to track focused image, utilized more caching, PR comment edits Co-authored-by: David Tsay <david.e.tsay@nasa.gov> Co-authored-by: charlesh88 <charlesh88@gmail.com>
2020-10-06 23:01:47 +00:00
}, IMAGE_DELAY);
return function () {
clearInterval(interval);
};
}
};
var historicalProvider = {
supportsRequest: function (domainObject, options) {
return domainObject.type === 'example.imagery'
&& options.strategy !== 'latest';
},
request: function (domainObject, options) {
var start = options.start;
var end = Math.min(options.end, Date.now());
var data = [];
Imagery Age to be displayed for realtime mode in Imagery View (#3308) * fix linting errors * removing testing units * WIP: stubbe in age in template, adding getAge function * WIP: stubbed in age in template, dummy function to start * added image age for realtime mode, ready for styling * reverting unnecesarry telemetryview file changes, not needed for this issue * checking for age tracking conditions on mount * Image age styling and changes - Cleaned up code in ImageryPlugin to use const instead of var, changed image delay time into a const * Image age styling and changes - WIP! - Layout changes for Imagery control-bar; - New animation effect, WIP; * Image age styling and changes - Markup and CSS updates for Imagery view; - Final layout for age indicator; * parsing image timestamp in case it is a string * using moment for human readable durations above 8 hours * UTC based timesystem check * reset "new" css class on image age when "time" updates * WIP: debuggin weird imagery plugin issue for first selection of image in thumbnails * fixing pause overwriting clicked images selection * making isImageNew a computed value * WIP: pr updates * WIP: tabling PR edits to focus on lower hanging PR edits for testathon * WIP * overhaul of imagery plugin logic for optimization PLUS imagery age * adding next/prev functionality to refactored plugin * added arrow left and right keys to navigate next and previous * added arrow key scrolling and scrolling thumbnail into view and hold down scrolling * adding in missing class * component based key listening, PR updates * refactor to use just imageIndex to track focused image, utilized more caching, PR comment edits Co-authored-by: David Tsay <david.e.tsay@nasa.gov> Co-authored-by: charlesh88 <charlesh88@gmail.com>
2020-10-06 23:01:47 +00:00
while (start <= end && data.length < IMAGE_DELAY) {
data.push(pointForTimestamp(start, domainObject.name));
Imagery Age to be displayed for realtime mode in Imagery View (#3308) * fix linting errors * removing testing units * WIP: stubbe in age in template, adding getAge function * WIP: stubbed in age in template, dummy function to start * added image age for realtime mode, ready for styling * reverting unnecesarry telemetryview file changes, not needed for this issue * checking for age tracking conditions on mount * Image age styling and changes - Cleaned up code in ImageryPlugin to use const instead of var, changed image delay time into a const * Image age styling and changes - WIP! - Layout changes for Imagery control-bar; - New animation effect, WIP; * Image age styling and changes - Markup and CSS updates for Imagery view; - Final layout for age indicator; * parsing image timestamp in case it is a string * using moment for human readable durations above 8 hours * UTC based timesystem check * reset "new" css class on image age when "time" updates * WIP: debuggin weird imagery plugin issue for first selection of image in thumbnails * fixing pause overwriting clicked images selection * making isImageNew a computed value * WIP: pr updates * WIP: tabling PR edits to focus on lower hanging PR edits for testathon * WIP * overhaul of imagery plugin logic for optimization PLUS imagery age * adding next/prev functionality to refactored plugin * added arrow left and right keys to navigate next and previous * added arrow key scrolling and scrolling thumbnail into view and hold down scrolling * adding in missing class * component based key listening, PR updates * refactor to use just imageIndex to track focused image, utilized more caching, PR comment edits Co-authored-by: David Tsay <david.e.tsay@nasa.gov> Co-authored-by: charlesh88 <charlesh88@gmail.com>
2020-10-06 23:01:47 +00:00
start += IMAGE_DELAY;
}
return Promise.resolve(data);
}
};
var ladProvider = {
supportsRequest: function (domainObject, options) {
return domainObject.type === 'example.imagery'
&& options.strategy === 'latest';
},
request: function (domainObject, options) {
return Promise.resolve([pointForTimestamp(Date.now(), domainObject.name)]);
}
};
2017-05-22 21:40:35 +00:00
return function install(openmct) {
openmct.types.addType('example.imagery', {
key: 'example.imagery',
name: 'Example Imagery',
cssClass: 'icon-image',
description: 'For development use. Creates example imagery '
+ 'data that mimics a live imagery stream.',
2017-05-22 21:40:35 +00:00
creatable: true,
initialize: function (object) {
object.telemetry = {
values: [
{
name: 'Name',
key: 'name'
},
2017-05-22 21:40:35 +00:00
{
name: 'Time',
2017-05-23 01:30:01 +00:00
key: 'utc',
2017-05-22 21:40:35 +00:00
format: 'utc',
hints: {
domain: 2
}
},
{
name: 'Local Time',
key: 'local',
format: 'local-format',
2017-05-22 21:40:35 +00:00
hints: {
domain: 1
}
},
{
name: 'Image',
key: 'url',
format: 'image',
2017-05-23 01:30:01 +00:00
hints: {
image: 1
}
},
{
name: 'Image Download Name',
key: 'imageDownloadName',
format: 'imageDownloadName',
hints: {
imageDownloadName: 1
}
2017-05-22 21:40:35 +00:00
}
]
};
2017-05-22 21:40:35 +00:00
}
});
openmct.telemetry.addProvider(realtimeProvider);
openmct.telemetry.addProvider(historicalProvider);
openmct.telemetry.addProvider(ladProvider);
2017-05-22 21:40:35 +00:00
};
}
2017-05-22 21:40:35 +00:00
return ImageryPlugin;
});