mirror of
https://github.com/nasa/openmct.git
synced 2025-06-25 02:29:24 +00:00
Compare commits
4 Commits
5211-tests
...
esm
Author | SHA1 | Date | |
---|---|---|---|
84c473cea8 | |||
b677d3b90e | |||
59a4d05a0b | |||
f663a6a5b1 |
@ -20,61 +20,79 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/EventTelemetryProvider"
|
||||
], function (
|
||||
EventTelemetryProvider
|
||||
) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/eventGenerator",
|
||||
definition: {
|
||||
"name": "Event Message Generator",
|
||||
"description": "For development use. Creates sample event message data that mimics a live data stream.",
|
||||
"extensions": {
|
||||
"components": [
|
||||
{
|
||||
"implementation": EventTelemetryProvider,
|
||||
"type": "provider",
|
||||
"provides": "telemetryService",
|
||||
"depends": [
|
||||
"$q",
|
||||
"$timeout"
|
||||
import EventTelemetryProvider from './src/EventTelemetryProvider';
|
||||
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/eventGenerator",
|
||||
definition: {
|
||||
"name": "Event Message Generator",
|
||||
"description": "For development use. Creates sample event message data that mimics a live data stream.",
|
||||
"extensions": {
|
||||
"components": [
|
||||
{
|
||||
"implementation": EventTelemetryProvider,
|
||||
"type": "provider",
|
||||
"provides": "telemetryService",
|
||||
"depends": [
|
||||
"$q",
|
||||
"$timeout"
|
||||
]
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"key": "eventGenerator",
|
||||
"name": "Event Message Generator",
|
||||
"cssClass": "icon-generator-events",
|
||||
"description": "For development use. Creates sample event message data that mimics a live data stream.",
|
||||
"priority": 10,
|
||||
"features": "creation",
|
||||
"model": {
|
||||
"telemetry": {}
|
||||
},
|
||||
"telemetry": {
|
||||
"source": "eventGenerator",
|
||||
"domains": [
|
||||
{
|
||||
"key": "utc",
|
||||
"name": "Timestamp",
|
||||
"format": "utc"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
{
|
||||
"key": "message",
|
||||
"name": "Message",
|
||||
"format": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"key": "eventGenerator",
|
||||
"name": "Event Message Generator",
|
||||
"cssClass": "icon-generator-events",
|
||||
"description": "For development use. Creates sample event message data that mimics a live data stream.",
|
||||
"priority": 10,
|
||||
"features": "creation",
|
||||
"model": {
|
||||
"telemetry": {}
|
||||
},
|
||||
"telemetry": {
|
||||
"source": "eventGenerator",
|
||||
"domains": [
|
||||
{
|
||||
"key": "utc",
|
||||
"name": "Timestamp",
|
||||
"format": "utc"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
{
|
||||
"key": "message",
|
||||
"name": "Message",
|
||||
"format": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -25,38 +25,62 @@
|
||||
* Created by chacskaylo on 06/18/2015.
|
||||
* Modified by shale on 06/23/2015.
|
||||
*/
|
||||
define(
|
||||
['../data/transcript.json'],
|
||||
function (messages) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
var firstObservedTime = Date.now();
|
||||
/**
|
||||
* Module defining EventTelemetry.
|
||||
* Created by chacskaylo on 06/18/2015.
|
||||
* Modified by shale on 06/23/2015.
|
||||
*/
|
||||
import messages from '../data/transcript.json';
|
||||
|
||||
function EventTelemetry(request, interval) {
|
||||
"use strict";
|
||||
|
||||
var latestObservedTime = Date.now(),
|
||||
count = Math.floor((latestObservedTime - firstObservedTime) / interval),
|
||||
generatorData = {};
|
||||
var firstObservedTime = Date.now();
|
||||
|
||||
generatorData.getPointCount = function () {
|
||||
return count;
|
||||
};
|
||||
function EventTelemetry(request, interval) {
|
||||
|
||||
generatorData.getDomainValue = function (i, domain) {
|
||||
return i * interval
|
||||
+ (domain !== 'delta' ? firstObservedTime : 0);
|
||||
};
|
||||
var latestObservedTime = Date.now(),
|
||||
count = Math.floor((latestObservedTime - firstObservedTime) / interval),
|
||||
generatorData = {};
|
||||
|
||||
generatorData.getRangeValue = function (i, range) {
|
||||
var domainDelta = this.getDomainValue(i) - firstObservedTime,
|
||||
ind = i % messages.length;
|
||||
generatorData.getPointCount = function () {
|
||||
return count;
|
||||
};
|
||||
|
||||
return messages[ind] + " - [" + domainDelta.toString() + "]";
|
||||
};
|
||||
generatorData.getDomainValue = function (i, domain) {
|
||||
return i * interval
|
||||
+ (domain !== 'delta' ? firstObservedTime : 0);
|
||||
};
|
||||
|
||||
return generatorData;
|
||||
}
|
||||
generatorData.getRangeValue = function (i, range) {
|
||||
var domainDelta = this.getDomainValue(i) - firstObservedTime,
|
||||
ind = i % messages.length;
|
||||
|
||||
return EventTelemetry;
|
||||
}
|
||||
);
|
||||
return messages[ind] + " - [" + domainDelta.toString() + "]";
|
||||
};
|
||||
|
||||
return generatorData;
|
||||
}
|
||||
|
||||
export default EventTelemetry;
|
@ -23,96 +23,118 @@
|
||||
/**
|
||||
* Module defining EventTelemetryProvider. Created by chacskaylo on 06/18/2015.
|
||||
*/
|
||||
define(
|
||||
["./EventTelemetry"],
|
||||
function (EventTelemetry) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function EventTelemetryProvider($q, $timeout) {
|
||||
var subscriptions = [],
|
||||
genInterval = 1000,
|
||||
/**
|
||||
* Module defining EventTelemetryProvider. Created by chacskaylo on 06/18/2015.
|
||||
*/
|
||||
import EventTelemetry from './EventTelemetry';
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function EventTelemetryProvider($q, $timeout) {
|
||||
var subscriptions = [],
|
||||
genInterval = 1000,
|
||||
generating = false;
|
||||
|
||||
//
|
||||
function matchesSource(request) {
|
||||
return request.source === "eventGenerator";
|
||||
}
|
||||
|
||||
// Used internally; this will be repacked by doPackage
|
||||
function generateData(request) {
|
||||
return {
|
||||
key: request.key,
|
||||
telemetry: new EventTelemetry(request, genInterval)
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
function doPackage(results) {
|
||||
var packaged = {};
|
||||
results.forEach(function (result) {
|
||||
packaged[result.key] = result.telemetry;
|
||||
});
|
||||
|
||||
// Format as expected (sources -> keys -> telemetry)
|
||||
return { eventGenerator: packaged };
|
||||
}
|
||||
|
||||
function requestTelemetry(requests) {
|
||||
return $timeout(function () {
|
||||
return doPackage(requests.filter(matchesSource).map(generateData));
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function handleSubscriptions(timeout) {
|
||||
subscriptions.forEach(function (subscription) {
|
||||
var requests = subscription.requests;
|
||||
subscription.callback(doPackage(
|
||||
requests.filter(matchesSource).map(generateData)
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
function startGenerating() {
|
||||
generating = true;
|
||||
$timeout(function () {
|
||||
handleSubscriptions();
|
||||
if (generating && subscriptions.length > 0) {
|
||||
startGenerating();
|
||||
} else {
|
||||
generating = false;
|
||||
|
||||
//
|
||||
function matchesSource(request) {
|
||||
return request.source === "eventGenerator";
|
||||
}
|
||||
}, genInterval);
|
||||
}
|
||||
|
||||
// Used internally; this will be repacked by doPackage
|
||||
function generateData(request) {
|
||||
return {
|
||||
key: request.key,
|
||||
telemetry: new EventTelemetry(request, genInterval)
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
function doPackage(results) {
|
||||
var packaged = {};
|
||||
results.forEach(function (result) {
|
||||
packaged[result.key] = result.telemetry;
|
||||
});
|
||||
|
||||
// Format as expected (sources -> keys -> telemetry)
|
||||
return { eventGenerator: packaged };
|
||||
}
|
||||
|
||||
function requestTelemetry(requests) {
|
||||
return $timeout(function () {
|
||||
return doPackage(requests.filter(matchesSource).map(generateData));
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function handleSubscriptions(timeout) {
|
||||
subscriptions.forEach(function (subscription) {
|
||||
var requests = subscription.requests;
|
||||
subscription.callback(doPackage(
|
||||
requests.filter(matchesSource).map(generateData)
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
function startGenerating() {
|
||||
generating = true;
|
||||
$timeout(function () {
|
||||
handleSubscriptions();
|
||||
if (generating && subscriptions.length > 0) {
|
||||
startGenerating();
|
||||
} else {
|
||||
generating = false;
|
||||
}
|
||||
}, genInterval);
|
||||
}
|
||||
|
||||
function subscribe(callback, requests) {
|
||||
var subscription = {
|
||||
callback: callback,
|
||||
requests: requests
|
||||
};
|
||||
function unsubscribe() {
|
||||
subscriptions = subscriptions.filter(function (s) {
|
||||
return s !== subscription;
|
||||
});
|
||||
}
|
||||
|
||||
subscriptions.push(subscription);
|
||||
if (!generating) {
|
||||
startGenerating();
|
||||
}
|
||||
|
||||
return unsubscribe;
|
||||
}
|
||||
|
||||
return {
|
||||
requestTelemetry: requestTelemetry,
|
||||
subscribe: subscribe
|
||||
};
|
||||
function subscribe(callback, requests) {
|
||||
var subscription = {
|
||||
callback: callback,
|
||||
requests: requests
|
||||
};
|
||||
function unsubscribe() {
|
||||
subscriptions = subscriptions.filter(function (s) {
|
||||
return s !== subscription;
|
||||
});
|
||||
}
|
||||
|
||||
return EventTelemetryProvider;
|
||||
subscriptions.push(subscription);
|
||||
if (!generating) {
|
||||
startGenerating();
|
||||
}
|
||||
|
||||
return unsubscribe;
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
requestTelemetry: requestTelemetry,
|
||||
subscribe: subscribe
|
||||
};
|
||||
}
|
||||
|
||||
export default EventTelemetryProvider;
|
@ -20,70 +20,90 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([], function () {
|
||||
'use strict';
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* An example of using the `exportService`; queries for telemetry
|
||||
* and provides the results as a CSV file.
|
||||
* @param {platform/exporters.ExportService} exportService the
|
||||
* service which will handle the CSV export
|
||||
* @param {ActionContext} context the action's context
|
||||
* @constructor
|
||||
* @memberof example/export
|
||||
* @implements {Action}
|
||||
*/
|
||||
function ExportTelemetryAsCSVAction(exportService, context) {
|
||||
this.exportService = exportService;
|
||||
this.context = context;
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* An example of using the `exportService`; queries for telemetry
|
||||
* and provides the results as a CSV file.
|
||||
* @param {platform/exporters.ExportService} exportService the
|
||||
* service which will handle the CSV export
|
||||
* @param {ActionContext} context the action's context
|
||||
* @constructor
|
||||
* @memberof example/export
|
||||
* @implements {Action}
|
||||
*/
|
||||
function ExportTelemetryAsCSVAction(exportService, context) {
|
||||
this.exportService = exportService;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
ExportTelemetryAsCSVAction.prototype.perform = function () {
|
||||
var context = this.context,
|
||||
domainObject = context.domainObject,
|
||||
telemetry = domainObject.getCapability("telemetry"),
|
||||
metadata = telemetry.getMetadata(),
|
||||
domains = metadata.domains,
|
||||
ranges = metadata.ranges,
|
||||
exportService = this.exportService;
|
||||
|
||||
function getName(domainOrRange) {
|
||||
return domainOrRange.name;
|
||||
}
|
||||
|
||||
ExportTelemetryAsCSVAction.prototype.perform = function () {
|
||||
var context = this.context,
|
||||
domainObject = context.domainObject,
|
||||
telemetry = domainObject.getCapability("telemetry"),
|
||||
metadata = telemetry.getMetadata(),
|
||||
domains = metadata.domains,
|
||||
ranges = metadata.ranges,
|
||||
exportService = this.exportService;
|
||||
telemetry.requestData({}).then(function (series) {
|
||||
var headers = domains.map(getName).concat(ranges.map(getName)),
|
||||
rows = [],
|
||||
row,
|
||||
i;
|
||||
|
||||
function getName(domainOrRange) {
|
||||
return domainOrRange.name;
|
||||
function copyDomainsToRow(telemetryRow, index) {
|
||||
domains.forEach(function (domain) {
|
||||
telemetryRow[domain.name] = series.getDomainValue(index, domain.key);
|
||||
});
|
||||
}
|
||||
|
||||
telemetry.requestData({}).then(function (series) {
|
||||
var headers = domains.map(getName).concat(ranges.map(getName)),
|
||||
rows = [],
|
||||
row,
|
||||
i;
|
||||
function copyRangesToRow(telemetryRow, index) {
|
||||
ranges.forEach(function (range) {
|
||||
telemetryRow[range.name] = series.getRangeValue(index, range.key);
|
||||
});
|
||||
}
|
||||
|
||||
function copyDomainsToRow(telemetryRow, index) {
|
||||
domains.forEach(function (domain) {
|
||||
telemetryRow[domain.name] = series.getDomainValue(index, domain.key);
|
||||
});
|
||||
}
|
||||
for (i = 0; i < series.getPointCount(); i += 1) {
|
||||
row = {};
|
||||
copyDomainsToRow(row, i);
|
||||
copyRangesToRow(row, i);
|
||||
rows.push(row);
|
||||
}
|
||||
|
||||
function copyRangesToRow(telemetryRow, index) {
|
||||
ranges.forEach(function (range) {
|
||||
telemetryRow[range.name] = series.getRangeValue(index, range.key);
|
||||
});
|
||||
}
|
||||
exportService.exportCSV(rows, { headers: headers });
|
||||
});
|
||||
};
|
||||
|
||||
for (i = 0; i < series.getPointCount(); i += 1) {
|
||||
row = {};
|
||||
copyDomainsToRow(row, i);
|
||||
copyRangesToRow(row, i);
|
||||
rows.push(row);
|
||||
}
|
||||
ExportTelemetryAsCSVAction.appliesTo = function (context) {
|
||||
return context.domainObject
|
||||
&& context.domainObject.hasCapability("telemetry");
|
||||
};
|
||||
|
||||
exportService.exportCSV(rows, { headers: headers });
|
||||
});
|
||||
};
|
||||
|
||||
ExportTelemetryAsCSVAction.appliesTo = function (context) {
|
||||
return context.domainObject
|
||||
&& context.domainObject.hasCapability("telemetry");
|
||||
};
|
||||
|
||||
return ExportTelemetryAsCSVAction;
|
||||
});
|
||||
export default ExportTelemetryAsCSVAction;
|
@ -20,27 +20,47 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'./ExportTelemetryAsCSVAction'
|
||||
], function (ExportTelemetryAsCSVAction) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/export",
|
||||
definition: {
|
||||
"name": "Example of using CSV Export",
|
||||
"extensions": {
|
||||
"actions": [
|
||||
{
|
||||
"key": "example.export",
|
||||
"name": "Export Telemetry as CSV",
|
||||
"implementation": ExportTelemetryAsCSVAction,
|
||||
"category": "contextual",
|
||||
"cssClass": "icon-download",
|
||||
"depends": ["exportService"]
|
||||
}
|
||||
]
|
||||
}
|
||||
import ExportTelemetryAsCSVAction from './ExportTelemetryAsCSVAction';
|
||||
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/export",
|
||||
definition: {
|
||||
"name": "Example of using CSV Export",
|
||||
"extensions": {
|
||||
"actions": [
|
||||
{
|
||||
"key": "example.export",
|
||||
"name": "Export Telemetry as CSV",
|
||||
"implementation": ExportTelemetryAsCSVAction,
|
||||
"category": "contextual",
|
||||
"cssClass": "icon-download",
|
||||
"depends": ["exportService"]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,34 +20,52 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/ExampleFormController"
|
||||
], function (
|
||||
ExampleFormController
|
||||
) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/forms",
|
||||
definition: {
|
||||
"name": "Declarative Forms example",
|
||||
"sources": "src",
|
||||
"extensions": {
|
||||
"controllers": [
|
||||
{
|
||||
"key": "ExampleFormController",
|
||||
"implementation": ExampleFormController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
}
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"templateUrl": "templates/exampleForm.html"
|
||||
}
|
||||
]
|
||||
}
|
||||
import ExampleFormController from './src/ExampleFormController';
|
||||
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/forms",
|
||||
definition: {
|
||||
"name": "Declarative Forms example",
|
||||
"sources": "src",
|
||||
"extensions": {
|
||||
"controllers": [
|
||||
{
|
||||
"key": "ExampleFormController",
|
||||
"implementation": ExampleFormController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
}
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"templateUrl": "templates/exampleForm.html"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,186 +20,203 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
function ExampleFormController($scope) {
|
||||
$scope.state = {
|
||||
"use strict";
|
||||
|
||||
};
|
||||
function ExampleFormController($scope) {
|
||||
$scope.state = {
|
||||
|
||||
$scope.toolbar = {
|
||||
name: "An example toolbar.",
|
||||
sections: [
|
||||
};
|
||||
|
||||
$scope.toolbar = {
|
||||
name: "An example toolbar.",
|
||||
sections: [
|
||||
{
|
||||
description: "First section",
|
||||
items: [
|
||||
{
|
||||
description: "First section",
|
||||
items: [
|
||||
{
|
||||
name: "X",
|
||||
description: "X coordinate",
|
||||
control: "textfield",
|
||||
pattern: "^\\d+$",
|
||||
disabled: true,
|
||||
size: 2,
|
||||
key: "x"
|
||||
},
|
||||
{
|
||||
name: "Y",
|
||||
description: "Y coordinate",
|
||||
control: "textfield",
|
||||
pattern: "^\\d+$",
|
||||
size: 2,
|
||||
key: "y"
|
||||
},
|
||||
{
|
||||
name: "W",
|
||||
description: "Cell width",
|
||||
control: "textfield",
|
||||
pattern: "^\\d+$",
|
||||
size: 2,
|
||||
key: "w"
|
||||
},
|
||||
{
|
||||
name: "H",
|
||||
description: "Cell height",
|
||||
control: "textfield",
|
||||
pattern: "^\\d+$",
|
||||
size: 2,
|
||||
key: "h"
|
||||
}
|
||||
|
||||
]
|
||||
name: "X",
|
||||
description: "X coordinate",
|
||||
control: "textfield",
|
||||
pattern: "^\\d+$",
|
||||
disabled: true,
|
||||
size: 2,
|
||||
key: "x"
|
||||
},
|
||||
{
|
||||
description: "Second section",
|
||||
items: [
|
||||
{
|
||||
control: "button",
|
||||
csslass: "icon-save",
|
||||
click: function () {
|
||||
console.log("Save");
|
||||
}
|
||||
},
|
||||
{
|
||||
control: "button",
|
||||
csslass: "icon-x",
|
||||
description: "Button B",
|
||||
click: function () {
|
||||
console.log("Cancel");
|
||||
}
|
||||
},
|
||||
{
|
||||
control: "button",
|
||||
csslass: "icon-trash",
|
||||
description: "Button C",
|
||||
disabled: true,
|
||||
click: function () {
|
||||
console.log("Delete");
|
||||
}
|
||||
}
|
||||
]
|
||||
name: "Y",
|
||||
description: "Y coordinate",
|
||||
control: "textfield",
|
||||
pattern: "^\\d+$",
|
||||
size: 2,
|
||||
key: "y"
|
||||
},
|
||||
{
|
||||
items: [
|
||||
{
|
||||
control: "color",
|
||||
key: "color"
|
||||
}
|
||||
]
|
||||
name: "W",
|
||||
description: "Cell width",
|
||||
control: "textfield",
|
||||
pattern: "^\\d+$",
|
||||
size: 2,
|
||||
key: "w"
|
||||
},
|
||||
{
|
||||
name: "H",
|
||||
description: "Cell height",
|
||||
control: "textfield",
|
||||
pattern: "^\\d+$",
|
||||
size: 2,
|
||||
key: "h"
|
||||
}
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
description: "Second section",
|
||||
items: [
|
||||
{
|
||||
control: "button",
|
||||
csslass: "icon-save",
|
||||
click: function () {
|
||||
console.log("Save");
|
||||
}
|
||||
},
|
||||
{
|
||||
control: "button",
|
||||
csslass: "icon-x",
|
||||
description: "Button B",
|
||||
click: function () {
|
||||
console.log("Cancel");
|
||||
}
|
||||
},
|
||||
{
|
||||
control: "button",
|
||||
csslass: "icon-trash",
|
||||
description: "Button C",
|
||||
disabled: true,
|
||||
click: function () {
|
||||
console.log("Delete");
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
$scope.form = {
|
||||
name: "An example form.",
|
||||
sections: [
|
||||
},
|
||||
{
|
||||
items: [
|
||||
{
|
||||
name: "First section",
|
||||
rows: [
|
||||
{
|
||||
name: "Check me",
|
||||
control: "checkbox",
|
||||
key: "checkMe"
|
||||
},
|
||||
{
|
||||
name: "Enter your name",
|
||||
required: true,
|
||||
control: "textfield",
|
||||
key: "yourName"
|
||||
},
|
||||
{
|
||||
name: "Enter a number",
|
||||
control: "textfield",
|
||||
pattern: "^\\d+$",
|
||||
key: "aNumber"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Second section",
|
||||
rows: [
|
||||
{
|
||||
name: "Pick a date",
|
||||
required: true,
|
||||
description: "Enter date in form YYYY-DDD",
|
||||
control: "datetime",
|
||||
key: "aDate"
|
||||
},
|
||||
{
|
||||
name: "Choose something",
|
||||
control: "select",
|
||||
options: [
|
||||
{
|
||||
name: "Hats",
|
||||
value: "hats"
|
||||
},
|
||||
{
|
||||
name: "Bats",
|
||||
value: "bats"
|
||||
},
|
||||
{
|
||||
name: "Cats",
|
||||
value: "cats"
|
||||
},
|
||||
{
|
||||
name: "Mats",
|
||||
value: "mats"
|
||||
}
|
||||
],
|
||||
key: "aChoice"
|
||||
},
|
||||
{
|
||||
name: "Choose something",
|
||||
control: "select",
|
||||
required: true,
|
||||
options: [
|
||||
{
|
||||
name: "Hats",
|
||||
value: "hats"
|
||||
},
|
||||
{
|
||||
name: "Bats",
|
||||
value: "bats"
|
||||
},
|
||||
{
|
||||
name: "Cats",
|
||||
value: "cats"
|
||||
},
|
||||
{
|
||||
name: "Mats",
|
||||
value: "mats"
|
||||
}
|
||||
],
|
||||
key: "aRequiredChoice"
|
||||
}
|
||||
]
|
||||
control: "color",
|
||||
key: "color"
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
return ExampleFormController;
|
||||
}
|
||||
);
|
||||
$scope.form = {
|
||||
name: "An example form.",
|
||||
sections: [
|
||||
{
|
||||
name: "First section",
|
||||
rows: [
|
||||
{
|
||||
name: "Check me",
|
||||
control: "checkbox",
|
||||
key: "checkMe"
|
||||
},
|
||||
{
|
||||
name: "Enter your name",
|
||||
required: true,
|
||||
control: "textfield",
|
||||
key: "yourName"
|
||||
},
|
||||
{
|
||||
name: "Enter a number",
|
||||
control: "textfield",
|
||||
pattern: "^\\d+$",
|
||||
key: "aNumber"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Second section",
|
||||
rows: [
|
||||
{
|
||||
name: "Pick a date",
|
||||
required: true,
|
||||
description: "Enter date in form YYYY-DDD",
|
||||
control: "datetime",
|
||||
key: "aDate"
|
||||
},
|
||||
{
|
||||
name: "Choose something",
|
||||
control: "select",
|
||||
options: [
|
||||
{
|
||||
name: "Hats",
|
||||
value: "hats"
|
||||
},
|
||||
{
|
||||
name: "Bats",
|
||||
value: "bats"
|
||||
},
|
||||
{
|
||||
name: "Cats",
|
||||
value: "cats"
|
||||
},
|
||||
{
|
||||
name: "Mats",
|
||||
value: "mats"
|
||||
}
|
||||
],
|
||||
key: "aChoice"
|
||||
},
|
||||
{
|
||||
name: "Choose something",
|
||||
control: "select",
|
||||
required: true,
|
||||
options: [
|
||||
{
|
||||
name: "Hats",
|
||||
value: "hats"
|
||||
},
|
||||
{
|
||||
name: "Bats",
|
||||
value: "bats"
|
||||
},
|
||||
{
|
||||
name: "Cats",
|
||||
value: "cats"
|
||||
},
|
||||
{
|
||||
name: "Mats",
|
||||
value: "mats"
|
||||
}
|
||||
],
|
||||
key: "aRequiredChoice"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
export default ExampleFormController;
|
@ -1,142 +1,136 @@
|
||||
define([
|
||||
'lodash'
|
||||
], function (
|
||||
_
|
||||
) {
|
||||
import _ from 'lodash';
|
||||
|
||||
var METADATA_BY_TYPE = {
|
||||
'generator': {
|
||||
values: [
|
||||
{
|
||||
key: "name",
|
||||
name: "Name",
|
||||
format: "string"
|
||||
},
|
||||
{
|
||||
key: "utc",
|
||||
name: "Time",
|
||||
format: "utc",
|
||||
hints: {
|
||||
domain: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "yesterday",
|
||||
name: "Yesterday",
|
||||
format: "utc",
|
||||
hints: {
|
||||
domain: 2
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "cos",
|
||||
name: "Cosine",
|
||||
unit: "deg",
|
||||
formatString: '%0.2f',
|
||||
hints: {
|
||||
domain: 3
|
||||
}
|
||||
},
|
||||
// Need to enable "LocalTimeSystem" plugin to make use of this
|
||||
// {
|
||||
// key: "local",
|
||||
// name: "Time",
|
||||
// format: "local-format",
|
||||
// source: "utc",
|
||||
// hints: {
|
||||
// domain: 3
|
||||
// }
|
||||
// },
|
||||
{
|
||||
key: "sin",
|
||||
name: "Sine",
|
||||
unit: "Hz",
|
||||
formatString: '%0.2f',
|
||||
hints: {
|
||||
range: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "cos",
|
||||
name: "Cosine",
|
||||
unit: "deg",
|
||||
formatString: '%0.2f',
|
||||
hints: {
|
||||
range: 2
|
||||
}
|
||||
var METADATA_BY_TYPE = {
|
||||
'generator': {
|
||||
values: [
|
||||
{
|
||||
key: "name",
|
||||
name: "Name",
|
||||
format: "string"
|
||||
},
|
||||
{
|
||||
key: "utc",
|
||||
name: "Time",
|
||||
format: "utc",
|
||||
hints: {
|
||||
domain: 1
|
||||
}
|
||||
]
|
||||
},
|
||||
'example.state-generator': {
|
||||
values: [
|
||||
{
|
||||
key: "name",
|
||||
name: "Name",
|
||||
format: "string"
|
||||
},
|
||||
{
|
||||
key: "utc",
|
||||
name: "Time",
|
||||
format: "utc",
|
||||
hints: {
|
||||
domain: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "local",
|
||||
name: "Time",
|
||||
format: "utc",
|
||||
source: "utc",
|
||||
hints: {
|
||||
domain: 2
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "state",
|
||||
source: "value",
|
||||
name: "State",
|
||||
format: "enum",
|
||||
enumerations: [
|
||||
{
|
||||
value: 0,
|
||||
string: "OFF"
|
||||
},
|
||||
{
|
||||
value: 1,
|
||||
string: "ON"
|
||||
}
|
||||
],
|
||||
hints: {
|
||||
range: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "value",
|
||||
name: "Value",
|
||||
hints: {
|
||||
range: 2
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "yesterday",
|
||||
name: "Yesterday",
|
||||
format: "utc",
|
||||
hints: {
|
||||
domain: 2
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
function GeneratorMetadataProvider() {
|
||||
|
||||
},
|
||||
{
|
||||
key: "cos",
|
||||
name: "Cosine",
|
||||
unit: "deg",
|
||||
formatString: '%0.2f',
|
||||
hints: {
|
||||
domain: 3
|
||||
}
|
||||
},
|
||||
// Need to enable "LocalTimeSystem" plugin to make use of this
|
||||
// {
|
||||
// key: "local",
|
||||
// name: "Time",
|
||||
// format: "local-format",
|
||||
// source: "utc",
|
||||
// hints: {
|
||||
// domain: 3
|
||||
// }
|
||||
// },
|
||||
{
|
||||
key: "sin",
|
||||
name: "Sine",
|
||||
unit: "Hz",
|
||||
formatString: '%0.2f',
|
||||
hints: {
|
||||
range: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "cos",
|
||||
name: "Cosine",
|
||||
unit: "deg",
|
||||
formatString: '%0.2f',
|
||||
hints: {
|
||||
range: 2
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
'example.state-generator': {
|
||||
values: [
|
||||
{
|
||||
key: "name",
|
||||
name: "Name",
|
||||
format: "string"
|
||||
},
|
||||
{
|
||||
key: "utc",
|
||||
name: "Time",
|
||||
format: "utc",
|
||||
hints: {
|
||||
domain: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "local",
|
||||
name: "Time",
|
||||
format: "utc",
|
||||
source: "utc",
|
||||
hints: {
|
||||
domain: 2
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "state",
|
||||
source: "value",
|
||||
name: "State",
|
||||
format: "enum",
|
||||
enumerations: [
|
||||
{
|
||||
value: 0,
|
||||
string: "OFF"
|
||||
},
|
||||
{
|
||||
value: 1,
|
||||
string: "ON"
|
||||
}
|
||||
],
|
||||
hints: {
|
||||
range: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "value",
|
||||
name: "Value",
|
||||
hints: {
|
||||
range: 2
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
GeneratorMetadataProvider.prototype.supportsMetadata = function (domainObject) {
|
||||
return Object.prototype.hasOwnProperty.call(METADATA_BY_TYPE, domainObject.type);
|
||||
};
|
||||
function GeneratorMetadataProvider() {
|
||||
|
||||
GeneratorMetadataProvider.prototype.getMetadata = function (domainObject) {
|
||||
return Object.assign(
|
||||
{},
|
||||
domainObject.telemetry,
|
||||
METADATA_BY_TYPE[domainObject.type]
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
return GeneratorMetadataProvider;
|
||||
GeneratorMetadataProvider.prototype.supportsMetadata = function (domainObject) {
|
||||
return Object.prototype.hasOwnProperty.call(METADATA_BY_TYPE, domainObject.type);
|
||||
};
|
||||
|
||||
});
|
||||
GeneratorMetadataProvider.prototype.getMetadata = function (domainObject) {
|
||||
return Object.assign(
|
||||
{},
|
||||
domainObject.telemetry,
|
||||
METADATA_BY_TYPE[domainObject.type]
|
||||
);
|
||||
};
|
||||
|
||||
export default GeneratorMetadataProvider;
|
||||
|
@ -20,81 +20,98 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'./WorkerInterface'
|
||||
], function (
|
||||
WorkerInterface
|
||||
) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
var REQUEST_DEFAULTS = {
|
||||
amplitude: 1,
|
||||
period: 10,
|
||||
offset: 0,
|
||||
dataRateInHz: 1,
|
||||
randomness: 0,
|
||||
phase: 0
|
||||
};
|
||||
import WorkerInterface from './WorkerInterface';
|
||||
|
||||
function GeneratorProvider() {
|
||||
this.workerInterface = new WorkerInterface();
|
||||
}
|
||||
var REQUEST_DEFAULTS = {
|
||||
amplitude: 1,
|
||||
period: 10,
|
||||
offset: 0,
|
||||
dataRateInHz: 1,
|
||||
randomness: 0,
|
||||
phase: 0
|
||||
};
|
||||
|
||||
GeneratorProvider.prototype.canProvideTelemetry = function (domainObject) {
|
||||
return domainObject.type === 'generator';
|
||||
};
|
||||
function GeneratorProvider() {
|
||||
this.workerInterface = new WorkerInterface();
|
||||
}
|
||||
|
||||
GeneratorProvider.prototype.supportsRequest =
|
||||
GeneratorProvider.prototype.supportsSubscribe =
|
||||
GeneratorProvider.prototype.canProvideTelemetry;
|
||||
GeneratorProvider.prototype.canProvideTelemetry = function (domainObject) {
|
||||
return domainObject.type === 'generator';
|
||||
};
|
||||
|
||||
GeneratorProvider.prototype.makeWorkerRequest = function (domainObject, request) {
|
||||
var props = [
|
||||
'amplitude',
|
||||
'period',
|
||||
'offset',
|
||||
'dataRateInHz',
|
||||
'phase',
|
||||
'randomness'
|
||||
];
|
||||
GeneratorProvider.prototype.supportsRequest =
|
||||
GeneratorProvider.prototype.supportsSubscribe =
|
||||
GeneratorProvider.prototype.canProvideTelemetry;
|
||||
|
||||
request = request || {};
|
||||
GeneratorProvider.prototype.makeWorkerRequest = function (domainObject, request) {
|
||||
var props = [
|
||||
'amplitude',
|
||||
'period',
|
||||
'offset',
|
||||
'dataRateInHz',
|
||||
'phase',
|
||||
'randomness'
|
||||
];
|
||||
|
||||
var workerRequest = {};
|
||||
request = request || {};
|
||||
|
||||
props.forEach(function (prop) {
|
||||
if (domainObject.telemetry && Object.prototype.hasOwnProperty.call(domainObject.telemetry, prop)) {
|
||||
workerRequest[prop] = domainObject.telemetry[prop];
|
||||
}
|
||||
var workerRequest = {};
|
||||
|
||||
if (request && Object.prototype.hasOwnProperty.call(request, prop)) {
|
||||
workerRequest[prop] = request[prop];
|
||||
}
|
||||
props.forEach(function (prop) {
|
||||
if (domainObject.telemetry && Object.prototype.hasOwnProperty.call(domainObject.telemetry, prop)) {
|
||||
workerRequest[prop] = domainObject.telemetry[prop];
|
||||
}
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(workerRequest, prop)) {
|
||||
workerRequest[prop] = REQUEST_DEFAULTS[prop];
|
||||
}
|
||||
if (request && Object.prototype.hasOwnProperty.call(request, prop)) {
|
||||
workerRequest[prop] = request[prop];
|
||||
}
|
||||
|
||||
workerRequest[prop] = Number(workerRequest[prop]);
|
||||
});
|
||||
if (!Object.prototype.hasOwnProperty.call(workerRequest, prop)) {
|
||||
workerRequest[prop] = REQUEST_DEFAULTS[prop];
|
||||
}
|
||||
|
||||
workerRequest.name = domainObject.name;
|
||||
workerRequest[prop] = Number(workerRequest[prop]);
|
||||
});
|
||||
|
||||
return workerRequest;
|
||||
};
|
||||
workerRequest.name = domainObject.name;
|
||||
|
||||
GeneratorProvider.prototype.request = function (domainObject, request) {
|
||||
var workerRequest = this.makeWorkerRequest(domainObject, request);
|
||||
workerRequest.start = request.start;
|
||||
workerRequest.end = request.end;
|
||||
return workerRequest;
|
||||
};
|
||||
|
||||
return this.workerInterface.request(workerRequest);
|
||||
};
|
||||
GeneratorProvider.prototype.request = function (domainObject, request) {
|
||||
var workerRequest = this.makeWorkerRequest(domainObject, request);
|
||||
workerRequest.start = request.start;
|
||||
workerRequest.end = request.end;
|
||||
|
||||
GeneratorProvider.prototype.subscribe = function (domainObject, callback) {
|
||||
var workerRequest = this.makeWorkerRequest(domainObject, {});
|
||||
return this.workerInterface.request(workerRequest);
|
||||
};
|
||||
|
||||
return this.workerInterface.subscribe(workerRequest, callback);
|
||||
};
|
||||
GeneratorProvider.prototype.subscribe = function (domainObject, callback) {
|
||||
var workerRequest = this.makeWorkerRequest(domainObject, {});
|
||||
|
||||
return GeneratorProvider;
|
||||
});
|
||||
return this.workerInterface.subscribe(workerRequest, callback);
|
||||
};
|
||||
|
||||
export default GeneratorProvider;
|
@ -20,155 +20,170 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
], function (
|
||||
|
||||
) {
|
||||
|
||||
var PURPLE = {
|
||||
var PURPLE = {
|
||||
sin: 2.2,
|
||||
cos: 2.2
|
||||
},
|
||||
RED = {
|
||||
sin: 0.9,
|
||||
cos: 0.9
|
||||
RED = {
|
||||
sin: 0.9,
|
||||
cos: 0.9
|
||||
},
|
||||
ORANGE = {
|
||||
sin: 0.7,
|
||||
cos: 0.7
|
||||
},
|
||||
YELLOW = {
|
||||
sin: 0.5,
|
||||
cos: 0.5
|
||||
},
|
||||
CYAN = {
|
||||
sin: 0.45,
|
||||
cos: 0.45
|
||||
},
|
||||
LIMITS = {
|
||||
rh: {
|
||||
cssClass: "is-limit--upr is-limit--red",
|
||||
low: RED,
|
||||
high: Number.POSITIVE_INFINITY,
|
||||
name: "Red High"
|
||||
},
|
||||
ORANGE = {
|
||||
sin: 0.7,
|
||||
cos: 0.7
|
||||
rl: {
|
||||
cssClass: "is-limit--lwr is-limit--red",
|
||||
high: -RED,
|
||||
low: Number.NEGATIVE_INFINITY,
|
||||
name: "Red Low"
|
||||
},
|
||||
YELLOW = {
|
||||
sin: 0.5,
|
||||
cos: 0.5
|
||||
yh: {
|
||||
cssClass: "is-limit--upr is-limit--yellow",
|
||||
low: YELLOW,
|
||||
high: RED,
|
||||
name: "Yellow High"
|
||||
},
|
||||
CYAN = {
|
||||
sin: 0.45,
|
||||
cos: 0.45
|
||||
},
|
||||
LIMITS = {
|
||||
rh: {
|
||||
cssClass: "is-limit--upr is-limit--red",
|
||||
low: RED,
|
||||
high: Number.POSITIVE_INFINITY,
|
||||
name: "Red High"
|
||||
},
|
||||
rl: {
|
||||
cssClass: "is-limit--lwr is-limit--red",
|
||||
high: -RED,
|
||||
low: Number.NEGATIVE_INFINITY,
|
||||
name: "Red Low"
|
||||
},
|
||||
yh: {
|
||||
cssClass: "is-limit--upr is-limit--yellow",
|
||||
low: YELLOW,
|
||||
high: RED,
|
||||
name: "Yellow High"
|
||||
},
|
||||
yl: {
|
||||
cssClass: "is-limit--lwr is-limit--yellow",
|
||||
low: -RED,
|
||||
high: -YELLOW,
|
||||
name: "Yellow Low"
|
||||
}
|
||||
};
|
||||
|
||||
function SinewaveLimitProvider() {
|
||||
|
||||
}
|
||||
|
||||
SinewaveLimitProvider.prototype.supportsLimits = function (domainObject) {
|
||||
return domainObject.type === 'generator';
|
||||
yl: {
|
||||
cssClass: "is-limit--lwr is-limit--yellow",
|
||||
low: -RED,
|
||||
high: -YELLOW,
|
||||
name: "Yellow Low"
|
||||
}
|
||||
};
|
||||
|
||||
SinewaveLimitProvider.prototype.getLimitEvaluator = function (domainObject) {
|
||||
return {
|
||||
evaluate: function (datum, valueMetadata) {
|
||||
var range = valueMetadata && valueMetadata.key;
|
||||
function SinewaveLimitProvider() {
|
||||
|
||||
if (datum[range] > RED[range]) {
|
||||
return LIMITS.rh;
|
||||
}
|
||||
}
|
||||
|
||||
if (datum[range] < -RED[range]) {
|
||||
return LIMITS.rl;
|
||||
}
|
||||
SinewaveLimitProvider.prototype.supportsLimits = function (domainObject) {
|
||||
return domainObject.type === 'generator';
|
||||
};
|
||||
|
||||
if (datum[range] > YELLOW[range]) {
|
||||
return LIMITS.yh;
|
||||
}
|
||||
SinewaveLimitProvider.prototype.getLimitEvaluator = function (domainObject) {
|
||||
return {
|
||||
evaluate: function (datum, valueMetadata) {
|
||||
var range = valueMetadata && valueMetadata.key;
|
||||
|
||||
if (datum[range] < -YELLOW[range]) {
|
||||
return LIMITS.yl;
|
||||
}
|
||||
if (datum[range] > RED[range]) {
|
||||
return LIMITS.rh;
|
||||
}
|
||||
};
|
||||
|
||||
if (datum[range] < -RED[range]) {
|
||||
return LIMITS.rl;
|
||||
}
|
||||
|
||||
if (datum[range] > YELLOW[range]) {
|
||||
return LIMITS.yh;
|
||||
}
|
||||
|
||||
if (datum[range] < -YELLOW[range]) {
|
||||
return LIMITS.yl;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
SinewaveLimitProvider.prototype.getLimits = function (domainObject) {
|
||||
SinewaveLimitProvider.prototype.getLimits = function (domainObject) {
|
||||
|
||||
return {
|
||||
limits: function () {
|
||||
return Promise.resolve({
|
||||
WATCH: {
|
||||
low: {
|
||||
color: "cyan",
|
||||
sin: -CYAN.sin,
|
||||
cos: -CYAN.cos
|
||||
},
|
||||
high: {
|
||||
color: "cyan",
|
||||
...CYAN
|
||||
}
|
||||
return {
|
||||
limits: function () {
|
||||
return Promise.resolve({
|
||||
WATCH: {
|
||||
low: {
|
||||
color: "cyan",
|
||||
sin: -CYAN.sin,
|
||||
cos: -CYAN.cos
|
||||
},
|
||||
WARNING: {
|
||||
low: {
|
||||
color: "yellow",
|
||||
sin: -YELLOW.sin,
|
||||
cos: -YELLOW.cos
|
||||
},
|
||||
high: {
|
||||
color: "yellow",
|
||||
...YELLOW
|
||||
}
|
||||
},
|
||||
DISTRESS: {
|
||||
low: {
|
||||
color: "orange",
|
||||
sin: -ORANGE.sin,
|
||||
cos: -ORANGE.cos
|
||||
},
|
||||
high: {
|
||||
color: "orange",
|
||||
...ORANGE
|
||||
}
|
||||
},
|
||||
CRITICAL: {
|
||||
low: {
|
||||
color: "red",
|
||||
sin: -RED.sin,
|
||||
cos: -RED.cos
|
||||
},
|
||||
high: {
|
||||
color: "red",
|
||||
...RED
|
||||
}
|
||||
},
|
||||
SEVERE: {
|
||||
low: {
|
||||
color: "purple",
|
||||
sin: -PURPLE.sin,
|
||||
cos: -PURPLE.cos
|
||||
},
|
||||
high: {
|
||||
color: "purple",
|
||||
...PURPLE
|
||||
}
|
||||
high: {
|
||||
color: "cyan",
|
||||
...CYAN
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
},
|
||||
WARNING: {
|
||||
low: {
|
||||
color: "yellow",
|
||||
sin: -YELLOW.sin,
|
||||
cos: -YELLOW.cos
|
||||
},
|
||||
high: {
|
||||
color: "yellow",
|
||||
...YELLOW
|
||||
}
|
||||
},
|
||||
DISTRESS: {
|
||||
low: {
|
||||
color: "orange",
|
||||
sin: -ORANGE.sin,
|
||||
cos: -ORANGE.cos
|
||||
},
|
||||
high: {
|
||||
color: "orange",
|
||||
...ORANGE
|
||||
}
|
||||
},
|
||||
CRITICAL: {
|
||||
low: {
|
||||
color: "red",
|
||||
sin: -RED.sin,
|
||||
cos: -RED.cos
|
||||
},
|
||||
high: {
|
||||
color: "red",
|
||||
...RED
|
||||
}
|
||||
},
|
||||
SEVERE: {
|
||||
low: {
|
||||
color: "purple",
|
||||
sin: -PURPLE.sin,
|
||||
cos: -PURPLE.cos
|
||||
},
|
||||
high: {
|
||||
color: "purple",
|
||||
...PURPLE
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return SinewaveLimitProvider;
|
||||
});
|
||||
export default SinewaveLimitProvider;
|
@ -20,64 +20,78 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
], function (
|
||||
function StateGeneratorProvider() {
|
||||
|
||||
) {
|
||||
}
|
||||
|
||||
function StateGeneratorProvider() {
|
||||
function pointForTimestamp(timestamp, duration, name) {
|
||||
return {
|
||||
name: name,
|
||||
utc: Math.floor(timestamp / duration) * duration,
|
||||
value: Math.floor(timestamp / duration) % 2
|
||||
};
|
||||
}
|
||||
|
||||
StateGeneratorProvider.prototype.supportsSubscribe = function (domainObject) {
|
||||
return domainObject.type === 'example.state-generator';
|
||||
};
|
||||
|
||||
StateGeneratorProvider.prototype.subscribe = function (domainObject, callback) {
|
||||
var duration = domainObject.telemetry.duration * 1000;
|
||||
|
||||
var interval = setInterval(function () {
|
||||
var now = Date.now();
|
||||
var datum = pointForTimestamp(now, duration, domainObject.name);
|
||||
datum.value = String(datum.value);
|
||||
callback(datum);
|
||||
}, duration);
|
||||
|
||||
return function () {
|
||||
clearInterval(interval);
|
||||
};
|
||||
};
|
||||
|
||||
StateGeneratorProvider.prototype.supportsRequest = function (domainObject, options) {
|
||||
return domainObject.type === 'example.state-generator';
|
||||
};
|
||||
|
||||
StateGeneratorProvider.prototype.request = function (domainObject, options) {
|
||||
var start = options.start;
|
||||
var end = Math.min(Date.now(), options.end); // no future values
|
||||
var duration = domainObject.telemetry.duration * 1000;
|
||||
if (options.strategy === 'latest' || options.size === 1) {
|
||||
start = end;
|
||||
}
|
||||
|
||||
function pointForTimestamp(timestamp, duration, name) {
|
||||
return {
|
||||
name: name,
|
||||
utc: Math.floor(timestamp / duration) * duration,
|
||||
value: Math.floor(timestamp / duration) % 2
|
||||
};
|
||||
var data = [];
|
||||
while (start <= end && data.length < 5000) {
|
||||
data.push(pointForTimestamp(start, duration, domainObject.name));
|
||||
start += duration;
|
||||
}
|
||||
|
||||
StateGeneratorProvider.prototype.supportsSubscribe = function (domainObject) {
|
||||
return domainObject.type === 'example.state-generator';
|
||||
};
|
||||
return Promise.resolve(data);
|
||||
};
|
||||
|
||||
StateGeneratorProvider.prototype.subscribe = function (domainObject, callback) {
|
||||
var duration = domainObject.telemetry.duration * 1000;
|
||||
|
||||
var interval = setInterval(function () {
|
||||
var now = Date.now();
|
||||
var datum = pointForTimestamp(now, duration, domainObject.name);
|
||||
datum.value = String(datum.value);
|
||||
callback(datum);
|
||||
}, duration);
|
||||
|
||||
return function () {
|
||||
clearInterval(interval);
|
||||
};
|
||||
};
|
||||
|
||||
StateGeneratorProvider.prototype.supportsRequest = function (domainObject, options) {
|
||||
return domainObject.type === 'example.state-generator';
|
||||
};
|
||||
|
||||
StateGeneratorProvider.prototype.request = function (domainObject, options) {
|
||||
var start = options.start;
|
||||
var end = Math.min(Date.now(), options.end); // no future values
|
||||
var duration = domainObject.telemetry.duration * 1000;
|
||||
if (options.strategy === 'latest' || options.size === 1) {
|
||||
start = end;
|
||||
}
|
||||
|
||||
var data = [];
|
||||
while (start <= end && data.length < 5000) {
|
||||
data.push(pointForTimestamp(start, duration, domainObject.name));
|
||||
start += duration;
|
||||
}
|
||||
|
||||
return Promise.resolve(data);
|
||||
};
|
||||
|
||||
return StateGeneratorProvider;
|
||||
|
||||
});
|
||||
export default StateGeneratorProvider;
|
@ -20,89 +20,106 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'raw-loader!./generatorWorker.js',
|
||||
'uuid'
|
||||
], function (
|
||||
workerText,
|
||||
uuid
|
||||
) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
var workerBlob = new Blob(
|
||||
[workerText],
|
||||
{type: 'application/javascript'}
|
||||
);
|
||||
var workerUrl = URL.createObjectURL(workerBlob);
|
||||
import workerText from 'raw-loader!./generatorWorker.js';
|
||||
|
||||
function WorkerInterface() {
|
||||
this.worker = new Worker(workerUrl);
|
||||
this.worker.onmessage = this.onMessage.bind(this);
|
||||
this.callbacks = {};
|
||||
import uuid from 'uuid';
|
||||
|
||||
var workerBlob = new Blob(
|
||||
[workerText],
|
||||
{type: 'application/javascript'}
|
||||
);
|
||||
var workerUrl = URL.createObjectURL(workerBlob);
|
||||
|
||||
function WorkerInterface() {
|
||||
this.worker = new Worker(workerUrl);
|
||||
this.worker.onmessage = this.onMessage.bind(this);
|
||||
this.callbacks = {};
|
||||
}
|
||||
|
||||
WorkerInterface.prototype.onMessage = function (message) {
|
||||
message = message.data;
|
||||
var callback = this.callbacks[message.id];
|
||||
if (callback) {
|
||||
callback(message);
|
||||
}
|
||||
};
|
||||
|
||||
WorkerInterface.prototype.dispatch = function (request, data, callback) {
|
||||
var message = {
|
||||
request: request,
|
||||
data: data,
|
||||
id: uuid()
|
||||
};
|
||||
|
||||
if (callback) {
|
||||
this.callbacks[message.id] = callback;
|
||||
}
|
||||
|
||||
WorkerInterface.prototype.onMessage = function (message) {
|
||||
message = message.data;
|
||||
var callback = this.callbacks[message.id];
|
||||
if (callback) {
|
||||
callback(message);
|
||||
}
|
||||
};
|
||||
this.worker.postMessage(message);
|
||||
|
||||
WorkerInterface.prototype.dispatch = function (request, data, callback) {
|
||||
var message = {
|
||||
request: request,
|
||||
data: data,
|
||||
id: uuid()
|
||||
};
|
||||
return message.id;
|
||||
};
|
||||
|
||||
if (callback) {
|
||||
this.callbacks[message.id] = callback;
|
||||
WorkerInterface.prototype.request = function (request) {
|
||||
var deferred = {};
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
deferred.resolve = resolve;
|
||||
deferred.reject = reject;
|
||||
});
|
||||
var messageId;
|
||||
|
||||
let self = this;
|
||||
function callback(message) {
|
||||
if (message.error) {
|
||||
deferred.reject(message.error);
|
||||
} else {
|
||||
deferred.resolve(message.data);
|
||||
}
|
||||
|
||||
this.worker.postMessage(message);
|
||||
delete self.callbacks[messageId];
|
||||
|
||||
return message.id;
|
||||
};
|
||||
}
|
||||
|
||||
WorkerInterface.prototype.request = function (request) {
|
||||
var deferred = {};
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
deferred.resolve = resolve;
|
||||
deferred.reject = reject;
|
||||
messageId = this.dispatch('request', request, callback.bind(this));
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
WorkerInterface.prototype.subscribe = function (request, cb) {
|
||||
function callback(message) {
|
||||
cb(message.data);
|
||||
}
|
||||
|
||||
var messageId = this.dispatch('subscribe', request, callback);
|
||||
|
||||
return function () {
|
||||
this.dispatch('unsubscribe', {
|
||||
id: messageId
|
||||
});
|
||||
var messageId;
|
||||
delete this.callbacks[messageId];
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
let self = this;
|
||||
function callback(message) {
|
||||
if (message.error) {
|
||||
deferred.reject(message.error);
|
||||
} else {
|
||||
deferred.resolve(message.data);
|
||||
}
|
||||
|
||||
delete self.callbacks[messageId];
|
||||
|
||||
}
|
||||
|
||||
messageId = this.dispatch('request', request, callback.bind(this));
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
WorkerInterface.prototype.subscribe = function (request, cb) {
|
||||
function callback(message) {
|
||||
cb(message.data);
|
||||
}
|
||||
|
||||
var messageId = this.dispatch('subscribe', request, callback);
|
||||
|
||||
return function () {
|
||||
this.dispatch('unsubscribe', {
|
||||
id: messageId
|
||||
});
|
||||
delete this.callbacks[messageId];
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
return WorkerInterface;
|
||||
});
|
||||
export default WorkerInterface;
|
@ -20,6 +20,28 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
(function () {
|
||||
|
||||
var FIFTEEN_MINUTES = 15 * 60 * 1000;
|
||||
@ -181,4 +203,4 @@
|
||||
}
|
||||
};
|
||||
|
||||
}());
|
||||
}());
|
@ -20,135 +20,149 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./GeneratorProvider",
|
||||
"./SinewaveLimitProvider",
|
||||
"./StateGeneratorProvider",
|
||||
"./GeneratorMetadataProvider"
|
||||
], function (
|
||||
GeneratorProvider,
|
||||
SinewaveLimitProvider,
|
||||
StateGeneratorProvider,
|
||||
GeneratorMetadataProvider
|
||||
) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return function (openmct) {
|
||||
import GeneratorProvider from './GeneratorProvider';
|
||||
|
||||
openmct.types.addType("example.state-generator", {
|
||||
name: "State Generator",
|
||||
description: "For development use. Generates test enumerated telemetry by cycling through a given set of states",
|
||||
cssClass: "icon-generator-telemetry",
|
||||
creatable: true,
|
||||
form: [
|
||||
{
|
||||
name: "State Duration (seconds)",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "duration",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"duration"
|
||||
]
|
||||
}
|
||||
],
|
||||
initialize: function (object) {
|
||||
object.telemetry = {
|
||||
duration: 5
|
||||
};
|
||||
import SinewaveLimitProvider from './SinewaveLimitProvider';
|
||||
import StateGeneratorProvider from './StateGeneratorProvider';
|
||||
import GeneratorMetadataProvider from './GeneratorMetadataProvider';
|
||||
|
||||
export default function (openmct) {
|
||||
|
||||
openmct.types.addType("example.state-generator", {
|
||||
name: "State Generator",
|
||||
description: "For development use. Generates test enumerated telemetry by cycling through a given set of states",
|
||||
cssClass: "icon-generator-telemetry",
|
||||
creatable: true,
|
||||
form: [
|
||||
{
|
||||
name: "State Duration (seconds)",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "duration",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"duration"
|
||||
]
|
||||
}
|
||||
});
|
||||
],
|
||||
initialize: function (object) {
|
||||
object.telemetry = {
|
||||
duration: 5
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
openmct.telemetry.addProvider(new StateGeneratorProvider());
|
||||
openmct.telemetry.addProvider(new StateGeneratorProvider());
|
||||
|
||||
openmct.types.addType("generator", {
|
||||
name: "Sine Wave Generator",
|
||||
description: "For development use. Generates example streaming telemetry data using a simple sine wave algorithm.",
|
||||
cssClass: "icon-generator-telemetry",
|
||||
creatable: true,
|
||||
form: [
|
||||
{
|
||||
name: "Period",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "period",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"period"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Amplitude",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "amplitude",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"amplitude"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Offset",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "offset",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"offset"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Data Rate (hz)",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "dataRateInHz",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"dataRateInHz"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Phase (radians)",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "phase",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"phase"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Randomness",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "randomness",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"randomness"
|
||||
]
|
||||
}
|
||||
],
|
||||
initialize: function (object) {
|
||||
object.telemetry = {
|
||||
period: 10,
|
||||
amplitude: 1,
|
||||
offset: 0,
|
||||
dataRateInHz: 1,
|
||||
phase: 0,
|
||||
randomness: 0
|
||||
};
|
||||
openmct.types.addType("generator", {
|
||||
name: "Sine Wave Generator",
|
||||
description: "For development use. Generates example streaming telemetry data using a simple sine wave algorithm.",
|
||||
cssClass: "icon-generator-telemetry",
|
||||
creatable: true,
|
||||
form: [
|
||||
{
|
||||
name: "Period",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "period",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"period"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Amplitude",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "amplitude",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"amplitude"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Offset",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "offset",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"offset"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Data Rate (hz)",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "dataRateInHz",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"dataRateInHz"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Phase (radians)",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "phase",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"phase"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Randomness",
|
||||
control: "numberfield",
|
||||
cssClass: "l-input-sm l-numeric",
|
||||
key: "randomness",
|
||||
required: true,
|
||||
property: [
|
||||
"telemetry",
|
||||
"randomness"
|
||||
]
|
||||
}
|
||||
});
|
||||
],
|
||||
initialize: function (object) {
|
||||
object.telemetry = {
|
||||
period: 10,
|
||||
amplitude: 1,
|
||||
offset: 0,
|
||||
dataRateInHz: 1,
|
||||
phase: 0,
|
||||
randomness: 0
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
openmct.telemetry.addProvider(new GeneratorProvider());
|
||||
openmct.telemetry.addProvider(new GeneratorMetadataProvider());
|
||||
openmct.telemetry.addProvider(new SinewaveLimitProvider());
|
||||
};
|
||||
|
||||
});
|
||||
openmct.telemetry.addProvider(new GeneratorProvider());
|
||||
openmct.telemetry.addProvider(new GeneratorMetadataProvider());
|
||||
openmct.telemetry.addProvider(new SinewaveLimitProvider());
|
||||
};
|
@ -20,29 +20,47 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/ExampleIdentityService"
|
||||
], function (
|
||||
ExampleIdentityService
|
||||
) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/identity",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"components": [
|
||||
{
|
||||
"implementation": ExampleIdentityService,
|
||||
"provides": "identityService",
|
||||
"type": "provider",
|
||||
"depends": [
|
||||
"dialogService",
|
||||
"$q"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
import ExampleIdentityService from './src/ExampleIdentityService';
|
||||
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/identity",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"components": [
|
||||
{
|
||||
"implementation": ExampleIdentityService,
|
||||
"provides": "identityService",
|
||||
"type": "provider",
|
||||
"depends": [
|
||||
"dialogService",
|
||||
"$q"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,75 +20,71 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
function () {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
var DEFAULT_IDENTITY = {
|
||||
key: "user",
|
||||
name: "Example User"
|
||||
},
|
||||
DIALOG_STRUCTURE = {
|
||||
name: "Identify Yourself",
|
||||
sections: [{
|
||||
rows: [
|
||||
{
|
||||
name: "User ID",
|
||||
control: "textfield",
|
||||
key: "key",
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: "Human name",
|
||||
control: "textfield",
|
||||
key: "name",
|
||||
required: true
|
||||
}
|
||||
]
|
||||
}]
|
||||
};
|
||||
var DEFAULT_IDENTITY = {
|
||||
key: "user",
|
||||
name: "Example User"
|
||||
},
|
||||
DIALOG_STRUCTURE = {
|
||||
name: "Identify Yourself",
|
||||
sections: [{
|
||||
rows: [
|
||||
{
|
||||
name: "User ID",
|
||||
control: "textfield",
|
||||
key: "key",
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: "Human name",
|
||||
control: "textfield",
|
||||
key: "name",
|
||||
required: true
|
||||
}
|
||||
]
|
||||
}]
|
||||
};
|
||||
|
||||
/**
|
||||
* Example implementation of an identity service. This prompts the
|
||||
* user to enter a name and user ID; in a more realistic
|
||||
* implementation, this would be read from a server, possibly
|
||||
* prompting for a user name and password (or similar) as
|
||||
* appropriate.
|
||||
*
|
||||
* @implements {IdentityService}
|
||||
* @memberof platform/identity
|
||||
*/
|
||||
function ExampleIdentityProvider(dialogService, $q) {
|
||||
this.dialogService = dialogService;
|
||||
this.$q = $q;
|
||||
/**
|
||||
* Example implementation of an identity service. This prompts the
|
||||
* user to enter a name and user ID; in a more realistic
|
||||
* implementation, this would be read from a server, possibly
|
||||
* prompting for a user name and password (or similar) as
|
||||
* appropriate.
|
||||
*
|
||||
* @implements {IdentityService}
|
||||
* @memberof platform/identity
|
||||
*/
|
||||
function ExampleIdentityProvider(dialogService, $q) {
|
||||
this.dialogService = dialogService;
|
||||
this.$q = $q;
|
||||
|
||||
this.returnUser = this.returnUser.bind(this);
|
||||
this.returnUndefined = this.returnUndefined.bind(this);
|
||||
}
|
||||
this.returnUser = this.returnUser.bind(this);
|
||||
this.returnUndefined = this.returnUndefined.bind(this);
|
||||
}
|
||||
|
||||
ExampleIdentityProvider.prototype.getUser = function () {
|
||||
if (this.user) {
|
||||
return this.$q.when(this.user);
|
||||
} else {
|
||||
return this.dialogService.getUserInput(DIALOG_STRUCTURE, DEFAULT_IDENTITY)
|
||||
.then(this.returnUser, this.returnUndefined);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ExampleIdentityProvider.prototype.returnUser = function (user) {
|
||||
return this.user = user;
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ExampleIdentityProvider.prototype.returnUndefined = function () {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
return ExampleIdentityProvider;
|
||||
ExampleIdentityProvider.prototype.getUser = function () {
|
||||
if (this.user) {
|
||||
return this.$q.when(this.user);
|
||||
} else {
|
||||
return this.dialogService.getUserInput(DIALOG_STRUCTURE, DEFAULT_IDENTITY)
|
||||
.then(this.returnUser, this.returnUndefined);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ExampleIdentityProvider.prototype.returnUser = function (user) {
|
||||
return this.user = user;
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ExampleIdentityProvider.prototype.returnUndefined = function () {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export default ExampleIdentityProvider;
|
@ -20,6 +20,28 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
const DEFAULT_IMAGE_SAMPLES = [
|
||||
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18731.jpg",
|
||||
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18732.jpg",
|
||||
@ -235,4 +257,4 @@ function pointForTimestamp(timestamp, name, imageSamples, delay) {
|
||||
heading: getCompassValues(0, 360),
|
||||
imageDownloadName
|
||||
};
|
||||
}
|
||||
}
|
@ -20,22 +20,42 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([], function () {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/mobile",
|
||||
definition: {
|
||||
"name": "Mobile",
|
||||
"description": "Allows elements with pertinence to mobile usage and development",
|
||||
"extensions": {
|
||||
"stylesheets": [
|
||||
{
|
||||
"stylesheetUrl": "css/mobile-example.css",
|
||||
"priority": "mandatory"
|
||||
}
|
||||
]
|
||||
}
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/mobile",
|
||||
definition: {
|
||||
"name": "Mobile",
|
||||
"description": "Allows elements with pertinence to mobile usage and development",
|
||||
"extensions": {
|
||||
"stylesheets": [
|
||||
{
|
||||
"stylesheetUrl": "css/mobile-example.css",
|
||||
"priority": "mandatory"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,96 +20,111 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/RemsTelemetryServerAdapter",
|
||||
"./src/RemsTelemetryModelProvider",
|
||||
"./src/RemsTelemetryProvider"
|
||||
], function (
|
||||
RemsTelemetryServerAdapter,
|
||||
RemsTelemetryModelProvider,
|
||||
RemsTelemetryProvider
|
||||
) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/msl",
|
||||
definition: {
|
||||
"name": "Mars Science Laboratory Data Adapter",
|
||||
"extensions": {
|
||||
"types": [
|
||||
{
|
||||
import RemsTelemetryServerAdapter from './src/RemsTelemetryServerAdapter';
|
||||
|
||||
import RemsTelemetryModelProvider from './src/RemsTelemetryModelProvider';
|
||||
import RemsTelemetryProvider from './src/RemsTelemetryProvider';
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/msl",
|
||||
definition: {
|
||||
"name": "Mars Science Laboratory Data Adapter",
|
||||
"extensions": {
|
||||
"types": [
|
||||
{
|
||||
"name": "Mars Science Laboratory",
|
||||
"key": "msl.curiosity",
|
||||
"cssClass": "icon-object"
|
||||
},
|
||||
{
|
||||
"name": "Instrument",
|
||||
"key": "msl.instrument",
|
||||
"cssClass": "icon-object",
|
||||
"model": {"composition": []}
|
||||
},
|
||||
{
|
||||
"name": "Measurement",
|
||||
"key": "msl.measurement",
|
||||
"cssClass": "icon-telemetry",
|
||||
"model": {"telemetry": {}},
|
||||
"telemetry": {
|
||||
"source": "rems.source",
|
||||
"domains": [
|
||||
{
|
||||
"name": "Time",
|
||||
"key": "utc",
|
||||
"format": "utc"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key": "REMS_WS_URL",
|
||||
"value": "/proxyUrl?url=http://cab.inta-csic.es/rems/wp-content/plugins/marsweather-widget/api.php"
|
||||
}
|
||||
],
|
||||
"roots": [
|
||||
{
|
||||
"id": "msl:curiosity"
|
||||
}
|
||||
],
|
||||
"models": [
|
||||
{
|
||||
"id": "msl:curiosity",
|
||||
"priority": "preferred",
|
||||
"model": {
|
||||
"type": "msl.curiosity",
|
||||
"name": "Mars Science Laboratory",
|
||||
"key": "msl.curiosity",
|
||||
"cssClass": "icon-object"
|
||||
},
|
||||
{
|
||||
"name": "Instrument",
|
||||
"key": "msl.instrument",
|
||||
"cssClass": "icon-object",
|
||||
"model": {"composition": []}
|
||||
},
|
||||
{
|
||||
"name": "Measurement",
|
||||
"key": "msl.measurement",
|
||||
"cssClass": "icon-telemetry",
|
||||
"model": {"telemetry": {}},
|
||||
"telemetry": {
|
||||
"source": "rems.source",
|
||||
"domains": [
|
||||
{
|
||||
"name": "Time",
|
||||
"key": "utc",
|
||||
"format": "utc"
|
||||
}
|
||||
]
|
||||
}
|
||||
"composition": ["msl_tlm:rems"]
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key": "REMS_WS_URL",
|
||||
"value": "/proxyUrl?url=http://cab.inta-csic.es/rems/wp-content/plugins/marsweather-widget/api.php"
|
||||
}
|
||||
],
|
||||
"roots": [
|
||||
{
|
||||
"id": "msl:curiosity"
|
||||
}
|
||||
],
|
||||
"models": [
|
||||
{
|
||||
"id": "msl:curiosity",
|
||||
"priority": "preferred",
|
||||
"model": {
|
||||
"type": "msl.curiosity",
|
||||
"name": "Mars Science Laboratory",
|
||||
"composition": ["msl_tlm:rems"]
|
||||
}
|
||||
}
|
||||
],
|
||||
"services": [
|
||||
{
|
||||
"key": "rems.adapter",
|
||||
"implementation": RemsTelemetryServerAdapter,
|
||||
"depends": ["$http", "$log", "REMS_WS_URL"]
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"provides": "modelService",
|
||||
"type": "provider",
|
||||
"implementation": RemsTelemetryModelProvider,
|
||||
"depends": ["rems.adapter"]
|
||||
},
|
||||
{
|
||||
"provides": "telemetryService",
|
||||
"type": "provider",
|
||||
"implementation": RemsTelemetryProvider,
|
||||
"depends": ["rems.adapter", "$q"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"services": [
|
||||
{
|
||||
"key": "rems.adapter",
|
||||
"implementation": RemsTelemetryServerAdapter,
|
||||
"depends": ["$http", "$log", "REMS_WS_URL"]
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"provides": "modelService",
|
||||
"type": "provider",
|
||||
"implementation": RemsTelemetryModelProvider,
|
||||
"depends": ["rems.adapter"]
|
||||
},
|
||||
{
|
||||
"provides": "telemetryService",
|
||||
"type": "provider",
|
||||
"implementation": RemsTelemetryProvider,
|
||||
"depends": ["rems.adapter", "$q"]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
}
|
||||
};
|
@ -20,59 +20,45 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
/**
|
||||
* A data dictionary describes the telemetry available from a data
|
||||
* source and its data types. The data dictionary will be parsed by a custom
|
||||
* server provider for this data source (in this case
|
||||
* {@link RemsTelemetryServerAdapter}).
|
||||
*
|
||||
* Typically a data dictionary would be made available alongside the
|
||||
* telemetry data source itself.
|
||||
*/
|
||||
function () {
|
||||
return {
|
||||
"name": "Mars Science Laboratory",
|
||||
"identifier": "msl",
|
||||
"instruments": [
|
||||
export default {
|
||||
"name": "Mars Science Laboratory",
|
||||
"identifier": "msl",
|
||||
"instruments": [
|
||||
{
|
||||
"name": "rems",
|
||||
"identifier": "rems",
|
||||
"measurements": [
|
||||
{
|
||||
"name": "rems",
|
||||
"identifier": "rems",
|
||||
"measurements": [
|
||||
{
|
||||
"name": "Min. Air Temperature",
|
||||
"identifier": "min_temp",
|
||||
"units": "Degrees (C)",
|
||||
"type": "float"
|
||||
},
|
||||
{
|
||||
"name": "Max. Air Temperature",
|
||||
"identifier": "max_temp",
|
||||
"units": "Degrees (C)",
|
||||
"type": "float"
|
||||
},
|
||||
{
|
||||
"name": "Atmospheric Pressure",
|
||||
"identifier": "pressure",
|
||||
"units": "Millibars",
|
||||
"type": "float"
|
||||
},
|
||||
{
|
||||
"name": "Min. Ground Temperature",
|
||||
"identifier": "min_gts_temp",
|
||||
"units": "Degrees (C)",
|
||||
"type": "float"
|
||||
},
|
||||
{
|
||||
"name": "Max. Ground Temperature",
|
||||
"identifier": "max_gts_temp",
|
||||
"units": "Degrees (C)",
|
||||
"type": "float"
|
||||
}
|
||||
]
|
||||
"name": "Min. Air Temperature",
|
||||
"identifier": "min_temp",
|
||||
"units": "Degrees (C)",
|
||||
"type": "float"
|
||||
},
|
||||
{
|
||||
"name": "Max. Air Temperature",
|
||||
"identifier": "max_temp",
|
||||
"units": "Degrees (C)",
|
||||
"type": "float"
|
||||
},
|
||||
{
|
||||
"name": "Atmospheric Pressure",
|
||||
"identifier": "pressure",
|
||||
"units": "Millibars",
|
||||
"type": "float"
|
||||
},
|
||||
{
|
||||
"name": "Min. Ground Temperature",
|
||||
"identifier": "min_gts_temp",
|
||||
"units": "Degrees (C)",
|
||||
"type": "float"
|
||||
},
|
||||
{
|
||||
"name": "Max. Ground Temperature",
|
||||
"identifier": "max_gts_temp",
|
||||
"units": "Degrees (C)",
|
||||
"type": "float"
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
]
|
||||
};
|
@ -20,77 +20,73 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
function () {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
var PREFIX = "msl_tlm:",
|
||||
FORMAT_MAPPINGS = {
|
||||
float: "number",
|
||||
integer: "number",
|
||||
string: "string"
|
||||
};
|
||||
var PREFIX = "msl_tlm:",
|
||||
FORMAT_MAPPINGS = {
|
||||
float: "number",
|
||||
integer: "number",
|
||||
string: "string"
|
||||
};
|
||||
|
||||
function RemsTelemetryModelProvider(adapter) {
|
||||
function RemsTelemetryModelProvider(adapter) {
|
||||
|
||||
function isRelevant(id) {
|
||||
return id.indexOf(PREFIX) === 0;
|
||||
}
|
||||
function isRelevant(id) {
|
||||
return id.indexOf(PREFIX) === 0;
|
||||
}
|
||||
|
||||
function makeId(element) {
|
||||
return PREFIX + element.identifier;
|
||||
}
|
||||
function makeId(element) {
|
||||
return PREFIX + element.identifier;
|
||||
}
|
||||
|
||||
function buildTaxonomy(dictionary) {
|
||||
var models = {};
|
||||
function buildTaxonomy(dictionary) {
|
||||
var models = {};
|
||||
|
||||
function addMeasurement(measurement, parent) {
|
||||
var format = FORMAT_MAPPINGS[measurement.type];
|
||||
models[makeId(measurement)] = {
|
||||
type: "msl.measurement",
|
||||
name: measurement.name,
|
||||
location: parent,
|
||||
telemetry: {
|
||||
key: measurement.identifier,
|
||||
ranges: [{
|
||||
key: "value",
|
||||
name: measurement.units,
|
||||
units: measurement.units,
|
||||
format: format
|
||||
}]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function addInstrument(subsystem, spacecraftId) {
|
||||
var measurements = (subsystem.measurements || []),
|
||||
instrumentId = makeId(subsystem);
|
||||
|
||||
models[instrumentId] = {
|
||||
type: "msl.instrument",
|
||||
name: subsystem.name,
|
||||
location: spacecraftId,
|
||||
composition: measurements.map(makeId)
|
||||
};
|
||||
measurements.forEach(function (measurement) {
|
||||
addMeasurement(measurement, instrumentId);
|
||||
});
|
||||
}
|
||||
|
||||
(dictionary.instruments || []).forEach(function (instrument) {
|
||||
addInstrument(instrument, "msl:curiosity");
|
||||
});
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
return {
|
||||
getModels: function (ids) {
|
||||
return ids.some(isRelevant) ? buildTaxonomy(adapter.dictionary) : {};
|
||||
function addMeasurement(measurement, parent) {
|
||||
var format = FORMAT_MAPPINGS[measurement.type];
|
||||
models[makeId(measurement)] = {
|
||||
type: "msl.measurement",
|
||||
name: measurement.name,
|
||||
location: parent,
|
||||
telemetry: {
|
||||
key: measurement.identifier,
|
||||
ranges: [{
|
||||
key: "value",
|
||||
name: measurement.units,
|
||||
units: measurement.units,
|
||||
format: format
|
||||
}]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return RemsTelemetryModelProvider;
|
||||
function addInstrument(subsystem, spacecraftId) {
|
||||
var measurements = (subsystem.measurements || []),
|
||||
instrumentId = makeId(subsystem);
|
||||
|
||||
models[instrumentId] = {
|
||||
type: "msl.instrument",
|
||||
name: subsystem.name,
|
||||
location: spacecraftId,
|
||||
composition: measurements.map(makeId)
|
||||
};
|
||||
measurements.forEach(function (measurement) {
|
||||
addMeasurement(measurement, instrumentId);
|
||||
});
|
||||
}
|
||||
|
||||
(dictionary.instruments || []).forEach(function (instrument) {
|
||||
addInstrument(instrument, "msl:curiosity");
|
||||
});
|
||||
|
||||
return models;
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
getModels: function (ids) {
|
||||
return ids.some(isRelevant) ? buildTaxonomy(adapter.dictionary) : {};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default RemsTelemetryModelProvider;
|
@ -19,65 +19,83 @@
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
define (
|
||||
['./RemsTelemetrySeries'],
|
||||
function (RemsTelemetrySeries) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
import RemsTelemetrySeries from './RemsTelemetrySeries';
|
||||
|
||||
var SOURCE = "rems.source";
|
||||
"use strict";
|
||||
|
||||
function RemsTelemetryProvider(adapter, $q) {
|
||||
this.adapter = adapter;
|
||||
this.$q = $q;
|
||||
}
|
||||
var SOURCE = "rems.source";
|
||||
|
||||
/**
|
||||
* Retrieve telemetry from this telemetry source.
|
||||
* @memberOf example/msl
|
||||
* @param {Array<TelemetryRequest>} requests An array of all request
|
||||
* objects (which needs to be filtered to only those relevant to this
|
||||
* source)
|
||||
* @returns {Promise} A {@link Promise} resolved with a {@link RemsTelemetrySeries}
|
||||
* object that wraps the telemetry returned from the telemetry source.
|
||||
*/
|
||||
RemsTelemetryProvider.prototype.requestTelemetry = function (requests) {
|
||||
var packaged = {},
|
||||
relevantReqs,
|
||||
adapter = this.adapter;
|
||||
function RemsTelemetryProvider(adapter, $q) {
|
||||
this.adapter = adapter;
|
||||
this.$q = $q;
|
||||
}
|
||||
|
||||
function matchesSource(request) {
|
||||
return (request.source === SOURCE);
|
||||
}
|
||||
/**
|
||||
* Retrieve telemetry from this telemetry source.
|
||||
* @memberOf example/msl
|
||||
* @param {Array<TelemetryRequest>} requests An array of all request
|
||||
* objects (which needs to be filtered to only those relevant to this
|
||||
* source)
|
||||
* @returns {Promise} A {@link Promise} resolved with a {@link RemsTelemetrySeries}
|
||||
* object that wraps the telemetry returned from the telemetry source.
|
||||
*/
|
||||
RemsTelemetryProvider.prototype.requestTelemetry = function (requests) {
|
||||
var packaged = {},
|
||||
relevantReqs,
|
||||
adapter = this.adapter;
|
||||
|
||||
function addToPackage(history) {
|
||||
packaged[SOURCE][history.id] =
|
||||
new RemsTelemetrySeries(history.values);
|
||||
}
|
||||
|
||||
function handleRequest(request) {
|
||||
return adapter.history(request).then(addToPackage);
|
||||
}
|
||||
|
||||
relevantReqs = requests.filter(matchesSource);
|
||||
packaged[SOURCE] = {};
|
||||
|
||||
return this.$q.all(relevantReqs.map(handleRequest))
|
||||
.then(function () {
|
||||
return packaged;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* This data source does not support real-time subscriptions
|
||||
*/
|
||||
RemsTelemetryProvider.prototype.subscribe = function (callback, requests) {
|
||||
return function () {};
|
||||
};
|
||||
|
||||
RemsTelemetryProvider.prototype.unsubscribe = function (callback, requests) {
|
||||
return function () {};
|
||||
};
|
||||
|
||||
return RemsTelemetryProvider;
|
||||
function matchesSource(request) {
|
||||
return (request.source === SOURCE);
|
||||
}
|
||||
);
|
||||
|
||||
function addToPackage(history) {
|
||||
packaged[SOURCE][history.id] =
|
||||
new RemsTelemetrySeries(history.values);
|
||||
}
|
||||
|
||||
function handleRequest(request) {
|
||||
return adapter.history(request).then(addToPackage);
|
||||
}
|
||||
|
||||
relevantReqs = requests.filter(matchesSource);
|
||||
packaged[SOURCE] = {};
|
||||
|
||||
return this.$q.all(relevantReqs.map(handleRequest))
|
||||
.then(function () {
|
||||
return packaged;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* This data source does not support real-time subscriptions
|
||||
*/
|
||||
RemsTelemetryProvider.prototype.subscribe = function (callback, requests) {
|
||||
return function () {};
|
||||
};
|
||||
|
||||
RemsTelemetryProvider.prototype.unsubscribe = function (callback, requests) {
|
||||
return function () {};
|
||||
};
|
||||
|
||||
export default RemsTelemetryProvider;
|
@ -19,66 +19,62 @@
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
define(
|
||||
function () {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @typedef {Object} RemsTelemetryValue
|
||||
* @memberOf example/msl
|
||||
* @property {number} date The date/time of the telemetry value. Constitutes the domain value of this value pair
|
||||
* @property {number} value The value of this telemetry datum.
|
||||
* A floating point value representing some observable quantity (eg.
|
||||
* temperature, air pressure, etc.)
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} RemsTelemetryValue
|
||||
* @memberOf example/msl
|
||||
* @property {number} date The date/time of the telemetry value. Constitutes the domain value of this value pair
|
||||
* @property {number} value The value of this telemetry datum.
|
||||
* A floating point value representing some observable quantity (eg.
|
||||
* temperature, air pressure, etc.)
|
||||
*/
|
||||
|
||||
/**
|
||||
* A representation of a collection of telemetry data. The REMS
|
||||
* telemetry data is time ordered, with the 'domain' value
|
||||
* constituting the time stamp of each data value and the
|
||||
* 'range' being the value itself.
|
||||
*
|
||||
* TelemetrySeries will typically wrap an array of telemetry data,
|
||||
* and provide an interface for retrieving individual an telemetry
|
||||
* value.
|
||||
* @memberOf example/msl
|
||||
* @param {Array<RemsTelemetryValue>} data An array of telemetry values
|
||||
* @constructor
|
||||
*/
|
||||
function RemsTelemetrySeries(data) {
|
||||
this.data = data;
|
||||
}
|
||||
/**
|
||||
* A representation of a collection of telemetry data. The REMS
|
||||
* telemetry data is time ordered, with the 'domain' value
|
||||
* constituting the time stamp of each data value and the
|
||||
* 'range' being the value itself.
|
||||
*
|
||||
* TelemetrySeries will typically wrap an array of telemetry data,
|
||||
* and provide an interface for retrieving individual an telemetry
|
||||
* value.
|
||||
* @memberOf example/msl
|
||||
* @param {Array<RemsTelemetryValue>} data An array of telemetry values
|
||||
* @constructor
|
||||
*/
|
||||
function RemsTelemetrySeries(data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {number} A count of the number of data values available in
|
||||
* this series
|
||||
*/
|
||||
RemsTelemetrySeries.prototype.getPointCount = function () {
|
||||
return this.data.length;
|
||||
};
|
||||
/**
|
||||
* @returns {number} A count of the number of data values available in
|
||||
* this series
|
||||
*/
|
||||
RemsTelemetrySeries.prototype.getPointCount = function () {
|
||||
return this.data.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* The domain value at the given index. The Rems telemetry data is
|
||||
* time ordered, so the domain value is the time stamp of each data
|
||||
* value.
|
||||
* @param index
|
||||
* @returns {number} the time value in ms since 1 January 1970
|
||||
*/
|
||||
RemsTelemetrySeries.prototype.getDomainValue = function (index) {
|
||||
return this.data[index].date;
|
||||
};
|
||||
/**
|
||||
* The domain value at the given index. The Rems telemetry data is
|
||||
* time ordered, so the domain value is the time stamp of each data
|
||||
* value.
|
||||
* @param index
|
||||
* @returns {number} the time value in ms since 1 January 1970
|
||||
*/
|
||||
RemsTelemetrySeries.prototype.getDomainValue = function (index) {
|
||||
return this.data[index].date;
|
||||
};
|
||||
|
||||
/**
|
||||
* The range value of the REMS data set is the value of the thing
|
||||
* being measured, be it temperature, air pressure, etc.
|
||||
* @param index The datum in the data series to return the range
|
||||
* value of.
|
||||
* @returns {number} A floating point number
|
||||
*/
|
||||
RemsTelemetrySeries.prototype.getRangeValue = function (index) {
|
||||
return this.data[index].value;
|
||||
};
|
||||
/**
|
||||
* The range value of the REMS data set is the value of the thing
|
||||
* being measured, be it temperature, air pressure, etc.
|
||||
* @param index The datum in the data series to return the range
|
||||
* value of.
|
||||
* @returns {number} A floating point number
|
||||
*/
|
||||
RemsTelemetrySeries.prototype.getRangeValue = function (index) {
|
||||
return this.data[index].value;
|
||||
};
|
||||
|
||||
return RemsTelemetrySeries;
|
||||
}
|
||||
);
|
||||
export default RemsTelemetrySeries;
|
@ -21,125 +21,142 @@
|
||||
*****************************************************************************/
|
||||
/*jslint es5: true */
|
||||
|
||||
define(
|
||||
[
|
||||
"./MSLDataDictionary",
|
||||
"module"
|
||||
],
|
||||
function (MSLDataDictionary, module) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
/*jslint es5: true */
|
||||
|
||||
var TERRESTRIAL_DATE = "terrestrial_date",
|
||||
LOCAL_DATA = "../data/rems.json";
|
||||
import MSLDataDictionary from './MSLDataDictionary';
|
||||
|
||||
/**
|
||||
* Fetches historical data from the REMS instrument on the Curiosity
|
||||
* Rover.
|
||||
* @memberOf example/msl
|
||||
* @param $q
|
||||
* @param $http
|
||||
* @param REMS_WS_URL The location of the REMS telemetry data.
|
||||
* @constructor
|
||||
*/
|
||||
function RemsTelemetryServerAdapter($http, $log, REMS_WS_URL) {
|
||||
this.localDataURI = module.uri.substring(0, module.uri.lastIndexOf('/') + 1) + LOCAL_DATA;
|
||||
this.REMS_WS_URL = REMS_WS_URL;
|
||||
this.$http = $http;
|
||||
this.$log = $log;
|
||||
this.promise = undefined;
|
||||
import module from 'module';
|
||||
"use strict";
|
||||
|
||||
this.dataTransforms = {
|
||||
//Convert from pascals to millibars
|
||||
'pressure': function pascalsToMillibars(pascals) {
|
||||
return pascals / 100;
|
||||
}
|
||||
};
|
||||
var TERRESTRIAL_DATE = "terrestrial_date",
|
||||
LOCAL_DATA = "../data/rems.json";
|
||||
|
||||
/**
|
||||
* Fetches historical data from the REMS instrument on the Curiosity
|
||||
* Rover.
|
||||
* @memberOf example/msl
|
||||
* @param $q
|
||||
* @param $http
|
||||
* @param REMS_WS_URL The location of the REMS telemetry data.
|
||||
* @constructor
|
||||
*/
|
||||
function RemsTelemetryServerAdapter($http, $log, REMS_WS_URL) {
|
||||
this.localDataURI = module.uri.substring(0, module.uri.lastIndexOf('/') + 1) + LOCAL_DATA;
|
||||
this.REMS_WS_URL = REMS_WS_URL;
|
||||
this.$http = $http;
|
||||
this.$log = $log;
|
||||
this.promise = undefined;
|
||||
|
||||
this.dataTransforms = {
|
||||
//Convert from pascals to millibars
|
||||
'pressure': function pascalsToMillibars(pascals) {
|
||||
return pascals / 100;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The data dictionary for this data source.
|
||||
* @type {MSLDataDictionary}
|
||||
/**
|
||||
* The data dictionary for this data source.
|
||||
* @type {MSLDataDictionary}
|
||||
*/
|
||||
RemsTelemetryServerAdapter.prototype.dictionary = MSLDataDictionary;
|
||||
|
||||
/**
|
||||
* Fetches historical data from source, and associates it with the
|
||||
* given request ID.
|
||||
* @private
|
||||
*/
|
||||
RemsTelemetryServerAdapter.prototype.requestHistory = function (request) {
|
||||
var self = this,
|
||||
id = request.key;
|
||||
|
||||
var dataTransforms = this.dataTransforms;
|
||||
|
||||
function processResponse(response) {
|
||||
var data = [];
|
||||
/*
|
||||
* History data is organised by Sol. Iterate over sols...
|
||||
*/
|
||||
RemsTelemetryServerAdapter.prototype.dictionary = MSLDataDictionary;
|
||||
|
||||
/**
|
||||
* Fetches historical data from source, and associates it with the
|
||||
* given request ID.
|
||||
* @private
|
||||
*/
|
||||
RemsTelemetryServerAdapter.prototype.requestHistory = function (request) {
|
||||
var self = this,
|
||||
id = request.key;
|
||||
|
||||
var dataTransforms = this.dataTransforms;
|
||||
|
||||
function processResponse(response) {
|
||||
var data = [];
|
||||
response.data.soles.forEach(function (solData) {
|
||||
/*
|
||||
* Check that valid data exists
|
||||
*/
|
||||
if (!isNaN(solData[id])) {
|
||||
var dataTransform = dataTransforms[id];
|
||||
/*
|
||||
* History data is organised by Sol. Iterate over sols...
|
||||
* Append each data point to the array of values
|
||||
* for this data point property (min. temp, etc).
|
||||
*/
|
||||
response.data.soles.forEach(function (solData) {
|
||||
/*
|
||||
* Check that valid data exists
|
||||
*/
|
||||
if (!isNaN(solData[id])) {
|
||||
var dataTransform = dataTransforms[id];
|
||||
/*
|
||||
* Append each data point to the array of values
|
||||
* for this data point property (min. temp, etc).
|
||||
*/
|
||||
data.unshift({
|
||||
date: Date.parse(solData[TERRESTRIAL_DATE]),
|
||||
value: dataTransform ? dataTransform(solData[id]) : solData[id]
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function fallbackToLocal() {
|
||||
self.$log.warn("Loading REMS data failed, probably due to"
|
||||
+ " cross origin policy. Falling back to local data");
|
||||
|
||||
return self.$http.get(self.localDataURI);
|
||||
}
|
||||
|
||||
//Filter results to match request parameters
|
||||
function filterResults(results) {
|
||||
return results.filter(function (result) {
|
||||
return result.date >= (request.start || Number.MIN_VALUE)
|
||||
&& result.date <= (request.end || Number.MAX_VALUE);
|
||||
data.unshift({
|
||||
date: Date.parse(solData[TERRESTRIAL_DATE]),
|
||||
value: dataTransform ? dataTransform(solData[id]) : solData[id]
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function packageAndResolve(results) {
|
||||
return {
|
||||
id: id,
|
||||
values: results
|
||||
};
|
||||
}
|
||||
|
||||
return (this.promise = this.promise || this.$http.get(this.REMS_WS_URL))
|
||||
.catch(fallbackToLocal)
|
||||
.then(processResponse)
|
||||
.then(filterResults)
|
||||
.then(packageAndResolve);
|
||||
};
|
||||
|
||||
/**
|
||||
* Requests historical telemetry for the named data attribute. In
|
||||
* the case of REMS, this data source exposes multiple different
|
||||
* data variables from the REMS instrument, including temperature
|
||||
* and others
|
||||
* @param id The telemetry data point key to be queried.
|
||||
* @returns {Promise | Array<RemsTelemetryValue>} that resolves with an Array of {@link RemsTelemetryValue} objects for the request data key.
|
||||
*/
|
||||
RemsTelemetryServerAdapter.prototype.history = function (request) {
|
||||
return this.requestHistory(request);
|
||||
};
|
||||
|
||||
return RemsTelemetryServerAdapter;
|
||||
return data;
|
||||
}
|
||||
);
|
||||
|
||||
function fallbackToLocal() {
|
||||
self.$log.warn("Loading REMS data failed, probably due to"
|
||||
+ " cross origin policy. Falling back to local data");
|
||||
|
||||
return self.$http.get(self.localDataURI);
|
||||
}
|
||||
|
||||
//Filter results to match request parameters
|
||||
function filterResults(results) {
|
||||
return results.filter(function (result) {
|
||||
return result.date >= (request.start || Number.MIN_VALUE)
|
||||
&& result.date <= (request.end || Number.MAX_VALUE);
|
||||
});
|
||||
}
|
||||
|
||||
function packageAndResolve(results) {
|
||||
return {
|
||||
id: id,
|
||||
values: results
|
||||
};
|
||||
}
|
||||
|
||||
return (this.promise = this.promise || this.$http.get(this.REMS_WS_URL))
|
||||
.catch(fallbackToLocal)
|
||||
.then(processResponse)
|
||||
.then(filterResults)
|
||||
.then(packageAndResolve);
|
||||
};
|
||||
|
||||
/**
|
||||
* Requests historical telemetry for the named data attribute. In
|
||||
* the case of REMS, this data source exposes multiple different
|
||||
* data variables from the REMS instrument, including temperature
|
||||
* and others
|
||||
* @param id The telemetry data point key to be queried.
|
||||
* @returns {Promise | Array<RemsTelemetryValue>} that resolves with an Array of {@link RemsTelemetryValue} objects for the request data key.
|
||||
*/
|
||||
RemsTelemetryServerAdapter.prototype.history = function (request) {
|
||||
return this.requestHistory(request);
|
||||
};
|
||||
|
||||
export default RemsTelemetryServerAdapter;
|
@ -20,71 +20,84 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/DialogLaunchController",
|
||||
"./src/NotificationLaunchController",
|
||||
"./src/DialogLaunchIndicator",
|
||||
"./src/NotificationLaunchIndicator",
|
||||
"./res/dialog-launch.html",
|
||||
"./res/notification-launch.html"
|
||||
], function (
|
||||
DialogLaunchController,
|
||||
NotificationLaunchController,
|
||||
DialogLaunchIndicator,
|
||||
NotificationLaunchIndicator,
|
||||
DialogLaunch,
|
||||
NotificationLaunch
|
||||
) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/notifications",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"templates": [
|
||||
{
|
||||
"key": "dialogLaunchTemplate",
|
||||
"template": DialogLaunch
|
||||
},
|
||||
{
|
||||
"key": "notificationLaunchTemplate",
|
||||
"template": NotificationLaunch
|
||||
}
|
||||
],
|
||||
"controllers": [
|
||||
{
|
||||
"key": "DialogLaunchController",
|
||||
"implementation": DialogLaunchController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout",
|
||||
"$log",
|
||||
"dialogService",
|
||||
"notificationService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "NotificationLaunchController",
|
||||
"implementation": NotificationLaunchController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout",
|
||||
"$log",
|
||||
"notificationService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"indicators": [
|
||||
{
|
||||
"implementation": DialogLaunchIndicator,
|
||||
"priority": "fallback"
|
||||
},
|
||||
{
|
||||
"implementation": NotificationLaunchIndicator,
|
||||
"priority": "fallback"
|
||||
}
|
||||
]
|
||||
}
|
||||
import DialogLaunchController from './src/DialogLaunchController';
|
||||
|
||||
import NotificationLaunchController from './src/NotificationLaunchController';
|
||||
import DialogLaunchIndicator from './src/DialogLaunchIndicator';
|
||||
import NotificationLaunchIndicator from './src/NotificationLaunchIndicator';
|
||||
import DialogLaunch from './res/dialog-launch.html';
|
||||
import NotificationLaunch from './res/notification-launch.html';
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/notifications",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"templates": [
|
||||
{
|
||||
"key": "dialogLaunchTemplate",
|
||||
"template": DialogLaunch
|
||||
},
|
||||
{
|
||||
"key": "notificationLaunchTemplate",
|
||||
"template": NotificationLaunch
|
||||
}
|
||||
],
|
||||
"controllers": [
|
||||
{
|
||||
"key": "DialogLaunchController",
|
||||
"implementation": DialogLaunchController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout",
|
||||
"$log",
|
||||
"dialogService",
|
||||
"notificationService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "NotificationLaunchController",
|
||||
"implementation": NotificationLaunchController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout",
|
||||
"$log",
|
||||
"notificationService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"indicators": [
|
||||
{
|
||||
"implementation": DialogLaunchIndicator,
|
||||
"priority": "fallback"
|
||||
},
|
||||
{
|
||||
"implementation": NotificationLaunchIndicator,
|
||||
"priority": "fallback"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,138 +20,155 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* A controller for the dialog launch view. This view allows manual
|
||||
* launching of dialogs for demonstration and testing purposes. It
|
||||
* also demonstrates the use of the DialogService.
|
||||
* @param $scope
|
||||
* @param $timeout
|
||||
* @param $log
|
||||
* @param dialogService
|
||||
* @param notificationService
|
||||
* @constructor
|
||||
*/
|
||||
function DialogLaunchController($scope, $timeout, $log, dialogService, notificationService) {
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Demonstrates launching a progress dialog and updating it
|
||||
periodically with the progress of an ongoing process.
|
||||
*/
|
||||
$scope.launchProgress = function (knownProgress) {
|
||||
var dialog,
|
||||
model = {
|
||||
title: "Progress Dialog Example",
|
||||
progress: 0,
|
||||
hint: "Do not navigate away from this page or close this browser tab while this operation is in progress.",
|
||||
actionText: "Calculating...",
|
||||
unknownProgress: !knownProgress,
|
||||
unknownDuration: false,
|
||||
severity: "info",
|
||||
options: [
|
||||
{
|
||||
label: "Cancel Operation",
|
||||
callback: function () {
|
||||
$log.debug("Operation cancelled");
|
||||
dialog.dismiss();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Do something else...",
|
||||
callback: function () {
|
||||
$log.debug("Something else pressed");
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
/**
|
||||
* A controller for the dialog launch view. This view allows manual
|
||||
* launching of dialogs for demonstration and testing purposes. It
|
||||
* also demonstrates the use of the DialogService.
|
||||
* @param $scope
|
||||
* @param $timeout
|
||||
* @param $log
|
||||
* @param dialogService
|
||||
* @param notificationService
|
||||
* @constructor
|
||||
*/
|
||||
function DialogLaunchController($scope, $timeout, $log, dialogService, notificationService) {
|
||||
|
||||
function incrementProgress() {
|
||||
model.progress = Math.min(100, Math.floor(model.progress + Math.random() * 30));
|
||||
model.progressText = ["Estimated time remaining: about ", 60 - Math.floor((model.progress / 100) * 60), " seconds"].join(" ");
|
||||
if (model.progress < 100) {
|
||||
$timeout(incrementProgress, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
dialog = dialogService.showBlockingMessage(model);
|
||||
|
||||
if (dialog) {
|
||||
//Do processing here
|
||||
model.actionText = "Processing 100 objects...";
|
||||
if (knownProgress) {
|
||||
$timeout(incrementProgress, 1000);
|
||||
}
|
||||
} else {
|
||||
$log.error("Could not display modal dialog");
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Demonstrates launching an error dialog
|
||||
*/
|
||||
$scope.launchError = function () {
|
||||
var dialog,
|
||||
model = {
|
||||
title: "Error Dialog Example",
|
||||
actionText: "Something happened, and it was not good.",
|
||||
severity: "error",
|
||||
options: [
|
||||
{
|
||||
label: "Try Again",
|
||||
callback: function () {
|
||||
$log.debug("Try Again Pressed");
|
||||
dialog.dismiss();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Cancel",
|
||||
callback: function () {
|
||||
$log.debug("Cancel Pressed");
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
dialog = dialogService.showBlockingMessage(model);
|
||||
|
||||
if (!dialog) {
|
||||
$log.error("Could not display modal dialog");
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Demonstrates launching an error dialog
|
||||
*/
|
||||
$scope.launchInfo = function () {
|
||||
var dialog,
|
||||
model = {
|
||||
title: "Info Dialog Example",
|
||||
actionText: "This is an example of a blocking info"
|
||||
+ " dialog. This dialog can be used to draw the user's"
|
||||
+ " attention to an event.",
|
||||
severity: "info",
|
||||
primaryOption: {
|
||||
label: "OK",
|
||||
callback: function () {
|
||||
$log.debug("OK Pressed");
|
||||
dialog.dismiss();
|
||||
}
|
||||
/*
|
||||
Demonstrates launching a progress dialog and updating it
|
||||
periodically with the progress of an ongoing process.
|
||||
*/
|
||||
$scope.launchProgress = function (knownProgress) {
|
||||
var dialog,
|
||||
model = {
|
||||
title: "Progress Dialog Example",
|
||||
progress: 0,
|
||||
hint: "Do not navigate away from this page or close this browser tab while this operation is in progress.",
|
||||
actionText: "Calculating...",
|
||||
unknownProgress: !knownProgress,
|
||||
unknownDuration: false,
|
||||
severity: "info",
|
||||
options: [
|
||||
{
|
||||
label: "Cancel Operation",
|
||||
callback: function () {
|
||||
$log.debug("Operation cancelled");
|
||||
dialog.dismiss();
|
||||
}
|
||||
};
|
||||
|
||||
dialog = dialogService.showBlockingMessage(model);
|
||||
|
||||
if (!dialog) {
|
||||
$log.error("Could not display modal dialog");
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Do something else...",
|
||||
callback: function () {
|
||||
$log.debug("Something else pressed");
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
function incrementProgress() {
|
||||
model.progress = Math.min(100, Math.floor(model.progress + Math.random() * 30));
|
||||
model.progressText = ["Estimated time remaining: about ", 60 - Math.floor((model.progress / 100) * 60), " seconds"].join(" ");
|
||||
if (model.progress < 100) {
|
||||
$timeout(incrementProgress, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
return DialogLaunchController;
|
||||
}
|
||||
);
|
||||
dialog = dialogService.showBlockingMessage(model);
|
||||
|
||||
if (dialog) {
|
||||
//Do processing here
|
||||
model.actionText = "Processing 100 objects...";
|
||||
if (knownProgress) {
|
||||
$timeout(incrementProgress, 1000);
|
||||
}
|
||||
} else {
|
||||
$log.error("Could not display modal dialog");
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Demonstrates launching an error dialog
|
||||
*/
|
||||
$scope.launchError = function () {
|
||||
var dialog,
|
||||
model = {
|
||||
title: "Error Dialog Example",
|
||||
actionText: "Something happened, and it was not good.",
|
||||
severity: "error",
|
||||
options: [
|
||||
{
|
||||
label: "Try Again",
|
||||
callback: function () {
|
||||
$log.debug("Try Again Pressed");
|
||||
dialog.dismiss();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Cancel",
|
||||
callback: function () {
|
||||
$log.debug("Cancel Pressed");
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
dialog = dialogService.showBlockingMessage(model);
|
||||
|
||||
if (!dialog) {
|
||||
$log.error("Could not display modal dialog");
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Demonstrates launching an error dialog
|
||||
*/
|
||||
$scope.launchInfo = function () {
|
||||
var dialog,
|
||||
model = {
|
||||
title: "Info Dialog Example",
|
||||
actionText: "This is an example of a blocking info"
|
||||
+ " dialog. This dialog can be used to draw the user's"
|
||||
+ " attention to an event.",
|
||||
severity: "info",
|
||||
primaryOption: {
|
||||
label: "OK",
|
||||
callback: function () {
|
||||
$log.debug("OK Pressed");
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
dialog = dialogService.showBlockingMessage(model);
|
||||
|
||||
if (!dialog) {
|
||||
$log.error("Could not display modal dialog");
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
export default DialogLaunchController;
|
@ -20,36 +20,53 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* A tool for manually invoking dialogs. When included this
|
||||
* indicator will allow for dialogs of different types to be
|
||||
* launched for demonstration and testing purposes.
|
||||
* @constructor
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
function DialogLaunchIndicator() {
|
||||
/**
|
||||
* A tool for manually invoking dialogs. When included this
|
||||
* indicator will allow for dialogs of different types to be
|
||||
* launched for demonstration and testing purposes.
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
}
|
||||
function DialogLaunchIndicator() {
|
||||
|
||||
DialogLaunchIndicator.template = 'dialogLaunchTemplate';
|
||||
}
|
||||
|
||||
DialogLaunchIndicator.prototype.getGlyphClass = function () {
|
||||
return 'ok';
|
||||
};
|
||||
DialogLaunchIndicator.template = 'dialogLaunchTemplate';
|
||||
|
||||
DialogLaunchIndicator.prototype.getText = function () {
|
||||
return "Launch test dialog";
|
||||
};
|
||||
DialogLaunchIndicator.prototype.getGlyphClass = function () {
|
||||
return 'ok';
|
||||
};
|
||||
|
||||
DialogLaunchIndicator.prototype.getDescription = function () {
|
||||
return "Launch test dialog";
|
||||
};
|
||||
DialogLaunchIndicator.prototype.getText = function () {
|
||||
return "Launch test dialog";
|
||||
};
|
||||
|
||||
return DialogLaunchIndicator;
|
||||
}
|
||||
);
|
||||
DialogLaunchIndicator.prototype.getDescription = function () {
|
||||
return "Launch test dialog";
|
||||
};
|
||||
|
||||
export default DialogLaunchIndicator;
|
@ -20,107 +20,124 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Allows launching of notification messages for the purposes of
|
||||
* demonstration and testing. Also demonstrates use of
|
||||
* the NotificationService. Notifications are non-blocking messages that
|
||||
* appear at the bottom of the screen to inform the user of events
|
||||
* in a non-intrusive way. For more information see the
|
||||
* {@link NotificationService}
|
||||
* @param $scope
|
||||
* @param $timeout
|
||||
* @param $log
|
||||
* @param notificationService
|
||||
* @constructor
|
||||
*/
|
||||
function NotificationLaunchController($scope, $timeout, $log, notificationService) {
|
||||
var messageCounter = 1;
|
||||
|
||||
function getExampleActionText() {
|
||||
var actionTexts = [
|
||||
"Adipiscing turpis mauris in enim elementu hac, enim aliquam etiam.",
|
||||
"Eros turpis, pulvinar turpis eros eu",
|
||||
"Lundium nascetur a, lectus montes ac, parturient in natoque, duis risus risus pulvinar pid rhoncus, habitasse auctor natoque!"
|
||||
];
|
||||
|
||||
return actionTexts[Math.floor(Math.random() * 3)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch a new notification with a severity level of 'Error'.
|
||||
*/
|
||||
$scope.newError = function () {
|
||||
notificationService.notify({
|
||||
title: "Example error notification " + messageCounter++,
|
||||
hint: "An error has occurred",
|
||||
severity: "error"
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Launch a new notification with a severity of 'Alert'.
|
||||
*/
|
||||
$scope.newAlert = function () {
|
||||
notificationService.notify({
|
||||
title: "Alert notification " + (messageCounter++),
|
||||
hint: "This is an alert message",
|
||||
severity: "alert",
|
||||
autoDismiss: true
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Launch a new notification with a progress bar that is updated
|
||||
* periodically, tracking an ongoing process.
|
||||
*/
|
||||
$scope.newProgress = function () {
|
||||
let progress = 0;
|
||||
var notificationModel = {
|
||||
title: "Progress notification example",
|
||||
severity: "info",
|
||||
progress: progress,
|
||||
actionText: getExampleActionText()
|
||||
};
|
||||
let notification;
|
||||
|
||||
/**
|
||||
* Allows launching of notification messages for the purposes of
|
||||
* demonstration and testing. Also demonstrates use of
|
||||
* the NotificationService. Notifications are non-blocking messages that
|
||||
* appear at the bottom of the screen to inform the user of events
|
||||
* in a non-intrusive way. For more information see the
|
||||
* {@link NotificationService}
|
||||
* @param $scope
|
||||
* @param $timeout
|
||||
* @param $log
|
||||
* @param notificationService
|
||||
* @constructor
|
||||
* Simulate an ongoing process and update the progress bar.
|
||||
* @param notification
|
||||
*/
|
||||
function NotificationLaunchController($scope, $timeout, $log, notificationService) {
|
||||
var messageCounter = 1;
|
||||
function incrementProgress() {
|
||||
progress = Math.min(100, Math.floor(progress + Math.random() * 30));
|
||||
let progressText = ["Estimated time"
|
||||
+ " remaining:"
|
||||
+ " about ", 60 - Math.floor((progress / 100) * 60), " seconds"].join(" ");
|
||||
notification.progress(progress, progressText);
|
||||
|
||||
function getExampleActionText() {
|
||||
var actionTexts = [
|
||||
"Adipiscing turpis mauris in enim elementu hac, enim aliquam etiam.",
|
||||
"Eros turpis, pulvinar turpis eros eu",
|
||||
"Lundium nascetur a, lectus montes ac, parturient in natoque, duis risus risus pulvinar pid rhoncus, habitasse auctor natoque!"
|
||||
];
|
||||
|
||||
return actionTexts[Math.floor(Math.random() * 3)];
|
||||
if (progress < 100) {
|
||||
$timeout(function () {
|
||||
incrementProgress(notificationModel);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch a new notification with a severity level of 'Error'.
|
||||
*/
|
||||
$scope.newError = function () {
|
||||
notificationService.notify({
|
||||
title: "Example error notification " + messageCounter++,
|
||||
hint: "An error has occurred",
|
||||
severity: "error"
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Launch a new notification with a severity of 'Alert'.
|
||||
*/
|
||||
$scope.newAlert = function () {
|
||||
notificationService.notify({
|
||||
title: "Alert notification " + (messageCounter++),
|
||||
hint: "This is an alert message",
|
||||
severity: "alert",
|
||||
autoDismiss: true
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Launch a new notification with a progress bar that is updated
|
||||
* periodically, tracking an ongoing process.
|
||||
*/
|
||||
$scope.newProgress = function () {
|
||||
let progress = 0;
|
||||
var notificationModel = {
|
||||
title: "Progress notification example",
|
||||
severity: "info",
|
||||
progress: progress,
|
||||
actionText: getExampleActionText()
|
||||
};
|
||||
let notification;
|
||||
|
||||
/**
|
||||
* Simulate an ongoing process and update the progress bar.
|
||||
* @param notification
|
||||
*/
|
||||
function incrementProgress() {
|
||||
progress = Math.min(100, Math.floor(progress + Math.random() * 30));
|
||||
let progressText = ["Estimated time"
|
||||
+ " remaining:"
|
||||
+ " about ", 60 - Math.floor((progress / 100) * 60), " seconds"].join(" ");
|
||||
notification.progress(progress, progressText);
|
||||
|
||||
if (progress < 100) {
|
||||
$timeout(function () {
|
||||
incrementProgress(notificationModel);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
notification = notificationService.notify(notificationModel);
|
||||
incrementProgress();
|
||||
};
|
||||
|
||||
/**
|
||||
* Launch a new notification with severity level of INFO.
|
||||
*/
|
||||
$scope.newInfo = function () {
|
||||
notificationService.info({
|
||||
title: "Example Info notification " + messageCounter++
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
return NotificationLaunchController;
|
||||
}
|
||||
);
|
||||
notification = notificationService.notify(notificationModel);
|
||||
incrementProgress();
|
||||
};
|
||||
|
||||
/**
|
||||
* Launch a new notification with severity level of INFO.
|
||||
*/
|
||||
$scope.newInfo = function () {
|
||||
notificationService.info({
|
||||
title: "Example Info notification " + messageCounter++
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
export default NotificationLaunchController;
|
@ -20,36 +20,53 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* A tool for manually invoking notifications. When included this
|
||||
* indicator will allow for notifications of different types to be
|
||||
* launched for demonstration and testing purposes.
|
||||
* @constructor
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
function NotificationLaunchIndicator() {
|
||||
/**
|
||||
* A tool for manually invoking notifications. When included this
|
||||
* indicator will allow for notifications of different types to be
|
||||
* launched for demonstration and testing purposes.
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
}
|
||||
function NotificationLaunchIndicator() {
|
||||
|
||||
NotificationLaunchIndicator.template = 'notificationLaunchTemplate';
|
||||
}
|
||||
|
||||
NotificationLaunchIndicator.prototype.getGlyphClass = function () {
|
||||
return 'ok';
|
||||
};
|
||||
NotificationLaunchIndicator.template = 'notificationLaunchTemplate';
|
||||
|
||||
NotificationLaunchIndicator.prototype.getText = function () {
|
||||
return "Launch notification";
|
||||
};
|
||||
NotificationLaunchIndicator.prototype.getGlyphClass = function () {
|
||||
return 'ok';
|
||||
};
|
||||
|
||||
NotificationLaunchIndicator.prototype.getDescription = function () {
|
||||
return "Launch notification";
|
||||
};
|
||||
NotificationLaunchIndicator.prototype.getText = function () {
|
||||
return "Launch notification";
|
||||
};
|
||||
|
||||
return NotificationLaunchIndicator;
|
||||
}
|
||||
);
|
||||
NotificationLaunchIndicator.prototype.getDescription = function () {
|
||||
return "Launch notification";
|
||||
};
|
||||
|
||||
export default NotificationLaunchIndicator;
|
@ -20,35 +20,53 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/BrowserPersistenceProvider"
|
||||
], function (
|
||||
BrowserPersistenceProvider
|
||||
) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/persistence",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"components": [
|
||||
{
|
||||
"provides": "persistenceService",
|
||||
"type": "provider",
|
||||
"implementation": BrowserPersistenceProvider,
|
||||
"depends": [
|
||||
"$q",
|
||||
"PERSISTENCE_SPACE"
|
||||
]
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key": "PERSISTENCE_SPACE",
|
||||
"value": "mct"
|
||||
}
|
||||
]
|
||||
}
|
||||
import BrowserPersistenceProvider from './src/BrowserPersistenceProvider';
|
||||
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/persistence",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"components": [
|
||||
{
|
||||
"provides": "persistenceService",
|
||||
"type": "provider",
|
||||
"implementation": BrowserPersistenceProvider,
|
||||
"depends": [
|
||||
"$q",
|
||||
"PERSISTENCE_SPACE"
|
||||
]
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key": "PERSISTENCE_SPACE",
|
||||
"value": "mct"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -24,79 +24,100 @@
|
||||
* Stubbed implementation of a persistence provider,
|
||||
* to permit objects to be created, saved, etc.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
'use strict';
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
function BrowserPersistenceProvider($q, SPACE) {
|
||||
var spaces = SPACE ? [SPACE] : [],
|
||||
caches = {},
|
||||
promises = {
|
||||
as: function (value) {
|
||||
return $q.when(value);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Stubbed implementation of a persistence provider,
|
||||
* to permit objects to be created, saved, etc.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
spaces.forEach(function (space) {
|
||||
caches[space] = {};
|
||||
});
|
||||
function BrowserPersistenceProvider($q, SPACE) {
|
||||
var spaces = SPACE ? [SPACE] : [],
|
||||
caches = {},
|
||||
promises = {
|
||||
as: function (value) {
|
||||
return $q.when(value);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
listSpaces: function () {
|
||||
return promises.as(spaces);
|
||||
},
|
||||
listObjects: function (space) {
|
||||
var cache = caches[space];
|
||||
spaces.forEach(function (space) {
|
||||
caches[space] = {};
|
||||
});
|
||||
|
||||
return promises.as(
|
||||
cache ? Object.keys(cache) : null
|
||||
);
|
||||
},
|
||||
createObject: function (space, key, value) {
|
||||
var cache = caches[space];
|
||||
return {
|
||||
listSpaces: function () {
|
||||
return promises.as(spaces);
|
||||
},
|
||||
listObjects: function (space) {
|
||||
var cache = caches[space];
|
||||
|
||||
if (!cache || cache[key]) {
|
||||
return promises.as(null);
|
||||
}
|
||||
return promises.as(
|
||||
cache ? Object.keys(cache) : null
|
||||
);
|
||||
},
|
||||
createObject: function (space, key, value) {
|
||||
var cache = caches[space];
|
||||
|
||||
cache[key] = value;
|
||||
if (!cache || cache[key]) {
|
||||
return promises.as(null);
|
||||
}
|
||||
|
||||
return promises.as(true);
|
||||
},
|
||||
readObject: function (space, key) {
|
||||
var cache = caches[space];
|
||||
cache[key] = value;
|
||||
|
||||
return promises.as(
|
||||
cache ? cache[key] : null
|
||||
);
|
||||
},
|
||||
updateObject: function (space, key, value) {
|
||||
var cache = caches[space];
|
||||
return promises.as(true);
|
||||
},
|
||||
readObject: function (space, key) {
|
||||
var cache = caches[space];
|
||||
|
||||
if (!cache || !cache[key]) {
|
||||
return promises.as(null);
|
||||
}
|
||||
return promises.as(
|
||||
cache ? cache[key] : null
|
||||
);
|
||||
},
|
||||
updateObject: function (space, key, value) {
|
||||
var cache = caches[space];
|
||||
|
||||
cache[key] = value;
|
||||
if (!cache || !cache[key]) {
|
||||
return promises.as(null);
|
||||
}
|
||||
|
||||
return promises.as(true);
|
||||
},
|
||||
deleteObject: function (space, key, value) {
|
||||
var cache = caches[space];
|
||||
cache[key] = value;
|
||||
|
||||
if (!cache || !cache[key]) {
|
||||
return promises.as(null);
|
||||
}
|
||||
return promises.as(true);
|
||||
},
|
||||
deleteObject: function (space, key, value) {
|
||||
var cache = caches[space];
|
||||
|
||||
delete cache[key];
|
||||
if (!cache || !cache[key]) {
|
||||
return promises.as(null);
|
||||
}
|
||||
|
||||
return promises.as(true);
|
||||
}
|
||||
};
|
||||
delete cache[key];
|
||||
|
||||
return promises.as(true);
|
||||
}
|
||||
};
|
||||
|
||||
return BrowserPersistenceProvider;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default BrowserPersistenceProvider;
|
@ -20,26 +20,44 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/ExamplePolicy"
|
||||
], function (
|
||||
ExamplePolicy
|
||||
) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/policy",
|
||||
definition: {
|
||||
"name": "Example Policy",
|
||||
"description": "Provides an example of using policies to prohibit actions.",
|
||||
"extensions": {
|
||||
"policies": [
|
||||
{
|
||||
"implementation": ExamplePolicy,
|
||||
"category": "action"
|
||||
}
|
||||
]
|
||||
}
|
||||
import ExamplePolicy from './src/ExamplePolicy';
|
||||
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/policy",
|
||||
definition: {
|
||||
"name": "Example Policy",
|
||||
"description": "Provides an example of using policies to prohibit actions.",
|
||||
"extensions": {
|
||||
"policies": [
|
||||
{
|
||||
"implementation": ExamplePolicy,
|
||||
"category": "action"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,28 +20,45 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
function ExamplePolicy() {
|
||||
return {
|
||||
/**
|
||||
* Disallow the Remove action on objects whose name contains
|
||||
* "foo."
|
||||
*/
|
||||
allow: function (action, context) {
|
||||
var domainObject = (context || {}).domainObject,
|
||||
model = (domainObject && domainObject.getModel()) || {},
|
||||
name = model.name || "",
|
||||
metadata = action.getMetadata() || {};
|
||||
"use strict";
|
||||
|
||||
return metadata.key !== 'remove' || name.indexOf('foo') < 0;
|
||||
}
|
||||
};
|
||||
function ExamplePolicy() {
|
||||
return {
|
||||
/**
|
||||
* Disallow the Remove action on objects whose name contains
|
||||
* "foo."
|
||||
*/
|
||||
allow: function (action, context) {
|
||||
var domainObject = (context || {}).domainObject,
|
||||
model = (domainObject && domainObject.getModel()) || {},
|
||||
name = model.name || "",
|
||||
metadata = action.getMetadata() || {};
|
||||
|
||||
return metadata.key !== 'remove' || name.indexOf('foo') < 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return ExamplePolicy;
|
||||
}
|
||||
);
|
||||
export default ExamplePolicy;
|
@ -20,36 +20,53 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/WatchIndicator",
|
||||
"./src/DigestIndicator"
|
||||
], function (
|
||||
WatchIndicator,
|
||||
DigestIndicator
|
||||
) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/profiling",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"indicators": [
|
||||
{
|
||||
"implementation": WatchIndicator,
|
||||
"depends": [
|
||||
"$interval",
|
||||
"$rootScope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"implementation": DigestIndicator,
|
||||
"depends": [
|
||||
"$interval",
|
||||
"$rootScope"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
import WatchIndicator from './src/WatchIndicator';
|
||||
|
||||
import DigestIndicator from './src/DigestIndicator';
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/profiling",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"indicators": [
|
||||
{
|
||||
"implementation": WatchIndicator,
|
||||
"depends": [
|
||||
"$interval",
|
||||
"$rootScope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"implementation": DigestIndicator,
|
||||
"depends": [
|
||||
"$interval",
|
||||
"$rootScope"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,63 +20,79 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Displays the number of digests that have occurred since the
|
||||
* indicator was first instantiated.
|
||||
* @constructor
|
||||
* @param $interval Angular's $interval
|
||||
* @implements {Indicator}
|
||||
*/
|
||||
function DigestIndicator($interval, $rootScope) {
|
||||
var digests = 0,
|
||||
displayed = 0,
|
||||
start = Date.now();
|
||||
"use strict";
|
||||
|
||||
function update() {
|
||||
var now = Date.now(),
|
||||
secs = (now - start) / 1000;
|
||||
displayed = Math.round(digests / secs);
|
||||
start = now;
|
||||
digests = 0;
|
||||
}
|
||||
|
||||
function increment() {
|
||||
digests += 1;
|
||||
}
|
||||
|
||||
$rootScope.$watch(increment);
|
||||
|
||||
// Update state every second
|
||||
$interval(update, 1000);
|
||||
|
||||
// Provide initial state, too
|
||||
update();
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the CSS class that defines the icon
|
||||
* to display in this indicator. This will appear
|
||||
* as a dataflow icon.
|
||||
* @returns {string} the cssClass of the dataflow icon
|
||||
*/
|
||||
getCssClass: function () {
|
||||
return "icon-connectivity";
|
||||
},
|
||||
getText: function () {
|
||||
return displayed + " digests/sec";
|
||||
},
|
||||
getDescription: function () {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return DigestIndicator;
|
||||
/**
|
||||
* Displays the number of digests that have occurred since the
|
||||
* indicator was first instantiated.
|
||||
* @constructor
|
||||
* @param $interval Angular's $interval
|
||||
* @implements {Indicator}
|
||||
*/
|
||||
function DigestIndicator($interval, $rootScope) {
|
||||
var digests = 0,
|
||||
displayed = 0,
|
||||
start = Date.now();
|
||||
|
||||
function update() {
|
||||
var now = Date.now(),
|
||||
secs = (now - start) / 1000;
|
||||
displayed = Math.round(digests / secs);
|
||||
start = now;
|
||||
digests = 0;
|
||||
}
|
||||
);
|
||||
|
||||
function increment() {
|
||||
digests += 1;
|
||||
}
|
||||
|
||||
$rootScope.$watch(increment);
|
||||
|
||||
// Update state every second
|
||||
$interval(update, 1000);
|
||||
|
||||
// Provide initial state, too
|
||||
update();
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the CSS class that defines the icon
|
||||
* to display in this indicator. This will appear
|
||||
* as a dataflow icon.
|
||||
* @returns {string} the cssClass of the dataflow icon
|
||||
*/
|
||||
getCssClass: function () {
|
||||
return "icon-connectivity";
|
||||
},
|
||||
getText: function () {
|
||||
return displayed + " digests/sec";
|
||||
},
|
||||
getDescription: function () {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default DigestIndicator;
|
@ -20,67 +20,83 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Updates a count of currently-active Angular watches.
|
||||
* @constructor
|
||||
* @param $interval Angular's $interval
|
||||
*/
|
||||
function WatchIndicator($interval, $rootScope) {
|
||||
var watches = 0;
|
||||
"use strict";
|
||||
|
||||
function count(scope) {
|
||||
if (scope) {
|
||||
watches += (scope.$$watchers || []).length;
|
||||
count(scope.$$childHead);
|
||||
count(scope.$$nextSibling);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Updates a count of currently-active Angular watches.
|
||||
* @constructor
|
||||
* @param $interval Angular's $interval
|
||||
*/
|
||||
function WatchIndicator($interval, $rootScope) {
|
||||
var watches = 0;
|
||||
|
||||
function update() {
|
||||
watches = 0;
|
||||
count($rootScope);
|
||||
}
|
||||
|
||||
// Update state every second
|
||||
$interval(update, 1000);
|
||||
|
||||
// Provide initial state, too
|
||||
update();
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the CSS class (single character used as an icon)
|
||||
* to display in this indicator. This will return ".",
|
||||
* which should appear as a database icon.
|
||||
* @returns {string} the character of the database icon
|
||||
*/
|
||||
getCssClass: function () {
|
||||
return "icon-database";
|
||||
},
|
||||
/**
|
||||
* Get the text that should appear in the indicator.
|
||||
* @returns {string} brief summary of connection status
|
||||
*/
|
||||
getText: function () {
|
||||
return watches + " watches";
|
||||
},
|
||||
/**
|
||||
* Get a longer-form description of the current connection
|
||||
* space, suitable for display in a tooltip
|
||||
* @returns {string} longer summary of connection status
|
||||
*/
|
||||
getDescription: function () {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
function count(scope) {
|
||||
if (scope) {
|
||||
watches += (scope.$$watchers || []).length;
|
||||
count(scope.$$childHead);
|
||||
count(scope.$$nextSibling);
|
||||
}
|
||||
|
||||
return WatchIndicator;
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
function update() {
|
||||
watches = 0;
|
||||
count($rootScope);
|
||||
}
|
||||
|
||||
// Update state every second
|
||||
$interval(update, 1000);
|
||||
|
||||
// Provide initial state, too
|
||||
update();
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the CSS class (single character used as an icon)
|
||||
* to display in this indicator. This will return ".",
|
||||
* which should appear as a database icon.
|
||||
* @returns {string} the character of the database icon
|
||||
*/
|
||||
getCssClass: function () {
|
||||
return "icon-database";
|
||||
},
|
||||
/**
|
||||
* Get the text that should appear in the indicator.
|
||||
* @returns {string} brief summary of connection status
|
||||
*/
|
||||
getText: function () {
|
||||
return watches + " watches";
|
||||
},
|
||||
/**
|
||||
* Get a longer-form description of the current connection
|
||||
* space, suitable for display in a tooltip
|
||||
* @returns {string} longer summary of connection status
|
||||
*/
|
||||
getDescription: function () {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default WatchIndicator;
|
@ -20,44 +20,62 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/ScratchPersistenceProvider"
|
||||
], function (
|
||||
ScratchPersistenceProvider
|
||||
) {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "example/scratchpad",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"roots": [
|
||||
{
|
||||
"id": "scratch:root"
|
||||
}
|
||||
],
|
||||
"models": [
|
||||
{
|
||||
"id": "scratch:root",
|
||||
"model": {
|
||||
"type": "folder",
|
||||
"composition": [],
|
||||
"name": "Scratchpad"
|
||||
},
|
||||
"priority": "preferred"
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"provides": "persistenceService",
|
||||
"type": "provider",
|
||||
"implementation": ScratchPersistenceProvider,
|
||||
"depends": [
|
||||
"$q"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
import ScratchPersistenceProvider from './src/ScratchPersistenceProvider';
|
||||
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
name: "example/scratchpad",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"roots": [
|
||||
{
|
||||
"id": "scratch:root"
|
||||
}
|
||||
],
|
||||
"models": [
|
||||
{
|
||||
"id": "scratch:root",
|
||||
"model": {
|
||||
"type": "folder",
|
||||
"composition": [],
|
||||
"name": "Scratchpad"
|
||||
},
|
||||
"priority": "preferred"
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"provides": "persistenceService",
|
||||
"type": "provider",
|
||||
"implementation": ScratchPersistenceProvider,
|
||||
"depends": [
|
||||
"$q"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,60 +20,77 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
'use strict';
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The ScratchPersistenceProvider keeps JSON documents in memory
|
||||
* and provides a persistence interface, but changes are lost on reload.
|
||||
* @memberof example/scratchpad
|
||||
* @constructor
|
||||
* @implements {PersistenceService}
|
||||
* @param q Angular's $q, for promises
|
||||
*/
|
||||
function ScratchPersistenceProvider($q) {
|
||||
this.$q = $q;
|
||||
this.table = {};
|
||||
}
|
||||
'use strict';
|
||||
|
||||
ScratchPersistenceProvider.prototype.listSpaces = function () {
|
||||
return this.$q.when(['scratch']);
|
||||
};
|
||||
/**
|
||||
* The ScratchPersistenceProvider keeps JSON documents in memory
|
||||
* and provides a persistence interface, but changes are lost on reload.
|
||||
* @memberof example/scratchpad
|
||||
* @constructor
|
||||
* @implements {PersistenceService}
|
||||
* @param q Angular's $q, for promises
|
||||
*/
|
||||
function ScratchPersistenceProvider($q) {
|
||||
this.$q = $q;
|
||||
this.table = {};
|
||||
}
|
||||
|
||||
ScratchPersistenceProvider.prototype.listObjects = function (space) {
|
||||
return this.$q.when(
|
||||
space === 'scratch' ? Object.keys(this.table) : []
|
||||
);
|
||||
};
|
||||
ScratchPersistenceProvider.prototype.listSpaces = function () {
|
||||
return this.$q.when(['scratch']);
|
||||
};
|
||||
|
||||
ScratchPersistenceProvider.prototype.createObject = function (space, key, value) {
|
||||
if (space === 'scratch') {
|
||||
this.table[key] = JSON.stringify(value);
|
||||
}
|
||||
ScratchPersistenceProvider.prototype.listObjects = function (space) {
|
||||
return this.$q.when(
|
||||
space === 'scratch' ? Object.keys(this.table) : []
|
||||
);
|
||||
};
|
||||
|
||||
return this.$q.when(space === 'scratch');
|
||||
};
|
||||
|
||||
ScratchPersistenceProvider.prototype.readObject = function (space, key) {
|
||||
return this.$q.when(
|
||||
(space === 'scratch' && this.table[key])
|
||||
? JSON.parse(this.table[key]) : undefined
|
||||
);
|
||||
};
|
||||
|
||||
ScratchPersistenceProvider.prototype.deleteObject = function (space, key, value) {
|
||||
if (space === 'scratch') {
|
||||
delete this.table[key];
|
||||
}
|
||||
|
||||
return this.$q.when(space === 'scratch');
|
||||
};
|
||||
|
||||
ScratchPersistenceProvider.prototype.updateObject =
|
||||
ScratchPersistenceProvider.prototype.createObject;
|
||||
|
||||
return ScratchPersistenceProvider;
|
||||
ScratchPersistenceProvider.prototype.createObject = function (space, key, value) {
|
||||
if (space === 'scratch') {
|
||||
this.table[key] = JSON.stringify(value);
|
||||
}
|
||||
);
|
||||
|
||||
return this.$q.when(space === 'scratch');
|
||||
};
|
||||
|
||||
ScratchPersistenceProvider.prototype.readObject = function (space, key) {
|
||||
return this.$q.when(
|
||||
(space === 'scratch' && this.table[key])
|
||||
? JSON.parse(this.table[key]) : undefined
|
||||
);
|
||||
};
|
||||
|
||||
ScratchPersistenceProvider.prototype.deleteObject = function (space, key, value) {
|
||||
if (space === 'scratch') {
|
||||
delete this.table[key];
|
||||
}
|
||||
|
||||
return this.$q.when(space === 'scratch');
|
||||
};
|
||||
|
||||
ScratchPersistenceProvider.prototype.updateObject =
|
||||
ScratchPersistenceProvider.prototype.createObject;
|
||||
|
||||
export default ScratchPersistenceProvider;
|
@ -1,188 +1,175 @@
|
||||
define([
|
||||
"./src/ExampleStyleGuideModelProvider",
|
||||
"./src/MCTExample",
|
||||
"./res/templates/intro.html",
|
||||
"./res/templates/standards.html",
|
||||
"./res/templates/colors.html",
|
||||
"./res/templates/status.html",
|
||||
"./res/templates/glyphs.html",
|
||||
"./res/templates/controls.html",
|
||||
"./res/templates/input.html",
|
||||
"./res/templates/menus.html"
|
||||
], function (
|
||||
ExampleStyleGuideModelProvider,
|
||||
MCTExample,
|
||||
introTemplate,
|
||||
standardsTemplate,
|
||||
colorsTemplate,
|
||||
statusTemplate,
|
||||
glyphsTemplate,
|
||||
controlsTemplate,
|
||||
inputTemplate,
|
||||
menusTemplate
|
||||
) {
|
||||
return {
|
||||
name: "example/styleguide",
|
||||
definition: {
|
||||
"name": "Open MCT Style Guide",
|
||||
"description": "Examples and documentation illustrating UI styles in use in Open MCT.",
|
||||
"extensions":
|
||||
{
|
||||
"types": [
|
||||
{
|
||||
"key": "styleguide.intro",
|
||||
"name": "Introduction",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Introduction and overview to the style guide"
|
||||
},
|
||||
{
|
||||
"key": "styleguide.standards",
|
||||
"name": "Standards",
|
||||
"cssClass": "icon-page",
|
||||
"description": ""
|
||||
},
|
||||
{
|
||||
"key": "styleguide.colors",
|
||||
"name": "Colors",
|
||||
"cssClass": "icon-page",
|
||||
"description": ""
|
||||
},
|
||||
{
|
||||
"key": "styleguide.status",
|
||||
"name": "status",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Limits, telemetry paused, etc."
|
||||
},
|
||||
{
|
||||
"key": "styleguide.glyphs",
|
||||
"name": "Glyphs",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Glyphs overview"
|
||||
},
|
||||
{
|
||||
"key": "styleguide.controls",
|
||||
"name": "Controls",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Buttons, selects, HTML controls"
|
||||
},
|
||||
{
|
||||
"key": "styleguide.input",
|
||||
"name": "Text Inputs",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Various text inputs"
|
||||
},
|
||||
{
|
||||
"key": "styleguide.menus",
|
||||
"name": "Menus",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Context menus, dropdowns"
|
||||
}
|
||||
],
|
||||
"views": [
|
||||
{
|
||||
"key": "styleguide.intro",
|
||||
"type": "styleguide.intro",
|
||||
"template": introTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.standards",
|
||||
"type": "styleguide.standards",
|
||||
"template": standardsTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.colors",
|
||||
"type": "styleguide.colors",
|
||||
"template": colorsTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.status",
|
||||
"type": "styleguide.status",
|
||||
"template": statusTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.glyphs",
|
||||
"type": "styleguide.glyphs",
|
||||
"template": glyphsTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.controls",
|
||||
"type": "styleguide.controls",
|
||||
"template": controlsTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.input",
|
||||
"type": "styleguide.input",
|
||||
"template": inputTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.menus",
|
||||
"type": "styleguide.menus",
|
||||
"template": menusTemplate,
|
||||
"editable": false
|
||||
}
|
||||
],
|
||||
"roots": [
|
||||
{
|
||||
"id": "styleguide:home"
|
||||
}
|
||||
],
|
||||
"models": [
|
||||
{
|
||||
"id": "styleguide:home",
|
||||
"priority": "preferred",
|
||||
"model": {
|
||||
"type": "noneditable.folder",
|
||||
"name": "Style Guide Home",
|
||||
"location": "ROOT",
|
||||
"composition": [
|
||||
"intro",
|
||||
"standards",
|
||||
"colors",
|
||||
"status",
|
||||
"glyphs",
|
||||
"styleguide:ui-elements"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "styleguide:ui-elements",
|
||||
"priority": "preferred",
|
||||
"model": {
|
||||
"type": "noneditable.folder",
|
||||
"name": "UI Elements",
|
||||
"location": "styleguide:home",
|
||||
"composition": [
|
||||
"controls",
|
||||
"input",
|
||||
"menus"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": [
|
||||
{
|
||||
"key": "mctExample",
|
||||
"implementation": MCTExample
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"provides": "modelService",
|
||||
"type": "provider",
|
||||
"implementation": ExampleStyleGuideModelProvider,
|
||||
"depends": [
|
||||
"$q"
|
||||
import ExampleStyleGuideModelProvider from './src/ExampleStyleGuideModelProvider';
|
||||
import MCTExample from './src/MCTExample';
|
||||
import introTemplate from './res/templates/intro.html';
|
||||
import standardsTemplate from './res/templates/standards.html';
|
||||
import colorsTemplate from './res/templates/colors.html';
|
||||
import statusTemplate from './res/templates/status.html';
|
||||
import glyphsTemplate from './res/templates/glyphs.html';
|
||||
import controlsTemplate from './res/templates/controls.html';
|
||||
import inputTemplate from './res/templates/input.html';
|
||||
import menusTemplate from './res/templates/menus.html';
|
||||
|
||||
export default {
|
||||
name: "example/styleguide",
|
||||
definition: {
|
||||
"name": "Open MCT Style Guide",
|
||||
"description": "Examples and documentation illustrating UI styles in use in Open MCT.",
|
||||
"extensions":
|
||||
{
|
||||
"types": [
|
||||
{
|
||||
"key": "styleguide.intro",
|
||||
"name": "Introduction",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Introduction and overview to the style guide"
|
||||
},
|
||||
{
|
||||
"key": "styleguide.standards",
|
||||
"name": "Standards",
|
||||
"cssClass": "icon-page",
|
||||
"description": ""
|
||||
},
|
||||
{
|
||||
"key": "styleguide.colors",
|
||||
"name": "Colors",
|
||||
"cssClass": "icon-page",
|
||||
"description": ""
|
||||
},
|
||||
{
|
||||
"key": "styleguide.status",
|
||||
"name": "status",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Limits, telemetry paused, etc."
|
||||
},
|
||||
{
|
||||
"key": "styleguide.glyphs",
|
||||
"name": "Glyphs",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Glyphs overview"
|
||||
},
|
||||
{
|
||||
"key": "styleguide.controls",
|
||||
"name": "Controls",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Buttons, selects, HTML controls"
|
||||
},
|
||||
{
|
||||
"key": "styleguide.input",
|
||||
"name": "Text Inputs",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Various text inputs"
|
||||
},
|
||||
{
|
||||
"key": "styleguide.menus",
|
||||
"name": "Menus",
|
||||
"cssClass": "icon-page",
|
||||
"description": "Context menus, dropdowns"
|
||||
}
|
||||
],
|
||||
"views": [
|
||||
{
|
||||
"key": "styleguide.intro",
|
||||
"type": "styleguide.intro",
|
||||
"template": introTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.standards",
|
||||
"type": "styleguide.standards",
|
||||
"template": standardsTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.colors",
|
||||
"type": "styleguide.colors",
|
||||
"template": colorsTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.status",
|
||||
"type": "styleguide.status",
|
||||
"template": statusTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.glyphs",
|
||||
"type": "styleguide.glyphs",
|
||||
"template": glyphsTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.controls",
|
||||
"type": "styleguide.controls",
|
||||
"template": controlsTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.input",
|
||||
"type": "styleguide.input",
|
||||
"template": inputTemplate,
|
||||
"editable": false
|
||||
},
|
||||
{
|
||||
"key": "styleguide.menus",
|
||||
"type": "styleguide.menus",
|
||||
"template": menusTemplate,
|
||||
"editable": false
|
||||
}
|
||||
],
|
||||
"roots": [
|
||||
{
|
||||
"id": "styleguide:home"
|
||||
}
|
||||
],
|
||||
"models": [
|
||||
{
|
||||
"id": "styleguide:home",
|
||||
"priority": "preferred",
|
||||
"model": {
|
||||
"type": "noneditable.folder",
|
||||
"name": "Style Guide Home",
|
||||
"location": "ROOT",
|
||||
"composition": [
|
||||
"intro",
|
||||
"standards",
|
||||
"colors",
|
||||
"status",
|
||||
"glyphs",
|
||||
"styleguide:ui-elements"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
{
|
||||
"id": "styleguide:ui-elements",
|
||||
"priority": "preferred",
|
||||
"model": {
|
||||
"type": "noneditable.folder",
|
||||
"name": "UI Elements",
|
||||
"location": "styleguide:home",
|
||||
"composition": [
|
||||
"controls",
|
||||
"input",
|
||||
"menus"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": [
|
||||
{
|
||||
"key": "mctExample",
|
||||
"implementation": MCTExample
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"provides": "modelService",
|
||||
"type": "provider",
|
||||
"implementation": ExampleStyleGuideModelProvider,
|
||||
"depends": [
|
||||
"$q"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -20,63 +20,80 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
function ExampleStyleGuideModelProvider($q) {
|
||||
var pages = {};
|
||||
"use strict";
|
||||
|
||||
// Add pages
|
||||
pages.intro = {
|
||||
name: "Introduction",
|
||||
type: "styleguide.intro",
|
||||
location: "styleguide:home"
|
||||
};
|
||||
pages.standards = {
|
||||
name: "Standards",
|
||||
type: "styleguide.standards",
|
||||
location: "styleguide:home"
|
||||
};
|
||||
pages.colors = {
|
||||
name: "Colors",
|
||||
type: "styleguide.colors",
|
||||
location: "styleguide:home"
|
||||
};
|
||||
pages.glyphs = {
|
||||
name: "Glyphs",
|
||||
type: "styleguide.glyphs",
|
||||
location: "styleguide:home"
|
||||
};
|
||||
pages.status = {
|
||||
name: "Status Indication",
|
||||
type: "styleguide.status",
|
||||
location: "styleguide:home"
|
||||
};
|
||||
pages.controls = {
|
||||
name: "Controls",
|
||||
type: "styleguide.controls",
|
||||
location: "styleguide:ui-elements"
|
||||
};
|
||||
pages.input = {
|
||||
name: "Text Inputs",
|
||||
type: "styleguide.input",
|
||||
location: "styleguide:ui-elements"
|
||||
};
|
||||
pages.menus = {
|
||||
name: "Menus",
|
||||
type: "styleguide.menus",
|
||||
location: "styleguide:ui-elements"
|
||||
};
|
||||
function ExampleStyleGuideModelProvider($q) {
|
||||
var pages = {};
|
||||
|
||||
return {
|
||||
getModels: function () {
|
||||
return $q.when(pages);
|
||||
}
|
||||
};
|
||||
// Add pages
|
||||
pages.intro = {
|
||||
name: "Introduction",
|
||||
type: "styleguide.intro",
|
||||
location: "styleguide:home"
|
||||
};
|
||||
pages.standards = {
|
||||
name: "Standards",
|
||||
type: "styleguide.standards",
|
||||
location: "styleguide:home"
|
||||
};
|
||||
pages.colors = {
|
||||
name: "Colors",
|
||||
type: "styleguide.colors",
|
||||
location: "styleguide:home"
|
||||
};
|
||||
pages.glyphs = {
|
||||
name: "Glyphs",
|
||||
type: "styleguide.glyphs",
|
||||
location: "styleguide:home"
|
||||
};
|
||||
pages.status = {
|
||||
name: "Status Indication",
|
||||
type: "styleguide.status",
|
||||
location: "styleguide:home"
|
||||
};
|
||||
pages.controls = {
|
||||
name: "Controls",
|
||||
type: "styleguide.controls",
|
||||
location: "styleguide:ui-elements"
|
||||
};
|
||||
pages.input = {
|
||||
name: "Text Inputs",
|
||||
type: "styleguide.input",
|
||||
location: "styleguide:ui-elements"
|
||||
};
|
||||
pages.menus = {
|
||||
name: "Menus",
|
||||
type: "styleguide.menus",
|
||||
location: "styleguide:ui-elements"
|
||||
};
|
||||
|
||||
return {
|
||||
getModels: function () {
|
||||
return $q.when(pages);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return ExampleStyleGuideModelProvider;
|
||||
}
|
||||
);
|
||||
export default ExampleStyleGuideModelProvider;
|
@ -1,30 +1,25 @@
|
||||
define([
|
||||
'../res/templates/mct-example.html'
|
||||
], function (
|
||||
MCTExampleTemplate
|
||||
) {
|
||||
import MCTExampleTemplate from '../res/templates/mct-example.html';
|
||||
|
||||
function MCTExample() {
|
||||
function link($scope, $element, $attrs, controller, $transclude) {
|
||||
var codeEl = $element.find('pre');
|
||||
var exampleEl = $element.find('div');
|
||||
function MCTExample() {
|
||||
function link($scope, $element, $attrs, controller, $transclude) {
|
||||
var codeEl = $element.find('pre');
|
||||
var exampleEl = $element.find('div');
|
||||
|
||||
$transclude(function (clone) {
|
||||
exampleEl.append(clone);
|
||||
codeEl.text(exampleEl.html()
|
||||
.replace(/ class="ng-scope"/g, "")
|
||||
.replace(/ ng-scope"/g, '"'));
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
restrict: "E",
|
||||
template: MCTExampleTemplate,
|
||||
transclude: true,
|
||||
link: link,
|
||||
replace: true
|
||||
};
|
||||
$transclude(function (clone) {
|
||||
exampleEl.append(clone);
|
||||
codeEl.text(exampleEl.html()
|
||||
.replace(/ class="ng-scope"/g, "")
|
||||
.replace(/ ng-scope"/g, '"'));
|
||||
});
|
||||
}
|
||||
|
||||
return MCTExample;
|
||||
});
|
||||
return {
|
||||
restrict: "E",
|
||||
template: MCTExampleTemplate,
|
||||
transclude: true,
|
||||
link: link,
|
||||
replace: true
|
||||
};
|
||||
}
|
||||
|
||||
export default MCTExample;
|
||||
|
@ -7,6 +7,7 @@
|
||||
"@percy/cli": "^1.0.0-beta.70",
|
||||
"@percy/playwright": "^1.0.1",
|
||||
"@playwright/test": "^1.16.3",
|
||||
"5to6-codemod": "^1.8.0",
|
||||
"allure-playwright": "^2.0.0-beta.14",
|
||||
"angular": ">=1.8.0",
|
||||
"angular-route": "1.4.14",
|
||||
@ -36,6 +37,7 @@
|
||||
"imports-loader": "^0.8.0",
|
||||
"istanbul-instrumenter-loader": "^3.0.1",
|
||||
"jasmine-core": "^3.7.1",
|
||||
"jscodeshift": "^0.13.0",
|
||||
"jsdoc": "^3.3.2",
|
||||
"karma": "6.3.9",
|
||||
"karma-chrome-launcher": "3.1.0",
|
||||
|
@ -20,139 +20,147 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/navigation/NavigationService",
|
||||
"./src/navigation/NavigateAction",
|
||||
"./src/navigation/OrphanNavigationHandler",
|
||||
"./res/templates/browse.html",
|
||||
"./res/templates/browse-object.html",
|
||||
"./res/templates/browse/object-header.html",
|
||||
"./res/templates/browse/object-header-frame.html",
|
||||
"./res/templates/menu-arrow.html",
|
||||
"./res/templates/back-arrow.html",
|
||||
"./res/templates/browse/object-properties.html",
|
||||
"./res/templates/browse/inspector-region.html"
|
||||
], function (
|
||||
NavigationService,
|
||||
NavigateAction,
|
||||
OrphanNavigationHandler,
|
||||
browseTemplate,
|
||||
browseObjectTemplate,
|
||||
objectHeaderTemplate,
|
||||
objectHeaderFrameTemplate,
|
||||
menuArrowTemplate,
|
||||
backArrowTemplate,
|
||||
objectPropertiesTemplate,
|
||||
inspectorRegionTemplate
|
||||
) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "platform/commonUI/browse",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"routes": [
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key": "DEFAULT_PATH",
|
||||
"value": "mine",
|
||||
"priority": "fallback"
|
||||
}
|
||||
],
|
||||
"representations": [
|
||||
{
|
||||
"key": "browse-object",
|
||||
"template": browseObjectTemplate,
|
||||
"gestures": [
|
||||
"drop"
|
||||
],
|
||||
"uses": [
|
||||
"view"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "object-header",
|
||||
"template": objectHeaderTemplate,
|
||||
"uses": [
|
||||
"type"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "object-header-frame",
|
||||
"template": objectHeaderFrameTemplate,
|
||||
"uses": [
|
||||
"type"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "menu-arrow",
|
||||
"template": menuArrowTemplate,
|
||||
"uses": [
|
||||
"action"
|
||||
],
|
||||
"gestures": [
|
||||
"menu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "back-arrow",
|
||||
"uses": [
|
||||
"context"
|
||||
],
|
||||
"template": backArrowTemplate
|
||||
},
|
||||
{
|
||||
"key": "object-properties",
|
||||
"template": objectPropertiesTemplate
|
||||
},
|
||||
{
|
||||
"key": "inspector-region",
|
||||
"template": inspectorRegionTemplate
|
||||
}
|
||||
],
|
||||
"services": [
|
||||
{
|
||||
"key": "navigationService",
|
||||
"implementation": NavigationService,
|
||||
"depends": [
|
||||
"$window"
|
||||
]
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"key": "navigate",
|
||||
"implementation": NavigateAction,
|
||||
"depends": [
|
||||
"navigationService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
"implementation": OrphanNavigationHandler,
|
||||
"depends": [
|
||||
"throttle",
|
||||
"topic",
|
||||
"navigationService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"templates": [
|
||||
{
|
||||
key: "browseRoot",
|
||||
template: browseTemplate
|
||||
},
|
||||
{
|
||||
key: "browseObject",
|
||||
template: browseObjectTemplate
|
||||
},
|
||||
{
|
||||
key: "inspectorRegion",
|
||||
template: inspectorRegionTemplate
|
||||
}
|
||||
]
|
||||
}
|
||||
import NavigationService from './src/navigation/NavigationService';
|
||||
|
||||
import NavigateAction from './src/navigation/NavigateAction';
|
||||
import OrphanNavigationHandler from './src/navigation/OrphanNavigationHandler';
|
||||
import browseTemplate from './res/templates/browse.html';
|
||||
import browseObjectTemplate from './res/templates/browse-object.html';
|
||||
import objectHeaderTemplate from './res/templates/browse/object-header.html';
|
||||
import objectHeaderFrameTemplate from './res/templates/browse/object-header-frame.html';
|
||||
import menuArrowTemplate from './res/templates/menu-arrow.html';
|
||||
import backArrowTemplate from './res/templates/back-arrow.html';
|
||||
import objectPropertiesTemplate from './res/templates/browse/object-properties.html';
|
||||
import inspectorRegionTemplate from './res/templates/browse/inspector-region.html';
|
||||
|
||||
export default {
|
||||
name: "platform/commonUI/browse",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"routes": [
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key": "DEFAULT_PATH",
|
||||
"value": "mine",
|
||||
"priority": "fallback"
|
||||
}
|
||||
],
|
||||
"representations": [
|
||||
{
|
||||
"key": "browse-object",
|
||||
"template": browseObjectTemplate,
|
||||
"gestures": [
|
||||
"drop"
|
||||
],
|
||||
"uses": [
|
||||
"view"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "object-header",
|
||||
"template": objectHeaderTemplate,
|
||||
"uses": [
|
||||
"type"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "object-header-frame",
|
||||
"template": objectHeaderFrameTemplate,
|
||||
"uses": [
|
||||
"type"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "menu-arrow",
|
||||
"template": menuArrowTemplate,
|
||||
"uses": [
|
||||
"action"
|
||||
],
|
||||
"gestures": [
|
||||
"menu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "back-arrow",
|
||||
"uses": [
|
||||
"context"
|
||||
],
|
||||
"template": backArrowTemplate
|
||||
},
|
||||
{
|
||||
"key": "object-properties",
|
||||
"template": objectPropertiesTemplate
|
||||
},
|
||||
{
|
||||
"key": "inspector-region",
|
||||
"template": inspectorRegionTemplate
|
||||
}
|
||||
],
|
||||
"services": [
|
||||
{
|
||||
"key": "navigationService",
|
||||
"implementation": NavigationService,
|
||||
"depends": [
|
||||
"$window"
|
||||
]
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"key": "navigate",
|
||||
"implementation": NavigateAction,
|
||||
"depends": [
|
||||
"navigationService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
"implementation": OrphanNavigationHandler,
|
||||
"depends": [
|
||||
"throttle",
|
||||
"topic",
|
||||
"navigationService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"templates": [
|
||||
{
|
||||
key: "browseRoot",
|
||||
template: browseTemplate
|
||||
},
|
||||
{
|
||||
key: "browseObject",
|
||||
template: browseObjectTemplate
|
||||
},
|
||||
{
|
||||
key: "inspectorRegion",
|
||||
template: inspectorRegionTemplate
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,48 +20,64 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[
|
||||
'../../regions/src/Region'
|
||||
],
|
||||
function (Region) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Defines the a default Inspector region. Captured in a class to
|
||||
* allow for modular extension and customization of regions based on
|
||||
* the typical case.
|
||||
* @memberOf platform/commonUI/regions
|
||||
* @constructor
|
||||
*/
|
||||
function InspectorRegion() {
|
||||
Region.call(this, {'name': 'Inspector'});
|
||||
import Region from '../../regions/src/Region';
|
||||
|
||||
this.buildRegion();
|
||||
/**
|
||||
* Defines the a default Inspector region. Captured in a class to
|
||||
* allow for modular extension and customization of regions based on
|
||||
* the typical case.
|
||||
* @memberOf platform/commonUI/regions
|
||||
* @constructor
|
||||
*/
|
||||
function InspectorRegion() {
|
||||
Region.call(this, {'name': 'Inspector'});
|
||||
|
||||
this.buildRegion();
|
||||
}
|
||||
|
||||
InspectorRegion.prototype = Object.create(Region.prototype);
|
||||
InspectorRegion.prototype.constructor = Region;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
InspectorRegion.prototype.buildRegion = function () {
|
||||
var metadataRegion = {
|
||||
name: 'metadata',
|
||||
title: 'Metadata Region',
|
||||
// Which modes should the region part be visible in? If
|
||||
// nothing provided here, then assumed that part is visible
|
||||
// in both. The visibility or otherwise of a region part
|
||||
// should be decided by a policy. In this case, 'modes' is a
|
||||
// shortcut that is used by the EditableRegionPolicy.
|
||||
modes: ['browse', 'edit'],
|
||||
content: {
|
||||
key: 'object-properties'
|
||||
}
|
||||
};
|
||||
this.addRegion(new Region(metadataRegion), 0);
|
||||
};
|
||||
|
||||
InspectorRegion.prototype = Object.create(Region.prototype);
|
||||
InspectorRegion.prototype.constructor = Region;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
InspectorRegion.prototype.buildRegion = function () {
|
||||
var metadataRegion = {
|
||||
name: 'metadata',
|
||||
title: 'Metadata Region',
|
||||
// Which modes should the region part be visible in? If
|
||||
// nothing provided here, then assumed that part is visible
|
||||
// in both. The visibility or otherwise of a region part
|
||||
// should be decided by a policy. In this case, 'modes' is a
|
||||
// shortcut that is used by the EditableRegionPolicy.
|
||||
modes: ['browse', 'edit'],
|
||||
content: {
|
||||
key: 'object-properties'
|
||||
}
|
||||
};
|
||||
this.addRegion(new Region(metadataRegion), 0);
|
||||
};
|
||||
|
||||
return InspectorRegion;
|
||||
}
|
||||
);
|
||||
export default InspectorRegion;
|
@ -23,47 +23,60 @@
|
||||
/**
|
||||
* Module defining NavigateAction. Created by vwoeltje on 11/10/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The navigate action navigates to a specific domain object.
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
*/
|
||||
function NavigateAction(navigationService, context) {
|
||||
this.domainObject = context.domainObject;
|
||||
this.navigationService = navigationService;
|
||||
}
|
||||
/**
|
||||
* Module defining NavigateAction. Created by vwoeltje on 11/10/14.
|
||||
*/
|
||||
function NavigateAction(navigationService, context) {
|
||||
this.domainObject = context.domainObject;
|
||||
this.navigationService = navigationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to the object described in the context.
|
||||
* @returns {Promise} a promise that is resolved once the
|
||||
* navigation has been updated
|
||||
*/
|
||||
NavigateAction.prototype.perform = function () {
|
||||
if (this.navigationService.shouldNavigate()) {
|
||||
this.navigationService.setNavigation(this.domainObject, true);
|
||||
/**
|
||||
* Navigate to the object described in the context.
|
||||
* @returns {Promise} a promise that is resolved once the
|
||||
* navigation has been updated
|
||||
*/
|
||||
NavigateAction.prototype.perform = function () {
|
||||
if (this.navigationService.shouldNavigate()) {
|
||||
this.navigationService.setNavigation(this.domainObject, true);
|
||||
|
||||
return Promise.resolve({});
|
||||
}
|
||||
|
||||
return Promise.reject('Navigation Prevented by User');
|
||||
};
|
||||
|
||||
/**
|
||||
* Navigate as an action is only applicable when a domain object
|
||||
* is described in the action context.
|
||||
* @param {ActionContext} context the context in which the action
|
||||
* will be performed
|
||||
* @returns {boolean} true if applicable
|
||||
*/
|
||||
NavigateAction.appliesTo = function (context) {
|
||||
return context.domainObject !== undefined;
|
||||
};
|
||||
|
||||
return NavigateAction;
|
||||
return Promise.resolve({});
|
||||
}
|
||||
);
|
||||
|
||||
return Promise.reject('Navigation Prevented by User');
|
||||
};
|
||||
|
||||
/**
|
||||
* Navigate as an action is only applicable when a domain object
|
||||
* is described in the action context.
|
||||
* @param {ActionContext} context the context in which the action
|
||||
* will be performed
|
||||
* @returns {boolean} true if applicable
|
||||
*/
|
||||
NavigateAction.appliesTo = function (context) {
|
||||
return context.domainObject !== undefined;
|
||||
};
|
||||
|
||||
export default NavigateAction;
|
@ -23,181 +23,193 @@
|
||||
/**
|
||||
* Module defining NavigationService. Created by vwoeltje on 11/10/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The navigation service maintains the application's current
|
||||
* navigation state, and allows listening for changes thereto.
|
||||
*
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
function NavigationService($window) {
|
||||
this.navigated = undefined;
|
||||
this.callbacks = [];
|
||||
this.checks = [];
|
||||
this.$window = $window;
|
||||
/**
|
||||
* Module defining NavigationService. Created by vwoeltje on 11/10/14.
|
||||
*/
|
||||
function NavigationService($window) {
|
||||
this.navigated = undefined;
|
||||
this.callbacks = [];
|
||||
this.checks = [];
|
||||
this.$window = $window;
|
||||
|
||||
this.oldUnload = $window.onbeforeunload;
|
||||
$window.onbeforeunload = this.onBeforeUnload.bind(this);
|
||||
}
|
||||
this.oldUnload = $window.onbeforeunload;
|
||||
$window.onbeforeunload = this.onBeforeUnload.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current navigation state.
|
||||
*
|
||||
* @returns {DomainObject} the object that is navigated-to
|
||||
*/
|
||||
NavigationService.prototype.getNavigation = function () {
|
||||
return this.navigated;
|
||||
};
|
||||
/**
|
||||
* Get the current navigation state.
|
||||
*
|
||||
* @returns {DomainObject} the object that is navigated-to
|
||||
*/
|
||||
NavigationService.prototype.getNavigation = function () {
|
||||
return this.navigated;
|
||||
};
|
||||
|
||||
/**
|
||||
* Navigate to a specified object. If navigation checks exist and
|
||||
* return reasons to prevent navigation, it will prompt the user before
|
||||
* continuing. Trying to navigate to the currently navigated object will
|
||||
* do nothing.
|
||||
*
|
||||
* If a truthy value is passed for `force`, it will skip navigation
|
||||
* and will not prevent navigation to an already selected object.
|
||||
*
|
||||
* @param {DomainObject} domainObject the domain object to navigate to
|
||||
* @param {Boolean} force if true, force navigation to occur.
|
||||
* @returns {Boolean} true if navigation occurred, otherwise false.
|
||||
*/
|
||||
NavigationService.prototype.setNavigation = function (domainObject, force) {
|
||||
if (force) {
|
||||
this.doNavigation(domainObject);
|
||||
/**
|
||||
* Navigate to a specified object. If navigation checks exist and
|
||||
* return reasons to prevent navigation, it will prompt the user before
|
||||
* continuing. Trying to navigate to the currently navigated object will
|
||||
* do nothing.
|
||||
*
|
||||
* If a truthy value is passed for `force`, it will skip navigation
|
||||
* and will not prevent navigation to an already selected object.
|
||||
*
|
||||
* @param {DomainObject} domainObject the domain object to navigate to
|
||||
* @param {Boolean} force if true, force navigation to occur.
|
||||
* @returns {Boolean} true if navigation occurred, otherwise false.
|
||||
*/
|
||||
NavigationService.prototype.setNavigation = function (domainObject, force) {
|
||||
if (force) {
|
||||
this.doNavigation(domainObject);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.navigated === domainObject) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var doNotNavigate = this.shouldWarnBeforeNavigate();
|
||||
if (doNotNavigate && !this.$window.confirm(doNotNavigate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.doNavigation(domainObject);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Listen for changes in navigation. The passed callback will
|
||||
* be invoked with the new domain object of navigation when
|
||||
* this changes.
|
||||
*
|
||||
* @param {function} callback the callback to invoke when
|
||||
* navigation state changes
|
||||
*/
|
||||
NavigationService.prototype.addListener = function (callback) {
|
||||
this.callbacks.push(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop listening for changes in navigation state.
|
||||
*
|
||||
* @param {function} callback the callback which should
|
||||
* no longer be invoked when navigation state
|
||||
* changes
|
||||
*/
|
||||
NavigationService.prototype.removeListener = function (callback) {
|
||||
this.callbacks = this.callbacks.filter(function (cb) {
|
||||
return cb !== callback;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if navigation should proceed. May prompt a user for input
|
||||
* if any checkFns return messages. Returns true if the user wishes to
|
||||
* navigate, otherwise false. If using this prior to calling
|
||||
* `setNavigation`, you should call `setNavigation` with `force=true`
|
||||
* to prevent duplicate dialogs being displayed to the user.
|
||||
*
|
||||
* @returns {Boolean} true if the user wishes to navigate, otherwise false.
|
||||
*/
|
||||
NavigationService.prototype.shouldNavigate = function () {
|
||||
var doNotNavigate = this.shouldWarnBeforeNavigate();
|
||||
|
||||
return !doNotNavigate || this.$window.confirm(doNotNavigate);
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a check function to be called before any navigation occurs.
|
||||
* Check functions should return a human readable "message" if
|
||||
* there are any reasons to prevent navigation. Otherwise, they should
|
||||
* return falsy. Returns a function which can be called to remove the
|
||||
* check function.
|
||||
*
|
||||
* @param {Function} checkFn a function to call before navigation occurs.
|
||||
* @returns {Function} removeCheck call to remove check
|
||||
*/
|
||||
NavigationService.prototype.checkBeforeNavigation = function (checkFn) {
|
||||
this.checks.push(checkFn);
|
||||
|
||||
return function removeCheck() {
|
||||
this.checks = this.checks.filter(function (fn) {
|
||||
return checkFn !== fn;
|
||||
});
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Private method to actually perform navigation.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
NavigationService.prototype.doNavigation = function (value) {
|
||||
this.navigated = value;
|
||||
this.callbacks.forEach(function (callback) {
|
||||
callback(value);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns either a false value, or a string that should be displayed
|
||||
* to the user before navigation is allowed.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
NavigationService.prototype.shouldWarnBeforeNavigate = function () {
|
||||
var reasons = [];
|
||||
this.checks.forEach(function (checkFn) {
|
||||
var reason = checkFn();
|
||||
if (reason) {
|
||||
reasons.push(reason);
|
||||
}
|
||||
});
|
||||
|
||||
if (reasons.length) {
|
||||
return reasons.join('\n');
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Listener for window on before unload event-- will warn before
|
||||
* navigation is allowed.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
NavigationService.prototype.onBeforeUnload = function () {
|
||||
var shouldWarnBeforeNavigate = this.shouldWarnBeforeNavigate();
|
||||
if (shouldWarnBeforeNavigate) {
|
||||
return shouldWarnBeforeNavigate;
|
||||
}
|
||||
|
||||
if (this.oldUnload) {
|
||||
return this.oldUnload.apply(undefined, [].slice.apply(arguments));
|
||||
}
|
||||
};
|
||||
|
||||
return NavigationService;
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
if (this.navigated === domainObject) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var doNotNavigate = this.shouldWarnBeforeNavigate();
|
||||
if (doNotNavigate && !this.$window.confirm(doNotNavigate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.doNavigation(domainObject);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Listen for changes in navigation. The passed callback will
|
||||
* be invoked with the new domain object of navigation when
|
||||
* this changes.
|
||||
*
|
||||
* @param {function} callback the callback to invoke when
|
||||
* navigation state changes
|
||||
*/
|
||||
NavigationService.prototype.addListener = function (callback) {
|
||||
this.callbacks.push(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop listening for changes in navigation state.
|
||||
*
|
||||
* @param {function} callback the callback which should
|
||||
* no longer be invoked when navigation state
|
||||
* changes
|
||||
*/
|
||||
NavigationService.prototype.removeListener = function (callback) {
|
||||
this.callbacks = this.callbacks.filter(function (cb) {
|
||||
return cb !== callback;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if navigation should proceed. May prompt a user for input
|
||||
* if any checkFns return messages. Returns true if the user wishes to
|
||||
* navigate, otherwise false. If using this prior to calling
|
||||
* `setNavigation`, you should call `setNavigation` with `force=true`
|
||||
* to prevent duplicate dialogs being displayed to the user.
|
||||
*
|
||||
* @returns {Boolean} true if the user wishes to navigate, otherwise false.
|
||||
*/
|
||||
NavigationService.prototype.shouldNavigate = function () {
|
||||
var doNotNavigate = this.shouldWarnBeforeNavigate();
|
||||
|
||||
return !doNotNavigate || this.$window.confirm(doNotNavigate);
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a check function to be called before any navigation occurs.
|
||||
* Check functions should return a human readable "message" if
|
||||
* there are any reasons to prevent navigation. Otherwise, they should
|
||||
* return falsy. Returns a function which can be called to remove the
|
||||
* check function.
|
||||
*
|
||||
* @param {Function} checkFn a function to call before navigation occurs.
|
||||
* @returns {Function} removeCheck call to remove check
|
||||
*/
|
||||
NavigationService.prototype.checkBeforeNavigation = function (checkFn) {
|
||||
this.checks.push(checkFn);
|
||||
|
||||
return function removeCheck() {
|
||||
this.checks = this.checks.filter(function (fn) {
|
||||
return checkFn !== fn;
|
||||
});
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Private method to actually perform navigation.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
NavigationService.prototype.doNavigation = function (value) {
|
||||
this.navigated = value;
|
||||
this.callbacks.forEach(function (callback) {
|
||||
callback(value);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns either a false value, or a string that should be displayed
|
||||
* to the user before navigation is allowed.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
NavigationService.prototype.shouldWarnBeforeNavigate = function () {
|
||||
var reasons = [];
|
||||
this.checks.forEach(function (checkFn) {
|
||||
var reason = checkFn();
|
||||
if (reason) {
|
||||
reasons.push(reason);
|
||||
}
|
||||
});
|
||||
|
||||
if (reasons.length) {
|
||||
return reasons.join('\n');
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Listener for window on before unload event-- will warn before
|
||||
* navigation is allowed.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
NavigationService.prototype.onBeforeUnload = function () {
|
||||
var shouldWarnBeforeNavigate = this.shouldWarnBeforeNavigate();
|
||||
if (shouldWarnBeforeNavigate) {
|
||||
return shouldWarnBeforeNavigate;
|
||||
}
|
||||
|
||||
if (this.oldUnload) {
|
||||
return this.oldUnload.apply(undefined, [].slice.apply(arguments));
|
||||
}
|
||||
};
|
||||
|
||||
export default NavigationService;
|
@ -20,57 +20,63 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([], function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Navigates away from orphan objects whenever they are detected.
|
||||
*
|
||||
* An orphan object is an object whose apparent parent does not
|
||||
* actually contain it. This may occur in certain circumstances, such
|
||||
* as when persistence succeeds for a newly-created object but fails
|
||||
* for its parent.
|
||||
*
|
||||
* @param throttle the `throttle` service
|
||||
* @param topic the `topic` service
|
||||
* @param navigationService the `navigationService`
|
||||
* @constructor
|
||||
*/
|
||||
function OrphanNavigationHandler(throttle, topic, navigationService) {
|
||||
var throttledCheckNavigation;
|
||||
function OrphanNavigationHandler(throttle, topic, navigationService) {
|
||||
var throttledCheckNavigation;
|
||||
|
||||
function getParent(domainObject) {
|
||||
var context = domainObject.getCapability('context');
|
||||
function getParent(domainObject) {
|
||||
var context = domainObject.getCapability('context');
|
||||
|
||||
return context.getParent();
|
||||
}
|
||||
|
||||
function preventOrphanNavigation(domainObject) {
|
||||
var parent = getParent(domainObject);
|
||||
parent.useCapability('composition')
|
||||
.then(function (composees) {
|
||||
var isOrphan = composees.every(function (c) {
|
||||
return c.getId() !== domainObject.getId();
|
||||
});
|
||||
if (isOrphan) {
|
||||
parent.getCapability('action').perform('navigate');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkNavigation() {
|
||||
var navigatedObject = navigationService.getNavigation();
|
||||
if (navigatedObject && navigatedObject.hasCapability('context')) {
|
||||
if (!navigatedObject.getCapability('editor').isEditContextRoot()) {
|
||||
preventOrphanNavigation(navigatedObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throttledCheckNavigation = throttle(checkNavigation);
|
||||
|
||||
navigationService.addListener(throttledCheckNavigation);
|
||||
topic('mutation').listen(throttledCheckNavigation);
|
||||
return context.getParent();
|
||||
}
|
||||
|
||||
return OrphanNavigationHandler;
|
||||
});
|
||||
function preventOrphanNavigation(domainObject) {
|
||||
var parent = getParent(domainObject);
|
||||
parent.useCapability('composition')
|
||||
.then(function (composees) {
|
||||
var isOrphan = composees.every(function (c) {
|
||||
return c.getId() !== domainObject.getId();
|
||||
});
|
||||
if (isOrphan) {
|
||||
parent.getCapability('action').perform('navigate');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkNavigation() {
|
||||
var navigatedObject = navigationService.getNavigation();
|
||||
if (navigatedObject && navigatedObject.hasCapability('context')) {
|
||||
if (!navigatedObject.getCapability('editor').isEditContextRoot()) {
|
||||
preventOrphanNavigation(navigatedObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throttledCheckNavigation = throttle(checkNavigation);
|
||||
|
||||
navigationService.addListener(throttledCheckNavigation);
|
||||
topic('mutation').listen(throttledCheckNavigation);
|
||||
}
|
||||
|
||||
export default OrphanNavigationHandler;
|
@ -23,21 +23,42 @@
|
||||
/**
|
||||
* MCTIncudeSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
define(
|
||||
["../src/InspectorRegion"],
|
||||
function (InspectorRegion) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The inspector region", function () {
|
||||
var inspectorRegion;
|
||||
/**
|
||||
* MCTIncudeSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
import InspectorRegion from '../src/InspectorRegion';
|
||||
|
||||
beforeEach(function () {
|
||||
inspectorRegion = new InspectorRegion();
|
||||
});
|
||||
describe("The inspector region", function () {
|
||||
var inspectorRegion;
|
||||
|
||||
it("creates default region parts", function () {
|
||||
expect(inspectorRegion.regions.length).toBe(1);
|
||||
});
|
||||
beforeEach(function () {
|
||||
inspectorRegion = new InspectorRegion();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
it("creates default region parts", function () {
|
||||
expect(inspectorRegion.regions.length).toBe(1);
|
||||
});
|
||||
|
||||
});
|
@ -23,63 +23,83 @@
|
||||
/**
|
||||
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
define([
|
||||
"../../src/navigation/NavigateAction"
|
||||
], function (
|
||||
NavigateAction
|
||||
) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The navigate action", function () {
|
||||
var mockNavigationService,
|
||||
mockDomainObject,
|
||||
action;
|
||||
/**
|
||||
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
import NavigateAction from '../../src/navigation/NavigateAction';
|
||||
|
||||
beforeEach(function () {
|
||||
mockNavigationService = jasmine.createSpyObj(
|
||||
"navigationService",
|
||||
[
|
||||
"shouldNavigate",
|
||||
"setNavigation"
|
||||
]
|
||||
);
|
||||
describe("The navigate action", function () {
|
||||
var mockNavigationService,
|
||||
mockDomainObject,
|
||||
action;
|
||||
|
||||
mockDomainObject = {};
|
||||
beforeEach(function () {
|
||||
mockNavigationService = jasmine.createSpyObj(
|
||||
"navigationService",
|
||||
[
|
||||
"shouldNavigate",
|
||||
"setNavigation"
|
||||
]
|
||||
);
|
||||
|
||||
action = new NavigateAction(
|
||||
mockNavigationService,
|
||||
{ domainObject: mockDomainObject }
|
||||
);
|
||||
});
|
||||
|
||||
it("sets navigation if it is allowed", function () {
|
||||
mockNavigationService.shouldNavigate.and.returnValue(true);
|
||||
|
||||
return action.perform()
|
||||
.then(function () {
|
||||
expect(mockNavigationService.setNavigation)
|
||||
.toHaveBeenCalledWith(mockDomainObject, true);
|
||||
});
|
||||
});
|
||||
|
||||
it("does not set navigation if it is not allowed", function () {
|
||||
mockNavigationService.shouldNavigate.and.returnValue(false);
|
||||
var onSuccess = jasmine.createSpy('onSuccess');
|
||||
|
||||
return action.perform()
|
||||
.then(onSuccess, function () {
|
||||
expect(onSuccess).not.toHaveBeenCalled();
|
||||
expect(mockNavigationService.setNavigation)
|
||||
.not
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
});
|
||||
|
||||
it("is only applicable when a domain object is in context", function () {
|
||||
expect(NavigateAction.appliesTo({})).toBeFalsy();
|
||||
expect(NavigateAction.appliesTo({
|
||||
domainObject: mockDomainObject
|
||||
})).toBeTruthy();
|
||||
});
|
||||
mockDomainObject = {};
|
||||
|
||||
action = new NavigateAction(
|
||||
mockNavigationService,
|
||||
{ domainObject: mockDomainObject }
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("sets navigation if it is allowed", function () {
|
||||
mockNavigationService.shouldNavigate.and.returnValue(true);
|
||||
|
||||
return action.perform()
|
||||
.then(function () {
|
||||
expect(mockNavigationService.setNavigation)
|
||||
.toHaveBeenCalledWith(mockDomainObject, true);
|
||||
});
|
||||
});
|
||||
|
||||
it("does not set navigation if it is not allowed", function () {
|
||||
mockNavigationService.shouldNavigate.and.returnValue(false);
|
||||
var onSuccess = jasmine.createSpy('onSuccess');
|
||||
|
||||
return action.perform()
|
||||
.then(onSuccess, function () {
|
||||
expect(onSuccess).not.toHaveBeenCalled();
|
||||
expect(mockNavigationService.setNavigation)
|
||||
.not
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
});
|
||||
|
||||
it("is only applicable when a domain object is in context", function () {
|
||||
expect(NavigateAction.appliesTo({})).toBeFalsy();
|
||||
expect(NavigateAction.appliesTo({
|
||||
domainObject: mockDomainObject
|
||||
})).toBeTruthy();
|
||||
});
|
||||
|
||||
});
|
@ -23,66 +23,87 @@
|
||||
/**
|
||||
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
define(
|
||||
["../../src/navigation/NavigationService"],
|
||||
function (NavigationService) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The navigation service", function () {
|
||||
var $window,
|
||||
navigationService;
|
||||
/**
|
||||
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
import NavigationService from '../../src/navigation/NavigationService';
|
||||
|
||||
beforeEach(function () {
|
||||
$window = jasmine.createSpyObj('$window', ['confirm']);
|
||||
navigationService = new NavigationService($window);
|
||||
});
|
||||
describe("The navigation service", function () {
|
||||
var $window,
|
||||
navigationService;
|
||||
|
||||
it("stores navigation state", function () {
|
||||
var testObject = { someKey: 42 },
|
||||
otherObject = { someKey: "some value" };
|
||||
expect(navigationService.getNavigation())
|
||||
.toBeUndefined();
|
||||
navigationService.setNavigation(testObject);
|
||||
expect(navigationService.getNavigation())
|
||||
.toBe(testObject);
|
||||
expect(navigationService.getNavigation())
|
||||
.toBe(testObject);
|
||||
navigationService.setNavigation(otherObject);
|
||||
expect(navigationService.getNavigation())
|
||||
.toBe(otherObject);
|
||||
});
|
||||
beforeEach(function () {
|
||||
$window = jasmine.createSpyObj('$window', ['confirm']);
|
||||
navigationService = new NavigationService($window);
|
||||
});
|
||||
|
||||
it("notifies listeners on change", function () {
|
||||
var testObject = { someKey: 42 },
|
||||
callback = jasmine.createSpy("callback");
|
||||
it("stores navigation state", function () {
|
||||
var testObject = { someKey: 42 },
|
||||
otherObject = { someKey: "some value" };
|
||||
expect(navigationService.getNavigation())
|
||||
.toBeUndefined();
|
||||
navigationService.setNavigation(testObject);
|
||||
expect(navigationService.getNavigation())
|
||||
.toBe(testObject);
|
||||
expect(navigationService.getNavigation())
|
||||
.toBe(testObject);
|
||||
navigationService.setNavigation(otherObject);
|
||||
expect(navigationService.getNavigation())
|
||||
.toBe(otherObject);
|
||||
});
|
||||
|
||||
navigationService.addListener(callback);
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
it("notifies listeners on change", function () {
|
||||
var testObject = { someKey: 42 },
|
||||
callback = jasmine.createSpy("callback");
|
||||
|
||||
navigationService.setNavigation(testObject);
|
||||
expect(callback).toHaveBeenCalledWith(testObject);
|
||||
});
|
||||
navigationService.addListener(callback);
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
|
||||
it("does not notify listeners when no changes occur", function () {
|
||||
var testObject = { someKey: 42 },
|
||||
callback = jasmine.createSpy("callback");
|
||||
navigationService.setNavigation(testObject);
|
||||
expect(callback).toHaveBeenCalledWith(testObject);
|
||||
});
|
||||
|
||||
navigationService.addListener(callback);
|
||||
navigationService.setNavigation(testObject);
|
||||
navigationService.setNavigation(testObject);
|
||||
expect(callback.calls.count()).toEqual(1);
|
||||
});
|
||||
it("does not notify listeners when no changes occur", function () {
|
||||
var testObject = { someKey: 42 },
|
||||
callback = jasmine.createSpy("callback");
|
||||
|
||||
it("stops notifying listeners after removal", function () {
|
||||
var testObject = { someKey: 42 },
|
||||
callback = jasmine.createSpy("callback");
|
||||
navigationService.addListener(callback);
|
||||
navigationService.setNavigation(testObject);
|
||||
navigationService.setNavigation(testObject);
|
||||
expect(callback.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
navigationService.addListener(callback);
|
||||
navigationService.removeListener(callback);
|
||||
it("stops notifying listeners after removal", function () {
|
||||
var testObject = { someKey: 42 },
|
||||
callback = jasmine.createSpy("callback");
|
||||
|
||||
navigationService.setNavigation(testObject);
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
});
|
||||
navigationService.addListener(callback);
|
||||
navigationService.removeListener(callback);
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
navigationService.setNavigation(testObject);
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
@ -20,163 +20,182 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'../../src/navigation/OrphanNavigationHandler'
|
||||
], function (OrphanNavigationHandler) {
|
||||
describe("OrphanNavigationHandler", function () {
|
||||
var mockTopic,
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
import OrphanNavigationHandler from '../../src/navigation/OrphanNavigationHandler';
|
||||
|
||||
describe("OrphanNavigationHandler", function () {
|
||||
var mockTopic,
|
||||
mockThrottle,
|
||||
mockMutationTopic,
|
||||
mockNavigationService,
|
||||
mockDomainObject,
|
||||
mockParentObject,
|
||||
mockContext,
|
||||
mockActionCapability,
|
||||
mockEditor,
|
||||
testParentComposition,
|
||||
testId,
|
||||
mockThrottledFns;
|
||||
|
||||
beforeEach(function () {
|
||||
testId = 'some-identifier';
|
||||
|
||||
mockThrottledFns = [];
|
||||
|
||||
mockTopic = jasmine.createSpy('topic');
|
||||
mockThrottle = jasmine.createSpy('throttle');
|
||||
mockNavigationService = jasmine.createSpyObj('navigationService', [
|
||||
'getNavigation',
|
||||
'addListener'
|
||||
]);
|
||||
mockMutationTopic = jasmine.createSpyObj('mutationTopic', [
|
||||
'listen'
|
||||
]);
|
||||
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
||||
'getId',
|
||||
'getCapability',
|
||||
'hasCapability'
|
||||
]);
|
||||
mockParentObject = jasmine.createSpyObj('domainObject', [
|
||||
'getId',
|
||||
'getCapability',
|
||||
'useCapability'
|
||||
]);
|
||||
mockContext = jasmine.createSpyObj('context', ['getParent']);
|
||||
mockActionCapability = jasmine.createSpyObj('action', ['perform']);
|
||||
mockEditor = jasmine.createSpyObj('editor', ['isEditContextRoot']);
|
||||
|
||||
mockThrottle.and.callFake(function (fn) {
|
||||
var mockThrottledFn =
|
||||
jasmine.createSpy('throttled-' + mockThrottledFns.length);
|
||||
mockThrottledFn.and.callFake(fn);
|
||||
mockThrottledFns.push(mockThrottledFn);
|
||||
|
||||
return mockThrottledFn;
|
||||
});
|
||||
mockTopic.and.returnValue(mockMutationTopic);
|
||||
mockDomainObject.getId.and.returnValue(testId);
|
||||
mockDomainObject.getCapability.and.callFake(function (c) {
|
||||
return {
|
||||
context: mockContext,
|
||||
editor: mockEditor
|
||||
}[c];
|
||||
});
|
||||
mockDomainObject.hasCapability.and.callFake(function (c) {
|
||||
return Boolean(mockDomainObject.getCapability(c));
|
||||
});
|
||||
mockParentObject.getCapability.and.callFake(function (c) {
|
||||
return {
|
||||
action: mockActionCapability
|
||||
}[c];
|
||||
});
|
||||
testParentComposition = [];
|
||||
mockParentObject.useCapability.and.returnValue(Promise.resolve(testParentComposition));
|
||||
|
||||
mockContext.getParent.and.returnValue(mockParentObject);
|
||||
mockNavigationService.getNavigation.and.returnValue(mockDomainObject);
|
||||
mockEditor.isEditContextRoot.and.returnValue(false);
|
||||
|
||||
return new OrphanNavigationHandler(
|
||||
mockThrottle,
|
||||
mockMutationTopic,
|
||||
mockNavigationService,
|
||||
mockDomainObject,
|
||||
mockParentObject,
|
||||
mockContext,
|
||||
mockActionCapability,
|
||||
mockEditor,
|
||||
testParentComposition,
|
||||
testId,
|
||||
mockThrottledFns;
|
||||
|
||||
beforeEach(function () {
|
||||
testId = 'some-identifier';
|
||||
|
||||
mockThrottledFns = [];
|
||||
|
||||
mockTopic = jasmine.createSpy('topic');
|
||||
mockThrottle = jasmine.createSpy('throttle');
|
||||
mockNavigationService = jasmine.createSpyObj('navigationService', [
|
||||
'getNavigation',
|
||||
'addListener'
|
||||
]);
|
||||
mockMutationTopic = jasmine.createSpyObj('mutationTopic', [
|
||||
'listen'
|
||||
]);
|
||||
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
||||
'getId',
|
||||
'getCapability',
|
||||
'hasCapability'
|
||||
]);
|
||||
mockParentObject = jasmine.createSpyObj('domainObject', [
|
||||
'getId',
|
||||
'getCapability',
|
||||
'useCapability'
|
||||
]);
|
||||
mockContext = jasmine.createSpyObj('context', ['getParent']);
|
||||
mockActionCapability = jasmine.createSpyObj('action', ['perform']);
|
||||
mockEditor = jasmine.createSpyObj('editor', ['isEditContextRoot']);
|
||||
|
||||
mockThrottle.and.callFake(function (fn) {
|
||||
var mockThrottledFn =
|
||||
jasmine.createSpy('throttled-' + mockThrottledFns.length);
|
||||
mockThrottledFn.and.callFake(fn);
|
||||
mockThrottledFns.push(mockThrottledFn);
|
||||
|
||||
return mockThrottledFn;
|
||||
});
|
||||
mockTopic.and.returnValue(mockMutationTopic);
|
||||
mockDomainObject.getId.and.returnValue(testId);
|
||||
mockDomainObject.getCapability.and.callFake(function (c) {
|
||||
return {
|
||||
context: mockContext,
|
||||
editor: mockEditor
|
||||
}[c];
|
||||
});
|
||||
mockDomainObject.hasCapability.and.callFake(function (c) {
|
||||
return Boolean(mockDomainObject.getCapability(c));
|
||||
});
|
||||
mockParentObject.getCapability.and.callFake(function (c) {
|
||||
return {
|
||||
action: mockActionCapability
|
||||
}[c];
|
||||
});
|
||||
testParentComposition = [];
|
||||
mockParentObject.useCapability.and.returnValue(Promise.resolve(testParentComposition));
|
||||
|
||||
mockContext.getParent.and.returnValue(mockParentObject);
|
||||
mockNavigationService.getNavigation.and.returnValue(mockDomainObject);
|
||||
mockEditor.isEditContextRoot.and.returnValue(false);
|
||||
|
||||
return new OrphanNavigationHandler(
|
||||
mockThrottle,
|
||||
mockTopic,
|
||||
mockNavigationService
|
||||
);
|
||||
});
|
||||
|
||||
it("listens for mutation with a throttled function", function () {
|
||||
expect(mockMutationTopic.listen)
|
||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||
expect(mockThrottledFns.indexOf(
|
||||
mockMutationTopic.listen.calls.mostRecent().args[0]
|
||||
)).not.toEqual(-1);
|
||||
});
|
||||
|
||||
it("listens for navigation changes with a throttled function", function () {
|
||||
expect(mockNavigationService.addListener)
|
||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||
expect(mockThrottledFns.indexOf(
|
||||
mockNavigationService.addListener.calls.mostRecent().args[0]
|
||||
)).not.toEqual(-1);
|
||||
});
|
||||
|
||||
[false, true].forEach(function (isOrphan) {
|
||||
var prefix = isOrphan ? "" : "non-";
|
||||
describe("for " + prefix + "orphan objects", function () {
|
||||
beforeEach(function () {
|
||||
if (!isOrphan) {
|
||||
testParentComposition.push(mockDomainObject);
|
||||
}
|
||||
});
|
||||
|
||||
[false, true].forEach(function (isEditRoot) {
|
||||
var caseName = isEditRoot
|
||||
? "that are being edited" : "that are not being edited";
|
||||
|
||||
function itNavigatesAsExpected() {
|
||||
if (isOrphan && !isEditRoot) {
|
||||
it("navigates to the parent", function () {
|
||||
return Promise.resolve().then(function () {
|
||||
expect(mockActionCapability.perform)
|
||||
.toHaveBeenCalledWith('navigate');
|
||||
});
|
||||
});
|
||||
} else {
|
||||
it("does nothing", function () {
|
||||
return Promise.resolve().then(function () {
|
||||
expect(mockActionCapability.perform)
|
||||
.not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
describe(caseName, function () {
|
||||
beforeEach(function () {
|
||||
mockEditor.isEditContextRoot.and.returnValue(isEditRoot);
|
||||
});
|
||||
|
||||
describe("when navigation changes", function () {
|
||||
beforeEach(function () {
|
||||
mockNavigationService.addListener.calls.mostRecent()
|
||||
.args[0](mockDomainObject);
|
||||
});
|
||||
itNavigatesAsExpected();
|
||||
});
|
||||
|
||||
describe("when mutation occurs", function () {
|
||||
beforeEach(function () {
|
||||
mockMutationTopic.listen.calls.mostRecent()
|
||||
.args[0](mockParentObject);
|
||||
});
|
||||
|
||||
itNavigatesAsExpected();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
mockTopic,
|
||||
mockNavigationService
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("listens for mutation with a throttled function", function () {
|
||||
expect(mockMutationTopic.listen)
|
||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||
expect(mockThrottledFns.indexOf(
|
||||
mockMutationTopic.listen.calls.mostRecent().args[0]
|
||||
)).not.toEqual(-1);
|
||||
});
|
||||
|
||||
it("listens for navigation changes with a throttled function", function () {
|
||||
expect(mockNavigationService.addListener)
|
||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||
expect(mockThrottledFns.indexOf(
|
||||
mockNavigationService.addListener.calls.mostRecent().args[0]
|
||||
)).not.toEqual(-1);
|
||||
});
|
||||
|
||||
[false, true].forEach(function (isOrphan) {
|
||||
var prefix = isOrphan ? "" : "non-";
|
||||
describe("for " + prefix + "orphan objects", function () {
|
||||
beforeEach(function () {
|
||||
if (!isOrphan) {
|
||||
testParentComposition.push(mockDomainObject);
|
||||
}
|
||||
});
|
||||
|
||||
[false, true].forEach(function (isEditRoot) {
|
||||
var caseName = isEditRoot
|
||||
? "that are being edited" : "that are not being edited";
|
||||
|
||||
function itNavigatesAsExpected() {
|
||||
if (isOrphan && !isEditRoot) {
|
||||
it("navigates to the parent", function () {
|
||||
return Promise.resolve().then(function () {
|
||||
expect(mockActionCapability.perform)
|
||||
.toHaveBeenCalledWith('navigate');
|
||||
});
|
||||
});
|
||||
} else {
|
||||
it("does nothing", function () {
|
||||
return Promise.resolve().then(function () {
|
||||
expect(mockActionCapability.perform)
|
||||
.not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
describe(caseName, function () {
|
||||
beforeEach(function () {
|
||||
mockEditor.isEditContextRoot.and.returnValue(isEditRoot);
|
||||
});
|
||||
|
||||
describe("when navigation changes", function () {
|
||||
beforeEach(function () {
|
||||
mockNavigationService.addListener.calls.mostRecent()
|
||||
.args[0](mockDomainObject);
|
||||
});
|
||||
itNavigatesAsExpected();
|
||||
});
|
||||
|
||||
describe("when mutation occurs", function () {
|
||||
beforeEach(function () {
|
||||
mockMutationTopic.listen.calls.mostRecent()
|
||||
.args[0](mockParentObject);
|
||||
});
|
||||
|
||||
itNavigatesAsExpected();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -20,93 +20,102 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/DialogService",
|
||||
"./src/OverlayService",
|
||||
"./res/templates/overlay-dialog.html",
|
||||
"./res/templates/overlay-options.html",
|
||||
"./res/templates/dialog.html",
|
||||
"./res/templates/overlay-blocking-message.html",
|
||||
"./res/templates/message.html",
|
||||
"./res/templates/notification-message.html",
|
||||
"./res/templates/overlay-message-list.html",
|
||||
"./res/templates/overlay.html"
|
||||
], function (
|
||||
DialogService,
|
||||
OverlayService,
|
||||
overlayDialogTemplate,
|
||||
overlayOptionsTemplate,
|
||||
dialogTemplate,
|
||||
overlayBlockingMessageTemplate,
|
||||
messageTemplate,
|
||||
notificationMessageTemplate,
|
||||
overlayMessageListTemplate,
|
||||
overlayTemplate
|
||||
) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "platform/commonUI/dialog",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"services": [
|
||||
{
|
||||
"key": "dialogService",
|
||||
"implementation": DialogService,
|
||||
"depends": [
|
||||
"overlayService",
|
||||
"$q",
|
||||
"$log",
|
||||
"$document"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "overlayService",
|
||||
"implementation": OverlayService,
|
||||
"depends": [
|
||||
"$document",
|
||||
"$compile",
|
||||
"$rootScope",
|
||||
"$timeout"
|
||||
]
|
||||
}
|
||||
],
|
||||
"templates": [
|
||||
{
|
||||
"key": "overlay-dialog",
|
||||
"template": overlayDialogTemplate
|
||||
},
|
||||
{
|
||||
"key": "overlay-options",
|
||||
"template": overlayOptionsTemplate
|
||||
},
|
||||
{
|
||||
"key": "form-dialog",
|
||||
"template": dialogTemplate
|
||||
},
|
||||
{
|
||||
"key": "overlay-blocking-message",
|
||||
"template": overlayBlockingMessageTemplate
|
||||
},
|
||||
{
|
||||
"key": "message",
|
||||
"template": messageTemplate
|
||||
},
|
||||
{
|
||||
"key": "notification-message",
|
||||
"template": notificationMessageTemplate
|
||||
},
|
||||
{
|
||||
"key": "overlay-message-list",
|
||||
"template": overlayMessageListTemplate
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
{
|
||||
"key": "overlay",
|
||||
"template": overlayTemplate
|
||||
}
|
||||
]
|
||||
}
|
||||
import DialogService from './src/DialogService';
|
||||
|
||||
import OverlayService from './src/OverlayService';
|
||||
import overlayDialogTemplate from './res/templates/overlay-dialog.html';
|
||||
import overlayOptionsTemplate from './res/templates/overlay-options.html';
|
||||
import dialogTemplate from './res/templates/dialog.html';
|
||||
import overlayBlockingMessageTemplate from './res/templates/overlay-blocking-message.html';
|
||||
import messageTemplate from './res/templates/message.html';
|
||||
import notificationMessageTemplate from './res/templates/notification-message.html';
|
||||
import overlayMessageListTemplate from './res/templates/overlay-message-list.html';
|
||||
import overlayTemplate from './res/templates/overlay.html';
|
||||
|
||||
export default {
|
||||
name: "platform/commonUI/dialog",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"services": [
|
||||
{
|
||||
"key": "dialogService",
|
||||
"implementation": DialogService,
|
||||
"depends": [
|
||||
"overlayService",
|
||||
"$q",
|
||||
"$log",
|
||||
"$document"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "overlayService",
|
||||
"implementation": OverlayService,
|
||||
"depends": [
|
||||
"$document",
|
||||
"$compile",
|
||||
"$rootScope",
|
||||
"$timeout"
|
||||
]
|
||||
}
|
||||
],
|
||||
"templates": [
|
||||
{
|
||||
"key": "overlay-dialog",
|
||||
"template": overlayDialogTemplate
|
||||
},
|
||||
{
|
||||
"key": "overlay-options",
|
||||
"template": overlayOptionsTemplate
|
||||
},
|
||||
{
|
||||
"key": "form-dialog",
|
||||
"template": dialogTemplate
|
||||
},
|
||||
{
|
||||
"key": "overlay-blocking-message",
|
||||
"template": overlayBlockingMessageTemplate
|
||||
},
|
||||
{
|
||||
"key": "message",
|
||||
"template": messageTemplate
|
||||
},
|
||||
{
|
||||
"key": "notification-message",
|
||||
"template": notificationMessageTemplate
|
||||
},
|
||||
{
|
||||
"key": "overlay-message-list",
|
||||
"template": overlayMessageListTemplate
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
{
|
||||
"key": "overlay",
|
||||
"template": overlayTemplate
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -25,247 +25,262 @@
|
||||
* launch dialogs for user input & notifications.
|
||||
* @namespace platform/commonUI/dialog
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/**
|
||||
* The dialog service is responsible for handling window-modal
|
||||
* communication with the user, such as displaying forms for user
|
||||
* input.
|
||||
* @memberof platform/commonUI/dialog
|
||||
* @constructor
|
||||
*/
|
||||
function DialogService(overlayService, $q, $log, $document) {
|
||||
this.overlayService = overlayService;
|
||||
this.$q = $q;
|
||||
this.$log = $log;
|
||||
this.activeOverlay = undefined;
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
this.findBody = function () {
|
||||
return $document.find('body');
|
||||
};
|
||||
}
|
||||
/**
|
||||
* This bundle implements the dialog service, which can be used to
|
||||
* launch dialogs for user input & notifications.
|
||||
* @namespace platform/commonUI/dialog
|
||||
*/
|
||||
function DialogService(overlayService, $q, $log, $document) {
|
||||
this.overlayService = overlayService;
|
||||
this.$q = $q;
|
||||
this.$log = $log;
|
||||
this.activeOverlay = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
DialogService.prototype.dismissOverlay = function (overlay) {
|
||||
//Dismiss the overlay
|
||||
overlay.dismiss();
|
||||
this.findBody = function () {
|
||||
return $document.find('body');
|
||||
};
|
||||
}
|
||||
|
||||
//If dialog is the current active one, dismiss it
|
||||
if (overlay === this.activeOverlay) {
|
||||
this.activeOverlay = undefined;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
DialogService.prototype.dismissOverlay = function (overlay) {
|
||||
//Dismiss the overlay
|
||||
overlay.dismiss();
|
||||
|
||||
DialogService.prototype.getDialogResponse = function (key, model, resultGetter, typeClass) {
|
||||
// We will return this result as a promise, because user
|
||||
// input is asynchronous.
|
||||
var deferred = this.$q.defer(),
|
||||
self = this,
|
||||
overlay,
|
||||
handleEscKeydown;
|
||||
|
||||
// Confirm function; this will be passed in to the
|
||||
// overlay-dialog template and associated with a
|
||||
// OK button click
|
||||
function confirm(value) {
|
||||
// Pass along the result
|
||||
deferred.resolve(resultGetter ? resultGetter() : value);
|
||||
self.dismissOverlay(overlay);
|
||||
}
|
||||
|
||||
// Cancel function; this will be passed in to the
|
||||
// overlay-dialog template and associated with a
|
||||
// Cancel or X button click
|
||||
function cancel() {
|
||||
deferred.reject();
|
||||
self.findBody().off('keydown', handleEscKeydown);
|
||||
self.dismissOverlay(overlay);
|
||||
}
|
||||
|
||||
handleEscKeydown = function (event) {
|
||||
if (event.keyCode === 27) {
|
||||
cancel();
|
||||
}
|
||||
};
|
||||
|
||||
// Add confirm/cancel callbacks
|
||||
model.confirm = confirm;
|
||||
model.cancel = cancel;
|
||||
|
||||
this.findBody().on('keydown', handleEscKeydown);
|
||||
|
||||
if (this.canShowDialog(model)) {
|
||||
// Add the overlay using the OverlayService, which
|
||||
// will handle actual insertion into the DOM
|
||||
overlay = this.activeOverlay = this.overlayService.createOverlay(
|
||||
key,
|
||||
model,
|
||||
typeClass || "t-dialog"
|
||||
);
|
||||
} else {
|
||||
deferred.reject();
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Request user input via a window-modal dialog.
|
||||
*
|
||||
* @param {FormModel} formModel a description of the form
|
||||
* to be shown (see platform/forms)
|
||||
* @param {object} value the initial state of the form
|
||||
* @returns {Promise} a promise for the form value that the
|
||||
* user has supplied; this may be rejected if
|
||||
* user input cannot be obtained (for instance,
|
||||
* because the user cancelled the dialog)
|
||||
*/
|
||||
DialogService.prototype.getUserInput = function (formModel, value) {
|
||||
var overlayModel = {
|
||||
title: formModel.name,
|
||||
message: formModel.message,
|
||||
structure: formModel,
|
||||
value: value
|
||||
};
|
||||
|
||||
// Provide result from the model
|
||||
function resultGetter() {
|
||||
return overlayModel.value;
|
||||
}
|
||||
|
||||
// Show the overlay-dialog
|
||||
return this.getDialogResponse(
|
||||
"overlay-dialog",
|
||||
overlayModel,
|
||||
resultGetter
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Request that the user chooses from a set of options,
|
||||
* which will be shown as buttons.
|
||||
*
|
||||
* @param dialogModel a description of the dialog to show
|
||||
* @return {Promise} a promise for the user's choice
|
||||
*/
|
||||
DialogService.prototype.getUserChoice = function (dialogModel) {
|
||||
// Show the overlay-options dialog
|
||||
return this.getDialogResponse(
|
||||
"overlay-options",
|
||||
{ dialog: dialogModel }
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests if a dialog can be displayed. A modal dialog may only be
|
||||
* displayed if one is not already visible.
|
||||
* Will log a warning message if it can't display a dialog.
|
||||
* @returns {boolean} true if dialog is currently visible, false
|
||||
* otherwise
|
||||
*/
|
||||
DialogService.prototype.canShowDialog = function (dialogModel) {
|
||||
if (this.activeOverlay) {
|
||||
// Only one dialog should be shown at a time.
|
||||
// The application design should be such that
|
||||
// we never even try to do this.
|
||||
this.$log.warn([
|
||||
"Dialog already showing; ",
|
||||
"unable to show ",
|
||||
dialogModel.title
|
||||
].join(""));
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A user action that can be performed from a blocking dialog. These
|
||||
* actions will be rendered as buttons within a blocking dialog.
|
||||
*
|
||||
* @typedef DialogOption
|
||||
* @property {string} label a label to be displayed as the button
|
||||
* text for this action
|
||||
* @property {function} callback a function to be called when the
|
||||
* button is clicked
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef DialogHandle
|
||||
* @property {function} dismiss a function to dismiss the given dialog
|
||||
*/
|
||||
|
||||
/**
|
||||
* A description of the model options that may be passed to the
|
||||
* showBlockingMessage method. Note that the DialogModel described
|
||||
* here is shared with the Notifications framework.
|
||||
* @see NotificationService
|
||||
*
|
||||
* @typedef DialogModel
|
||||
* @property {string} title the title to use for the dialog
|
||||
* @property {string} severity the severity level of this message.
|
||||
* These are defined in a bundle constant with key 'dialogSeverity'
|
||||
* @property {string} hint the 'hint' message to show below the title
|
||||
* @property {string} actionText text that indicates a current action,
|
||||
* shown above a progress bar to indicate what's happening.
|
||||
* @property {number} progress a percentage value (1-100)
|
||||
* indicating the completion of the blocking task
|
||||
* @property {boolean} delay adds a brief delay before loading
|
||||
* the dialog. Useful for removing the dialog flicker when the
|
||||
* conditions for displaying the dialog change rapidly.
|
||||
* @property {string} progressText the message to show below a
|
||||
* progress bar to indicate progress. For example, this might be
|
||||
* used to indicate time remaining, or items still to process.
|
||||
* @property {boolean} unknownProgress some tasks may be
|
||||
* impossible to provide an estimate for. Providing a true value for
|
||||
* this attribute will indicate to the user that the progress and
|
||||
* duration cannot be estimated.
|
||||
* @property {DialogOption} primaryOption an action that will
|
||||
* be added to the dialog as a button. The primary action can be
|
||||
* used as the suggested course of action for the user. Making it
|
||||
* distinct from other actions allows it to be styled differently,
|
||||
* and treated preferentially in banner mode.
|
||||
* @property {DialogOption[]} options a list of actions that will
|
||||
* be added to the dialog as buttons.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Displays a blocking (modal) dialog. This dialog can be used for
|
||||
* displaying messages that require the user's
|
||||
* immediate attention. The message may include an indication of
|
||||
* progress, as well as a series of actions that
|
||||
* the user can take if necessary
|
||||
* @param {DialogModel} dialogModel defines options for the dialog
|
||||
* @param {typeClass} string tells overlayService that this overlay should use appropriate CSS class
|
||||
* @returns {boolean | {DialogHandle}}
|
||||
*/
|
||||
DialogService.prototype.showBlockingMessage = function (dialogModel) {
|
||||
if (this.canShowDialog(dialogModel)) {
|
||||
// Add the overlay using the OverlayService, which
|
||||
// will handle actual insertion into the DOM
|
||||
var self = this,
|
||||
overlay = this.overlayService.createOverlay(
|
||||
"overlay-blocking-message",
|
||||
dialogModel,
|
||||
"t-dialog-sm"
|
||||
);
|
||||
|
||||
this.activeOverlay = overlay;
|
||||
|
||||
return {
|
||||
dismiss: function () {
|
||||
self.dismissOverlay(overlay);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return DialogService;
|
||||
//If dialog is the current active one, dismiss it
|
||||
if (overlay === this.activeOverlay) {
|
||||
this.activeOverlay = undefined;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
DialogService.prototype.getDialogResponse = function (key, model, resultGetter, typeClass) {
|
||||
// We will return this result as a promise, because user
|
||||
// input is asynchronous.
|
||||
var deferred = this.$q.defer(),
|
||||
self = this,
|
||||
overlay,
|
||||
handleEscKeydown;
|
||||
|
||||
// Confirm function; this will be passed in to the
|
||||
// overlay-dialog template and associated with a
|
||||
// OK button click
|
||||
function confirm(value) {
|
||||
// Pass along the result
|
||||
deferred.resolve(resultGetter ? resultGetter() : value);
|
||||
self.dismissOverlay(overlay);
|
||||
}
|
||||
|
||||
// Cancel function; this will be passed in to the
|
||||
// overlay-dialog template and associated with a
|
||||
// Cancel or X button click
|
||||
function cancel() {
|
||||
deferred.reject();
|
||||
self.findBody().off('keydown', handleEscKeydown);
|
||||
self.dismissOverlay(overlay);
|
||||
}
|
||||
|
||||
handleEscKeydown = function (event) {
|
||||
if (event.keyCode === 27) {
|
||||
cancel();
|
||||
}
|
||||
};
|
||||
|
||||
// Add confirm/cancel callbacks
|
||||
model.confirm = confirm;
|
||||
model.cancel = cancel;
|
||||
|
||||
this.findBody().on('keydown', handleEscKeydown);
|
||||
|
||||
if (this.canShowDialog(model)) {
|
||||
// Add the overlay using the OverlayService, which
|
||||
// will handle actual insertion into the DOM
|
||||
overlay = this.activeOverlay = this.overlayService.createOverlay(
|
||||
key,
|
||||
model,
|
||||
typeClass || "t-dialog"
|
||||
);
|
||||
} else {
|
||||
deferred.reject();
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Request user input via a window-modal dialog.
|
||||
*
|
||||
* @param {FormModel} formModel a description of the form
|
||||
* to be shown (see platform/forms)
|
||||
* @param {object} value the initial state of the form
|
||||
* @returns {Promise} a promise for the form value that the
|
||||
* user has supplied; this may be rejected if
|
||||
* user input cannot be obtained (for instance,
|
||||
* because the user cancelled the dialog)
|
||||
*/
|
||||
DialogService.prototype.getUserInput = function (formModel, value) {
|
||||
var overlayModel = {
|
||||
title: formModel.name,
|
||||
message: formModel.message,
|
||||
structure: formModel,
|
||||
value: value
|
||||
};
|
||||
|
||||
// Provide result from the model
|
||||
function resultGetter() {
|
||||
return overlayModel.value;
|
||||
}
|
||||
|
||||
// Show the overlay-dialog
|
||||
return this.getDialogResponse(
|
||||
"overlay-dialog",
|
||||
overlayModel,
|
||||
resultGetter
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Request that the user chooses from a set of options,
|
||||
* which will be shown as buttons.
|
||||
*
|
||||
* @param dialogModel a description of the dialog to show
|
||||
* @return {Promise} a promise for the user's choice
|
||||
*/
|
||||
DialogService.prototype.getUserChoice = function (dialogModel) {
|
||||
// Show the overlay-options dialog
|
||||
return this.getDialogResponse(
|
||||
"overlay-options",
|
||||
{ dialog: dialogModel }
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests if a dialog can be displayed. A modal dialog may only be
|
||||
* displayed if one is not already visible.
|
||||
* Will log a warning message if it can't display a dialog.
|
||||
* @returns {boolean} true if dialog is currently visible, false
|
||||
* otherwise
|
||||
*/
|
||||
DialogService.prototype.canShowDialog = function (dialogModel) {
|
||||
if (this.activeOverlay) {
|
||||
// Only one dialog should be shown at a time.
|
||||
// The application design should be such that
|
||||
// we never even try to do this.
|
||||
this.$log.warn([
|
||||
"Dialog already showing; ",
|
||||
"unable to show ",
|
||||
dialogModel.title
|
||||
].join(""));
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A user action that can be performed from a blocking dialog. These
|
||||
* actions will be rendered as buttons within a blocking dialog.
|
||||
*
|
||||
* @typedef DialogOption
|
||||
* @property {string} label a label to be displayed as the button
|
||||
* text for this action
|
||||
* @property {function} callback a function to be called when the
|
||||
* button is clicked
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef DialogHandle
|
||||
* @property {function} dismiss a function to dismiss the given dialog
|
||||
*/
|
||||
|
||||
/**
|
||||
* A description of the model options that may be passed to the
|
||||
* showBlockingMessage method. Note that the DialogModel described
|
||||
* here is shared with the Notifications framework.
|
||||
* @see NotificationService
|
||||
*
|
||||
* @typedef DialogModel
|
||||
* @property {string} title the title to use for the dialog
|
||||
* @property {string} severity the severity level of this message.
|
||||
* These are defined in a bundle constant with key 'dialogSeverity'
|
||||
* @property {string} hint the 'hint' message to show below the title
|
||||
* @property {string} actionText text that indicates a current action,
|
||||
* shown above a progress bar to indicate what's happening.
|
||||
* @property {number} progress a percentage value (1-100)
|
||||
* indicating the completion of the blocking task
|
||||
* @property {boolean} delay adds a brief delay before loading
|
||||
* the dialog. Useful for removing the dialog flicker when the
|
||||
* conditions for displaying the dialog change rapidly.
|
||||
* @property {string} progressText the message to show below a
|
||||
* progress bar to indicate progress. For example, this might be
|
||||
* used to indicate time remaining, or items still to process.
|
||||
* @property {boolean} unknownProgress some tasks may be
|
||||
* impossible to provide an estimate for. Providing a true value for
|
||||
* this attribute will indicate to the user that the progress and
|
||||
* duration cannot be estimated.
|
||||
* @property {DialogOption} primaryOption an action that will
|
||||
* be added to the dialog as a button. The primary action can be
|
||||
* used as the suggested course of action for the user. Making it
|
||||
* distinct from other actions allows it to be styled differently,
|
||||
* and treated preferentially in banner mode.
|
||||
* @property {DialogOption[]} options a list of actions that will
|
||||
* be added to the dialog as buttons.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Displays a blocking (modal) dialog. This dialog can be used for
|
||||
* displaying messages that require the user's
|
||||
* immediate attention. The message may include an indication of
|
||||
* progress, as well as a series of actions that
|
||||
* the user can take if necessary
|
||||
* @param {DialogModel} dialogModel defines options for the dialog
|
||||
* @param {typeClass} string tells overlayService that this overlay should use appropriate CSS class
|
||||
* @returns {boolean | {DialogHandle}}
|
||||
*/
|
||||
DialogService.prototype.showBlockingMessage = function (dialogModel) {
|
||||
if (this.canShowDialog(dialogModel)) {
|
||||
// Add the overlay using the OverlayService, which
|
||||
// will handle actual insertion into the DOM
|
||||
var self = this,
|
||||
overlay = this.overlayService.createOverlay(
|
||||
"overlay-blocking-message",
|
||||
dialogModel,
|
||||
"t-dialog-sm"
|
||||
);
|
||||
|
||||
this.activeOverlay = overlay;
|
||||
|
||||
return {
|
||||
dismiss: function () {
|
||||
self.dismissOverlay(overlay);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export default DialogService;
|
@ -20,94 +20,108 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
// Template to inject into the DOM to show the dialog; really just points to
|
||||
// the a specific template that can be included via mct-include
|
||||
var TEMPLATE = '<mct-include ng-model="overlay" key="key" ng-class="typeClass"></mct-include>';
|
||||
var TEMPLATE = '<mct-include ng-model="overlay" key="key" ng-class="typeClass"></mct-include>';
|
||||
|
||||
/**
|
||||
* The OverlayService is responsible for pre-pending templates to
|
||||
* the body of the document, which is useful for displaying templates
|
||||
* which need to block the full screen.
|
||||
*
|
||||
* This is intended to be used by the DialogService; by design, it
|
||||
* does not have any protections in place to prevent multiple overlays
|
||||
* from being shown at once. (The DialogService does have these
|
||||
* protections, and should be used for most overlay-type interactions,
|
||||
* particularly where a multiple-overlay effect is not specifically
|
||||
* desired).
|
||||
*
|
||||
* @memberof platform/commonUI/dialog
|
||||
* @constructor
|
||||
*/
|
||||
function OverlayService($document, $compile, $rootScope, $timeout) {
|
||||
this.$compile = $compile;
|
||||
this.$timeout = $timeout;
|
||||
/**
|
||||
* The OverlayService is responsible for pre-pending templates to
|
||||
* the body of the document, which is useful for displaying templates
|
||||
* which need to block the full screen.
|
||||
*
|
||||
* This is intended to be used by the DialogService; by design, it
|
||||
* does not have any protections in place to prevent multiple overlays
|
||||
* from being shown at once. (The DialogService does have these
|
||||
* protections, and should be used for most overlay-type interactions,
|
||||
* particularly where a multiple-overlay effect is not specifically
|
||||
* desired).
|
||||
*
|
||||
* @memberof platform/commonUI/dialog
|
||||
* @constructor
|
||||
*/
|
||||
function OverlayService($document, $compile, $rootScope, $timeout) {
|
||||
this.$compile = $compile;
|
||||
this.$timeout = $timeout;
|
||||
|
||||
// Don't include $document and $rootScope directly;
|
||||
// avoids https://docs.angularjs.org/error/ng/cpws
|
||||
this.findBody = function () {
|
||||
return $document.find('body');
|
||||
};
|
||||
// Don't include $document and $rootScope directly;
|
||||
// avoids https://docs.angularjs.org/error/ng/cpws
|
||||
this.findBody = function () {
|
||||
return $document.find('body');
|
||||
};
|
||||
|
||||
this.newScope = function () {
|
||||
return $rootScope.$new();
|
||||
};
|
||||
}
|
||||
this.newScope = function () {
|
||||
return $rootScope.$new();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new overlay to the document. This will be
|
||||
* prepended to the document body; the overlay's
|
||||
* template (as pointed to by the `key` argument) is
|
||||
* responsible for having a useful z-order, and for
|
||||
* blocking user interactions if appropriate.
|
||||
*
|
||||
* @param {string} key the symbolic key which identifies
|
||||
* the template of the overlay to be shown
|
||||
* @param {object} overlayModel the model to pass to the
|
||||
* included overlay template (this will be passed
|
||||
* in via ng-model)
|
||||
* @param {string} typeClass the element class to use in rendering
|
||||
* the overlay. Can be specified to provide custom styling of
|
||||
* overlays
|
||||
*/
|
||||
OverlayService.prototype.createOverlay = function (key, overlayModel, typeClass) {
|
||||
// Create a new scope for this overlay
|
||||
var scope = this.newScope(),
|
||||
element;
|
||||
/**
|
||||
* Add a new overlay to the document. This will be
|
||||
* prepended to the document body; the overlay's
|
||||
* template (as pointed to by the `key` argument) is
|
||||
* responsible for having a useful z-order, and for
|
||||
* blocking user interactions if appropriate.
|
||||
*
|
||||
* @param {string} key the symbolic key which identifies
|
||||
* the template of the overlay to be shown
|
||||
* @param {object} overlayModel the model to pass to the
|
||||
* included overlay template (this will be passed
|
||||
* in via ng-model)
|
||||
* @param {string} typeClass the element class to use in rendering
|
||||
* the overlay. Can be specified to provide custom styling of
|
||||
* overlays
|
||||
*/
|
||||
OverlayService.prototype.createOverlay = function (key, overlayModel, typeClass) {
|
||||
// Create a new scope for this overlay
|
||||
var scope = this.newScope(),
|
||||
element;
|
||||
|
||||
// Stop showing the overlay; additionally, release the scope
|
||||
// that it uses.
|
||||
function dismiss() {
|
||||
scope.$destroy();
|
||||
element.remove();
|
||||
}
|
||||
|
||||
// If no model is supplied, just fill in a default "cancel"
|
||||
overlayModel = overlayModel || { cancel: dismiss };
|
||||
|
||||
// Populate the scope; will be passed directly to the template
|
||||
scope.overlay = overlayModel;
|
||||
scope.key = key;
|
||||
scope.typeClass = typeClass || 't-dialog';
|
||||
|
||||
this.$timeout(() => {
|
||||
// Create the overlay element and add it to the document's body
|
||||
element = this.$compile(TEMPLATE)(scope);
|
||||
|
||||
// Append so that most recent dialog is last in DOM. This means the most recent dialog will be on top when
|
||||
// multiple overlays with the same z-index are active.
|
||||
this.findBody().append(element);
|
||||
});
|
||||
|
||||
return {
|
||||
dismiss: dismiss
|
||||
};
|
||||
};
|
||||
|
||||
return OverlayService;
|
||||
// Stop showing the overlay; additionally, release the scope
|
||||
// that it uses.
|
||||
function dismiss() {
|
||||
scope.$destroy();
|
||||
element.remove();
|
||||
}
|
||||
);
|
||||
|
||||
// If no model is supplied, just fill in a default "cancel"
|
||||
overlayModel = overlayModel || { cancel: dismiss };
|
||||
|
||||
// Populate the scope; will be passed directly to the template
|
||||
scope.overlay = overlayModel;
|
||||
scope.key = key;
|
||||
scope.typeClass = typeClass || 't-dialog';
|
||||
|
||||
this.$timeout(() => {
|
||||
// Create the overlay element and add it to the document's body
|
||||
element = this.$compile(TEMPLATE)(scope);
|
||||
|
||||
// Append so that most recent dialog is last in DOM. This means the most recent dialog will be on top when
|
||||
// multiple overlays with the same z-index are active.
|
||||
this.findBody().append(element);
|
||||
});
|
||||
|
||||
return {
|
||||
dismiss: dismiss
|
||||
};
|
||||
};
|
||||
|
||||
export default OverlayService;
|
@ -23,192 +23,213 @@
|
||||
/**
|
||||
* MCTIncudeSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
define(
|
||||
["../src/DialogService"],
|
||||
function (DialogService) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The dialog service", function () {
|
||||
var mockOverlayService,
|
||||
mockQ,
|
||||
mockLog,
|
||||
mockOverlay,
|
||||
mockDeferred,
|
||||
mockDocument,
|
||||
mockBody,
|
||||
dialogService;
|
||||
/**
|
||||
* MCTIncudeSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
import DialogService from '../src/DialogService';
|
||||
|
||||
beforeEach(function () {
|
||||
mockOverlayService = jasmine.createSpyObj(
|
||||
"overlayService",
|
||||
["createOverlay"]
|
||||
);
|
||||
mockQ = jasmine.createSpyObj(
|
||||
"$q",
|
||||
["defer"]
|
||||
);
|
||||
mockLog = jasmine.createSpyObj(
|
||||
"$log",
|
||||
["warn", "info", "debug"]
|
||||
);
|
||||
mockOverlay = jasmine.createSpyObj(
|
||||
"overlay",
|
||||
["dismiss"]
|
||||
);
|
||||
mockDeferred = jasmine.createSpyObj(
|
||||
"deferred",
|
||||
["resolve", "reject"]
|
||||
);
|
||||
mockDocument = jasmine.createSpyObj(
|
||||
"$document",
|
||||
["find"]
|
||||
);
|
||||
mockBody = jasmine.createSpyObj('body', ['on', 'off']);
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
describe("The dialog service", function () {
|
||||
var mockOverlayService,
|
||||
mockQ,
|
||||
mockLog,
|
||||
mockOverlay,
|
||||
mockDeferred,
|
||||
mockDocument,
|
||||
mockBody,
|
||||
dialogService;
|
||||
|
||||
mockDeferred.promise = "mock promise";
|
||||
beforeEach(function () {
|
||||
mockOverlayService = jasmine.createSpyObj(
|
||||
"overlayService",
|
||||
["createOverlay"]
|
||||
);
|
||||
mockQ = jasmine.createSpyObj(
|
||||
"$q",
|
||||
["defer"]
|
||||
);
|
||||
mockLog = jasmine.createSpyObj(
|
||||
"$log",
|
||||
["warn", "info", "debug"]
|
||||
);
|
||||
mockOverlay = jasmine.createSpyObj(
|
||||
"overlay",
|
||||
["dismiss"]
|
||||
);
|
||||
mockDeferred = jasmine.createSpyObj(
|
||||
"deferred",
|
||||
["resolve", "reject"]
|
||||
);
|
||||
mockDocument = jasmine.createSpyObj(
|
||||
"$document",
|
||||
["find"]
|
||||
);
|
||||
mockBody = jasmine.createSpyObj('body', ['on', 'off']);
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
|
||||
mockQ.defer.and.returnValue(mockDeferred);
|
||||
mockOverlayService.createOverlay.and.returnValue(mockOverlay);
|
||||
mockDeferred.promise = "mock promise";
|
||||
|
||||
dialogService = new DialogService(
|
||||
mockOverlayService,
|
||||
mockQ,
|
||||
mockLog,
|
||||
mockDocument
|
||||
);
|
||||
});
|
||||
mockQ.defer.and.returnValue(mockDeferred);
|
||||
mockOverlayService.createOverlay.and.returnValue(mockOverlay);
|
||||
|
||||
it("adds an overlay when user input is requested", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockOverlayService.createOverlay).toHaveBeenCalled();
|
||||
});
|
||||
dialogService = new DialogService(
|
||||
mockOverlayService,
|
||||
mockQ,
|
||||
mockLog,
|
||||
mockDocument
|
||||
);
|
||||
});
|
||||
|
||||
it("allows user input to be canceled", function () {
|
||||
dialogService.getUserInput({}, { someKey: "some value" });
|
||||
mockOverlayService.createOverlay.calls.mostRecent().args[1].cancel();
|
||||
expect(mockDeferred.reject).toHaveBeenCalled();
|
||||
expect(mockDeferred.resolve).not.toHaveBeenCalled();
|
||||
});
|
||||
it("adds an overlay when user input is requested", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockOverlayService.createOverlay).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("passes back the result of user input when confirmed", function () {
|
||||
var value = { someKey: 42 };
|
||||
dialogService.getUserInput({}, value);
|
||||
mockOverlayService.createOverlay.calls.mostRecent().args[1].confirm();
|
||||
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
||||
expect(mockDeferred.resolve).toHaveBeenCalledWith(value);
|
||||
});
|
||||
it("allows user input to be canceled", function () {
|
||||
dialogService.getUserInput({}, { someKey: "some value" });
|
||||
mockOverlayService.createOverlay.calls.mostRecent().args[1].cancel();
|
||||
expect(mockDeferred.reject).toHaveBeenCalled();
|
||||
expect(mockDeferred.resolve).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("logs a warning when a dialog is already showing", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockLog.warn).toHaveBeenCalled();
|
||||
expect(mockDeferred.reject).toHaveBeenCalled();
|
||||
});
|
||||
it("passes back the result of user input when confirmed", function () {
|
||||
var value = { someKey: 42 };
|
||||
dialogService.getUserInput({}, value);
|
||||
mockOverlayService.createOverlay.calls.mostRecent().args[1].confirm();
|
||||
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
||||
expect(mockDeferred.resolve).toHaveBeenCalledWith(value);
|
||||
});
|
||||
|
||||
it("can show multiple dialogs if prior ones are dismissed", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||
mockOverlayService.createOverlay.calls.mostRecent().args[1].confirm();
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
||||
});
|
||||
it("logs a warning when a dialog is already showing", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockLog.warn).toHaveBeenCalled();
|
||||
expect(mockDeferred.reject).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("provides an options dialogs", function () {
|
||||
var dialogModel = {};
|
||||
dialogService.getUserChoice(dialogModel);
|
||||
expect(mockOverlayService.createOverlay).toHaveBeenCalledWith(
|
||||
'overlay-options',
|
||||
{
|
||||
dialog: dialogModel,
|
||||
confirm: jasmine.any(Function),
|
||||
cancel: jasmine.any(Function)
|
||||
},
|
||||
't-dialog'
|
||||
);
|
||||
});
|
||||
it("can show multiple dialogs if prior ones are dismissed", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||
mockOverlayService.createOverlay.calls.mostRecent().args[1].confirm();
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("invokes the overlay service with the correct parameters when"
|
||||
+ " a blocking dialog is requested", function () {
|
||||
var dialogModel = {};
|
||||
expect(dialogService.showBlockingMessage(dialogModel)).not.toBe(false);
|
||||
expect(mockOverlayService.createOverlay).toHaveBeenCalledWith(
|
||||
"overlay-blocking-message",
|
||||
dialogModel,
|
||||
"t-dialog-sm"
|
||||
);
|
||||
});
|
||||
it("provides an options dialogs", function () {
|
||||
var dialogModel = {};
|
||||
dialogService.getUserChoice(dialogModel);
|
||||
expect(mockOverlayService.createOverlay).toHaveBeenCalledWith(
|
||||
'overlay-options',
|
||||
{
|
||||
dialog: dialogModel,
|
||||
confirm: jasmine.any(Function),
|
||||
cancel: jasmine.any(Function)
|
||||
},
|
||||
't-dialog'
|
||||
);
|
||||
});
|
||||
|
||||
it("adds a keydown event listener to the body", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockDocument.find).toHaveBeenCalledWith("body");
|
||||
expect(mockBody.on).toHaveBeenCalledWith("keydown", jasmine.any(Function));
|
||||
});
|
||||
it("invokes the overlay service with the correct parameters when"
|
||||
+ " a blocking dialog is requested", function () {
|
||||
var dialogModel = {};
|
||||
expect(dialogService.showBlockingMessage(dialogModel)).not.toBe(false);
|
||||
expect(mockOverlayService.createOverlay).toHaveBeenCalledWith(
|
||||
"overlay-blocking-message",
|
||||
dialogModel,
|
||||
"t-dialog-sm"
|
||||
);
|
||||
});
|
||||
|
||||
it("destroys the event listener when the dialog is cancelled", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
mockOverlayService.createOverlay.calls.mostRecent().args[1].cancel();
|
||||
expect(mockBody.off).toHaveBeenCalledWith("keydown", jasmine.any(Function));
|
||||
});
|
||||
it("adds a keydown event listener to the body", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
expect(mockDocument.find).toHaveBeenCalledWith("body");
|
||||
expect(mockBody.on).toHaveBeenCalledWith("keydown", jasmine.any(Function));
|
||||
});
|
||||
|
||||
it("cancels the dialog when an escape keydown event is triggered", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
mockBody.on.calls.mostRecent().args[1]({
|
||||
keyCode: 27
|
||||
});
|
||||
expect(mockDeferred.reject).toHaveBeenCalled();
|
||||
expect(mockDeferred.resolve).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("ignores non escape keydown events", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
mockBody.on.calls.mostRecent().args[1]({
|
||||
keyCode: 13
|
||||
});
|
||||
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
||||
expect(mockDeferred.resolve).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("the blocking message dialog", function () {
|
||||
var dialogModel = {};
|
||||
var dialogHandle;
|
||||
|
||||
beforeEach(function () {
|
||||
dialogHandle = dialogService.showBlockingMessage(dialogModel);
|
||||
});
|
||||
|
||||
it("returns a handle to the dialog", function () {
|
||||
expect(dialogHandle).not.toBe(undefined);
|
||||
});
|
||||
|
||||
it("dismissing the dialog dismisses the overlay", function () {
|
||||
dialogHandle.dismiss();
|
||||
expect(mockOverlay.dismiss).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("individual dialogs can be dismissed", function () {
|
||||
var secondDialogHandle,
|
||||
secondMockOverlay;
|
||||
|
||||
dialogHandle.dismiss();
|
||||
|
||||
secondMockOverlay = jasmine.createSpyObj(
|
||||
"overlay",
|
||||
["dismiss"]
|
||||
);
|
||||
mockOverlayService.createOverlay.and.returnValue(secondMockOverlay);
|
||||
secondDialogHandle = dialogService.showBlockingMessage(dialogModel);
|
||||
|
||||
//Dismiss the first dialog. It should only dismiss if it
|
||||
// is active
|
||||
dialogHandle.dismiss();
|
||||
expect(secondMockOverlay.dismiss).not.toHaveBeenCalled();
|
||||
secondDialogHandle.dismiss();
|
||||
expect(secondMockOverlay.dismiss).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
it("destroys the event listener when the dialog is cancelled", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
mockOverlayService.createOverlay.calls.mostRecent().args[1].cancel();
|
||||
expect(mockBody.off).toHaveBeenCalledWith("keydown", jasmine.any(Function));
|
||||
});
|
||||
|
||||
it("cancels the dialog when an escape keydown event is triggered", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
mockBody.on.calls.mostRecent().args[1]({
|
||||
keyCode: 27
|
||||
});
|
||||
}
|
||||
);
|
||||
expect(mockDeferred.reject).toHaveBeenCalled();
|
||||
expect(mockDeferred.resolve).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("ignores non escape keydown events", function () {
|
||||
dialogService.getUserInput({}, {});
|
||||
mockBody.on.calls.mostRecent().args[1]({
|
||||
keyCode: 13
|
||||
});
|
||||
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
||||
expect(mockDeferred.resolve).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("the blocking message dialog", function () {
|
||||
var dialogModel = {};
|
||||
var dialogHandle;
|
||||
|
||||
beforeEach(function () {
|
||||
dialogHandle = dialogService.showBlockingMessage(dialogModel);
|
||||
});
|
||||
|
||||
it("returns a handle to the dialog", function () {
|
||||
expect(dialogHandle).not.toBe(undefined);
|
||||
});
|
||||
|
||||
it("dismissing the dialog dismisses the overlay", function () {
|
||||
dialogHandle.dismiss();
|
||||
expect(mockOverlay.dismiss).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("individual dialogs can be dismissed", function () {
|
||||
var secondDialogHandle,
|
||||
secondMockOverlay;
|
||||
|
||||
dialogHandle.dismiss();
|
||||
|
||||
secondMockOverlay = jasmine.createSpyObj(
|
||||
"overlay",
|
||||
["dismiss"]
|
||||
);
|
||||
mockOverlayService.createOverlay.and.returnValue(secondMockOverlay);
|
||||
secondDialogHandle = dialogService.showBlockingMessage(dialogModel);
|
||||
|
||||
//Dismiss the first dialog. It should only dismiss if it
|
||||
// is active
|
||||
dialogHandle.dismiss();
|
||||
expect(secondMockOverlay.dismiss).not.toHaveBeenCalled();
|
||||
secondDialogHandle.dismiss();
|
||||
expect(secondMockOverlay.dismiss).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -23,82 +23,103 @@
|
||||
/**
|
||||
* MCTIncudeSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
define(
|
||||
["../src/OverlayService"],
|
||||
function (OverlayService) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The overlay service", function () {
|
||||
var mockDocument,
|
||||
mockCompile,
|
||||
mockRootScope,
|
||||
mockBody,
|
||||
mockTemplate,
|
||||
mockElement,
|
||||
mockScope,
|
||||
mockTimeout,
|
||||
overlayService;
|
||||
/**
|
||||
* MCTIncudeSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
import OverlayService from '../src/OverlayService';
|
||||
|
||||
beforeEach(function () {
|
||||
mockDocument = jasmine.createSpyObj("$document", ["find"]);
|
||||
mockCompile = jasmine.createSpy("$compile");
|
||||
mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]);
|
||||
mockBody = jasmine.createSpyObj("body", ["append"]);
|
||||
mockTemplate = jasmine.createSpy("template");
|
||||
mockElement = jasmine.createSpyObj("element", ["remove"]);
|
||||
mockScope = jasmine.createSpyObj("scope", ["$destroy"]);
|
||||
mockTimeout = function (callback) {
|
||||
callback();
|
||||
};
|
||||
describe("The overlay service", function () {
|
||||
var mockDocument,
|
||||
mockCompile,
|
||||
mockRootScope,
|
||||
mockBody,
|
||||
mockTemplate,
|
||||
mockElement,
|
||||
mockScope,
|
||||
mockTimeout,
|
||||
overlayService;
|
||||
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
mockCompile.and.returnValue(mockTemplate);
|
||||
mockRootScope.$new.and.returnValue(mockScope);
|
||||
mockTemplate.and.returnValue(mockElement);
|
||||
beforeEach(function () {
|
||||
mockDocument = jasmine.createSpyObj("$document", ["find"]);
|
||||
mockCompile = jasmine.createSpy("$compile");
|
||||
mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]);
|
||||
mockBody = jasmine.createSpyObj("body", ["append"]);
|
||||
mockTemplate = jasmine.createSpy("template");
|
||||
mockElement = jasmine.createSpyObj("element", ["remove"]);
|
||||
mockScope = jasmine.createSpyObj("scope", ["$destroy"]);
|
||||
mockTimeout = function (callback) {
|
||||
callback();
|
||||
};
|
||||
|
||||
overlayService = new OverlayService(
|
||||
mockDocument,
|
||||
mockCompile,
|
||||
mockRootScope,
|
||||
mockTimeout
|
||||
);
|
||||
});
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
mockCompile.and.returnValue(mockTemplate);
|
||||
mockRootScope.$new.and.returnValue(mockScope);
|
||||
mockTemplate.and.returnValue(mockElement);
|
||||
|
||||
it("prepends an mct-include to create overlays", function () {
|
||||
overlayService.createOverlay("test", {});
|
||||
expect(mockCompile).toHaveBeenCalled();
|
||||
expect(mockCompile.calls.mostRecent().args[0].indexOf("mct-include"))
|
||||
.not.toEqual(-1);
|
||||
});
|
||||
overlayService = new OverlayService(
|
||||
mockDocument,
|
||||
mockCompile,
|
||||
mockRootScope,
|
||||
mockTimeout
|
||||
);
|
||||
});
|
||||
|
||||
it("adds the templated element to the body", function () {
|
||||
overlayService.createOverlay("test", {});
|
||||
expect(mockBody.append).toHaveBeenCalledWith(mockElement);
|
||||
});
|
||||
it("prepends an mct-include to create overlays", function () {
|
||||
overlayService.createOverlay("test", {});
|
||||
expect(mockCompile).toHaveBeenCalled();
|
||||
expect(mockCompile.calls.mostRecent().args[0].indexOf("mct-include"))
|
||||
.not.toEqual(-1);
|
||||
});
|
||||
|
||||
it("places the provided model/key in its template's scope", function () {
|
||||
overlayService.createOverlay("test", { someKey: 42 });
|
||||
expect(mockScope.overlay).toEqual({ someKey: 42 });
|
||||
expect(mockScope.key).toEqual("test");
|
||||
it("adds the templated element to the body", function () {
|
||||
overlayService.createOverlay("test", {});
|
||||
expect(mockBody.append).toHaveBeenCalledWith(mockElement);
|
||||
});
|
||||
|
||||
// Make sure this is actually what was rendered, too
|
||||
expect(mockTemplate).toHaveBeenCalledWith(mockScope);
|
||||
});
|
||||
it("places the provided model/key in its template's scope", function () {
|
||||
overlayService.createOverlay("test", { someKey: 42 });
|
||||
expect(mockScope.overlay).toEqual({ someKey: 42 });
|
||||
expect(mockScope.key).toEqual("test");
|
||||
|
||||
it("removes the prepended element on request", function () {
|
||||
var overlay = overlayService.createOverlay("test", {});
|
||||
// Make sure this is actually what was rendered, too
|
||||
expect(mockTemplate).toHaveBeenCalledWith(mockScope);
|
||||
});
|
||||
|
||||
// Verify precondition
|
||||
expect(mockElement.remove).not.toHaveBeenCalled();
|
||||
expect(mockScope.$destroy).not.toHaveBeenCalled();
|
||||
it("removes the prepended element on request", function () {
|
||||
var overlay = overlayService.createOverlay("test", {});
|
||||
|
||||
// Dismiss the overlay
|
||||
overlay.dismiss();
|
||||
// Verify precondition
|
||||
expect(mockElement.remove).not.toHaveBeenCalled();
|
||||
expect(mockScope.$destroy).not.toHaveBeenCalled();
|
||||
|
||||
// Now it should have been removed, and the scope destroyed
|
||||
expect(mockElement.remove).toHaveBeenCalled();
|
||||
expect(mockScope.$destroy).toHaveBeenCalled();
|
||||
});
|
||||
// Dismiss the overlay
|
||||
overlay.dismiss();
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
// Now it should have been removed, and the scope destroyed
|
||||
expect(mockElement.remove).toHaveBeenCalled();
|
||||
expect(mockScope.$destroy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
@ -20,190 +20,195 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/controllers/EditActionController",
|
||||
"./src/controllers/EditPanesController",
|
||||
"./src/controllers/EditObjectController",
|
||||
"./src/actions/EditAndComposeAction",
|
||||
"./src/actions/EditAction",
|
||||
"./src/actions/SaveAction",
|
||||
"./src/actions/SaveAndStopEditingAction",
|
||||
"./src/actions/CancelAction",
|
||||
"./src/policies/EditPersistableObjectsPolicy",
|
||||
"./src/representers/EditRepresenter",
|
||||
"./src/capabilities/EditorCapability",
|
||||
"./res/templates/library.html",
|
||||
"./res/templates/edit-object.html",
|
||||
"./res/templates/edit-action-buttons.html",
|
||||
"./res/templates/topbar-edit.html"
|
||||
], function (
|
||||
EditActionController,
|
||||
EditPanesController,
|
||||
EditObjectController,
|
||||
EditAndComposeAction,
|
||||
EditAction,
|
||||
SaveAction,
|
||||
SaveAndStopEditingAction,
|
||||
CancelAction,
|
||||
EditPersistableObjectsPolicy,
|
||||
EditRepresenter,
|
||||
EditorCapability,
|
||||
libraryTemplate,
|
||||
editObjectTemplate,
|
||||
editActionButtonsTemplate,
|
||||
topbarEditTemplate
|
||||
) {
|
||||
return {
|
||||
name: "platform/commonUI/edit",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"controllers": [
|
||||
{
|
||||
"key": "EditActionController",
|
||||
"implementation": EditActionController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "EditPanesController",
|
||||
"implementation": EditPanesController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "EditObjectController",
|
||||
"implementation": EditObjectController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$location",
|
||||
"navigationService"
|
||||
]
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
import EditActionController from './src/controllers/EditActionController';
|
||||
|
||||
import EditPanesController from './src/controllers/EditPanesController';
|
||||
import EditObjectController from './src/controllers/EditObjectController';
|
||||
import EditAndComposeAction from './src/actions/EditAndComposeAction';
|
||||
import EditAction from './src/actions/EditAction';
|
||||
import SaveAction from './src/actions/SaveAction';
|
||||
import SaveAndStopEditingAction from './src/actions/SaveAndStopEditingAction';
|
||||
import CancelAction from './src/actions/CancelAction';
|
||||
import EditPersistableObjectsPolicy from './src/policies/EditPersistableObjectsPolicy';
|
||||
import EditRepresenter from './src/representers/EditRepresenter';
|
||||
import EditorCapability from './src/capabilities/EditorCapability';
|
||||
import libraryTemplate from './res/templates/library.html';
|
||||
import editObjectTemplate from './res/templates/edit-object.html';
|
||||
import editActionButtonsTemplate from './res/templates/edit-action-buttons.html';
|
||||
import topbarEditTemplate from './res/templates/topbar-edit.html';
|
||||
|
||||
export default {
|
||||
name: "platform/commonUI/edit",
|
||||
definition: {
|
||||
"extensions": {
|
||||
"controllers": [
|
||||
{
|
||||
"key": "EditActionController",
|
||||
"implementation": EditActionController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "EditPanesController",
|
||||
"implementation": EditPanesController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "EditObjectController",
|
||||
"implementation": EditObjectController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$location",
|
||||
"navigationService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"key": "compose",
|
||||
"implementation": EditAndComposeAction
|
||||
},
|
||||
{
|
||||
"key": "edit",
|
||||
"implementation": EditAction,
|
||||
"depends": [
|
||||
"$location",
|
||||
"navigationService",
|
||||
"$log"
|
||||
],
|
||||
"description": "Edit",
|
||||
"category": "view-control",
|
||||
"cssClass": "major icon-pencil",
|
||||
"group": "action",
|
||||
"priority": 10
|
||||
},
|
||||
{
|
||||
"key": "save-and-stop-editing",
|
||||
"category": "save",
|
||||
"implementation": SaveAndStopEditingAction,
|
||||
"name": "Save and Finish Editing",
|
||||
"cssClass": "icon-save labeled",
|
||||
"description": "Save changes made to these objects.",
|
||||
"depends": [
|
||||
"dialogService",
|
||||
"notificationService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "save",
|
||||
"category": "save",
|
||||
"implementation": SaveAction,
|
||||
"name": "Save and Continue Editing",
|
||||
"cssClass": "icon-save labeled",
|
||||
"description": "Save changes made to these objects.",
|
||||
"depends": [
|
||||
"dialogService",
|
||||
"notificationService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "cancel",
|
||||
"category": "conclude-editing",
|
||||
"implementation": CancelAction,
|
||||
// Because we use the name as label for edit buttons and mct-control buttons need
|
||||
// the label to be set to undefined in order to not apply the labeled CSS rule.
|
||||
"name": undefined,
|
||||
"cssClass": "icon-x no-label",
|
||||
"description": "Discard changes made to these objects.",
|
||||
"depends": []
|
||||
}
|
||||
],
|
||||
"policies": [
|
||||
{
|
||||
"category": "action",
|
||||
"implementation": EditPersistableObjectsPolicy,
|
||||
"depends": ["openmct"]
|
||||
}
|
||||
],
|
||||
"templates": [
|
||||
{
|
||||
"key": "edit-library",
|
||||
"template": libraryTemplate
|
||||
}
|
||||
],
|
||||
"representations": [
|
||||
{
|
||||
"key": "edit-object",
|
||||
"template": editObjectTemplate,
|
||||
"uses": [
|
||||
"view"
|
||||
],
|
||||
"gestures": [
|
||||
"drop"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "edit-action-buttons",
|
||||
"template": editActionButtonsTemplate,
|
||||
"uses": [
|
||||
"action"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "topbar-edit",
|
||||
"template": topbarEditTemplate
|
||||
}
|
||||
],
|
||||
"representers": [
|
||||
{
|
||||
"implementation": EditRepresenter,
|
||||
"depends": [
|
||||
"$log"
|
||||
]
|
||||
}
|
||||
],
|
||||
"capabilities": [
|
||||
{
|
||||
"key": "editor",
|
||||
"name": "Editor Capability",
|
||||
"description": "Provides transactional editing capabilities",
|
||||
"implementation": EditorCapability,
|
||||
"depends": [
|
||||
"openmct"
|
||||
]
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
depends: [
|
||||
"toolbars[]",
|
||||
"openmct"
|
||||
],
|
||||
implementation: function (toolbars, openmct) {
|
||||
toolbars.forEach(openmct.toolbars.addProvider, openmct.toolbars);
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"key": "compose",
|
||||
"implementation": EditAndComposeAction
|
||||
},
|
||||
{
|
||||
"key": "edit",
|
||||
"implementation": EditAction,
|
||||
"depends": [
|
||||
"$location",
|
||||
"navigationService",
|
||||
"$log"
|
||||
],
|
||||
"description": "Edit",
|
||||
"category": "view-control",
|
||||
"cssClass": "major icon-pencil",
|
||||
"group": "action",
|
||||
"priority": 10
|
||||
},
|
||||
{
|
||||
"key": "save-and-stop-editing",
|
||||
"category": "save",
|
||||
"implementation": SaveAndStopEditingAction,
|
||||
"name": "Save and Finish Editing",
|
||||
"cssClass": "icon-save labeled",
|
||||
"description": "Save changes made to these objects.",
|
||||
"depends": [
|
||||
"dialogService",
|
||||
"notificationService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "save",
|
||||
"category": "save",
|
||||
"implementation": SaveAction,
|
||||
"name": "Save and Continue Editing",
|
||||
"cssClass": "icon-save labeled",
|
||||
"description": "Save changes made to these objects.",
|
||||
"depends": [
|
||||
"dialogService",
|
||||
"notificationService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "cancel",
|
||||
"category": "conclude-editing",
|
||||
"implementation": CancelAction,
|
||||
// Because we use the name as label for edit buttons and mct-control buttons need
|
||||
// the label to be set to undefined in order to not apply the labeled CSS rule.
|
||||
"name": undefined,
|
||||
"cssClass": "icon-x no-label",
|
||||
"description": "Discard changes made to these objects.",
|
||||
"depends": []
|
||||
}
|
||||
],
|
||||
"policies": [
|
||||
{
|
||||
"category": "action",
|
||||
"implementation": EditPersistableObjectsPolicy,
|
||||
"depends": ["openmct"]
|
||||
}
|
||||
],
|
||||
"templates": [
|
||||
{
|
||||
"key": "edit-library",
|
||||
"template": libraryTemplate
|
||||
}
|
||||
],
|
||||
"representations": [
|
||||
{
|
||||
"key": "edit-object",
|
||||
"template": editObjectTemplate,
|
||||
"uses": [
|
||||
"view"
|
||||
],
|
||||
"gestures": [
|
||||
"drop"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "edit-action-buttons",
|
||||
"template": editActionButtonsTemplate,
|
||||
"uses": [
|
||||
"action"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "topbar-edit",
|
||||
"template": topbarEditTemplate
|
||||
}
|
||||
],
|
||||
"representers": [
|
||||
{
|
||||
"implementation": EditRepresenter,
|
||||
"depends": [
|
||||
"$log"
|
||||
]
|
||||
}
|
||||
],
|
||||
"capabilities": [
|
||||
{
|
||||
"key": "editor",
|
||||
"name": "Editor Capability",
|
||||
"description": "Provides transactional editing capabilities",
|
||||
"implementation": EditorCapability,
|
||||
"depends": [
|
||||
"openmct"
|
||||
]
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
depends: [
|
||||
"toolbars[]",
|
||||
"openmct"
|
||||
],
|
||||
implementation: function (toolbars, openmct) {
|
||||
toolbars.forEach(openmct.toolbars.addProvider, openmct.toolbars);
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,71 +20,66 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
function () {
|
||||
/**
|
||||
* The "Cancel" action; the action triggered by clicking Cancel from
|
||||
* Edit Mode. Exits the editing user interface and invokes object
|
||||
* capabilities to persist the changes that have been made.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Action}
|
||||
*/
|
||||
function CancelAction(context) {
|
||||
this.domainObject = context.domainObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* The "Cancel" action; the action triggered by clicking Cancel from
|
||||
* Edit Mode. Exits the editing user interface and invokes object
|
||||
* capabilities to persist the changes that have been made.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Action}
|
||||
*/
|
||||
function CancelAction(context) {
|
||||
this.domainObject = context.domainObject;
|
||||
/**
|
||||
* Cancel editing.
|
||||
*
|
||||
* @returns {Promise} a promise that will be fulfilled when
|
||||
* cancellation has completed
|
||||
*/
|
||||
CancelAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject;
|
||||
|
||||
function returnToBrowse() {
|
||||
var parent;
|
||||
|
||||
//If the object existed already, navigate to refresh view
|
||||
// with previous object state.
|
||||
if (domainObject.getModel().persisted) {
|
||||
return domainObject.getCapability("action").perform("navigate");
|
||||
} else {
|
||||
//If the object was new, and user has cancelled, then
|
||||
//navigate back to parent because nothing to show.
|
||||
return domainObject.getCapability("location").getOriginal().then(function (original) {
|
||||
parent = original.getCapability("context").getParent();
|
||||
|
||||
return parent.getCapability("action").perform("navigate");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel editing.
|
||||
*
|
||||
* @returns {Promise} a promise that will be fulfilled when
|
||||
* cancellation has completed
|
||||
*/
|
||||
CancelAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject;
|
||||
|
||||
function returnToBrowse() {
|
||||
var parent;
|
||||
|
||||
//If the object existed already, navigate to refresh view
|
||||
// with previous object state.
|
||||
if (domainObject.getModel().persisted) {
|
||||
return domainObject.getCapability("action").perform("navigate");
|
||||
} else {
|
||||
//If the object was new, and user has cancelled, then
|
||||
//navigate back to parent because nothing to show.
|
||||
return domainObject.getCapability("location").getOriginal().then(function (original) {
|
||||
parent = original.getCapability("context").getParent();
|
||||
|
||||
return parent.getCapability("action").perform("navigate");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
return domainObject.getCapability("editor").finish();
|
||||
}
|
||||
|
||||
//Do navigation first in order to trigger unsaved changes dialog
|
||||
return returnToBrowse()
|
||||
.then(cancel);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this action is applicable in a given context.
|
||||
* This will ensure that a domain object is present in the context,
|
||||
* and that this domain object is in Edit mode.
|
||||
* @returns {boolean} true if applicable
|
||||
*/
|
||||
CancelAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
|
||||
return domainObject !== undefined
|
||||
&& domainObject.hasCapability('editor')
|
||||
&& domainObject.getCapability('editor').isEditContextRoot();
|
||||
};
|
||||
|
||||
return CancelAction;
|
||||
}
|
||||
);
|
||||
|
||||
function cancel() {
|
||||
return domainObject.getCapability("editor").finish();
|
||||
}
|
||||
|
||||
//Do navigation first in order to trigger unsaved changes dialog
|
||||
return returnToBrowse()
|
||||
.then(cancel);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this action is applicable in a given context.
|
||||
* This will ensure that a domain object is present in the context,
|
||||
* and that this domain object is in Edit mode.
|
||||
* @returns {boolean} true if applicable
|
||||
*/
|
||||
CancelAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
|
||||
return domainObject !== undefined
|
||||
&& domainObject.hasCapability('editor')
|
||||
&& domainObject.getCapability('editor').isEditContextRoot();
|
||||
};
|
||||
|
||||
export default CancelAction;
|
@ -23,79 +23,96 @@
|
||||
/**
|
||||
* Module defining EditAction. Created by vwoeltje on 11/14/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
// A no-op action to return in the event that the action cannot
|
||||
// be completed.
|
||||
var NULL_ACTION = {
|
||||
perform: function () {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The Edit action is performed when the user wishes to enter Edit
|
||||
* mode (typically triggered by the Edit button.) This will
|
||||
* show the user interface for editing (by way of a change in
|
||||
* route)
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
*/
|
||||
function EditAction($location, navigationService, $log, context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
|
||||
// We cannot enter Edit mode if we have no domain object to
|
||||
// edit, so verify that one was defined as part of the
|
||||
// context. (This is also verified in appliesTo, so this
|
||||
// would indicate abnormal behavior.)
|
||||
if (!domainObject) {
|
||||
$log.warn([
|
||||
"No domain object to edit; ",
|
||||
"edit action is not valid."
|
||||
].join(""));
|
||||
|
||||
return NULL_ACTION;
|
||||
}
|
||||
|
||||
this.domainObject = domainObject;
|
||||
this.$location = $location;
|
||||
this.navigationService = navigationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter edit mode.
|
||||
*/
|
||||
EditAction.prototype.perform = function () {
|
||||
|
||||
//If this is not the currently navigated object, then navigate
|
||||
// to it.
|
||||
if (this.navigationService.getNavigation() !== this.domainObject) {
|
||||
this.navigationService.setNavigation(this.domainObject);
|
||||
}
|
||||
|
||||
this.domainObject.useCapability("editor");
|
||||
};
|
||||
|
||||
/**
|
||||
* Check for applicability; verify that a domain object is present
|
||||
* for this action to be performed upon.
|
||||
* @param {ActionContext} context the context in which this action
|
||||
* will be performed; should contain a `domainObject` property
|
||||
*/
|
||||
EditAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject,
|
||||
type = domainObject && domainObject.getCapability('type');
|
||||
|
||||
// Only allow editing of types that support it and are not already
|
||||
// being edited
|
||||
return type && type.hasFeature('creation')
|
||||
&& domainObject.hasCapability('editor')
|
||||
&& !domainObject.getCapability('editor').isEditContextRoot();
|
||||
};
|
||||
|
||||
return EditAction;
|
||||
/**
|
||||
* Module defining EditAction. Created by vwoeltje on 11/14/14.
|
||||
*/
|
||||
var NULL_ACTION = {
|
||||
perform: function () {
|
||||
return undefined;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* The Edit action is performed when the user wishes to enter Edit
|
||||
* mode (typically triggered by the Edit button.) This will
|
||||
* show the user interface for editing (by way of a change in
|
||||
* route)
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
*/
|
||||
function EditAction($location, navigationService, $log, context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
|
||||
// We cannot enter Edit mode if we have no domain object to
|
||||
// edit, so verify that one was defined as part of the
|
||||
// context. (This is also verified in appliesTo, so this
|
||||
// would indicate abnormal behavior.)
|
||||
if (!domainObject) {
|
||||
$log.warn([
|
||||
"No domain object to edit; ",
|
||||
"edit action is not valid."
|
||||
].join(""));
|
||||
|
||||
return NULL_ACTION;
|
||||
}
|
||||
|
||||
this.domainObject = domainObject;
|
||||
this.$location = $location;
|
||||
this.navigationService = navigationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter edit mode.
|
||||
*/
|
||||
EditAction.prototype.perform = function () {
|
||||
|
||||
//If this is not the currently navigated object, then navigate
|
||||
// to it.
|
||||
if (this.navigationService.getNavigation() !== this.domainObject) {
|
||||
this.navigationService.setNavigation(this.domainObject);
|
||||
}
|
||||
|
||||
this.domainObject.useCapability("editor");
|
||||
};
|
||||
|
||||
/**
|
||||
* Check for applicability; verify that a domain object is present
|
||||
* for this action to be performed upon.
|
||||
* @param {ActionContext} context the context in which this action
|
||||
* will be performed; should contain a `domainObject` property
|
||||
*/
|
||||
EditAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject,
|
||||
type = domainObject && domainObject.getCapability('type');
|
||||
|
||||
// Only allow editing of types that support it and are not already
|
||||
// being edited
|
||||
return type && type.hasFeature('creation')
|
||||
&& domainObject.hasCapability('editor')
|
||||
&& !domainObject.getCapability('editor').isEditContextRoot();
|
||||
};
|
||||
|
||||
export default EditAction;
|
@ -20,40 +20,50 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Add one domain object to another's composition.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Action}
|
||||
*/
|
||||
function EditAndComposeAction(context) {
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.selectedObject = (context || {}).selectedObject;
|
||||
}
|
||||
function EditAndComposeAction(context) {
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.selectedObject = (context || {}).selectedObject;
|
||||
}
|
||||
|
||||
EditAndComposeAction.prototype.perform = function () {
|
||||
var self = this,
|
||||
editAction = this.domainObject.getCapability('action').getActions("edit")[0];
|
||||
EditAndComposeAction.prototype.perform = function () {
|
||||
var self = this,
|
||||
editAction = this.domainObject.getCapability('action').getActions("edit")[0];
|
||||
|
||||
// Link these objects
|
||||
function doLink() {
|
||||
var composition = self.domainObject
|
||||
&& self.domainObject.getCapability('composition');
|
||||
// Link these objects
|
||||
function doLink() {
|
||||
var composition = self.domainObject
|
||||
&& self.domainObject.getCapability('composition');
|
||||
|
||||
return composition && composition.add(self.selectedObject);
|
||||
}
|
||||
|
||||
if (editAction) {
|
||||
editAction.perform();
|
||||
}
|
||||
|
||||
return this.selectedObject && doLink();
|
||||
};
|
||||
|
||||
return EditAndComposeAction;
|
||||
return composition && composition.add(self.selectedObject);
|
||||
}
|
||||
);
|
||||
|
||||
if (editAction) {
|
||||
editAction.perform();
|
||||
}
|
||||
|
||||
return this.selectedObject && doLink();
|
||||
};
|
||||
|
||||
export default EditAndComposeAction;
|
@ -20,79 +20,97 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
['./SaveInProgressDialog'],
|
||||
function (SaveInProgressDialog) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The "Save" action; it invokes object capabilities to persist
|
||||
* the changes that have been made.
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
* @memberof platform/commonUI/edit
|
||||
*/
|
||||
function SaveAction(
|
||||
dialogService,
|
||||
notificationService,
|
||||
context
|
||||
) {
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.dialogService = dialogService;
|
||||
this.notificationService = notificationService;
|
||||
}
|
||||
import SaveInProgressDialog from './SaveInProgressDialog';
|
||||
|
||||
/**
|
||||
* Save changes.
|
||||
*
|
||||
* @returns {Promise} a promise that will be fulfilled when
|
||||
* cancellation has completed
|
||||
* @memberof platform/commonUI/edit.SaveAction#
|
||||
*/
|
||||
SaveAction.prototype.perform = function () {
|
||||
var self = this,
|
||||
domainObject = this.domainObject,
|
||||
dialog = new SaveInProgressDialog(this.dialogService);
|
||||
/**
|
||||
* The "Save" action; it invokes object capabilities to persist
|
||||
* the changes that have been made.
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
* @memberof platform/commonUI/edit
|
||||
*/
|
||||
function SaveAction(
|
||||
dialogService,
|
||||
notificationService,
|
||||
context
|
||||
) {
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.dialogService = dialogService;
|
||||
this.notificationService = notificationService;
|
||||
}
|
||||
|
||||
// Invoke any save behavior introduced by the editor capability;
|
||||
// this is introduced by EditableDomainObject which is
|
||||
// used to insulate underlying objects from changes made
|
||||
// during editing.
|
||||
function doSave() {
|
||||
return domainObject.getCapability("editor").save();
|
||||
}
|
||||
/**
|
||||
* Save changes.
|
||||
*
|
||||
* @returns {Promise} a promise that will be fulfilled when
|
||||
* cancellation has completed
|
||||
* @memberof platform/commonUI/edit.SaveAction#
|
||||
*/
|
||||
SaveAction.prototype.perform = function () {
|
||||
var self = this,
|
||||
domainObject = this.domainObject,
|
||||
dialog = new SaveInProgressDialog(this.dialogService);
|
||||
|
||||
function onSuccess() {
|
||||
dialog.hide();
|
||||
self.notificationService.info("Save Succeeded");
|
||||
}
|
||||
|
||||
function onFailure() {
|
||||
dialog.hide();
|
||||
self.notificationService.error("Save Failed");
|
||||
}
|
||||
|
||||
dialog.show();
|
||||
|
||||
return doSave()
|
||||
.then(onSuccess)
|
||||
.catch(onFailure);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this action is applicable in a given context.
|
||||
* This will ensure that a domain object is present in the context,
|
||||
* and that this domain object is in Edit mode.
|
||||
* @returns true if applicable
|
||||
*/
|
||||
SaveAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
|
||||
return domainObject !== undefined
|
||||
&& domainObject.hasCapability('editor')
|
||||
&& domainObject.getCapability('editor').isEditContextRoot()
|
||||
&& domainObject.getModel().persisted !== undefined;
|
||||
};
|
||||
|
||||
return SaveAction;
|
||||
// Invoke any save behavior introduced by the editor capability;
|
||||
// this is introduced by EditableDomainObject which is
|
||||
// used to insulate underlying objects from changes made
|
||||
// during editing.
|
||||
function doSave() {
|
||||
return domainObject.getCapability("editor").save();
|
||||
}
|
||||
);
|
||||
|
||||
function onSuccess() {
|
||||
dialog.hide();
|
||||
self.notificationService.info("Save Succeeded");
|
||||
}
|
||||
|
||||
function onFailure() {
|
||||
dialog.hide();
|
||||
self.notificationService.error("Save Failed");
|
||||
}
|
||||
|
||||
dialog.show();
|
||||
|
||||
return doSave()
|
||||
.then(onSuccess)
|
||||
.catch(onFailure);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this action is applicable in a given context.
|
||||
* This will ensure that a domain object is present in the context,
|
||||
* and that this domain object is in Edit mode.
|
||||
* @returns true if applicable
|
||||
*/
|
||||
SaveAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
|
||||
return domainObject !== undefined
|
||||
&& domainObject.hasCapability('editor')
|
||||
&& domainObject.getCapability('editor').isEditContextRoot()
|
||||
&& domainObject.getModel().persisted !== undefined;
|
||||
};
|
||||
|
||||
export default SaveAction;
|
@ -20,56 +20,74 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["./SaveAction"],
|
||||
function (SaveAction) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The "Save and Stop Editing" action performs a [Save action]{@link SaveAction}
|
||||
* on the object under edit followed by exiting the edit user interface.
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
* @memberof platform/commonUI/edit
|
||||
*/
|
||||
function SaveAndStopEditingAction(
|
||||
dialogService,
|
||||
notificationService,
|
||||
context
|
||||
) {
|
||||
this.context = context;
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.dialogService = dialogService;
|
||||
this.notificationService = notificationService;
|
||||
}
|
||||
import SaveAction from './SaveAction';
|
||||
|
||||
/**
|
||||
* Trigger a save operation and exit edit mode.
|
||||
*
|
||||
* @returns {Promise} a promise that will be fulfilled when
|
||||
* cancellation has completed
|
||||
* @memberof platform/commonUI/edit.SaveAndStopEditingAction#
|
||||
*/
|
||||
SaveAndStopEditingAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject,
|
||||
saveAction = new SaveAction(this.dialogService, this.notificationService, this.context);
|
||||
/**
|
||||
* The "Save and Stop Editing" action performs a [Save action]{@link SaveAction}
|
||||
* on the object under edit followed by exiting the edit user interface.
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
* @memberof platform/commonUI/edit
|
||||
*/
|
||||
function SaveAndStopEditingAction(
|
||||
dialogService,
|
||||
notificationService,
|
||||
context
|
||||
) {
|
||||
this.context = context;
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.dialogService = dialogService;
|
||||
this.notificationService = notificationService;
|
||||
}
|
||||
|
||||
function closeEditor() {
|
||||
return domainObject.getCapability("editor").finish();
|
||||
}
|
||||
/**
|
||||
* Trigger a save operation and exit edit mode.
|
||||
*
|
||||
* @returns {Promise} a promise that will be fulfilled when
|
||||
* cancellation has completed
|
||||
* @memberof platform/commonUI/edit.SaveAndStopEditingAction#
|
||||
*/
|
||||
SaveAndStopEditingAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject,
|
||||
saveAction = new SaveAction(this.dialogService, this.notificationService, this.context);
|
||||
|
||||
return saveAction.perform()
|
||||
.then(closeEditor)
|
||||
.catch(closeEditor);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this action is applicable in a given context.
|
||||
* This will ensure that a domain object is present in the context,
|
||||
* and that this domain object is in Edit mode.
|
||||
* @returns true if applicable
|
||||
*/
|
||||
SaveAndStopEditingAction.appliesTo = SaveAction.appliesTo;
|
||||
|
||||
return SaveAndStopEditingAction;
|
||||
function closeEditor() {
|
||||
return domainObject.getCapability("editor").finish();
|
||||
}
|
||||
);
|
||||
|
||||
return saveAction.perform()
|
||||
.then(closeEditor)
|
||||
.catch(closeEditor);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this action is applicable in a given context.
|
||||
* This will ensure that a domain object is present in the context,
|
||||
* and that this domain object is in Edit mode.
|
||||
* @returns true if applicable
|
||||
*/
|
||||
SaveAndStopEditingAction.appliesTo = SaveAction.appliesTo;
|
||||
|
||||
export default SaveAndStopEditingAction;
|
@ -1,24 +1,22 @@
|
||||
define([], function () {
|
||||
function SaveInProgressDialog(dialogService) {
|
||||
this.dialogService = dialogService;
|
||||
this.dialog = undefined;
|
||||
function SaveInProgressDialog(dialogService) {
|
||||
this.dialogService = dialogService;
|
||||
this.dialog = undefined;
|
||||
}
|
||||
|
||||
SaveInProgressDialog.prototype.show = function () {
|
||||
this.dialog = this.dialogService.showBlockingMessage({
|
||||
title: "Saving",
|
||||
hint: "Do not navigate away from this page or close this browser tab while this message is displayed.",
|
||||
unknownProgress: true,
|
||||
severity: "info",
|
||||
delay: true
|
||||
});
|
||||
};
|
||||
|
||||
SaveInProgressDialog.prototype.hide = function () {
|
||||
if (this.dialog) {
|
||||
this.dialog.dismiss();
|
||||
}
|
||||
};
|
||||
|
||||
SaveInProgressDialog.prototype.show = function () {
|
||||
this.dialog = this.dialogService.showBlockingMessage({
|
||||
title: "Saving",
|
||||
hint: "Do not navigate away from this page or close this browser tab while this message is displayed.",
|
||||
unknownProgress: true,
|
||||
severity: "info",
|
||||
delay: true
|
||||
});
|
||||
};
|
||||
|
||||
SaveInProgressDialog.prototype.hide = function () {
|
||||
if (this.dialog) {
|
||||
this.dialog.dismiss();
|
||||
}
|
||||
};
|
||||
|
||||
return SaveInProgressDialog;
|
||||
});
|
||||
export default SaveInProgressDialog;
|
||||
|
@ -20,45 +20,52 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* A capability that implements an editing 'session' for a domain
|
||||
* object. An editing session is initiated via a call to .edit().
|
||||
* Once initiated, any persist operations will be queued pending a
|
||||
* subsequent call to [.save()](@link #save) or [.finish()](@link
|
||||
* #finish).
|
||||
* @param domainObject
|
||||
* @constructor
|
||||
*/
|
||||
function EditorCapability(
|
||||
openmct,
|
||||
domainObject
|
||||
) {
|
||||
this.openmct = openmct;
|
||||
this.domainObject = domainObject;
|
||||
}
|
||||
function EditorCapability(
|
||||
openmct,
|
||||
domainObject
|
||||
) {
|
||||
this.openmct = openmct;
|
||||
this.domainObject = domainObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether this object, or any of its ancestors are
|
||||
* currently being edited.
|
||||
* @returns boolean
|
||||
*/
|
||||
EditorCapability.prototype.inEditContext = function () {
|
||||
return this.openmct.editor.isEditing();
|
||||
};
|
||||
/**
|
||||
* Determines whether this object, or any of its ancestors are
|
||||
* currently being edited.
|
||||
* @returns boolean
|
||||
*/
|
||||
EditorCapability.prototype.inEditContext = function () {
|
||||
return this.openmct.editor.isEditing();
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this the root editing object (ie. the object that the user
|
||||
* clicked 'edit' on)?
|
||||
* @returns {*}
|
||||
*/
|
||||
EditorCapability.prototype.isEditContextRoot = function () {
|
||||
return this.openmct.editor.isEditing();
|
||||
};
|
||||
/**
|
||||
* Is this the root editing object (ie. the object that the user
|
||||
* clicked 'edit' on)?
|
||||
* @returns {*}
|
||||
*/
|
||||
EditorCapability.prototype.isEditContextRoot = function () {
|
||||
return this.openmct.editor.isEditing();
|
||||
};
|
||||
|
||||
return EditorCapability;
|
||||
}
|
||||
);
|
||||
export default EditorCapability;
|
@ -23,57 +23,76 @@
|
||||
/**
|
||||
* Module defining EditActionController. Created by vwoeltje on 11/17/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
var SAVE_ACTION_CONTEXT = { category: 'save' };
|
||||
var OTHERS_ACTION_CONTEXT = { category: 'conclude-editing' };
|
||||
/**
|
||||
* Module defining EditActionController. Created by vwoeltje on 11/17/14.
|
||||
*/
|
||||
var SAVE_ACTION_CONTEXT = { category: 'save' };
|
||||
var OTHERS_ACTION_CONTEXT = { category: 'conclude-editing' };
|
||||
|
||||
/**
|
||||
* Controller which supplies action instances for Save/Cancel.
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditActionController($scope) {
|
||||
/**
|
||||
* Controller which supplies action instances for Save/Cancel.
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditActionController($scope) {
|
||||
|
||||
function actionToMenuOption(action) {
|
||||
return {
|
||||
key: action,
|
||||
name: action.getMetadata().name,
|
||||
cssClass: action.getMetadata().cssClass
|
||||
};
|
||||
}
|
||||
|
||||
// Maintain all "conclude-editing" and "save" actions in the
|
||||
// present context.
|
||||
function updateActions() {
|
||||
$scope.saveActions = $scope.action
|
||||
? $scope.action.getActions(SAVE_ACTION_CONTEXT)
|
||||
: [];
|
||||
|
||||
$scope.saveActionsAsMenuOptions = $scope.saveActions.map(actionToMenuOption);
|
||||
|
||||
$scope.saveActionMenuClickHandler = function (clickedAction) {
|
||||
clickedAction.perform();
|
||||
};
|
||||
|
||||
$scope.otherEditActions = $scope.action
|
||||
? $scope.action.getActions(OTHERS_ACTION_CONTEXT)
|
||||
: [];
|
||||
|
||||
// Required because Angular does not allow 'bind'
|
||||
// in expressions.
|
||||
$scope.actionPerformer = function (action) {
|
||||
return action.perform.bind(action);
|
||||
};
|
||||
}
|
||||
|
||||
// Update set of actions whenever the action capability
|
||||
// changes or becomes available.
|
||||
$scope.$watch("action", updateActions);
|
||||
}
|
||||
|
||||
return EditActionController;
|
||||
function actionToMenuOption(action) {
|
||||
return {
|
||||
key: action,
|
||||
name: action.getMetadata().name,
|
||||
cssClass: action.getMetadata().cssClass
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
// Maintain all "conclude-editing" and "save" actions in the
|
||||
// present context.
|
||||
function updateActions() {
|
||||
$scope.saveActions = $scope.action
|
||||
? $scope.action.getActions(SAVE_ACTION_CONTEXT)
|
||||
: [];
|
||||
|
||||
$scope.saveActionsAsMenuOptions = $scope.saveActions.map(actionToMenuOption);
|
||||
|
||||
$scope.saveActionMenuClickHandler = function (clickedAction) {
|
||||
clickedAction.perform();
|
||||
};
|
||||
|
||||
$scope.otherEditActions = $scope.action
|
||||
? $scope.action.getActions(OTHERS_ACTION_CONTEXT)
|
||||
: [];
|
||||
|
||||
// Required because Angular does not allow 'bind'
|
||||
// in expressions.
|
||||
$scope.actionPerformer = function (action) {
|
||||
return action.perform.bind(action);
|
||||
};
|
||||
}
|
||||
|
||||
// Update set of actions whenever the action capability
|
||||
// changes or becomes available.
|
||||
$scope.$watch("action", updateActions);
|
||||
}
|
||||
|
||||
export default EditActionController;
|
@ -24,63 +24,83 @@
|
||||
* This bundle implements Edit mode.
|
||||
* @namespace platform/commonUI/edit
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
function cancelEditing(domainObject) {
|
||||
var navigatedObject = domainObject,
|
||||
editorCapability = navigatedObject
|
||||
&& navigatedObject.getCapability("editor");
|
||||
/**
|
||||
* This bundle implements Edit mode.
|
||||
* @namespace platform/commonUI/edit
|
||||
*/
|
||||
function cancelEditing(domainObject) {
|
||||
var navigatedObject = domainObject,
|
||||
editorCapability = navigatedObject
|
||||
&& navigatedObject.getCapability("editor");
|
||||
|
||||
return editorCapability
|
||||
&& editorCapability.finish();
|
||||
}
|
||||
return editorCapability
|
||||
&& editorCapability.finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller which is responsible for populating the scope for
|
||||
* Edit mode
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditObjectController($scope, $location, navigationService) {
|
||||
this.scope = $scope;
|
||||
var domainObject = $scope.domainObject;
|
||||
/**
|
||||
* Controller which is responsible for populating the scope for
|
||||
* Edit mode
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditObjectController($scope, $location, navigationService) {
|
||||
this.scope = $scope;
|
||||
var domainObject = $scope.domainObject;
|
||||
|
||||
var removeCheck = navigationService
|
||||
.checkBeforeNavigation(function () {
|
||||
return "Continuing will cause the loss of any unsaved changes.";
|
||||
});
|
||||
var removeCheck = navigationService
|
||||
.checkBeforeNavigation(function () {
|
||||
return "Continuing will cause the loss of any unsaved changes.";
|
||||
});
|
||||
|
||||
$scope.$on('$destroy', function () {
|
||||
removeCheck();
|
||||
cancelEditing(domainObject);
|
||||
});
|
||||
$scope.$on('$destroy', function () {
|
||||
removeCheck();
|
||||
cancelEditing(domainObject);
|
||||
});
|
||||
|
||||
function setViewForDomainObject() {
|
||||
function setViewForDomainObject() {
|
||||
|
||||
var locationViewKey = $location.search().view;
|
||||
var locationViewKey = $location.search().view;
|
||||
|
||||
function selectViewIfMatching(view) {
|
||||
if (view.key === locationViewKey) {
|
||||
$scope.representation = $scope.representation || {};
|
||||
$scope.representation.selected = view;
|
||||
}
|
||||
}
|
||||
|
||||
if (locationViewKey) {
|
||||
((domainObject && domainObject.useCapability('view')) || [])
|
||||
.forEach(selectViewIfMatching);
|
||||
}
|
||||
function selectViewIfMatching(view) {
|
||||
if (view.key === locationViewKey) {
|
||||
$scope.representation = $scope.representation || {};
|
||||
$scope.representation.selected = view;
|
||||
}
|
||||
|
||||
setViewForDomainObject();
|
||||
|
||||
$scope.doAction = function (action) {
|
||||
return $scope[action] && $scope[action]();
|
||||
};
|
||||
}
|
||||
|
||||
return EditObjectController;
|
||||
if (locationViewKey) {
|
||||
((domainObject && domainObject.useCapability('view')) || [])
|
||||
.forEach(selectViewIfMatching);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
setViewForDomainObject();
|
||||
|
||||
$scope.doAction = function (action) {
|
||||
return $scope[action] && $scope[action]();
|
||||
};
|
||||
}
|
||||
|
||||
export default EditObjectController;
|
@ -20,47 +20,58 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Supports the Library and Elements panes in Edit mode.
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditPanesController($scope) {
|
||||
var self = this;
|
||||
function EditPanesController($scope) {
|
||||
var self = this;
|
||||
|
||||
// Update root object based on represented object
|
||||
function updateRoot(domainObject) {
|
||||
var root = self.rootDomainObject,
|
||||
context = domainObject
|
||||
&& domainObject.getCapability('context'),
|
||||
newRoot = context && context.getTrueRoot(),
|
||||
oldId = root && root.getId(),
|
||||
newId = newRoot && newRoot.getId();
|
||||
// Update root object based on represented object
|
||||
function updateRoot(domainObject) {
|
||||
var root = self.rootDomainObject,
|
||||
context = domainObject
|
||||
&& domainObject.getCapability('context'),
|
||||
newRoot = context && context.getTrueRoot(),
|
||||
oldId = root && root.getId(),
|
||||
newId = newRoot && newRoot.getId();
|
||||
|
||||
// Only update if this has actually changed,
|
||||
// to avoid excessive refreshing.
|
||||
if (oldId !== newId) {
|
||||
self.rootDomainObject = newRoot;
|
||||
}
|
||||
}
|
||||
|
||||
// Update root when represented object changes
|
||||
$scope.$watch('domainObject', updateRoot);
|
||||
// Only update if this has actually changed,
|
||||
// to avoid excessive refreshing.
|
||||
if (oldId !== newId) {
|
||||
self.rootDomainObject = newRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root-level domain object, as reported by the
|
||||
* represented domain object.
|
||||
* @returns {DomainObject} the root object
|
||||
*/
|
||||
EditPanesController.prototype.getRoot = function () {
|
||||
return this.rootDomainObject;
|
||||
};
|
||||
|
||||
return EditPanesController;
|
||||
}
|
||||
);
|
||||
|
||||
// Update root when represented object changes
|
||||
$scope.$watch('domainObject', updateRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root-level domain object, as reported by the
|
||||
* represented domain object.
|
||||
* @returns {DomainObject} the root object
|
||||
*/
|
||||
EditPanesController.prototype.getRoot = function () {
|
||||
return this.rootDomainObject;
|
||||
};
|
||||
|
||||
export default EditPanesController;
|
@ -20,38 +20,56 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
['objectUtils'],
|
||||
function (objectUtils) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Policy that prevents editing of any object from a provider that does not
|
||||
* support persistence (ie. the 'save' operation). Editing is prevented
|
||||
* as a subsequent save would fail, causing the loss of a user's changes.
|
||||
* @param openmct
|
||||
* @constructor
|
||||
*/
|
||||
function EditPersistableObjectsPolicy(openmct) {
|
||||
this.openmct = openmct;
|
||||
}
|
||||
import objectUtils from 'objectUtils';
|
||||
|
||||
EditPersistableObjectsPolicy.prototype.allow = function (action, context) {
|
||||
var domainObject = context.domainObject;
|
||||
var key = action.getMetadata().key;
|
||||
var category = (context || {}).category;
|
||||
/**
|
||||
* Policy that prevents editing of any object from a provider that does not
|
||||
* support persistence (ie. the 'save' operation). Editing is prevented
|
||||
* as a subsequent save would fail, causing the loss of a user's changes.
|
||||
* @param openmct
|
||||
* @constructor
|
||||
*/
|
||||
function EditPersistableObjectsPolicy(openmct) {
|
||||
this.openmct = openmct;
|
||||
}
|
||||
|
||||
// Use category to selectively block edit from the view. Edit action
|
||||
// is also invoked during the create process which should be allowed,
|
||||
// because it may be saved elsewhere
|
||||
if ((key === 'edit' && category === 'view-control') || key === 'properties') {
|
||||
let identifier = this.openmct.objects.parseKeyString(domainObject.getId());
|
||||
EditPersistableObjectsPolicy.prototype.allow = function (action, context) {
|
||||
var domainObject = context.domainObject;
|
||||
var key = action.getMetadata().key;
|
||||
var category = (context || {}).category;
|
||||
|
||||
return this.openmct.objects.isPersistable(identifier);
|
||||
}
|
||||
// Use category to selectively block edit from the view. Edit action
|
||||
// is also invoked during the create process which should be allowed,
|
||||
// because it may be saved elsewhere
|
||||
if ((key === 'edit' && category === 'view-control') || key === 'properties') {
|
||||
let identifier = this.openmct.objects.parseKeyString(domainObject.getId());
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
return EditPersistableObjectsPolicy;
|
||||
return this.openmct.objects.isPersistable(identifier);
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default EditPersistableObjectsPolicy;
|
@ -20,80 +20,77 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The EditRepresenter is responsible for implementing
|
||||
* representation-level behavior relevant to Edit mode.
|
||||
* Specifically, this listens for changes to view configuration
|
||||
* or to domain object models, and triggers persistence when
|
||||
* these are detected.
|
||||
*
|
||||
* This is exposed as an extension of category `representers`,
|
||||
* which mct-representation will utilize to add additional
|
||||
* behavior to each representation.
|
||||
*
|
||||
* This will be called once per mct-representation directive,
|
||||
* and may be reused for different domain objects and/or
|
||||
* representations resulting from changes there.
|
||||
*
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Representer}
|
||||
* @constructor
|
||||
*/
|
||||
function EditRepresenter($log, $scope) {
|
||||
this.$log = $log;
|
||||
this.$scope = $scope;
|
||||
function EditRepresenter($log, $scope) {
|
||||
this.$log = $log;
|
||||
this.$scope = $scope;
|
||||
|
||||
this.$scope.commit = this.commit.bind(this);
|
||||
this.$scope.commit = this.commit.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit any changes made to the in-scope model to the domain object.
|
||||
* Also commits any changes made to $scope.configuration to the proper
|
||||
* configuration value for the current representation.
|
||||
*
|
||||
* @param {String} message a message to log with the commit message.
|
||||
*/
|
||||
EditRepresenter.prototype.commit = function (message) {
|
||||
var model = this.$scope.model,
|
||||
configuration = this.$scope.configuration,
|
||||
domainObject = this.domainObject;
|
||||
|
||||
this.$log.debug([
|
||||
"Committing ",
|
||||
domainObject && domainObject.getModel().name,
|
||||
"(" + (domainObject && domainObject.getId()) + "):",
|
||||
message
|
||||
].join(" "));
|
||||
|
||||
if (this.domainObject) {
|
||||
if (this.key && configuration) {
|
||||
model.configuration = model.configuration || {};
|
||||
model.configuration[this.key] = configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit any changes made to the in-scope model to the domain object.
|
||||
* Also commits any changes made to $scope.configuration to the proper
|
||||
* configuration value for the current representation.
|
||||
*
|
||||
* @param {String} message a message to log with the commit message.
|
||||
*/
|
||||
EditRepresenter.prototype.commit = function (message) {
|
||||
var model = this.$scope.model,
|
||||
configuration = this.$scope.configuration,
|
||||
domainObject = this.domainObject;
|
||||
|
||||
this.$log.debug([
|
||||
"Committing ",
|
||||
domainObject && domainObject.getModel().name,
|
||||
"(" + (domainObject && domainObject.getId()) + "):",
|
||||
message
|
||||
].join(" "));
|
||||
|
||||
if (this.domainObject) {
|
||||
if (this.key && configuration) {
|
||||
model.configuration = model.configuration || {};
|
||||
model.configuration[this.key] = configuration;
|
||||
}
|
||||
|
||||
domainObject.useCapability('mutation', function () {
|
||||
return model;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Handle a specific representation of a specific domain object
|
||||
EditRepresenter.prototype.represent = function (representation, representedObject) {
|
||||
this.domainObject = representedObject;
|
||||
if (representation) {
|
||||
this.key = representation.key;
|
||||
} else {
|
||||
delete this.key;
|
||||
}
|
||||
};
|
||||
|
||||
// Respond to the destruction of the current representation.
|
||||
EditRepresenter.prototype.destroy = function () {};
|
||||
|
||||
return EditRepresenter;
|
||||
domainObject.useCapability('mutation', function () {
|
||||
return model;
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Handle a specific representation of a specific domain object
|
||||
EditRepresenter.prototype.represent = function (representation, representedObject) {
|
||||
this.domainObject = representedObject;
|
||||
if (representation) {
|
||||
this.key = representation.key;
|
||||
} else {
|
||||
delete this.key;
|
||||
}
|
||||
};
|
||||
|
||||
// Respond to the destruction of the current representation.
|
||||
EditRepresenter.prototype.destroy = function () {};
|
||||
|
||||
export default EditRepresenter;
|
@ -20,136 +20,154 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/actions/CancelAction"],
|
||||
function (CancelAction) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The Cancel action", function () {
|
||||
var mockDomainObject,
|
||||
mockParentObject,
|
||||
capabilities = {},
|
||||
parentCapabilities = {},
|
||||
actionContext,
|
||||
action;
|
||||
import CancelAction from '../../src/actions/CancelAction';
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
}
|
||||
};
|
||||
describe("The Cancel action", function () {
|
||||
var mockDomainObject,
|
||||
mockParentObject,
|
||||
capabilities = {},
|
||||
parentCapabilities = {},
|
||||
actionContext,
|
||||
action;
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[
|
||||
"getCapability",
|
||||
"hasCapability",
|
||||
"getModel"
|
||||
]
|
||||
);
|
||||
mockDomainObject.getModel.and.returnValue({});
|
||||
|
||||
mockParentObject = jasmine.createSpyObj(
|
||||
"parentObject",
|
||||
[
|
||||
"getCapability"
|
||||
]
|
||||
);
|
||||
mockParentObject.getCapability.and.callFake(function (name) {
|
||||
return parentCapabilities[name];
|
||||
});
|
||||
|
||||
capabilities.editor = jasmine.createSpyObj(
|
||||
"editor",
|
||||
["save", "finish", "isEditContextRoot"]
|
||||
);
|
||||
capabilities.action = jasmine.createSpyObj(
|
||||
"actionCapability",
|
||||
[
|
||||
"perform"
|
||||
]
|
||||
);
|
||||
capabilities.location = jasmine.createSpyObj(
|
||||
"locationCapability",
|
||||
[
|
||||
"getOriginal"
|
||||
]
|
||||
);
|
||||
capabilities.location.getOriginal.and.returnValue(mockPromise(mockDomainObject));
|
||||
capabilities.context = jasmine.createSpyObj(
|
||||
"contextCapability",
|
||||
[
|
||||
"getParent"
|
||||
]
|
||||
);
|
||||
capabilities.context.getParent.and.returnValue(mockParentObject);
|
||||
|
||||
parentCapabilities.action = jasmine.createSpyObj(
|
||||
"actionCapability",
|
||||
[
|
||||
"perform"
|
||||
]
|
||||
);
|
||||
|
||||
actionContext = {
|
||||
domainObject: mockDomainObject
|
||||
};
|
||||
|
||||
mockDomainObject.getCapability.and.callFake(function (name) {
|
||||
return capabilities[name];
|
||||
});
|
||||
|
||||
mockDomainObject.hasCapability.and.callFake(function (name) {
|
||||
return Boolean(capabilities[name]);
|
||||
});
|
||||
|
||||
capabilities.editor.finish.and.returnValue(mockPromise(true));
|
||||
|
||||
action = new CancelAction(actionContext);
|
||||
|
||||
});
|
||||
|
||||
it("only applies to domain object that is being edited", function () {
|
||||
capabilities.editor.isEditContextRoot.and.returnValue(true);
|
||||
expect(CancelAction.appliesTo(actionContext)).toBeTruthy();
|
||||
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
|
||||
|
||||
capabilities.editor.isEditContextRoot.and.returnValue(false);
|
||||
expect(CancelAction.appliesTo(actionContext)).toBeFalsy();
|
||||
|
||||
mockDomainObject.hasCapability.and.returnValue(false);
|
||||
expect(CancelAction.appliesTo(actionContext)).toBeFalsy();
|
||||
});
|
||||
|
||||
it("invokes the editor capability's cancel functionality when"
|
||||
+ " performed", function () {
|
||||
mockDomainObject.getModel.and.returnValue({persisted: 1});
|
||||
//Return true from navigate action
|
||||
capabilities.action.perform.and.returnValue(mockPromise(true));
|
||||
action.perform();
|
||||
|
||||
// Should have called finish
|
||||
expect(capabilities.editor.finish).toHaveBeenCalled();
|
||||
|
||||
// Definitely shouldn't call save!
|
||||
expect(capabilities.editor.save).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("navigates to object if existing using navigate action", function () {
|
||||
mockDomainObject.getModel.and.returnValue({persisted: 1});
|
||||
//Return true from navigate action
|
||||
capabilities.action.perform.and.returnValue(mockPromise(true));
|
||||
action.perform();
|
||||
expect(capabilities.action.perform).toHaveBeenCalledWith("navigate");
|
||||
});
|
||||
|
||||
it("navigates to parent if new using navigate action", function () {
|
||||
mockDomainObject.getModel.and.returnValue({persisted: undefined});
|
||||
action.perform();
|
||||
expect(parentCapabilities.action.perform).toHaveBeenCalledWith("navigate");
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[
|
||||
"getCapability",
|
||||
"hasCapability",
|
||||
"getModel"
|
||||
]
|
||||
);
|
||||
mockDomainObject.getModel.and.returnValue({});
|
||||
|
||||
mockParentObject = jasmine.createSpyObj(
|
||||
"parentObject",
|
||||
[
|
||||
"getCapability"
|
||||
]
|
||||
);
|
||||
mockParentObject.getCapability.and.callFake(function (name) {
|
||||
return parentCapabilities[name];
|
||||
});
|
||||
|
||||
capabilities.editor = jasmine.createSpyObj(
|
||||
"editor",
|
||||
["save", "finish", "isEditContextRoot"]
|
||||
);
|
||||
capabilities.action = jasmine.createSpyObj(
|
||||
"actionCapability",
|
||||
[
|
||||
"perform"
|
||||
]
|
||||
);
|
||||
capabilities.location = jasmine.createSpyObj(
|
||||
"locationCapability",
|
||||
[
|
||||
"getOriginal"
|
||||
]
|
||||
);
|
||||
capabilities.location.getOriginal.and.returnValue(mockPromise(mockDomainObject));
|
||||
capabilities.context = jasmine.createSpyObj(
|
||||
"contextCapability",
|
||||
[
|
||||
"getParent"
|
||||
]
|
||||
);
|
||||
capabilities.context.getParent.and.returnValue(mockParentObject);
|
||||
|
||||
parentCapabilities.action = jasmine.createSpyObj(
|
||||
"actionCapability",
|
||||
[
|
||||
"perform"
|
||||
]
|
||||
);
|
||||
|
||||
actionContext = {
|
||||
domainObject: mockDomainObject
|
||||
};
|
||||
|
||||
mockDomainObject.getCapability.and.callFake(function (name) {
|
||||
return capabilities[name];
|
||||
});
|
||||
|
||||
mockDomainObject.hasCapability.and.callFake(function (name) {
|
||||
return Boolean(capabilities[name]);
|
||||
});
|
||||
|
||||
capabilities.editor.finish.and.returnValue(mockPromise(true));
|
||||
|
||||
action = new CancelAction(actionContext);
|
||||
|
||||
});
|
||||
|
||||
it("only applies to domain object that is being edited", function () {
|
||||
capabilities.editor.isEditContextRoot.and.returnValue(true);
|
||||
expect(CancelAction.appliesTo(actionContext)).toBeTruthy();
|
||||
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
|
||||
|
||||
capabilities.editor.isEditContextRoot.and.returnValue(false);
|
||||
expect(CancelAction.appliesTo(actionContext)).toBeFalsy();
|
||||
|
||||
mockDomainObject.hasCapability.and.returnValue(false);
|
||||
expect(CancelAction.appliesTo(actionContext)).toBeFalsy();
|
||||
});
|
||||
|
||||
it("invokes the editor capability's cancel functionality when"
|
||||
+ " performed", function () {
|
||||
mockDomainObject.getModel.and.returnValue({persisted: 1});
|
||||
//Return true from navigate action
|
||||
capabilities.action.perform.and.returnValue(mockPromise(true));
|
||||
action.perform();
|
||||
|
||||
// Should have called finish
|
||||
expect(capabilities.editor.finish).toHaveBeenCalled();
|
||||
|
||||
// Definitely shouldn't call save!
|
||||
expect(capabilities.editor.save).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("navigates to object if existing using navigate action", function () {
|
||||
mockDomainObject.getModel.and.returnValue({persisted: 1});
|
||||
//Return true from navigate action
|
||||
capabilities.action.perform.and.returnValue(mockPromise(true));
|
||||
action.perform();
|
||||
expect(capabilities.action.perform).toHaveBeenCalledWith("navigate");
|
||||
});
|
||||
|
||||
it("navigates to parent if new using navigate action", function () {
|
||||
mockDomainObject.getModel.and.returnValue({persisted: undefined});
|
||||
action.perform();
|
||||
expect(parentCapabilities.action.perform).toHaveBeenCalledWith("navigate");
|
||||
});
|
||||
});
|
@ -20,89 +20,107 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/actions/EditAction"],
|
||||
function (EditAction) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The Edit action", function () {
|
||||
var mockLocation,
|
||||
mockNavigationService,
|
||||
mockLog,
|
||||
mockDomainObject,
|
||||
mockType,
|
||||
mockEditor,
|
||||
actionContext,
|
||||
capabilities,
|
||||
action;
|
||||
import EditAction from '../../src/actions/EditAction';
|
||||
|
||||
beforeEach(function () {
|
||||
mockLocation = jasmine.createSpyObj(
|
||||
"$location",
|
||||
["path"]
|
||||
);
|
||||
mockNavigationService = jasmine.createSpyObj(
|
||||
"navigationService",
|
||||
["setNavigation", "getNavigation", "addListener", "removeListener"]
|
||||
);
|
||||
mockLog = jasmine.createSpyObj(
|
||||
"$log",
|
||||
["error", "warn", "info", "debug"]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
|
||||
);
|
||||
mockType = jasmine.createSpyObj(
|
||||
"type",
|
||||
["hasFeature"]
|
||||
);
|
||||
mockEditor = jasmine.createSpyObj(
|
||||
"editorCapability",
|
||||
["edit", "isEditContextRoot"]
|
||||
);
|
||||
describe("The Edit action", function () {
|
||||
var mockLocation,
|
||||
mockNavigationService,
|
||||
mockLog,
|
||||
mockDomainObject,
|
||||
mockType,
|
||||
mockEditor,
|
||||
actionContext,
|
||||
capabilities,
|
||||
action;
|
||||
|
||||
capabilities = {
|
||||
type: mockType,
|
||||
editor: mockEditor
|
||||
};
|
||||
beforeEach(function () {
|
||||
mockLocation = jasmine.createSpyObj(
|
||||
"$location",
|
||||
["path"]
|
||||
);
|
||||
mockNavigationService = jasmine.createSpyObj(
|
||||
"navigationService",
|
||||
["setNavigation", "getNavigation", "addListener", "removeListener"]
|
||||
);
|
||||
mockLog = jasmine.createSpyObj(
|
||||
"$log",
|
||||
["error", "warn", "info", "debug"]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
|
||||
);
|
||||
mockType = jasmine.createSpyObj(
|
||||
"type",
|
||||
["hasFeature"]
|
||||
);
|
||||
mockEditor = jasmine.createSpyObj(
|
||||
"editorCapability",
|
||||
["edit", "isEditContextRoot"]
|
||||
);
|
||||
|
||||
mockDomainObject.getCapability.and.callFake(function (name) {
|
||||
return capabilities[name];
|
||||
});
|
||||
mockDomainObject.hasCapability.and.returnValue(true);
|
||||
mockType.hasFeature.and.returnValue(true);
|
||||
|
||||
actionContext = { domainObject: mockDomainObject };
|
||||
|
||||
action = new EditAction(
|
||||
mockLocation,
|
||||
mockNavigationService,
|
||||
mockLog,
|
||||
actionContext
|
||||
);
|
||||
});
|
||||
|
||||
it("is only applicable when an editable domain object is present", function () {
|
||||
expect(EditAction.appliesTo(actionContext)).toBeTruthy();
|
||||
expect(EditAction.appliesTo({})).toBeFalsy();
|
||||
|
||||
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith('editor');
|
||||
// Should have checked for creatability
|
||||
expect(mockType.hasFeature).toHaveBeenCalledWith('creation');
|
||||
});
|
||||
|
||||
it("is only applicable to objects not already in edit mode", function () {
|
||||
mockEditor.isEditContextRoot.and.returnValue(false);
|
||||
expect(EditAction.appliesTo(actionContext)).toBe(true);
|
||||
mockEditor.isEditContextRoot.and.returnValue(true);
|
||||
expect(EditAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
|
||||
it ("invokes the Edit capability on the object", function () {
|
||||
action.perform();
|
||||
expect(mockDomainObject.useCapability).toHaveBeenCalledWith("editor");
|
||||
});
|
||||
capabilities = {
|
||||
type: mockType,
|
||||
editor: mockEditor
|
||||
};
|
||||
|
||||
mockDomainObject.getCapability.and.callFake(function (name) {
|
||||
return capabilities[name];
|
||||
});
|
||||
}
|
||||
);
|
||||
mockDomainObject.hasCapability.and.returnValue(true);
|
||||
mockType.hasFeature.and.returnValue(true);
|
||||
|
||||
actionContext = { domainObject: mockDomainObject };
|
||||
|
||||
action = new EditAction(
|
||||
mockLocation,
|
||||
mockNavigationService,
|
||||
mockLog,
|
||||
actionContext
|
||||
);
|
||||
});
|
||||
|
||||
it("is only applicable when an editable domain object is present", function () {
|
||||
expect(EditAction.appliesTo(actionContext)).toBeTruthy();
|
||||
expect(EditAction.appliesTo({})).toBeFalsy();
|
||||
|
||||
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith('editor');
|
||||
// Should have checked for creatability
|
||||
expect(mockType.hasFeature).toHaveBeenCalledWith('creation');
|
||||
});
|
||||
|
||||
it("is only applicable to objects not already in edit mode", function () {
|
||||
mockEditor.isEditContextRoot.and.returnValue(false);
|
||||
expect(EditAction.appliesTo(actionContext)).toBe(true);
|
||||
mockEditor.isEditContextRoot.and.returnValue(true);
|
||||
expect(EditAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
|
||||
it ("invokes the Edit capability on the object", function () {
|
||||
action.perform();
|
||||
expect(mockDomainObject.useCapability).toHaveBeenCalledWith("editor");
|
||||
});
|
||||
|
||||
});
|
@ -20,100 +20,118 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/actions/EditAndComposeAction"],
|
||||
function (EditAndComposeAction) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The Link action", function () {
|
||||
var mockDomainObject,
|
||||
mockParent,
|
||||
mockContext,
|
||||
mockComposition,
|
||||
mockActionCapability,
|
||||
mockEditAction,
|
||||
mockType,
|
||||
actionContext,
|
||||
model,
|
||||
capabilities,
|
||||
action;
|
||||
import EditAndComposeAction from '../../src/actions/EditAndComposeAction';
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
}
|
||||
};
|
||||
describe("The Link action", function () {
|
||||
var mockDomainObject,
|
||||
mockParent,
|
||||
mockContext,
|
||||
mockComposition,
|
||||
mockActionCapability,
|
||||
mockEditAction,
|
||||
mockType,
|
||||
actionContext,
|
||||
model,
|
||||
capabilities,
|
||||
action;
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
["getId", "getCapability"]
|
||||
);
|
||||
mockParent = {
|
||||
getModel: function () {
|
||||
return model;
|
||||
},
|
||||
getCapability: function (k) {
|
||||
return capabilities[k];
|
||||
},
|
||||
useCapability: function (k, v) {
|
||||
return capabilities[k].invoke(v);
|
||||
}
|
||||
};
|
||||
mockContext = jasmine.createSpyObj("context", ["getParent"]);
|
||||
mockComposition = jasmine.createSpyObj("composition", ["invoke", "add"]);
|
||||
mockType = jasmine.createSpyObj("type", ["hasFeature", "getKey"]);
|
||||
mockActionCapability = jasmine.createSpyObj("actionCapability", ["getActions"]);
|
||||
mockEditAction = jasmine.createSpyObj("editAction", ["perform"]);
|
||||
|
||||
mockDomainObject.getId.and.returnValue("test");
|
||||
mockDomainObject.getCapability.and.returnValue(mockContext);
|
||||
mockContext.getParent.and.returnValue(mockParent);
|
||||
mockType.hasFeature.and.returnValue(true);
|
||||
mockType.getKey.and.returnValue("layout");
|
||||
mockComposition.invoke.and.returnValue(mockPromise(true));
|
||||
mockComposition.add.and.returnValue(mockPromise(true));
|
||||
mockActionCapability.getActions.and.returnValue([]);
|
||||
|
||||
capabilities = {
|
||||
composition: mockComposition,
|
||||
action: mockActionCapability,
|
||||
type: mockType
|
||||
};
|
||||
model = {
|
||||
composition: ["a", "b", "c"]
|
||||
};
|
||||
|
||||
actionContext = {
|
||||
domainObject: mockParent,
|
||||
selectedObject: mockDomainObject
|
||||
};
|
||||
|
||||
action = new EditAndComposeAction(actionContext);
|
||||
});
|
||||
|
||||
it("adds to the parent's composition when performed", function () {
|
||||
action.perform();
|
||||
expect(mockComposition.add)
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
|
||||
it("enables edit mode for objects that have an edit action", function () {
|
||||
mockActionCapability.getActions.and.returnValue([mockEditAction]);
|
||||
action.perform();
|
||||
expect(mockEditAction.perform).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Does not enable edit mode for objects that do not have an"
|
||||
+ " edit action", function () {
|
||||
mockActionCapability.getActions.and.returnValue([]);
|
||||
action.perform();
|
||||
expect(mockEditAction.perform).not.toHaveBeenCalled();
|
||||
expect(mockComposition.add)
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
["getId", "getCapability"]
|
||||
);
|
||||
mockParent = {
|
||||
getModel: function () {
|
||||
return model;
|
||||
},
|
||||
getCapability: function (k) {
|
||||
return capabilities[k];
|
||||
},
|
||||
useCapability: function (k, v) {
|
||||
return capabilities[k].invoke(v);
|
||||
}
|
||||
};
|
||||
mockContext = jasmine.createSpyObj("context", ["getParent"]);
|
||||
mockComposition = jasmine.createSpyObj("composition", ["invoke", "add"]);
|
||||
mockType = jasmine.createSpyObj("type", ["hasFeature", "getKey"]);
|
||||
mockActionCapability = jasmine.createSpyObj("actionCapability", ["getActions"]);
|
||||
mockEditAction = jasmine.createSpyObj("editAction", ["perform"]);
|
||||
|
||||
mockDomainObject.getId.and.returnValue("test");
|
||||
mockDomainObject.getCapability.and.returnValue(mockContext);
|
||||
mockContext.getParent.and.returnValue(mockParent);
|
||||
mockType.hasFeature.and.returnValue(true);
|
||||
mockType.getKey.and.returnValue("layout");
|
||||
mockComposition.invoke.and.returnValue(mockPromise(true));
|
||||
mockComposition.add.and.returnValue(mockPromise(true));
|
||||
mockActionCapability.getActions.and.returnValue([]);
|
||||
|
||||
capabilities = {
|
||||
composition: mockComposition,
|
||||
action: mockActionCapability,
|
||||
type: mockType
|
||||
};
|
||||
model = {
|
||||
composition: ["a", "b", "c"]
|
||||
};
|
||||
|
||||
actionContext = {
|
||||
domainObject: mockParent,
|
||||
selectedObject: mockDomainObject
|
||||
};
|
||||
|
||||
action = new EditAndComposeAction(actionContext);
|
||||
});
|
||||
|
||||
it("adds to the parent's composition when performed", function () {
|
||||
action.perform();
|
||||
expect(mockComposition.add)
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
|
||||
it("enables edit mode for objects that have an edit action", function () {
|
||||
mockActionCapability.getActions.and.returnValue([mockEditAction]);
|
||||
action.perform();
|
||||
expect(mockEditAction.perform).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Does not enable edit mode for objects that do not have an"
|
||||
+ " edit action", function () {
|
||||
mockActionCapability.getActions.and.returnValue([]);
|
||||
action.perform();
|
||||
expect(mockEditAction.perform).not.toHaveBeenCalled();
|
||||
expect(mockComposition.add)
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
|
||||
});
|
@ -20,140 +20,158 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/actions/SaveAction"],
|
||||
function (SaveAction) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The Save action", function () {
|
||||
var mockDomainObject,
|
||||
mockEditorCapability,
|
||||
actionContext,
|
||||
mockDialogService,
|
||||
mockNotificationService,
|
||||
mockActionCapability,
|
||||
capabilities = {},
|
||||
action;
|
||||
import SaveAction from '../../src/actions/SaveAction';
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
},
|
||||
catch: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
}
|
||||
};
|
||||
describe("The Save action", function () {
|
||||
var mockDomainObject,
|
||||
mockEditorCapability,
|
||||
actionContext,
|
||||
mockDialogService,
|
||||
mockNotificationService,
|
||||
mockActionCapability,
|
||||
capabilities = {},
|
||||
action;
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
},
|
||||
catch: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[
|
||||
"getCapability",
|
||||
"hasCapability",
|
||||
"getModel",
|
||||
"getOriginalObject"
|
||||
]
|
||||
);
|
||||
mockEditorCapability = jasmine.createSpyObj(
|
||||
"editor",
|
||||
["save", "isEditContextRoot"]
|
||||
);
|
||||
mockActionCapability = jasmine.createSpyObj(
|
||||
"actionCapability",
|
||||
["perform"]
|
||||
);
|
||||
capabilities.editor = mockEditorCapability;
|
||||
capabilities.action = mockActionCapability;
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[
|
||||
"getCapability",
|
||||
"hasCapability",
|
||||
"getModel",
|
||||
"getOriginalObject"
|
||||
]
|
||||
);
|
||||
mockEditorCapability = jasmine.createSpyObj(
|
||||
"editor",
|
||||
["save", "isEditContextRoot"]
|
||||
);
|
||||
mockActionCapability = jasmine.createSpyObj(
|
||||
"actionCapability",
|
||||
["perform"]
|
||||
);
|
||||
capabilities.editor = mockEditorCapability;
|
||||
capabilities.action = mockActionCapability;
|
||||
|
||||
actionContext = {
|
||||
domainObject: mockDomainObject
|
||||
};
|
||||
actionContext = {
|
||||
domainObject: mockDomainObject
|
||||
};
|
||||
|
||||
mockDialogService = jasmine.createSpyObj(
|
||||
"dialogService",
|
||||
["showBlockingMessage"]
|
||||
);
|
||||
mockDialogService = jasmine.createSpyObj(
|
||||
"dialogService",
|
||||
["showBlockingMessage"]
|
||||
);
|
||||
|
||||
mockNotificationService = jasmine.createSpyObj(
|
||||
"notificationService",
|
||||
["info", "error"]
|
||||
);
|
||||
mockNotificationService = jasmine.createSpyObj(
|
||||
"notificationService",
|
||||
["info", "error"]
|
||||
);
|
||||
|
||||
mockDomainObject.hasCapability.and.returnValue(true);
|
||||
mockDomainObject.getCapability.and.callFake(function (capability) {
|
||||
return capabilities[capability];
|
||||
});
|
||||
mockDomainObject.getModel.and.returnValue({persisted: 0});
|
||||
mockEditorCapability.save.and.returnValue(mockPromise(true));
|
||||
mockEditorCapability.isEditContextRoot.and.returnValue(true);
|
||||
mockDomainObject.hasCapability.and.returnValue(true);
|
||||
mockDomainObject.getCapability.and.callFake(function (capability) {
|
||||
return capabilities[capability];
|
||||
});
|
||||
mockDomainObject.getModel.and.returnValue({persisted: 0});
|
||||
mockEditorCapability.save.and.returnValue(mockPromise(true));
|
||||
mockEditorCapability.isEditContextRoot.and.returnValue(true);
|
||||
|
||||
action = new SaveAction(mockDialogService, mockNotificationService, actionContext);
|
||||
});
|
||||
action = new SaveAction(mockDialogService, mockNotificationService, actionContext);
|
||||
});
|
||||
|
||||
it("only applies to domain object with an editor capability", function () {
|
||||
expect(SaveAction.appliesTo(actionContext)).toBe(true);
|
||||
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
|
||||
it("only applies to domain object with an editor capability", function () {
|
||||
expect(SaveAction.appliesTo(actionContext)).toBe(true);
|
||||
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
|
||||
|
||||
mockDomainObject.hasCapability.and.returnValue(false);
|
||||
mockDomainObject.getCapability.and.returnValue(undefined);
|
||||
expect(SaveAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
mockDomainObject.hasCapability.and.returnValue(false);
|
||||
mockDomainObject.getCapability.and.returnValue(undefined);
|
||||
expect(SaveAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
|
||||
it("only applies to domain object that has already been persisted",
|
||||
function () {
|
||||
mockDomainObject.getModel.and.returnValue({persisted: undefined});
|
||||
expect(SaveAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
it("only applies to domain object that has already been persisted",
|
||||
function () {
|
||||
mockDomainObject.getModel.and.returnValue({persisted: undefined});
|
||||
expect(SaveAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
|
||||
it("uses the editor capability to save the object",
|
||||
function () {
|
||||
action.perform();
|
||||
expect(mockEditorCapability.save).toHaveBeenCalled();
|
||||
});
|
||||
it("uses the editor capability to save the object",
|
||||
function () {
|
||||
action.perform();
|
||||
expect(mockEditorCapability.save).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("in order to keep the user in the loop", function () {
|
||||
var mockDialogHandle;
|
||||
describe("in order to keep the user in the loop", function () {
|
||||
var mockDialogHandle;
|
||||
|
||||
beforeEach(function () {
|
||||
mockDialogHandle = jasmine.createSpyObj("dialogHandle", ["dismiss"]);
|
||||
mockDialogService.showBlockingMessage.and.returnValue(mockDialogHandle);
|
||||
});
|
||||
beforeEach(function () {
|
||||
mockDialogHandle = jasmine.createSpyObj("dialogHandle", ["dismiss"]);
|
||||
mockDialogService.showBlockingMessage.and.returnValue(mockDialogHandle);
|
||||
});
|
||||
|
||||
it("shows a dialog while saving", function () {
|
||||
mockEditorCapability.save.and.returnValue(new Promise(function () {
|
||||
}));
|
||||
action.perform();
|
||||
expect(mockDialogService.showBlockingMessage).toHaveBeenCalled();
|
||||
expect(mockDialogHandle.dismiss).not.toHaveBeenCalled();
|
||||
});
|
||||
it("shows a dialog while saving", function () {
|
||||
mockEditorCapability.save.and.returnValue(new Promise(function () {
|
||||
}));
|
||||
action.perform();
|
||||
expect(mockDialogService.showBlockingMessage).toHaveBeenCalled();
|
||||
expect(mockDialogHandle.dismiss).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("hides the dialog when saving is complete", function () {
|
||||
action.perform();
|
||||
expect(mockDialogService.showBlockingMessage).toHaveBeenCalled();
|
||||
expect(mockDialogHandle.dismiss).toHaveBeenCalled();
|
||||
});
|
||||
it("hides the dialog when saving is complete", function () {
|
||||
action.perform();
|
||||
expect(mockDialogService.showBlockingMessage).toHaveBeenCalled();
|
||||
expect(mockDialogHandle.dismiss).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("notifies if saving succeeded", function () {
|
||||
var mockCallback = jasmine.createSpy("callback");
|
||||
mockEditorCapability.save.and.returnValue(Promise.resolve());
|
||||
it("notifies if saving succeeded", function () {
|
||||
var mockCallback = jasmine.createSpy("callback");
|
||||
mockEditorCapability.save.and.returnValue(Promise.resolve());
|
||||
|
||||
return action.perform().then(mockCallback).then(function () {
|
||||
expect(mockNotificationService.info).toHaveBeenCalled();
|
||||
expect(mockNotificationService.error).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it("notifies if saving failed", function () {
|
||||
var mockCallback = jasmine.createSpy("callback");
|
||||
mockEditorCapability.save.and.returnValue(Promise.reject("some failure reason"));
|
||||
|
||||
return action.perform().then(mockCallback).then(function () {
|
||||
expect(mockNotificationService.error).toHaveBeenCalled();
|
||||
expect(mockNotificationService.info).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
return action.perform().then(mockCallback).then(function () {
|
||||
expect(mockNotificationService.info).toHaveBeenCalled();
|
||||
expect(mockNotificationService.error).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
it("notifies if saving failed", function () {
|
||||
var mockCallback = jasmine.createSpy("callback");
|
||||
mockEditorCapability.save.and.returnValue(Promise.reject("some failure reason"));
|
||||
|
||||
return action.perform().then(mockCallback).then(function () {
|
||||
expect(mockNotificationService.error).toHaveBeenCalled();
|
||||
expect(mockNotificationService.info).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -20,109 +20,127 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/actions/SaveAndStopEditingAction"],
|
||||
function (SaveAndStopEditingAction) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The Save and Stop Editing action", function () {
|
||||
import SaveAndStopEditingAction from '../../src/actions/SaveAndStopEditingAction';
|
||||
|
||||
// Some mocks appear unused because the
|
||||
// underlying SaveAction that this action
|
||||
// depends on is not mocked, so we mock some
|
||||
// of SaveAction's own dependencies to make
|
||||
// it run.
|
||||
var mockDomainObject,
|
||||
mockEditorCapability,
|
||||
actionContext,
|
||||
dialogService,
|
||||
notificationService,
|
||||
mockActionCapability,
|
||||
capabilities = {},
|
||||
action;
|
||||
describe("The Save and Stop Editing action", function () {
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
},
|
||||
catch: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
}
|
||||
};
|
||||
// Some mocks appear unused because the
|
||||
// underlying SaveAction that this action
|
||||
// depends on is not mocked, so we mock some
|
||||
// of SaveAction's own dependencies to make
|
||||
// it run.
|
||||
var mockDomainObject,
|
||||
mockEditorCapability,
|
||||
actionContext,
|
||||
dialogService,
|
||||
notificationService,
|
||||
mockActionCapability,
|
||||
capabilities = {},
|
||||
action;
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
},
|
||||
catch: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[
|
||||
"getCapability",
|
||||
"hasCapability",
|
||||
"getModel",
|
||||
"getOriginalObject"
|
||||
]
|
||||
);
|
||||
mockEditorCapability = jasmine.createSpyObj(
|
||||
"editor",
|
||||
["save", "finish", "isEditContextRoot"]
|
||||
);
|
||||
mockActionCapability = jasmine.createSpyObj(
|
||||
"actionCapability",
|
||||
["perform"]
|
||||
);
|
||||
capabilities.editor = mockEditorCapability;
|
||||
capabilities.action = mockActionCapability;
|
||||
|
||||
actionContext = {
|
||||
domainObject: mockDomainObject
|
||||
};
|
||||
dialogService = jasmine.createSpyObj(
|
||||
"dialogService",
|
||||
["showBlockingMessage"]
|
||||
);
|
||||
|
||||
notificationService = jasmine.createSpyObj(
|
||||
"notificationService",
|
||||
["info", "error"]
|
||||
);
|
||||
|
||||
mockDomainObject.hasCapability.and.returnValue(true);
|
||||
mockDomainObject.getCapability.and.callFake(function (capability) {
|
||||
return capabilities[capability];
|
||||
});
|
||||
mockDomainObject.getModel.and.returnValue({ persisted: 0 });
|
||||
mockEditorCapability.save.and.returnValue(mockPromise(true));
|
||||
mockEditorCapability.isEditContextRoot.and.returnValue(true);
|
||||
|
||||
action = new SaveAndStopEditingAction(dialogService, notificationService, actionContext);
|
||||
});
|
||||
|
||||
it("only applies to domain object with an editor capability", function () {
|
||||
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(true);
|
||||
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
|
||||
|
||||
mockDomainObject.hasCapability.and.returnValue(false);
|
||||
mockDomainObject.getCapability.and.returnValue(undefined);
|
||||
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
|
||||
it("only applies to domain object that has already been persisted", function () {
|
||||
mockDomainObject.getModel.and.returnValue({ persisted: undefined });
|
||||
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
|
||||
it("does not close the editor before completing the save", function () {
|
||||
mockEditorCapability.save.and.returnValue(new Promise(function () {
|
||||
}));
|
||||
action.perform();
|
||||
expect(mockEditorCapability.save).toHaveBeenCalled();
|
||||
expect(mockEditorCapability.finish).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("closes the editor after saving", function () {
|
||||
action.perform();
|
||||
expect(mockEditorCapability.save).toHaveBeenCalled();
|
||||
expect(mockEditorCapability.finish).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[
|
||||
"getCapability",
|
||||
"hasCapability",
|
||||
"getModel",
|
||||
"getOriginalObject"
|
||||
]
|
||||
);
|
||||
mockEditorCapability = jasmine.createSpyObj(
|
||||
"editor",
|
||||
["save", "finish", "isEditContextRoot"]
|
||||
);
|
||||
mockActionCapability = jasmine.createSpyObj(
|
||||
"actionCapability",
|
||||
["perform"]
|
||||
);
|
||||
capabilities.editor = mockEditorCapability;
|
||||
capabilities.action = mockActionCapability;
|
||||
|
||||
actionContext = {
|
||||
domainObject: mockDomainObject
|
||||
};
|
||||
dialogService = jasmine.createSpyObj(
|
||||
"dialogService",
|
||||
["showBlockingMessage"]
|
||||
);
|
||||
|
||||
notificationService = jasmine.createSpyObj(
|
||||
"notificationService",
|
||||
["info", "error"]
|
||||
);
|
||||
|
||||
mockDomainObject.hasCapability.and.returnValue(true);
|
||||
mockDomainObject.getCapability.and.callFake(function (capability) {
|
||||
return capabilities[capability];
|
||||
});
|
||||
mockDomainObject.getModel.and.returnValue({ persisted: 0 });
|
||||
mockEditorCapability.save.and.returnValue(mockPromise(true));
|
||||
mockEditorCapability.isEditContextRoot.and.returnValue(true);
|
||||
|
||||
action = new SaveAndStopEditingAction(dialogService, notificationService, actionContext);
|
||||
});
|
||||
|
||||
it("only applies to domain object with an editor capability", function () {
|
||||
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(true);
|
||||
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
|
||||
|
||||
mockDomainObject.hasCapability.and.returnValue(false);
|
||||
mockDomainObject.getCapability.and.returnValue(undefined);
|
||||
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
|
||||
it("only applies to domain object that has already been persisted", function () {
|
||||
mockDomainObject.getModel.and.returnValue({ persisted: undefined });
|
||||
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
|
||||
it("does not close the editor before completing the save", function () {
|
||||
mockEditorCapability.save.and.returnValue(new Promise(function () {
|
||||
}));
|
||||
action.perform();
|
||||
expect(mockEditorCapability.save).toHaveBeenCalled();
|
||||
expect(mockEditorCapability.finish).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("closes the editor after saving", function () {
|
||||
action.perform();
|
||||
expect(mockEditorCapability.save).toHaveBeenCalled();
|
||||
expect(mockEditorCapability.finish).toHaveBeenCalled();
|
||||
});
|
||||
});
|
@ -20,87 +20,105 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/controllers/EditActionController"],
|
||||
function (EditActionController) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The Edit Action controller", function () {
|
||||
var mockSaveActionMetadata = {
|
||||
name: "mocked-save-action",
|
||||
cssClass: "mocked-save-action-css"
|
||||
};
|
||||
import EditActionController from '../../src/controllers/EditActionController';
|
||||
|
||||
function fakeGetActions(actionContext) {
|
||||
if (actionContext.category === "save") {
|
||||
var mockedSaveActions = [
|
||||
jasmine.createSpyObj("mockSaveAction", ["getMetadata", "perform"]),
|
||||
jasmine.createSpyObj("mockSaveAction", ["getMetadata", "perform"])
|
||||
];
|
||||
mockedSaveActions.forEach(function (action) {
|
||||
action.getMetadata.and.returnValue(mockSaveActionMetadata);
|
||||
});
|
||||
describe("The Edit Action controller", function () {
|
||||
var mockSaveActionMetadata = {
|
||||
name: "mocked-save-action",
|
||||
cssClass: "mocked-save-action-css"
|
||||
};
|
||||
|
||||
return mockedSaveActions;
|
||||
} else if (actionContext.category === "conclude-editing") {
|
||||
return ["a", "b", "c"];
|
||||
} else {
|
||||
throw "EditActionController uses a context that's not covered by tests.";
|
||||
}
|
||||
}
|
||||
|
||||
var mockScope,
|
||||
mockActions,
|
||||
controller;
|
||||
|
||||
beforeEach(function () {
|
||||
mockActions = jasmine.createSpyObj("action", ["getActions"]);
|
||||
mockActions.getActions.and.callFake(fakeGetActions);
|
||||
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
|
||||
mockScope.action = mockActions;
|
||||
controller = new EditActionController(mockScope);
|
||||
function fakeGetActions(actionContext) {
|
||||
if (actionContext.category === "save") {
|
||||
var mockedSaveActions = [
|
||||
jasmine.createSpyObj("mockSaveAction", ["getMetadata", "perform"]),
|
||||
jasmine.createSpyObj("mockSaveAction", ["getMetadata", "perform"])
|
||||
];
|
||||
mockedSaveActions.forEach(function (action) {
|
||||
action.getMetadata.and.returnValue(mockSaveActionMetadata);
|
||||
});
|
||||
|
||||
function makeControllerUpdateActions() {
|
||||
mockScope.$watch.calls.mostRecent().args[1]();
|
||||
}
|
||||
|
||||
it("watches scope that may change applicable actions", function () {
|
||||
// The action capability
|
||||
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||
"action",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
it("populates the scope with 'save' actions", function () {
|
||||
makeControllerUpdateActions();
|
||||
expect(mockScope.saveActions.length).toEqual(2);
|
||||
});
|
||||
|
||||
it("converts 'save' actions to their menu counterparts", function () {
|
||||
makeControllerUpdateActions();
|
||||
var menuOptions = mockScope.saveActionsAsMenuOptions;
|
||||
|
||||
expect(menuOptions.length).toEqual(2);
|
||||
expect(menuOptions[0].key).toEqual(mockScope.saveActions[0]);
|
||||
expect(menuOptions[1].key).toEqual(mockScope.saveActions[1]);
|
||||
menuOptions.forEach(function (option) {
|
||||
expect(option.name).toEqual(mockSaveActionMetadata.name);
|
||||
expect(option.cssClass).toEqual(mockSaveActionMetadata.cssClass);
|
||||
});
|
||||
});
|
||||
|
||||
it("uses a click handler to perform the clicked action", function () {
|
||||
makeControllerUpdateActions();
|
||||
var sampleSaveAction = mockScope.saveActions[0];
|
||||
mockScope.saveActionMenuClickHandler(sampleSaveAction);
|
||||
expect(sampleSaveAction.perform).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("populates the scope with other editing actions", function () {
|
||||
makeControllerUpdateActions();
|
||||
expect(mockScope.otherEditActions).toEqual(["a", "b", "c"]);
|
||||
});
|
||||
});
|
||||
return mockedSaveActions;
|
||||
} else if (actionContext.category === "conclude-editing") {
|
||||
return ["a", "b", "c"];
|
||||
} else {
|
||||
throw "EditActionController uses a context that's not covered by tests.";
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
var mockScope,
|
||||
mockActions,
|
||||
controller;
|
||||
|
||||
beforeEach(function () {
|
||||
mockActions = jasmine.createSpyObj("action", ["getActions"]);
|
||||
mockActions.getActions.and.callFake(fakeGetActions);
|
||||
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
|
||||
mockScope.action = mockActions;
|
||||
controller = new EditActionController(mockScope);
|
||||
});
|
||||
|
||||
function makeControllerUpdateActions() {
|
||||
mockScope.$watch.calls.mostRecent().args[1]();
|
||||
}
|
||||
|
||||
it("watches scope that may change applicable actions", function () {
|
||||
// The action capability
|
||||
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||
"action",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
it("populates the scope with 'save' actions", function () {
|
||||
makeControllerUpdateActions();
|
||||
expect(mockScope.saveActions.length).toEqual(2);
|
||||
});
|
||||
|
||||
it("converts 'save' actions to their menu counterparts", function () {
|
||||
makeControllerUpdateActions();
|
||||
var menuOptions = mockScope.saveActionsAsMenuOptions;
|
||||
|
||||
expect(menuOptions.length).toEqual(2);
|
||||
expect(menuOptions[0].key).toEqual(mockScope.saveActions[0]);
|
||||
expect(menuOptions[1].key).toEqual(mockScope.saveActions[1]);
|
||||
menuOptions.forEach(function (option) {
|
||||
expect(option.name).toEqual(mockSaveActionMetadata.name);
|
||||
expect(option.cssClass).toEqual(mockSaveActionMetadata.cssClass);
|
||||
});
|
||||
});
|
||||
|
||||
it("uses a click handler to perform the clicked action", function () {
|
||||
makeControllerUpdateActions();
|
||||
var sampleSaveAction = mockScope.saveActions[0];
|
||||
mockScope.saveActionMenuClickHandler(sampleSaveAction);
|
||||
expect(sampleSaveAction.perform).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("populates the scope with other editing actions", function () {
|
||||
makeControllerUpdateActions();
|
||||
expect(mockScope.otherEditActions).toEqual(["a", "b", "c"]);
|
||||
});
|
||||
});
|
@ -20,119 +20,137 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/controllers/EditObjectController"],
|
||||
function (EditObjectController) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The Edit Object controller", function () {
|
||||
var mockScope,
|
||||
mockObject,
|
||||
testViews,
|
||||
mockEditorCapability,
|
||||
mockLocation,
|
||||
mockNavigationService,
|
||||
removeCheck,
|
||||
mockStatusCapability,
|
||||
mockCapabilities,
|
||||
controller;
|
||||
import EditObjectController from '../../src/controllers/EditObjectController';
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj(
|
||||
"$scope",
|
||||
["$on", "$watch"]
|
||||
);
|
||||
mockObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
|
||||
);
|
||||
mockEditorCapability = jasmine.createSpyObj(
|
||||
"mockEditorCapability",
|
||||
["isEditContextRoot", "dirty", "finish"]
|
||||
);
|
||||
mockStatusCapability = jasmine.createSpyObj('statusCapability',
|
||||
["get"]
|
||||
);
|
||||
describe("The Edit Object controller", function () {
|
||||
var mockScope,
|
||||
mockObject,
|
||||
testViews,
|
||||
mockEditorCapability,
|
||||
mockLocation,
|
||||
mockNavigationService,
|
||||
removeCheck,
|
||||
mockStatusCapability,
|
||||
mockCapabilities,
|
||||
controller;
|
||||
|
||||
mockCapabilities = {
|
||||
"editor": mockEditorCapability,
|
||||
"status": mockStatusCapability
|
||||
};
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj(
|
||||
"$scope",
|
||||
["$on", "$watch"]
|
||||
);
|
||||
mockObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
|
||||
);
|
||||
mockEditorCapability = jasmine.createSpyObj(
|
||||
"mockEditorCapability",
|
||||
["isEditContextRoot", "dirty", "finish"]
|
||||
);
|
||||
mockStatusCapability = jasmine.createSpyObj('statusCapability',
|
||||
["get"]
|
||||
);
|
||||
|
||||
mockLocation = jasmine.createSpyObj('$location',
|
||||
["search"]
|
||||
);
|
||||
mockLocation.search.and.returnValue({"view": "fixed"});
|
||||
mockNavigationService = jasmine.createSpyObj('navigationService',
|
||||
["checkBeforeNavigation"]
|
||||
);
|
||||
mockCapabilities = {
|
||||
"editor": mockEditorCapability,
|
||||
"status": mockStatusCapability
|
||||
};
|
||||
|
||||
removeCheck = jasmine.createSpy('removeCheck');
|
||||
mockNavigationService.checkBeforeNavigation.and.returnValue(removeCheck);
|
||||
mockLocation = jasmine.createSpyObj('$location',
|
||||
["search"]
|
||||
);
|
||||
mockLocation.search.and.returnValue({"view": "fixed"});
|
||||
mockNavigationService = jasmine.createSpyObj('navigationService',
|
||||
["checkBeforeNavigation"]
|
||||
);
|
||||
|
||||
mockObject.getId.and.returnValue("test");
|
||||
mockObject.getModel.and.returnValue({ name: "Test object" });
|
||||
mockObject.getCapability.and.callFake(function (key) {
|
||||
return mockCapabilities[key];
|
||||
});
|
||||
|
||||
testViews = [
|
||||
{ key: 'abc' },
|
||||
{
|
||||
key: 'def',
|
||||
someKey: 'some value'
|
||||
},
|
||||
{ key: 'xyz' }
|
||||
];
|
||||
|
||||
mockObject.useCapability.and.callFake(function (c) {
|
||||
return (c === 'view') && testViews;
|
||||
});
|
||||
mockLocation.search.and.returnValue({ view: 'def' });
|
||||
|
||||
mockScope.domainObject = mockObject;
|
||||
|
||||
controller = new EditObjectController(
|
||||
mockScope,
|
||||
mockLocation,
|
||||
mockNavigationService
|
||||
);
|
||||
});
|
||||
|
||||
it("adds a check before navigation", function () {
|
||||
expect(mockNavigationService.checkBeforeNavigation)
|
||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||
|
||||
var checkFn = mockNavigationService.checkBeforeNavigation.calls.mostRecent().args[0];
|
||||
|
||||
mockEditorCapability.isEditContextRoot.and.returnValue(false);
|
||||
mockEditorCapability.dirty.and.returnValue(false);
|
||||
|
||||
expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes.");
|
||||
|
||||
mockEditorCapability.isEditContextRoot.and.returnValue(true);
|
||||
expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes.");
|
||||
|
||||
mockEditorCapability.dirty.and.returnValue(true);
|
||||
expect(checkFn())
|
||||
.toBe("Continuing will cause the loss of any unsaved changes.");
|
||||
|
||||
});
|
||||
|
||||
it("cleans up on destroy", function () {
|
||||
expect(mockScope.$on)
|
||||
.toHaveBeenCalledWith("$destroy", jasmine.any(Function));
|
||||
|
||||
mockScope.$on.calls.mostRecent().args[1]();
|
||||
|
||||
expect(mockEditorCapability.finish).toHaveBeenCalled();
|
||||
expect(removeCheck).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sets the active view from query parameters", function () {
|
||||
expect(mockScope.representation.selected)
|
||||
.toEqual(testViews[1]);
|
||||
});
|
||||
removeCheck = jasmine.createSpy('removeCheck');
|
||||
mockNavigationService.checkBeforeNavigation.and.returnValue(removeCheck);
|
||||
|
||||
mockObject.getId.and.returnValue("test");
|
||||
mockObject.getModel.and.returnValue({ name: "Test object" });
|
||||
mockObject.getCapability.and.callFake(function (key) {
|
||||
return mockCapabilities[key];
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
testViews = [
|
||||
{ key: 'abc' },
|
||||
{
|
||||
key: 'def',
|
||||
someKey: 'some value'
|
||||
},
|
||||
{ key: 'xyz' }
|
||||
];
|
||||
|
||||
mockObject.useCapability.and.callFake(function (c) {
|
||||
return (c === 'view') && testViews;
|
||||
});
|
||||
mockLocation.search.and.returnValue({ view: 'def' });
|
||||
|
||||
mockScope.domainObject = mockObject;
|
||||
|
||||
controller = new EditObjectController(
|
||||
mockScope,
|
||||
mockLocation,
|
||||
mockNavigationService
|
||||
);
|
||||
});
|
||||
|
||||
it("adds a check before navigation", function () {
|
||||
expect(mockNavigationService.checkBeforeNavigation)
|
||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||
|
||||
var checkFn = mockNavigationService.checkBeforeNavigation.calls.mostRecent().args[0];
|
||||
|
||||
mockEditorCapability.isEditContextRoot.and.returnValue(false);
|
||||
mockEditorCapability.dirty.and.returnValue(false);
|
||||
|
||||
expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes.");
|
||||
|
||||
mockEditorCapability.isEditContextRoot.and.returnValue(true);
|
||||
expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes.");
|
||||
|
||||
mockEditorCapability.dirty.and.returnValue(true);
|
||||
expect(checkFn())
|
||||
.toBe("Continuing will cause the loss of any unsaved changes.");
|
||||
|
||||
});
|
||||
|
||||
it("cleans up on destroy", function () {
|
||||
expect(mockScope.$on)
|
||||
.toHaveBeenCalledWith("$destroy", jasmine.any(Function));
|
||||
|
||||
mockScope.$on.calls.mostRecent().args[1]();
|
||||
|
||||
expect(mockEditorCapability.finish).toHaveBeenCalled();
|
||||
expect(removeCheck).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sets the active view from query parameters", function () {
|
||||
expect(mockScope.representation.selected)
|
||||
.toEqual(testViews[1]);
|
||||
});
|
||||
|
||||
});
|
@ -20,95 +20,113 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/controllers/EditPanesController"],
|
||||
function (EditPanesController) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The Edit Panes controller", function () {
|
||||
var mockScope,
|
||||
mockDomainObject,
|
||||
mockContext,
|
||||
controller;
|
||||
import EditPanesController from '../../src/controllers/EditPanesController';
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
['getId', 'getCapability']
|
||||
);
|
||||
mockContext = jasmine.createSpyObj(
|
||||
'context',
|
||||
['getTrueRoot']
|
||||
);
|
||||
describe("The Edit Panes controller", function () {
|
||||
var mockScope,
|
||||
mockDomainObject,
|
||||
mockContext,
|
||||
controller;
|
||||
|
||||
mockDomainObject.getId.and.returnValue('test-id');
|
||||
mockDomainObject.getCapability.and.returnValue(mockContext);
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
['getId', 'getCapability']
|
||||
);
|
||||
mockContext = jasmine.createSpyObj(
|
||||
'context',
|
||||
['getTrueRoot']
|
||||
);
|
||||
|
||||
// Return a new instance of the root object each time
|
||||
mockContext.getTrueRoot.and.callFake(function () {
|
||||
var mockRoot = jasmine.createSpyObj('root', ['getId']);
|
||||
mockRoot.getId.and.returnValue('root-id');
|
||||
mockDomainObject.getId.and.returnValue('test-id');
|
||||
mockDomainObject.getCapability.and.returnValue(mockContext);
|
||||
|
||||
return mockRoot;
|
||||
});
|
||||
// Return a new instance of the root object each time
|
||||
mockContext.getTrueRoot.and.callFake(function () {
|
||||
var mockRoot = jasmine.createSpyObj('root', ['getId']);
|
||||
mockRoot.getId.and.returnValue('root-id');
|
||||
|
||||
controller = new EditPanesController(mockScope);
|
||||
});
|
||||
|
||||
it("watches for the domain object in view", function () {
|
||||
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||
"domainObject",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
it("exposes the root object found via the object's context capability", function () {
|
||||
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
|
||||
|
||||
// Verify that the correct capability was used
|
||||
expect(mockDomainObject.getCapability)
|
||||
.toHaveBeenCalledWith('context');
|
||||
|
||||
// Should have exposed the root from getRoot
|
||||
expect(controller.getRoot().getId()).toEqual('root-id');
|
||||
});
|
||||
|
||||
it("preserves the same root instance to avoid excessive refreshing", function () {
|
||||
var firstRoot;
|
||||
// Expose the domain object
|
||||
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
|
||||
firstRoot = controller.getRoot();
|
||||
// Update!
|
||||
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
|
||||
// Should still have the same object instance, to avoid
|
||||
// triggering the watch used by the template we're supporting
|
||||
expect(controller.getRoot()).toBe(firstRoot);
|
||||
});
|
||||
|
||||
// Complements the test above; the object pointed to should change
|
||||
// when the actual root has changed (detected by identifier)
|
||||
it("updates the root when it changes", function () {
|
||||
var firstRoot;
|
||||
// Expose the domain object
|
||||
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
|
||||
firstRoot = controller.getRoot();
|
||||
|
||||
// Change the exposed root
|
||||
mockContext.getTrueRoot.and.callFake(function () {
|
||||
var mockRoot = jasmine.createSpyObj('root', ['getId']);
|
||||
mockRoot.getId.and.returnValue('other-root-id');
|
||||
|
||||
return mockRoot;
|
||||
});
|
||||
|
||||
// Update!
|
||||
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
|
||||
|
||||
// Should still have the same object instance, to avoid
|
||||
// triggering the watch used by the template we're supporting
|
||||
expect(controller.getRoot()).not.toBe(firstRoot);
|
||||
expect(controller.getRoot().getId()).toEqual('other-root-id');
|
||||
});
|
||||
return mockRoot;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
controller = new EditPanesController(mockScope);
|
||||
});
|
||||
|
||||
it("watches for the domain object in view", function () {
|
||||
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||
"domainObject",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
it("exposes the root object found via the object's context capability", function () {
|
||||
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
|
||||
|
||||
// Verify that the correct capability was used
|
||||
expect(mockDomainObject.getCapability)
|
||||
.toHaveBeenCalledWith('context');
|
||||
|
||||
// Should have exposed the root from getRoot
|
||||
expect(controller.getRoot().getId()).toEqual('root-id');
|
||||
});
|
||||
|
||||
it("preserves the same root instance to avoid excessive refreshing", function () {
|
||||
var firstRoot;
|
||||
// Expose the domain object
|
||||
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
|
||||
firstRoot = controller.getRoot();
|
||||
// Update!
|
||||
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
|
||||
// Should still have the same object instance, to avoid
|
||||
// triggering the watch used by the template we're supporting
|
||||
expect(controller.getRoot()).toBe(firstRoot);
|
||||
});
|
||||
|
||||
// Complements the test above; the object pointed to should change
|
||||
// when the actual root has changed (detected by identifier)
|
||||
it("updates the root when it changes", function () {
|
||||
var firstRoot;
|
||||
// Expose the domain object
|
||||
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
|
||||
firstRoot = controller.getRoot();
|
||||
|
||||
// Change the exposed root
|
||||
mockContext.getTrueRoot.and.callFake(function () {
|
||||
var mockRoot = jasmine.createSpyObj('root', ['getId']);
|
||||
mockRoot.getId.and.returnValue('other-root-id');
|
||||
|
||||
return mockRoot;
|
||||
});
|
||||
|
||||
// Update!
|
||||
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
|
||||
|
||||
// Should still have the same object instance, to avoid
|
||||
// triggering the watch used by the template we're supporting
|
||||
expect(controller.getRoot()).not.toBe(firstRoot);
|
||||
expect(controller.getRoot().getId()).toEqual('other-root-id');
|
||||
});
|
||||
});
|
@ -20,83 +20,101 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/policies/EditPersistableObjectsPolicy"],
|
||||
function (EditPersistableObjectsPolicy) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
describe("The Edit persistable objects policy", function () {
|
||||
var mockDomainObject,
|
||||
mockEditAction,
|
||||
mockPropertiesAction,
|
||||
mockOtherAction,
|
||||
mockAPI,
|
||||
mockObjectAPI,
|
||||
testContext,
|
||||
policy;
|
||||
import EditPersistableObjectsPolicy from '../../src/policies/EditPersistableObjectsPolicy';
|
||||
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
[
|
||||
'getId'
|
||||
]
|
||||
);
|
||||
describe("The Edit persistable objects policy", function () {
|
||||
var mockDomainObject,
|
||||
mockEditAction,
|
||||
mockPropertiesAction,
|
||||
mockOtherAction,
|
||||
mockAPI,
|
||||
mockObjectAPI,
|
||||
testContext,
|
||||
policy;
|
||||
|
||||
mockObjectAPI = jasmine.createSpyObj('objectAPI', [
|
||||
'isPersistable',
|
||||
'parseKeyString'
|
||||
]);
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
[
|
||||
'getId'
|
||||
]
|
||||
);
|
||||
|
||||
mockAPI = {
|
||||
objects: mockObjectAPI
|
||||
};
|
||||
mockObjectAPI = jasmine.createSpyObj('objectAPI', [
|
||||
'isPersistable',
|
||||
'parseKeyString'
|
||||
]);
|
||||
|
||||
mockEditAction = jasmine.createSpyObj('edit', ['getMetadata']);
|
||||
mockPropertiesAction = jasmine.createSpyObj('properties', ['getMetadata']);
|
||||
mockOtherAction = jasmine.createSpyObj('other', ['getMetadata']);
|
||||
mockAPI = {
|
||||
objects: mockObjectAPI
|
||||
};
|
||||
|
||||
mockEditAction.getMetadata.and.returnValue({ key: 'edit' });
|
||||
mockPropertiesAction.getMetadata.and.returnValue({ key: 'properties' });
|
||||
mockOtherAction.getMetadata.and.returnValue({key: 'other'});
|
||||
mockEditAction = jasmine.createSpyObj('edit', ['getMetadata']);
|
||||
mockPropertiesAction = jasmine.createSpyObj('properties', ['getMetadata']);
|
||||
mockOtherAction = jasmine.createSpyObj('other', ['getMetadata']);
|
||||
|
||||
mockDomainObject.getId.and.returnValue('test:testId');
|
||||
mockEditAction.getMetadata.and.returnValue({ key: 'edit' });
|
||||
mockPropertiesAction.getMetadata.and.returnValue({ key: 'properties' });
|
||||
mockOtherAction.getMetadata.and.returnValue({key: 'other'});
|
||||
|
||||
testContext = {
|
||||
domainObject: mockDomainObject,
|
||||
category: 'view-control'
|
||||
};
|
||||
mockDomainObject.getId.and.returnValue('test:testId');
|
||||
|
||||
policy = new EditPersistableObjectsPolicy(mockAPI);
|
||||
});
|
||||
testContext = {
|
||||
domainObject: mockDomainObject,
|
||||
category: 'view-control'
|
||||
};
|
||||
|
||||
it("Applies to edit action", function () {
|
||||
expect(mockObjectAPI.isPersistable).not.toHaveBeenCalled();
|
||||
policy = new EditPersistableObjectsPolicy(mockAPI);
|
||||
});
|
||||
|
||||
policy.allow(mockEditAction, testContext);
|
||||
expect(mockObjectAPI.isPersistable).toHaveBeenCalled();
|
||||
});
|
||||
it("Applies to edit action", function () {
|
||||
expect(mockObjectAPI.isPersistable).not.toHaveBeenCalled();
|
||||
|
||||
it("Applies to properties action", function () {
|
||||
expect(mockObjectAPI.isPersistable).not.toHaveBeenCalled();
|
||||
policy.allow(mockEditAction, testContext);
|
||||
expect(mockObjectAPI.isPersistable).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
policy.allow(mockPropertiesAction, testContext);
|
||||
expect(mockObjectAPI.isPersistable).toHaveBeenCalled();
|
||||
});
|
||||
it("Applies to properties action", function () {
|
||||
expect(mockObjectAPI.isPersistable).not.toHaveBeenCalled();
|
||||
|
||||
it("does not apply to other actions", function () {
|
||||
expect(mockObjectAPI.isPersistable).not.toHaveBeenCalled();
|
||||
policy.allow(mockPropertiesAction, testContext);
|
||||
expect(mockObjectAPI.isPersistable).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
policy.allow(mockOtherAction, testContext);
|
||||
expect(mockObjectAPI.isPersistable).not.toHaveBeenCalled();
|
||||
});
|
||||
it("does not apply to other actions", function () {
|
||||
expect(mockObjectAPI.isPersistable).not.toHaveBeenCalled();
|
||||
|
||||
it("Tests object provider for editability", function () {
|
||||
mockObjectAPI.isPersistable.and.returnValue(false);
|
||||
expect(policy.allow(mockEditAction, testContext)).toBe(false);
|
||||
expect(mockObjectAPI.isPersistable).toHaveBeenCalled();
|
||||
mockObjectAPI.isPersistable.and.returnValue(true);
|
||||
expect(policy.allow(mockEditAction, testContext)).toBe(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
policy.allow(mockOtherAction, testContext);
|
||||
expect(mockObjectAPI.isPersistable).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Tests object provider for editability", function () {
|
||||
mockObjectAPI.isPersistable.and.returnValue(false);
|
||||
expect(policy.allow(mockEditAction, testContext)).toBe(false);
|
||||
expect(mockObjectAPI.isPersistable).toHaveBeenCalled();
|
||||
mockObjectAPI.isPersistable.and.returnValue(true);
|
||||
expect(policy.allow(mockEditAction, testContext)).toBe(true);
|
||||
});
|
||||
});
|
@ -20,68 +20,86 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'../../src/representers/EditRepresenter'
|
||||
], function (
|
||||
EditRepresenter
|
||||
) {
|
||||
describe('EditRepresenter', function () {
|
||||
var $log,
|
||||
$scope,
|
||||
representer;
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
import EditRepresenter from '../../src/representers/EditRepresenter';
|
||||
|
||||
describe('EditRepresenter', function () {
|
||||
var $log,
|
||||
$scope,
|
||||
representer;
|
||||
|
||||
beforeEach(function () {
|
||||
$log = jasmine.createSpyObj('$log', ['debug']);
|
||||
$scope = {};
|
||||
representer = new EditRepresenter($log, $scope);
|
||||
});
|
||||
|
||||
it('injects a commit function in scope', function () {
|
||||
expect($scope.commit).toEqual(jasmine.any(Function));
|
||||
});
|
||||
|
||||
describe('representation', function () {
|
||||
var domainObject,
|
||||
representation;
|
||||
|
||||
beforeEach(function () {
|
||||
$log = jasmine.createSpyObj('$log', ['debug']);
|
||||
$scope = {};
|
||||
representer = new EditRepresenter($log, $scope);
|
||||
domainObject = jasmine.createSpyObj('domainObject', [
|
||||
'getId',
|
||||
'getModel',
|
||||
'useCapability'
|
||||
]);
|
||||
|
||||
domainObject.getId.and.returnValue('anId');
|
||||
domainObject.getModel.and.returnValue({name: 'anObject'});
|
||||
|
||||
representation = {
|
||||
key: 'someRepresentation'
|
||||
};
|
||||
$scope.model = {name: 'anotherName'};
|
||||
$scope.configuration = {some: 'config'};
|
||||
representer.represent(representation, domainObject);
|
||||
});
|
||||
|
||||
it('injects a commit function in scope', function () {
|
||||
expect($scope.commit).toEqual(jasmine.any(Function));
|
||||
it('logs a message when commiting', function () {
|
||||
$scope.commit('Test Message');
|
||||
expect($log.debug)
|
||||
.toHaveBeenCalledWith('Committing anObject (anId): Test Message');
|
||||
});
|
||||
|
||||
describe('representation', function () {
|
||||
var domainObject,
|
||||
representation;
|
||||
it('mutates the object when committing', function () {
|
||||
$scope.commit('Test Message');
|
||||
|
||||
beforeEach(function () {
|
||||
domainObject = jasmine.createSpyObj('domainObject', [
|
||||
'getId',
|
||||
'getModel',
|
||||
'useCapability'
|
||||
]);
|
||||
expect(domainObject.useCapability)
|
||||
.toHaveBeenCalledWith('mutation', jasmine.any(Function));
|
||||
|
||||
domainObject.getId.and.returnValue('anId');
|
||||
domainObject.getModel.and.returnValue({name: 'anObject'});
|
||||
|
||||
representation = {
|
||||
key: 'someRepresentation'
|
||||
};
|
||||
$scope.model = {name: 'anotherName'};
|
||||
$scope.configuration = {some: 'config'};
|
||||
representer.represent(representation, domainObject);
|
||||
});
|
||||
|
||||
it('logs a message when commiting', function () {
|
||||
$scope.commit('Test Message');
|
||||
expect($log.debug)
|
||||
.toHaveBeenCalledWith('Committing anObject (anId): Test Message');
|
||||
});
|
||||
|
||||
it('mutates the object when committing', function () {
|
||||
$scope.commit('Test Message');
|
||||
|
||||
expect(domainObject.useCapability)
|
||||
.toHaveBeenCalledWith('mutation', jasmine.any(Function));
|
||||
|
||||
var mutateValue = domainObject.useCapability.calls.all()[0].args[1]();
|
||||
|
||||
expect(mutateValue.configuration.someRepresentation)
|
||||
.toEqual({some: 'config'});
|
||||
expect(mutateValue.name).toEqual('anotherName');
|
||||
});
|
||||
var mutateValue = domainObject.useCapability.calls.all()[0].args[1]();
|
||||
|
||||
expect(mutateValue.configuration.someRepresentation)
|
||||
.toEqual({some: 'config'});
|
||||
expect(mutateValue.name).toEqual('anotherName');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -20,53 +20,71 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/FormatProvider",
|
||||
"./src/DurationFormat"
|
||||
], function (
|
||||
FormatProvider,
|
||||
DurationFormat
|
||||
) {
|
||||
return {
|
||||
name: "platform/commonUI/formats",
|
||||
definition: {
|
||||
"name": "Format Registry",
|
||||
"description": "Provides a registry for formats, which allow parsing and formatting of values.",
|
||||
"extensions": {
|
||||
"components": [
|
||||
{
|
||||
"provides": "formatService",
|
||||
"type": "provider",
|
||||
"implementation": FormatProvider,
|
||||
"depends": [
|
||||
"formats[]"
|
||||
]
|
||||
}
|
||||
],
|
||||
"formats": [
|
||||
{
|
||||
"key": "duration",
|
||||
"implementation": DurationFormat
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key": "DEFAULT_TIME_FORMAT",
|
||||
"value": "utc"
|
||||
}
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"name": "d3",
|
||||
"version": "3.0.0",
|
||||
"description": "Incorporates modified code from d3 Time Scales",
|
||||
"author": "Mike Bostock",
|
||||
"copyright": "Copyright 2010-2016 Mike Bostock. "
|
||||
+ "All rights reserved.",
|
||||
"link": "https://github.com/d3/d3/blob/master/LICENSE"
|
||||
}
|
||||
]
|
||||
}
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
import FormatProvider from './src/FormatProvider';
|
||||
|
||||
import DurationFormat from './src/DurationFormat';
|
||||
|
||||
export default {
|
||||
name: "platform/commonUI/formats",
|
||||
definition: {
|
||||
"name": "Format Registry",
|
||||
"description": "Provides a registry for formats, which allow parsing and formatting of values.",
|
||||
"extensions": {
|
||||
"components": [
|
||||
{
|
||||
"provides": "formatService",
|
||||
"type": "provider",
|
||||
"implementation": FormatProvider,
|
||||
"depends": [
|
||||
"formats[]"
|
||||
]
|
||||
}
|
||||
],
|
||||
"formats": [
|
||||
{
|
||||
"key": "duration",
|
||||
"implementation": DurationFormat
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key": "DEFAULT_TIME_FORMAT",
|
||||
"value": "utc"
|
||||
}
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"name": "d3",
|
||||
"version": "3.0.0",
|
||||
"description": "Incorporates modified code from d3 Time Scales",
|
||||
"author": "Mike Bostock",
|
||||
"copyright": "Copyright 2010-2016 Mike Bostock. "
|
||||
+ "All rights reserved.",
|
||||
"link": "https://github.com/d3/d3/blob/master/LICENSE"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,43 +20,60 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'moment'
|
||||
], function (
|
||||
moment
|
||||
) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
var DATE_FORMAT = "HH:mm:ss",
|
||||
DATE_FORMATS = [
|
||||
DATE_FORMAT
|
||||
];
|
||||
import moment from 'moment';
|
||||
|
||||
/**
|
||||
* Formatter for duration. Uses moment to produce a date from a given
|
||||
* value, but output is formatted to display only time. Can be used for
|
||||
* specifying a time duration. For specifying duration, it's best to
|
||||
* specify a date of January 1, 1970, as the ms offset will equal the
|
||||
* duration represented by the time.
|
||||
*
|
||||
* @implements {Format}
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/formats
|
||||
*/
|
||||
function DurationFormat() {
|
||||
this.key = "duration";
|
||||
}
|
||||
var DATE_FORMAT = "HH:mm:ss",
|
||||
DATE_FORMATS = [
|
||||
DATE_FORMAT
|
||||
];
|
||||
|
||||
DurationFormat.prototype.format = function (value) {
|
||||
return moment.utc(value).format(DATE_FORMAT);
|
||||
};
|
||||
/**
|
||||
* Formatter for duration. Uses moment to produce a date from a given
|
||||
* value, but output is formatted to display only time. Can be used for
|
||||
* specifying a time duration. For specifying duration, it's best to
|
||||
* specify a date of January 1, 1970, as the ms offset will equal the
|
||||
* duration represented by the time.
|
||||
*
|
||||
* @implements {Format}
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/formats
|
||||
*/
|
||||
function DurationFormat() {
|
||||
this.key = "duration";
|
||||
}
|
||||
|
||||
DurationFormat.prototype.parse = function (text) {
|
||||
return moment.duration(text).asMilliseconds();
|
||||
};
|
||||
DurationFormat.prototype.format = function (value) {
|
||||
return moment.utc(value).format(DATE_FORMAT);
|
||||
};
|
||||
|
||||
DurationFormat.prototype.validate = function (text) {
|
||||
return moment.utc(text, DATE_FORMATS, true).isValid();
|
||||
};
|
||||
DurationFormat.prototype.parse = function (text) {
|
||||
return moment.duration(text).asMilliseconds();
|
||||
};
|
||||
|
||||
return DurationFormat;
|
||||
});
|
||||
DurationFormat.prototype.validate = function (text) {
|
||||
return moment.utc(text, DATE_FORMATS, true).isValid();
|
||||
};
|
||||
|
||||
export default DurationFormat;
|
@ -20,104 +20,49 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
], function (
|
||||
function FormatProvider(formats) {
|
||||
var formatMap = {};
|
||||
|
||||
) {
|
||||
|
||||
/**
|
||||
* An object used to convert between numeric values and text values,
|
||||
* typically used to display these values to the user and to convert
|
||||
* user input to a numeric format, particularly for time formats.
|
||||
* @interface Format
|
||||
*/
|
||||
/**
|
||||
* Parse text (typically user input) to a numeric value.
|
||||
* Behavior is undefined when the text cannot be parsed;
|
||||
* `validate` should be called first if the text may be invalid.
|
||||
* @method Format#parse
|
||||
* @memberof Format#
|
||||
* @param {string} text the text to parse
|
||||
* @returns {number} the parsed numeric value
|
||||
*/
|
||||
|
||||
/**
|
||||
* @property {string} key A unique identifier for this formatter.
|
||||
* @memberof Format#
|
||||
*/
|
||||
|
||||
/**
|
||||
* Determine whether or not some text (typically user input) can
|
||||
* be parsed to a numeric value by this format.
|
||||
* @method validate
|
||||
* @memberof Format#
|
||||
* @param {string} text the text to parse
|
||||
* @returns {boolean} true if the text can be parsed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Convert a numeric value to a text value for display using
|
||||
* this format.
|
||||
* @method format
|
||||
* @memberof Format#
|
||||
* @param {number} value the numeric value to format
|
||||
* @param {number} [minValue] Contextual information for scaled formatting used in linear scales such as conductor
|
||||
* and plot axes. Specifies the smallest number on the scale.
|
||||
* @param {number} [maxValue] Contextual information for scaled formatting used in linear scales such as conductor
|
||||
* and plot axes. Specifies the largest number on the scale
|
||||
* @param {number} [count] Contextual information for scaled formatting used in linear scales such as conductor
|
||||
* and plot axes. The number of labels on the scale.
|
||||
* @returns {string} the text representation of the value
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides access to `Format` objects which can be used to
|
||||
* convert values between human-readable text and numeric
|
||||
* representations.
|
||||
* @interface FormatService
|
||||
*/
|
||||
|
||||
/**
|
||||
* Look up a format by its symbolic identifier.
|
||||
* @method getFormat
|
||||
* @memberof FormatService#
|
||||
* @param {string} key the identifier for this format
|
||||
* @returns {Format} the format
|
||||
* @throws {Error} errors when the requested format is unrecognized
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides formats from the `formats` extension category.
|
||||
* @constructor
|
||||
* @implements {FormatService}
|
||||
* @memberof platform/commonUI/formats
|
||||
* @param {Array.<function(new : Format)>} format constructors,
|
||||
* from the `formats` extension category.
|
||||
*/
|
||||
function FormatProvider(formats) {
|
||||
var formatMap = {};
|
||||
|
||||
function addToMap(Format) {
|
||||
var key = Format.key;
|
||||
if (key && !formatMap[key]) {
|
||||
formatMap[key] = new Format();
|
||||
}
|
||||
function addToMap(Format) {
|
||||
var key = Format.key;
|
||||
if (key && !formatMap[key]) {
|
||||
formatMap[key] = new Format();
|
||||
}
|
||||
|
||||
formats.forEach(addToMap);
|
||||
this.formatMap = formatMap;
|
||||
}
|
||||
|
||||
FormatProvider.prototype.getFormat = function (key) {
|
||||
var format = this.formatMap[key];
|
||||
if (!format) {
|
||||
throw new Error("FormatProvider: No format found for " + key);
|
||||
}
|
||||
formats.forEach(addToMap);
|
||||
this.formatMap = formatMap;
|
||||
}
|
||||
|
||||
return format;
|
||||
};
|
||||
FormatProvider.prototype.getFormat = function (key) {
|
||||
var format = this.formatMap[key];
|
||||
if (!format) {
|
||||
throw new Error("FormatProvider: No format found for " + key);
|
||||
}
|
||||
|
||||
return FormatProvider;
|
||||
return format;
|
||||
};
|
||||
|
||||
});
|
||||
export default FormatProvider;
|
@ -20,50 +20,68 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
['../src/FormatProvider'],
|
||||
function (FormatProvider) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
var KEYS = ['a', 'b', 'c'];
|
||||
import FormatProvider from '../src/FormatProvider';
|
||||
|
||||
describe("The FormatProvider", function () {
|
||||
var mockFormats,
|
||||
mockFormatInstances,
|
||||
provider;
|
||||
var KEYS = ['a', 'b', 'c'];
|
||||
|
||||
beforeEach(function () {
|
||||
mockFormatInstances = KEYS.map(function (k) {
|
||||
return jasmine.createSpyObj(
|
||||
'format-' + k,
|
||||
['parse', 'validate', 'format']
|
||||
);
|
||||
});
|
||||
// Return constructors
|
||||
mockFormats = KEYS.map(function (k, i) {
|
||||
function MockFormat() {
|
||||
return mockFormatInstances[i];
|
||||
}
|
||||
|
||||
MockFormat.key = k;
|
||||
|
||||
return MockFormat;
|
||||
});
|
||||
provider = new FormatProvider(mockFormats);
|
||||
});
|
||||
|
||||
it("looks up formats by key", function () {
|
||||
KEYS.forEach(function (k, i) {
|
||||
expect(provider.getFormat(k))
|
||||
.toEqual(mockFormatInstances[i]);
|
||||
});
|
||||
});
|
||||
|
||||
it("throws an error about unknown formats", function () {
|
||||
expect(function () {
|
||||
provider.getFormat('some-unknown-format');
|
||||
}).toThrow();
|
||||
});
|
||||
describe("The FormatProvider", function () {
|
||||
var mockFormats,
|
||||
mockFormatInstances,
|
||||
provider;
|
||||
|
||||
beforeEach(function () {
|
||||
mockFormatInstances = KEYS.map(function (k) {
|
||||
return jasmine.createSpyObj(
|
||||
'format-' + k,
|
||||
['parse', 'validate', 'format']
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
// Return constructors
|
||||
mockFormats = KEYS.map(function (k, i) {
|
||||
function MockFormat() {
|
||||
return mockFormatInstances[i];
|
||||
}
|
||||
|
||||
MockFormat.key = k;
|
||||
|
||||
return MockFormat;
|
||||
});
|
||||
provider = new FormatProvider(mockFormats);
|
||||
});
|
||||
|
||||
it("looks up formats by key", function () {
|
||||
KEYS.forEach(function (k, i) {
|
||||
expect(provider.getFormat(k))
|
||||
.toEqual(mockFormatInstances[i]);
|
||||
});
|
||||
});
|
||||
|
||||
it("throws an error about unknown formats", function () {
|
||||
expect(function () {
|
||||
provider.getFormat('some-unknown-format');
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
@ -20,510 +20,483 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
"./src/services/UrlService",
|
||||
"./src/services/PopupService",
|
||||
"./src/SplashScreenManager",
|
||||
"./src/StyleSheetLoader",
|
||||
"./src/controllers/TimeRangeController",
|
||||
"./src/controllers/DateTimePickerController",
|
||||
"./src/controllers/DateTimeFieldController",
|
||||
"./src/controllers/TreeNodeController",
|
||||
"./src/controllers/ActionGroupController",
|
||||
"./src/controllers/ToggleController",
|
||||
"./src/controllers/ClickAwayController",
|
||||
"./src/controllers/ViewSwitcherController",
|
||||
"./src/controllers/GetterSetterController",
|
||||
"./src/controllers/SelectorController",
|
||||
"./src/controllers/ObjectInspectorController",
|
||||
"./src/controllers/BannerController",
|
||||
"./src/directives/MCTContainer",
|
||||
"./src/directives/MCTDrag",
|
||||
"./src/directives/MCTSelectable",
|
||||
"./src/directives/MCTClickElsewhere",
|
||||
"./src/directives/MCTResize",
|
||||
"./src/directives/MCTPopup",
|
||||
"./src/directives/MCTScroll",
|
||||
"./src/directives/MCTSplitPane",
|
||||
"./src/directives/MCTSplitter",
|
||||
"./src/directives/MCTTree",
|
||||
"./src/directives/MCTIndicators",
|
||||
"./src/filters/ReverseFilter",
|
||||
"./res/templates/bottombar.html",
|
||||
"./res/templates/controls/action-button.html",
|
||||
"./res/templates/controls/input-filter.html",
|
||||
"./res/templates/angular-indicator.html",
|
||||
"./res/templates/message-banner.html",
|
||||
"./res/templates/progress-bar.html",
|
||||
"./res/templates/controls/time-controller.html",
|
||||
"./res/templates/containers/accordion.html",
|
||||
"./res/templates/subtree.html",
|
||||
"./res/templates/tree.html",
|
||||
"./res/templates/tree-node.html",
|
||||
"./res/templates/label.html",
|
||||
"./res/templates/controls/action-group.html",
|
||||
"./res/templates/controls/switcher.html",
|
||||
"./res/templates/object-inspector.html",
|
||||
"./res/templates/controls/selector.html",
|
||||
"./res/templates/controls/datetime-picker.html",
|
||||
"./res/templates/controls/datetime-field.html"
|
||||
], function (
|
||||
UrlService,
|
||||
PopupService,
|
||||
SplashScreenManager,
|
||||
StyleSheetLoader,
|
||||
TimeRangeController,
|
||||
DateTimePickerController,
|
||||
DateTimeFieldController,
|
||||
TreeNodeController,
|
||||
ActionGroupController,
|
||||
ToggleController,
|
||||
ClickAwayController,
|
||||
ViewSwitcherController,
|
||||
GetterSetterController,
|
||||
SelectorController,
|
||||
ObjectInspectorController,
|
||||
BannerController,
|
||||
MCTContainer,
|
||||
MCTDrag,
|
||||
MCTSelectable,
|
||||
MCTClickElsewhere,
|
||||
MCTResize,
|
||||
MCTPopup,
|
||||
MCTScroll,
|
||||
MCTSplitPane,
|
||||
MCTSplitter,
|
||||
MCTTree,
|
||||
MCTIndicators,
|
||||
ReverseFilter,
|
||||
bottombarTemplate,
|
||||
actionButtonTemplate,
|
||||
inputFilterTemplate,
|
||||
indicatorTemplate,
|
||||
messageBannerTemplate,
|
||||
progressBarTemplate,
|
||||
timeControllerTemplate,
|
||||
accordionTemplate,
|
||||
subtreeTemplate,
|
||||
treeTemplate,
|
||||
treeNodeTemplate,
|
||||
labelTemplate,
|
||||
actionGroupTemplate,
|
||||
switcherTemplate,
|
||||
objectInspectorTemplate,
|
||||
selectorTemplate,
|
||||
datetimePickerTemplate,
|
||||
datetimeFieldTemplate
|
||||
) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
return {
|
||||
name: "platform/commonUI/general",
|
||||
definition: {
|
||||
"name": "General UI elements",
|
||||
"description": "General UI elements, meant to be reused across modes",
|
||||
"resources": "res",
|
||||
"extensions": {
|
||||
"services": [
|
||||
{
|
||||
"key": "urlService",
|
||||
"implementation": UrlService,
|
||||
"depends": [
|
||||
"$location"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "popupService",
|
||||
"implementation": PopupService,
|
||||
"depends": [
|
||||
"$document",
|
||||
"$window"
|
||||
]
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
"implementation": StyleSheetLoader,
|
||||
"depends": [
|
||||
"stylesheets[]",
|
||||
"$document",
|
||||
"THEME",
|
||||
"ASSETS_PATH"
|
||||
]
|
||||
},
|
||||
{
|
||||
"implementation": SplashScreenManager,
|
||||
"depends": [
|
||||
"$document"
|
||||
]
|
||||
}
|
||||
],
|
||||
"filters": [
|
||||
{
|
||||
"implementation": ReverseFilter,
|
||||
"key": "reverse"
|
||||
}
|
||||
],
|
||||
"templates": [
|
||||
{
|
||||
"key": "bottombar",
|
||||
"template": bottombarTemplate
|
||||
},
|
||||
{
|
||||
"key": "action-button",
|
||||
"template": actionButtonTemplate
|
||||
},
|
||||
{
|
||||
"key": "input-filter",
|
||||
"template": inputFilterTemplate
|
||||
},
|
||||
{
|
||||
"key": "indicator",
|
||||
"template": indicatorTemplate
|
||||
},
|
||||
{
|
||||
"key": "message-banner",
|
||||
"template": messageBannerTemplate
|
||||
},
|
||||
{
|
||||
"key": "progress-bar",
|
||||
"template": progressBarTemplate
|
||||
},
|
||||
{
|
||||
"key": "time-controller",
|
||||
"template": timeControllerTemplate
|
||||
}
|
||||
],
|
||||
"controllers": [
|
||||
{
|
||||
"key": "TimeRangeController",
|
||||
"implementation": TimeRangeController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout",
|
||||
"formatService",
|
||||
"DEFAULT_TIME_FORMAT",
|
||||
"now"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "DateTimePickerController",
|
||||
"implementation": DateTimePickerController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"now"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "DateTimeFieldController",
|
||||
"implementation": DateTimeFieldController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"formatService",
|
||||
"DEFAULT_TIME_FORMAT"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "TreeNodeController",
|
||||
"implementation": TreeNodeController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout",
|
||||
"navigationService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "ActionGroupController",
|
||||
"implementation": ActionGroupController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "ToggleController",
|
||||
"implementation": ToggleController
|
||||
},
|
||||
{
|
||||
"key": "ClickAwayController",
|
||||
"implementation": ClickAwayController,
|
||||
"depends": [
|
||||
"$document",
|
||||
"$timeout"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "ViewSwitcherController",
|
||||
"implementation": ViewSwitcherController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "GetterSetterController",
|
||||
"implementation": GetterSetterController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "SelectorController",
|
||||
"implementation": SelectorController,
|
||||
"depends": [
|
||||
"objectService",
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "ObjectInspectorController",
|
||||
"implementation": ObjectInspectorController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"objectService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "BannerController",
|
||||
"implementation": BannerController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"notificationService",
|
||||
"dialogService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"directives": [
|
||||
{
|
||||
"key": "mctContainer",
|
||||
"implementation": MCTContainer,
|
||||
"depends": [
|
||||
"containers[]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctDrag",
|
||||
"implementation": MCTDrag,
|
||||
"depends": [
|
||||
"$document",
|
||||
"agentService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctSelectable",
|
||||
"implementation": MCTSelectable,
|
||||
"depends": [
|
||||
"openmct"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctClickElsewhere",
|
||||
"implementation": MCTClickElsewhere,
|
||||
"depends": [
|
||||
"$document"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctResize",
|
||||
"implementation": MCTResize,
|
||||
"depends": [
|
||||
"$timeout"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctPopup",
|
||||
"implementation": MCTPopup,
|
||||
"depends": [
|
||||
"$compile",
|
||||
"popupService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctScrollX",
|
||||
"implementation": MCTScroll,
|
||||
"depends": [
|
||||
"$parse",
|
||||
"MCT_SCROLL_X_PROPERTY",
|
||||
"MCT_SCROLL_X_ATTRIBUTE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctScrollY",
|
||||
"implementation": MCTScroll,
|
||||
"depends": [
|
||||
"$parse",
|
||||
"MCT_SCROLL_Y_PROPERTY",
|
||||
"MCT_SCROLL_Y_ATTRIBUTE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctSplitPane",
|
||||
"implementation": MCTSplitPane,
|
||||
"depends": [
|
||||
"$parse",
|
||||
"$log",
|
||||
"$interval",
|
||||
"$window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctSplitter",
|
||||
"implementation": MCTSplitter
|
||||
},
|
||||
{
|
||||
"key": "mctTree",
|
||||
"implementation": MCTTree,
|
||||
"depends": ['gestureService', 'openmct']
|
||||
},
|
||||
{
|
||||
"key": "mctIndicators",
|
||||
"implementation": MCTIndicators,
|
||||
"depends": ['openmct']
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key": "MCT_SCROLL_X_PROPERTY",
|
||||
"value": "scrollLeft"
|
||||
},
|
||||
{
|
||||
"key": "MCT_SCROLL_X_ATTRIBUTE",
|
||||
"value": "mctScrollX"
|
||||
},
|
||||
{
|
||||
"key": "MCT_SCROLL_Y_PROPERTY",
|
||||
"value": "scrollTop"
|
||||
},
|
||||
{
|
||||
"key": "MCT_SCROLL_Y_ATTRIBUTE",
|
||||
"value": "mctScrollY"
|
||||
},
|
||||
{
|
||||
"key": "THEME",
|
||||
"value": "unspecified",
|
||||
"priority": "fallback"
|
||||
},
|
||||
{
|
||||
"key": "ASSETS_PATH",
|
||||
"value": ".",
|
||||
"priority": "fallback"
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
{
|
||||
"key": "accordion",
|
||||
"template": accordionTemplate,
|
||||
"attributes": [
|
||||
"label"
|
||||
]
|
||||
}
|
||||
],
|
||||
"representations": [
|
||||
{
|
||||
"key": "tree",
|
||||
"template": subtreeTemplate,
|
||||
"uses": [
|
||||
"composition"
|
||||
],
|
||||
"type": "root",
|
||||
"priority": "preferred"
|
||||
},
|
||||
{
|
||||
"key": "tree",
|
||||
"template": treeTemplate
|
||||
},
|
||||
{
|
||||
"key": "subtree",
|
||||
"template": subtreeTemplate,
|
||||
"uses": [
|
||||
"composition"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "tree-node",
|
||||
"template": treeNodeTemplate,
|
||||
"uses": [
|
||||
"action"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "label",
|
||||
"template": labelTemplate,
|
||||
"uses": [
|
||||
"type",
|
||||
"location"
|
||||
],
|
||||
"gestures": [
|
||||
"drag",
|
||||
"menu",
|
||||
"info"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "node",
|
||||
"template": labelTemplate,
|
||||
"uses": [
|
||||
"type"
|
||||
],
|
||||
"gestures": [
|
||||
"drag",
|
||||
"menu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "action-group",
|
||||
"template": actionGroupTemplate,
|
||||
"uses": [
|
||||
"action"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "switcher",
|
||||
"template": switcherTemplate,
|
||||
"uses": [
|
||||
"view"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "object-inspector",
|
||||
"template": objectInspectorTemplate
|
||||
}
|
||||
],
|
||||
"controls": [
|
||||
{
|
||||
"key": "selector",
|
||||
"template": selectorTemplate
|
||||
},
|
||||
{
|
||||
"key": "datetime-picker",
|
||||
"template": datetimePickerTemplate
|
||||
},
|
||||
{
|
||||
"key": "datetime-field",
|
||||
"template": datetimeFieldTemplate
|
||||
}
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"name": "Normalize.css",
|
||||
"version": "1.1.2",
|
||||
"description": "Browser style normalization",
|
||||
"author": "Nicolas Gallagher, Jonathan Neal",
|
||||
"website": "http://necolas.github.io/normalize.css/",
|
||||
"copyright": "Copyright (c) Nicolas Gallagher and Jonathan Neal",
|
||||
"license": "license-mit",
|
||||
"link": "https://github.com/necolas/normalize.css/blob/v1.1.2/LICENSE.md"
|
||||
},
|
||||
{
|
||||
"name": "Zepto",
|
||||
"version": "1.1.6",
|
||||
"description": "DOM manipulation",
|
||||
"author": "Thomas Fuchs",
|
||||
"website": "http://zeptojs.com/",
|
||||
"copyright": "Copyright (c) 2010-2016 Thomas Fuchs",
|
||||
"license": "license-mit",
|
||||
"link": "https://github.com/madrobby/zepto/blob/master/MIT-LICENSE"
|
||||
}
|
||||
]
|
||||
}
|
||||
import UrlService from './src/services/UrlService';
|
||||
|
||||
import PopupService from './src/services/PopupService';
|
||||
import SplashScreenManager from './src/SplashScreenManager';
|
||||
import StyleSheetLoader from './src/StyleSheetLoader';
|
||||
import TimeRangeController from './src/controllers/TimeRangeController';
|
||||
import DateTimePickerController from './src/controllers/DateTimePickerController';
|
||||
import DateTimeFieldController from './src/controllers/DateTimeFieldController';
|
||||
import TreeNodeController from './src/controllers/TreeNodeController';
|
||||
import ActionGroupController from './src/controllers/ActionGroupController';
|
||||
import ToggleController from './src/controllers/ToggleController';
|
||||
import ClickAwayController from './src/controllers/ClickAwayController';
|
||||
import ViewSwitcherController from './src/controllers/ViewSwitcherController';
|
||||
import GetterSetterController from './src/controllers/GetterSetterController';
|
||||
import SelectorController from './src/controllers/SelectorController';
|
||||
import ObjectInspectorController from './src/controllers/ObjectInspectorController';
|
||||
import BannerController from './src/controllers/BannerController';
|
||||
import MCTContainer from './src/directives/MCTContainer';
|
||||
import MCTDrag from './src/directives/MCTDrag';
|
||||
import MCTSelectable from './src/directives/MCTSelectable';
|
||||
import MCTClickElsewhere from './src/directives/MCTClickElsewhere';
|
||||
import MCTResize from './src/directives/MCTResize';
|
||||
import MCTPopup from './src/directives/MCTPopup';
|
||||
import MCTScroll from './src/directives/MCTScroll';
|
||||
import MCTSplitPane from './src/directives/MCTSplitPane';
|
||||
import MCTSplitter from './src/directives/MCTSplitter';
|
||||
import MCTTree from './src/directives/MCTTree';
|
||||
import MCTIndicators from './src/directives/MCTIndicators';
|
||||
import ReverseFilter from './src/filters/ReverseFilter';
|
||||
import bottombarTemplate from './res/templates/bottombar.html';
|
||||
import actionButtonTemplate from './res/templates/controls/action-button.html';
|
||||
import inputFilterTemplate from './res/templates/controls/input-filter.html';
|
||||
import indicatorTemplate from './res/templates/angular-indicator.html';
|
||||
import messageBannerTemplate from './res/templates/message-banner.html';
|
||||
import progressBarTemplate from './res/templates/progress-bar.html';
|
||||
import timeControllerTemplate from './res/templates/controls/time-controller.html';
|
||||
import accordionTemplate from './res/templates/containers/accordion.html';
|
||||
import subtreeTemplate from './res/templates/subtree.html';
|
||||
import treeTemplate from './res/templates/tree.html';
|
||||
import treeNodeTemplate from './res/templates/tree-node.html';
|
||||
import labelTemplate from './res/templates/label.html';
|
||||
import actionGroupTemplate from './res/templates/controls/action-group.html';
|
||||
import switcherTemplate from './res/templates/controls/switcher.html';
|
||||
import objectInspectorTemplate from './res/templates/object-inspector.html';
|
||||
import selectorTemplate from './res/templates/controls/selector.html';
|
||||
import datetimePickerTemplate from './res/templates/controls/datetime-picker.html';
|
||||
import datetimeFieldTemplate from './res/templates/controls/datetime-field.html';
|
||||
|
||||
export default {
|
||||
name: "platform/commonUI/general",
|
||||
definition: {
|
||||
"name": "General UI elements",
|
||||
"description": "General UI elements, meant to be reused across modes",
|
||||
"resources": "res",
|
||||
"extensions": {
|
||||
"services": [
|
||||
{
|
||||
"key": "urlService",
|
||||
"implementation": UrlService,
|
||||
"depends": [
|
||||
"$location"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "popupService",
|
||||
"implementation": PopupService,
|
||||
"depends": [
|
||||
"$document",
|
||||
"$window"
|
||||
]
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
"implementation": StyleSheetLoader,
|
||||
"depends": [
|
||||
"stylesheets[]",
|
||||
"$document",
|
||||
"THEME",
|
||||
"ASSETS_PATH"
|
||||
]
|
||||
},
|
||||
{
|
||||
"implementation": SplashScreenManager,
|
||||
"depends": [
|
||||
"$document"
|
||||
]
|
||||
}
|
||||
],
|
||||
"filters": [
|
||||
{
|
||||
"implementation": ReverseFilter,
|
||||
"key": "reverse"
|
||||
}
|
||||
],
|
||||
"templates": [
|
||||
{
|
||||
"key": "bottombar",
|
||||
"template": bottombarTemplate
|
||||
},
|
||||
{
|
||||
"key": "action-button",
|
||||
"template": actionButtonTemplate
|
||||
},
|
||||
{
|
||||
"key": "input-filter",
|
||||
"template": inputFilterTemplate
|
||||
},
|
||||
{
|
||||
"key": "indicator",
|
||||
"template": indicatorTemplate
|
||||
},
|
||||
{
|
||||
"key": "message-banner",
|
||||
"template": messageBannerTemplate
|
||||
},
|
||||
{
|
||||
"key": "progress-bar",
|
||||
"template": progressBarTemplate
|
||||
},
|
||||
{
|
||||
"key": "time-controller",
|
||||
"template": timeControllerTemplate
|
||||
}
|
||||
],
|
||||
"controllers": [
|
||||
{
|
||||
"key": "TimeRangeController",
|
||||
"implementation": TimeRangeController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout",
|
||||
"formatService",
|
||||
"DEFAULT_TIME_FORMAT",
|
||||
"now"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "DateTimePickerController",
|
||||
"implementation": DateTimePickerController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"now"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "DateTimeFieldController",
|
||||
"implementation": DateTimeFieldController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"formatService",
|
||||
"DEFAULT_TIME_FORMAT"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "TreeNodeController",
|
||||
"implementation": TreeNodeController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout",
|
||||
"navigationService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "ActionGroupController",
|
||||
"implementation": ActionGroupController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "ToggleController",
|
||||
"implementation": ToggleController
|
||||
},
|
||||
{
|
||||
"key": "ClickAwayController",
|
||||
"implementation": ClickAwayController,
|
||||
"depends": [
|
||||
"$document",
|
||||
"$timeout"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "ViewSwitcherController",
|
||||
"implementation": ViewSwitcherController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "GetterSetterController",
|
||||
"implementation": GetterSetterController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "SelectorController",
|
||||
"implementation": SelectorController,
|
||||
"depends": [
|
||||
"objectService",
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "ObjectInspectorController",
|
||||
"implementation": ObjectInspectorController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"objectService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "BannerController",
|
||||
"implementation": BannerController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"notificationService",
|
||||
"dialogService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"directives": [
|
||||
{
|
||||
"key": "mctContainer",
|
||||
"implementation": MCTContainer,
|
||||
"depends": [
|
||||
"containers[]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctDrag",
|
||||
"implementation": MCTDrag,
|
||||
"depends": [
|
||||
"$document",
|
||||
"agentService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctSelectable",
|
||||
"implementation": MCTSelectable,
|
||||
"depends": [
|
||||
"openmct"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctClickElsewhere",
|
||||
"implementation": MCTClickElsewhere,
|
||||
"depends": [
|
||||
"$document"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctResize",
|
||||
"implementation": MCTResize,
|
||||
"depends": [
|
||||
"$timeout"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctPopup",
|
||||
"implementation": MCTPopup,
|
||||
"depends": [
|
||||
"$compile",
|
||||
"popupService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctScrollX",
|
||||
"implementation": MCTScroll,
|
||||
"depends": [
|
||||
"$parse",
|
||||
"MCT_SCROLL_X_PROPERTY",
|
||||
"MCT_SCROLL_X_ATTRIBUTE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctScrollY",
|
||||
"implementation": MCTScroll,
|
||||
"depends": [
|
||||
"$parse",
|
||||
"MCT_SCROLL_Y_PROPERTY",
|
||||
"MCT_SCROLL_Y_ATTRIBUTE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctSplitPane",
|
||||
"implementation": MCTSplitPane,
|
||||
"depends": [
|
||||
"$parse",
|
||||
"$log",
|
||||
"$interval",
|
||||
"$window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "mctSplitter",
|
||||
"implementation": MCTSplitter
|
||||
},
|
||||
{
|
||||
"key": "mctTree",
|
||||
"implementation": MCTTree,
|
||||
"depends": ['gestureService', 'openmct']
|
||||
},
|
||||
{
|
||||
"key": "mctIndicators",
|
||||
"implementation": MCTIndicators,
|
||||
"depends": ['openmct']
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key": "MCT_SCROLL_X_PROPERTY",
|
||||
"value": "scrollLeft"
|
||||
},
|
||||
{
|
||||
"key": "MCT_SCROLL_X_ATTRIBUTE",
|
||||
"value": "mctScrollX"
|
||||
},
|
||||
{
|
||||
"key": "MCT_SCROLL_Y_PROPERTY",
|
||||
"value": "scrollTop"
|
||||
},
|
||||
{
|
||||
"key": "MCT_SCROLL_Y_ATTRIBUTE",
|
||||
"value": "mctScrollY"
|
||||
},
|
||||
{
|
||||
"key": "THEME",
|
||||
"value": "unspecified",
|
||||
"priority": "fallback"
|
||||
},
|
||||
{
|
||||
"key": "ASSETS_PATH",
|
||||
"value": ".",
|
||||
"priority": "fallback"
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
{
|
||||
"key": "accordion",
|
||||
"template": accordionTemplate,
|
||||
"attributes": [
|
||||
"label"
|
||||
]
|
||||
}
|
||||
],
|
||||
"representations": [
|
||||
{
|
||||
"key": "tree",
|
||||
"template": subtreeTemplate,
|
||||
"uses": [
|
||||
"composition"
|
||||
],
|
||||
"type": "root",
|
||||
"priority": "preferred"
|
||||
},
|
||||
{
|
||||
"key": "tree",
|
||||
"template": treeTemplate
|
||||
},
|
||||
{
|
||||
"key": "subtree",
|
||||
"template": subtreeTemplate,
|
||||
"uses": [
|
||||
"composition"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "tree-node",
|
||||
"template": treeNodeTemplate,
|
||||
"uses": [
|
||||
"action"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "label",
|
||||
"template": labelTemplate,
|
||||
"uses": [
|
||||
"type",
|
||||
"location"
|
||||
],
|
||||
"gestures": [
|
||||
"drag",
|
||||
"menu",
|
||||
"info"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "node",
|
||||
"template": labelTemplate,
|
||||
"uses": [
|
||||
"type"
|
||||
],
|
||||
"gestures": [
|
||||
"drag",
|
||||
"menu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "action-group",
|
||||
"template": actionGroupTemplate,
|
||||
"uses": [
|
||||
"action"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "switcher",
|
||||
"template": switcherTemplate,
|
||||
"uses": [
|
||||
"view"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "object-inspector",
|
||||
"template": objectInspectorTemplate
|
||||
}
|
||||
],
|
||||
"controls": [
|
||||
{
|
||||
"key": "selector",
|
||||
"template": selectorTemplate
|
||||
},
|
||||
{
|
||||
"key": "datetime-picker",
|
||||
"template": datetimePickerTemplate
|
||||
},
|
||||
{
|
||||
"key": "datetime-field",
|
||||
"template": datetimeFieldTemplate
|
||||
}
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"name": "Normalize.css",
|
||||
"version": "1.1.2",
|
||||
"description": "Browser style normalization",
|
||||
"author": "Nicolas Gallagher, Jonathan Neal",
|
||||
"website": "http://necolas.github.io/normalize.css/",
|
||||
"copyright": "Copyright (c) Nicolas Gallagher and Jonathan Neal",
|
||||
"license": "license-mit",
|
||||
"link": "https://github.com/necolas/normalize.css/blob/v1.1.2/LICENSE.md"
|
||||
},
|
||||
{
|
||||
"name": "Zepto",
|
||||
"version": "1.1.6",
|
||||
"description": "DOM manipulation",
|
||||
"author": "Thomas Fuchs",
|
||||
"website": "http://zeptojs.com/",
|
||||
"copyright": "Copyright (c) 2010-2016 Thomas Fuchs",
|
||||
"license": "license-mit",
|
||||
"link": "https://github.com/madrobby/zepto/blob/master/MIT-LICENSE"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
@ -20,25 +20,40 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
], function (
|
||||
|
||||
) {
|
||||
|
||||
function SplashScreenManager($document) {
|
||||
var splash;
|
||||
$document = $document[0];
|
||||
splash = $document.querySelectorAll('.l-splash-holder')[0];
|
||||
if (!splash) {
|
||||
return;
|
||||
}
|
||||
|
||||
splash.className += ' fadeout';
|
||||
splash.addEventListener('transitionend', function () {
|
||||
splash.parentNode.removeChild(splash);
|
||||
});
|
||||
function SplashScreenManager($document) {
|
||||
var splash;
|
||||
$document = $document[0];
|
||||
splash = $document.querySelectorAll('.l-splash-holder')[0];
|
||||
if (!splash) {
|
||||
return;
|
||||
}
|
||||
|
||||
return SplashScreenManager;
|
||||
});
|
||||
splash.className += ' fadeout';
|
||||
splash.addEventListener('transitionend', function () {
|
||||
splash.parentNode.removeChild(splash);
|
||||
});
|
||||
}
|
||||
|
||||
export default SplashScreenManager;
|
@ -25,58 +25,68 @@
|
||||
* platform styling.
|
||||
* @namespace platform/commonUI/general
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The StyleSheetLoader adds links to style sheets exposed from
|
||||
* various bundles as extensions of category `stylesheets`.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param {object[]} stylesheets stylesheet extension definitions
|
||||
* @param $document Angular's jqLite-wrapped document element
|
||||
* @param {string} activeTheme the theme in use
|
||||
* @param {string} [assetPath] the directory relative to which
|
||||
* stylesheets will be found
|
||||
*/
|
||||
function StyleSheetLoader(stylesheets, $document, activeTheme, assetPath) {
|
||||
var head = $document.find('head'),
|
||||
document = $document[0];
|
||||
/**
|
||||
* This bundle provides various general-purpose UI elements, including
|
||||
* platform styling.
|
||||
* @namespace platform/commonUI/general
|
||||
*/
|
||||
function StyleSheetLoader(stylesheets, $document, activeTheme, assetPath) {
|
||||
var head = $document.find('head'),
|
||||
document = $document[0];
|
||||
|
||||
// Procedure for adding a single stylesheet
|
||||
function addStyleSheet(stylesheet) {
|
||||
// Create a link element, and construct full path
|
||||
var link = document.createElement('link'),
|
||||
path = [
|
||||
assetPath,
|
||||
stylesheet.bundle.path,
|
||||
stylesheet.bundle.resources,
|
||||
stylesheet.stylesheetUrl
|
||||
].join("/");
|
||||
// Procedure for adding a single stylesheet
|
||||
function addStyleSheet(stylesheet) {
|
||||
// Create a link element, and construct full path
|
||||
var link = document.createElement('link'),
|
||||
path = [
|
||||
assetPath,
|
||||
stylesheet.bundle.path,
|
||||
stylesheet.bundle.resources,
|
||||
stylesheet.stylesheetUrl
|
||||
].join("/");
|
||||
|
||||
// Initialize attributes on the link
|
||||
link.setAttribute("rel", "stylesheet");
|
||||
link.setAttribute("type", "text/css");
|
||||
link.setAttribute("href", path);
|
||||
// Initialize attributes on the link
|
||||
link.setAttribute("rel", "stylesheet");
|
||||
link.setAttribute("type", "text/css");
|
||||
link.setAttribute("href", path);
|
||||
|
||||
// Append the link to the head element
|
||||
head.append(link);
|
||||
}
|
||||
|
||||
// Stylesheets which specify themes should only be applied
|
||||
// when that theme has been declared.
|
||||
function matchesTheme(stylesheet) {
|
||||
return stylesheet.theme === undefined
|
||||
|| stylesheet.theme === activeTheme;
|
||||
}
|
||||
|
||||
assetPath = assetPath || ".";
|
||||
|
||||
// Add all stylesheets from extensions
|
||||
stylesheets.filter(matchesTheme).forEach(addStyleSheet);
|
||||
}
|
||||
|
||||
return StyleSheetLoader;
|
||||
// Append the link to the head element
|
||||
head.append(link);
|
||||
}
|
||||
);
|
||||
|
||||
// Stylesheets which specify themes should only be applied
|
||||
// when that theme has been declared.
|
||||
function matchesTheme(stylesheet) {
|
||||
return stylesheet.theme === undefined
|
||||
|| stylesheet.theme === activeTheme;
|
||||
}
|
||||
|
||||
assetPath = assetPath || ".";
|
||||
|
||||
// Add all stylesheets from extensions
|
||||
stylesheets.filter(matchesTheme).forEach(addStyleSheet);
|
||||
}
|
||||
|
||||
export default StyleSheetLoader;
|
@ -23,82 +23,85 @@
|
||||
/**
|
||||
* Module defining ActionGroupController. Created by vwoeltje on 11/14/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Controller which keeps an up-to-date list of actions of
|
||||
* a certain category, and additionally bins them into
|
||||
* groups as described by their metadata. Used specifically
|
||||
* to support button groups.
|
||||
*
|
||||
* This will maintain two fields in the scope:
|
||||
* * `groups`: An array of arrays. Each element in the outer
|
||||
* array corresponds to a group; the inner array contains
|
||||
* the actions which are in that group.
|
||||
* * `ungrouped`: All actions which did not have a defined
|
||||
* group.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function ActionGroupController($scope) {
|
||||
/**
|
||||
* Module defining ActionGroupController. Created by vwoeltje on 11/14/14.
|
||||
*/
|
||||
function ActionGroupController($scope) {
|
||||
|
||||
// Separate out the actions that have been retrieved
|
||||
// into groups, and populate scope with this.
|
||||
function groupActions(actions) {
|
||||
var groups = {},
|
||||
ungrouped = [];
|
||||
// Separate out the actions that have been retrieved
|
||||
// into groups, and populate scope with this.
|
||||
function groupActions(actions) {
|
||||
var groups = {},
|
||||
ungrouped = [];
|
||||
|
||||
function assignToGroup(action) {
|
||||
var metadata = action.getMetadata(),
|
||||
group = metadata.group;
|
||||
if (group) {
|
||||
groups[group] = groups[group] || [];
|
||||
groups[group].push(action);
|
||||
} else {
|
||||
ungrouped.push(action);
|
||||
}
|
||||
}
|
||||
|
||||
(actions || []).forEach(assignToGroup);
|
||||
|
||||
$scope.ungrouped = ungrouped;
|
||||
$scope.groups = Object.keys(groups).sort().map(function (k) {
|
||||
return groups[k];
|
||||
});
|
||||
function assignToGroup(action) {
|
||||
var metadata = action.getMetadata(),
|
||||
group = metadata.group;
|
||||
if (group) {
|
||||
groups[group] = groups[group] || [];
|
||||
groups[group].push(action);
|
||||
} else {
|
||||
ungrouped.push(action);
|
||||
}
|
||||
|
||||
// Callback for when state which might influence action groupings
|
||||
// changes.
|
||||
function updateGroups() {
|
||||
var actionCapability = $scope.action,
|
||||
params = $scope.parameters || {},
|
||||
category = params.category;
|
||||
|
||||
if (actionCapability && category) {
|
||||
// Get actions by capability, and group them
|
||||
groupActions(actionCapability.getActions({
|
||||
category: category
|
||||
}));
|
||||
} else {
|
||||
// We don't have enough information to get any actions.
|
||||
groupActions([]);
|
||||
}
|
||||
}
|
||||
|
||||
// Changes to the represented object, to its action capability, or
|
||||
// to the chosen action category may all require an update.
|
||||
$scope.$watch("domainObject", updateGroups);
|
||||
$scope.$watch("action", updateGroups);
|
||||
$scope.$watch("parameters.category", updateGroups);
|
||||
|
||||
// Start with empty arrays.
|
||||
$scope.ungrouped = [];
|
||||
$scope.groups = [];
|
||||
}
|
||||
|
||||
return ActionGroupController;
|
||||
(actions || []).forEach(assignToGroup);
|
||||
|
||||
$scope.ungrouped = ungrouped;
|
||||
$scope.groups = Object.keys(groups).sort().map(function (k) {
|
||||
return groups[k];
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
// Callback for when state which might influence action groupings
|
||||
// changes.
|
||||
function updateGroups() {
|
||||
var actionCapability = $scope.action,
|
||||
params = $scope.parameters || {},
|
||||
category = params.category;
|
||||
|
||||
if (actionCapability && category) {
|
||||
// Get actions by capability, and group them
|
||||
groupActions(actionCapability.getActions({
|
||||
category: category
|
||||
}));
|
||||
} else {
|
||||
// We don't have enough information to get any actions.
|
||||
groupActions([]);
|
||||
}
|
||||
}
|
||||
|
||||
// Changes to the represented object, to its action capability, or
|
||||
// to the chosen action category may all require an update.
|
||||
$scope.$watch("domainObject", updateGroups);
|
||||
$scope.$watch("action", updateGroups);
|
||||
$scope.$watch("parameters.category", updateGroups);
|
||||
|
||||
// Start with empty arrays.
|
||||
$scope.ungrouped = [];
|
||||
$scope.groups = [];
|
||||
}
|
||||
|
||||
export default ActionGroupController;
|
@ -20,58 +20,62 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* A controller for banner notifications. Banner notifications are a
|
||||
* non-blocking way of drawing the user's attention to an event such
|
||||
* as system errors, or the progress or successful completion of an
|
||||
* ongoing task. This controller provides scoped functions for
|
||||
* dismissing and 'maximizing' notifications. See {@link NotificationService}
|
||||
* for more details on Notifications.
|
||||
*
|
||||
* @param $scope
|
||||
* @param notificationService
|
||||
* @param dialogService
|
||||
* @constructor
|
||||
function BannerController($scope, notificationService, dialogService) {
|
||||
$scope.active = notificationService.active;
|
||||
|
||||
$scope.action = function (action, $event) {
|
||||
/*
|
||||
Prevents default 'maximize' behaviour when clicking on
|
||||
notification button
|
||||
*/
|
||||
function BannerController($scope, notificationService, dialogService) {
|
||||
$scope.active = notificationService.active;
|
||||
$event.stopPropagation();
|
||||
|
||||
$scope.action = function (action, $event) {
|
||||
/*
|
||||
Prevents default 'maximize' behaviour when clicking on
|
||||
notification button
|
||||
*/
|
||||
$event.stopPropagation();
|
||||
return action();
|
||||
};
|
||||
|
||||
return action();
|
||||
$scope.dismiss = function (notification, $event) {
|
||||
$event.stopPropagation();
|
||||
notification.dismiss();
|
||||
};
|
||||
|
||||
$scope.maximize = function (notification) {
|
||||
if (notification.model.severity !== "info") {
|
||||
var dialog;
|
||||
notification.model.cancel = function () {
|
||||
dialog.dismiss();
|
||||
};
|
||||
|
||||
$scope.dismiss = function (notification, $event) {
|
||||
$event.stopPropagation();
|
||||
notification.dismiss();
|
||||
};
|
||||
//If the notification is dismissed by the user, close
|
||||
// the dialog.
|
||||
notification.on('dismiss', function () {
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
$scope.maximize = function (notification) {
|
||||
if (notification.model.severity !== "info") {
|
||||
var dialog;
|
||||
notification.model.cancel = function () {
|
||||
dialog.dismiss();
|
||||
};
|
||||
|
||||
//If the notification is dismissed by the user, close
|
||||
// the dialog.
|
||||
notification.on('dismiss', function () {
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
dialog = dialogService.showBlockingMessage(notification.model);
|
||||
}
|
||||
};
|
||||
dialog = dialogService.showBlockingMessage(notification.model);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return BannerController;
|
||||
});
|
||||
export default BannerController;
|
@ -20,78 +20,84 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* A ClickAwayController is used to toggle things (such as context
|
||||
* menus) where clicking elsewhere in the document while the toggle
|
||||
* is in an active state is intended to dismiss the toggle.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param $scope the scope in which this controller is active
|
||||
* @param $document the document element, injected by Angular
|
||||
*/
|
||||
function ClickAwayController($document, $timeout) {
|
||||
var self = this;
|
||||
function ClickAwayController($document, $timeout) {
|
||||
var self = this;
|
||||
|
||||
this.state = false;
|
||||
this.$document = $document;
|
||||
this.state = false;
|
||||
this.$document = $document;
|
||||
|
||||
// Callback used by the document listener. Timeout ensures that
|
||||
// `clickaway` action occurs after `toggle` if `toggle` is
|
||||
// triggered by a click/mouseup.
|
||||
this.clickaway = function () {
|
||||
$timeout(function () {
|
||||
self.deactivate();
|
||||
});
|
||||
};
|
||||
}
|
||||
// Callback used by the document listener. Timeout ensures that
|
||||
// `clickaway` action occurs after `toggle` if `toggle` is
|
||||
// triggered by a click/mouseup.
|
||||
this.clickaway = function () {
|
||||
$timeout(function () {
|
||||
self.deactivate();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// Track state, but also attach and detach a listener for
|
||||
// mouseup events on the document.
|
||||
ClickAwayController.prototype.deactivate = function () {
|
||||
this.state = false;
|
||||
this.$document.off("mouseup", this.clickaway);
|
||||
};
|
||||
// Track state, but also attach and detach a listener for
|
||||
// mouseup events on the document.
|
||||
ClickAwayController.prototype.deactivate = function () {
|
||||
this.state = false;
|
||||
this.$document.off("mouseup", this.clickaway);
|
||||
};
|
||||
|
||||
ClickAwayController.prototype.activate = function () {
|
||||
this.state = true;
|
||||
this.$document.on("mouseup", this.clickaway);
|
||||
};
|
||||
ClickAwayController.prototype.activate = function () {
|
||||
this.state = true;
|
||||
this.$document.on("mouseup", this.clickaway);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the current state of the toggle.
|
||||
* @return {boolean} true if active
|
||||
*/
|
||||
ClickAwayController.prototype.isActive = function () {
|
||||
return this.state;
|
||||
};
|
||||
/**
|
||||
* Get the current state of the toggle.
|
||||
* @return {boolean} true if active
|
||||
*/
|
||||
ClickAwayController.prototype.isActive = function () {
|
||||
return this.state;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set a new state for the toggle.
|
||||
* @return {boolean} true to activate
|
||||
*/
|
||||
ClickAwayController.prototype.setState = function (newState) {
|
||||
if (this.state !== newState) {
|
||||
this.toggle();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle the current state; activate if it is inactive,
|
||||
* deactivate if it is active.
|
||||
*/
|
||||
ClickAwayController.prototype.toggle = function () {
|
||||
if (this.state) {
|
||||
this.deactivate();
|
||||
} else {
|
||||
this.activate();
|
||||
}
|
||||
};
|
||||
|
||||
return ClickAwayController;
|
||||
/**
|
||||
* Set a new state for the toggle.
|
||||
* @return {boolean} true to activate
|
||||
*/
|
||||
ClickAwayController.prototype.setState = function (newState) {
|
||||
if (this.state !== newState) {
|
||||
this.toggle();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle the current state; activate if it is inactive,
|
||||
* deactivate if it is active.
|
||||
*/
|
||||
ClickAwayController.prototype.toggle = function () {
|
||||
if (this.state) {
|
||||
this.deactivate();
|
||||
} else {
|
||||
this.activate();
|
||||
}
|
||||
};
|
||||
|
||||
export default ClickAwayController;
|
@ -20,93 +20,92 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Controller to support the date-time entry field.
|
||||
*
|
||||
* Accepts a `format` property in the `structure` attribute
|
||||
* which allows a date/time to be specified via its symbolic
|
||||
* key (as will be used to look up said format from the
|
||||
* `formatService`.)
|
||||
*
|
||||
* {@see FormatService}
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/general
|
||||
* @param $scope the Angular scope for this controller
|
||||
* @param {FormatService} formatService the service to user to format
|
||||
* domain values
|
||||
* @param {string} defaultFormat the format to request when no
|
||||
* format has been otherwise specified
|
||||
*/
|
||||
function DateTimeFieldController($scope, formatService, defaultFormat) {
|
||||
var formatter = formatService.getFormat(defaultFormat);
|
||||
function DateTimeFieldController($scope, formatService, defaultFormat) {
|
||||
var formatter = formatService.getFormat(defaultFormat);
|
||||
|
||||
function updateFromModel(value) {
|
||||
// Only reformat if the value is different from user
|
||||
// input (to avoid reformatting valid input while typing.)
|
||||
if (!formatter.validate($scope.textValue)
|
||||
|| formatter.parse($scope.textValue) !== value) {
|
||||
$scope.textValue = formatter.format(value);
|
||||
$scope.textInvalid = false;
|
||||
$scope.lastValidValue = $scope.textValue;
|
||||
}
|
||||
|
||||
$scope.pickerModel = { value: value };
|
||||
}
|
||||
|
||||
function updateFromView(textValue) {
|
||||
$scope.textInvalid = !formatter.validate(textValue);
|
||||
if (!$scope.textInvalid) {
|
||||
$scope.ngModel[$scope.field] =
|
||||
formatter.parse(textValue);
|
||||
$scope.lastValidValue = $scope.textValue;
|
||||
}
|
||||
}
|
||||
|
||||
function updateFromPicker(value) {
|
||||
if (value !== $scope.ngModel[$scope.field]) {
|
||||
$scope.ngModel[$scope.field] = value;
|
||||
updateFromModel(value);
|
||||
if ($scope.ngBlur) {
|
||||
$scope.ngBlur();
|
||||
}
|
||||
|
||||
// If picker is active, dismiss it when valid value has been selected
|
||||
// This 'if' is to avoid unnecessary validation if picker is not active
|
||||
if ($scope.picker.active) {
|
||||
if ($scope.structure.validate && $scope.structure.validate($scope.ngModel[$scope.field])) {
|
||||
$scope.picker.active = false;
|
||||
} else if (!$scope.structure.validate) {
|
||||
//If picker visible, but no validation function, hide picker
|
||||
$scope.picker.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setFormat(format) {
|
||||
formatter = formatService.getFormat(format || defaultFormat);
|
||||
updateFromModel($scope.ngModel[$scope.field]);
|
||||
}
|
||||
|
||||
function restoreTextValue() {
|
||||
$scope.textValue = $scope.lastValidValue;
|
||||
updateFromView($scope.textValue);
|
||||
}
|
||||
|
||||
$scope.restoreTextValue = restoreTextValue;
|
||||
|
||||
$scope.picker = { active: false };
|
||||
|
||||
$scope.$watch('structure.format', setFormat);
|
||||
$scope.$watch('ngModel[field]', updateFromModel);
|
||||
$scope.$watch('pickerModel.value', updateFromPicker);
|
||||
$scope.$watch('textValue', updateFromView);
|
||||
function updateFromModel(value) {
|
||||
// Only reformat if the value is different from user
|
||||
// input (to avoid reformatting valid input while typing.)
|
||||
if (!formatter.validate($scope.textValue)
|
||||
|| formatter.parse($scope.textValue) !== value) {
|
||||
$scope.textValue = formatter.format(value);
|
||||
$scope.textInvalid = false;
|
||||
$scope.lastValidValue = $scope.textValue;
|
||||
}
|
||||
|
||||
return DateTimeFieldController;
|
||||
$scope.pickerModel = { value: value };
|
||||
}
|
||||
);
|
||||
|
||||
function updateFromView(textValue) {
|
||||
$scope.textInvalid = !formatter.validate(textValue);
|
||||
if (!$scope.textInvalid) {
|
||||
$scope.ngModel[$scope.field] =
|
||||
formatter.parse(textValue);
|
||||
$scope.lastValidValue = $scope.textValue;
|
||||
}
|
||||
}
|
||||
|
||||
function updateFromPicker(value) {
|
||||
if (value !== $scope.ngModel[$scope.field]) {
|
||||
$scope.ngModel[$scope.field] = value;
|
||||
updateFromModel(value);
|
||||
if ($scope.ngBlur) {
|
||||
$scope.ngBlur();
|
||||
}
|
||||
|
||||
// If picker is active, dismiss it when valid value has been selected
|
||||
// This 'if' is to avoid unnecessary validation if picker is not active
|
||||
if ($scope.picker.active) {
|
||||
if ($scope.structure.validate && $scope.structure.validate($scope.ngModel[$scope.field])) {
|
||||
$scope.picker.active = false;
|
||||
} else if (!$scope.structure.validate) {
|
||||
//If picker visible, but no validation function, hide picker
|
||||
$scope.picker.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setFormat(format) {
|
||||
formatter = formatService.getFormat(format || defaultFormat);
|
||||
updateFromModel($scope.ngModel[$scope.field]);
|
||||
}
|
||||
|
||||
function restoreTextValue() {
|
||||
$scope.textValue = $scope.lastValidValue;
|
||||
updateFromView($scope.textValue);
|
||||
}
|
||||
|
||||
$scope.restoreTextValue = restoreTextValue;
|
||||
|
||||
$scope.picker = { active: false };
|
||||
|
||||
$scope.$watch('structure.format', setFormat);
|
||||
$scope.$watch('ngModel[field]', updateFromModel);
|
||||
$scope.$watch('pickerModel.value', updateFromPicker);
|
||||
$scope.$watch('textValue', updateFromView);
|
||||
}
|
||||
|
||||
export default DateTimeFieldController;
|
@ -20,188 +20,206 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
['moment'],
|
||||
function (moment) {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
var TIME_NAMES = {
|
||||
'hours': "Hour",
|
||||
'minutes': "Minute",
|
||||
'seconds': "Second"
|
||||
},
|
||||
MONTHS = moment.months(),
|
||||
TIME_OPTIONS = (function makeRanges() {
|
||||
var arr = [];
|
||||
while (arr.length < 60) {
|
||||
arr.push(arr.length);
|
||||
}
|
||||
import moment from 'moment';
|
||||
|
||||
return {
|
||||
hours: arr.slice(0, 24),
|
||||
minutes: arr,
|
||||
seconds: arr
|
||||
};
|
||||
}());
|
||||
|
||||
/**
|
||||
* Controller to support the date-time picker.
|
||||
*
|
||||
* Adds/uses the following properties in scope:
|
||||
* * `year`: Year being displayed in picker
|
||||
* * `month`: Month being displayed
|
||||
* * `table`: Table being displayed; array of arrays of
|
||||
* * `day`: Day of month
|
||||
* * `dayOfYear`: Day of year
|
||||
* * `month`: Month associated with the day
|
||||
* * `year`: Year associated with the day.
|
||||
* * `date`: Date chosen
|
||||
* * `year`: Year selected
|
||||
* * `month`: Month selected (0-indexed)
|
||||
* * `day`: Day of month selected
|
||||
* * `time`: Chosen time (hours/minutes/seconds)
|
||||
* * `hours`: Hours chosen
|
||||
* * `minutes`: Minutes chosen
|
||||
* * `seconds`: Seconds chosen
|
||||
*
|
||||
* Months are zero-indexed, day-of-months are one-indexed.
|
||||
*/
|
||||
function DateTimePickerController($scope, now) {
|
||||
var year,
|
||||
month, // For picker state, not model state
|
||||
interacted = false;
|
||||
|
||||
function generateTable() {
|
||||
var m = moment.utc({
|
||||
year: year,
|
||||
month: month
|
||||
}).day(0),
|
||||
table = [],
|
||||
row,
|
||||
col;
|
||||
|
||||
for (row = 0; row < 6; row += 1) {
|
||||
table.push([]);
|
||||
for (col = 0; col < 7; col += 1) {
|
||||
table[row].push({
|
||||
year: m.year(),
|
||||
month: m.month(),
|
||||
day: m.date(),
|
||||
dayOfYear: m.dayOfYear()
|
||||
});
|
||||
m.add(1, 'days'); // Next day!
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
function updateScopeForMonth() {
|
||||
$scope.month = MONTHS[month];
|
||||
$scope.year = year;
|
||||
$scope.table = generateTable();
|
||||
}
|
||||
|
||||
function updateFromModel(ngModel) {
|
||||
var m;
|
||||
|
||||
m = moment.utc(ngModel);
|
||||
|
||||
$scope.date = {
|
||||
year: m.year(),
|
||||
month: m.month(),
|
||||
day: m.date()
|
||||
};
|
||||
$scope.time = {
|
||||
hours: m.hour(),
|
||||
minutes: m.minute(),
|
||||
seconds: m.second()
|
||||
};
|
||||
|
||||
//window.alert($scope.date.day + " " + ngModel);
|
||||
|
||||
// Zoom to that date in the picker, but
|
||||
// only if the user hasn't interacted with it yet.
|
||||
if (!interacted) {
|
||||
year = m.year();
|
||||
month = m.month();
|
||||
updateScopeForMonth();
|
||||
}
|
||||
}
|
||||
|
||||
function updateFromView() {
|
||||
var m = moment.utc({
|
||||
year: $scope.date.year,
|
||||
month: $scope.date.month,
|
||||
day: $scope.date.day,
|
||||
hour: $scope.time.hours,
|
||||
minute: $scope.time.minutes,
|
||||
second: $scope.time.seconds
|
||||
});
|
||||
$scope.ngModel[$scope.field] = m.valueOf();
|
||||
}
|
||||
|
||||
$scope.isInCurrentMonth = function (cell) {
|
||||
return cell.month === month;
|
||||
};
|
||||
|
||||
$scope.isSelected = function (cell) {
|
||||
var date = $scope.date || {};
|
||||
|
||||
return cell.day === date.day
|
||||
&& cell.month === date.month
|
||||
&& cell.year === date.year;
|
||||
};
|
||||
|
||||
$scope.select = function (cell) {
|
||||
$scope.date = $scope.date || {};
|
||||
$scope.date.month = cell.month;
|
||||
$scope.date.year = cell.year;
|
||||
$scope.date.day = cell.day;
|
||||
updateFromView();
|
||||
};
|
||||
|
||||
$scope.dateEquals = function (d1, d2) {
|
||||
return d1.year === d2.year
|
||||
&& d1.month === d2.month
|
||||
&& d1.day === d2.day;
|
||||
};
|
||||
|
||||
$scope.changeMonth = function (delta) {
|
||||
month += delta;
|
||||
if (month > 11) {
|
||||
month = 0;
|
||||
year += 1;
|
||||
}
|
||||
|
||||
if (month < 0) {
|
||||
month = 11;
|
||||
year -= 1;
|
||||
}
|
||||
|
||||
interacted = true;
|
||||
updateScopeForMonth();
|
||||
};
|
||||
|
||||
$scope.nameFor = function (key) {
|
||||
return TIME_NAMES[key];
|
||||
};
|
||||
|
||||
$scope.optionsFor = function (key) {
|
||||
return TIME_OPTIONS[key];
|
||||
};
|
||||
|
||||
updateScopeForMonth();
|
||||
|
||||
// Ensure some useful default
|
||||
$scope.ngModel[$scope.field] =
|
||||
$scope.ngModel[$scope.field] === undefined
|
||||
? now() : $scope.ngModel[$scope.field];
|
||||
|
||||
$scope.$watch('ngModel[field]', updateFromModel);
|
||||
$scope.$watchCollection('date', updateFromView);
|
||||
$scope.$watchCollection('time', updateFromView);
|
||||
var TIME_NAMES = {
|
||||
'hours': "Hour",
|
||||
'minutes': "Minute",
|
||||
'seconds': "Second"
|
||||
},
|
||||
MONTHS = moment.months(),
|
||||
TIME_OPTIONS = (function makeRanges() {
|
||||
var arr = [];
|
||||
while (arr.length < 60) {
|
||||
arr.push(arr.length);
|
||||
}
|
||||
|
||||
return DateTimePickerController;
|
||||
return {
|
||||
hours: arr.slice(0, 24),
|
||||
minutes: arr,
|
||||
seconds: arr
|
||||
};
|
||||
}());
|
||||
|
||||
/**
|
||||
* Controller to support the date-time picker.
|
||||
*
|
||||
* Adds/uses the following properties in scope:
|
||||
* * `year`: Year being displayed in picker
|
||||
* * `month`: Month being displayed
|
||||
* * `table`: Table being displayed; array of arrays of
|
||||
* * `day`: Day of month
|
||||
* * `dayOfYear`: Day of year
|
||||
* * `month`: Month associated with the day
|
||||
* * `year`: Year associated with the day.
|
||||
* * `date`: Date chosen
|
||||
* * `year`: Year selected
|
||||
* * `month`: Month selected (0-indexed)
|
||||
* * `day`: Day of month selected
|
||||
* * `time`: Chosen time (hours/minutes/seconds)
|
||||
* * `hours`: Hours chosen
|
||||
* * `minutes`: Minutes chosen
|
||||
* * `seconds`: Seconds chosen
|
||||
*
|
||||
* Months are zero-indexed, day-of-months are one-indexed.
|
||||
*/
|
||||
function DateTimePickerController($scope, now) {
|
||||
var year,
|
||||
month, // For picker state, not model state
|
||||
interacted = false;
|
||||
|
||||
function generateTable() {
|
||||
var m = moment.utc({
|
||||
year: year,
|
||||
month: month
|
||||
}).day(0),
|
||||
table = [],
|
||||
row,
|
||||
col;
|
||||
|
||||
for (row = 0; row < 6; row += 1) {
|
||||
table.push([]);
|
||||
for (col = 0; col < 7; col += 1) {
|
||||
table[row].push({
|
||||
year: m.year(),
|
||||
month: m.month(),
|
||||
day: m.date(),
|
||||
dayOfYear: m.dayOfYear()
|
||||
});
|
||||
m.add(1, 'days'); // Next day!
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
);
|
||||
|
||||
function updateScopeForMonth() {
|
||||
$scope.month = MONTHS[month];
|
||||
$scope.year = year;
|
||||
$scope.table = generateTable();
|
||||
}
|
||||
|
||||
function updateFromModel(ngModel) {
|
||||
var m;
|
||||
|
||||
m = moment.utc(ngModel);
|
||||
|
||||
$scope.date = {
|
||||
year: m.year(),
|
||||
month: m.month(),
|
||||
day: m.date()
|
||||
};
|
||||
$scope.time = {
|
||||
hours: m.hour(),
|
||||
minutes: m.minute(),
|
||||
seconds: m.second()
|
||||
};
|
||||
|
||||
//window.alert($scope.date.day + " " + ngModel);
|
||||
|
||||
// Zoom to that date in the picker, but
|
||||
// only if the user hasn't interacted with it yet.
|
||||
if (!interacted) {
|
||||
year = m.year();
|
||||
month = m.month();
|
||||
updateScopeForMonth();
|
||||
}
|
||||
}
|
||||
|
||||
function updateFromView() {
|
||||
var m = moment.utc({
|
||||
year: $scope.date.year,
|
||||
month: $scope.date.month,
|
||||
day: $scope.date.day,
|
||||
hour: $scope.time.hours,
|
||||
minute: $scope.time.minutes,
|
||||
second: $scope.time.seconds
|
||||
});
|
||||
$scope.ngModel[$scope.field] = m.valueOf();
|
||||
}
|
||||
|
||||
$scope.isInCurrentMonth = function (cell) {
|
||||
return cell.month === month;
|
||||
};
|
||||
|
||||
$scope.isSelected = function (cell) {
|
||||
var date = $scope.date || {};
|
||||
|
||||
return cell.day === date.day
|
||||
&& cell.month === date.month
|
||||
&& cell.year === date.year;
|
||||
};
|
||||
|
||||
$scope.select = function (cell) {
|
||||
$scope.date = $scope.date || {};
|
||||
$scope.date.month = cell.month;
|
||||
$scope.date.year = cell.year;
|
||||
$scope.date.day = cell.day;
|
||||
updateFromView();
|
||||
};
|
||||
|
||||
$scope.dateEquals = function (d1, d2) {
|
||||
return d1.year === d2.year
|
||||
&& d1.month === d2.month
|
||||
&& d1.day === d2.day;
|
||||
};
|
||||
|
||||
$scope.changeMonth = function (delta) {
|
||||
month += delta;
|
||||
if (month > 11) {
|
||||
month = 0;
|
||||
year += 1;
|
||||
}
|
||||
|
||||
if (month < 0) {
|
||||
month = 11;
|
||||
year -= 1;
|
||||
}
|
||||
|
||||
interacted = true;
|
||||
updateScopeForMonth();
|
||||
};
|
||||
|
||||
$scope.nameFor = function (key) {
|
||||
return TIME_NAMES[key];
|
||||
};
|
||||
|
||||
$scope.optionsFor = function (key) {
|
||||
return TIME_OPTIONS[key];
|
||||
};
|
||||
|
||||
updateScopeForMonth();
|
||||
|
||||
// Ensure some useful default
|
||||
$scope.ngModel[$scope.field] =
|
||||
$scope.ngModel[$scope.field] === undefined
|
||||
? now() : $scope.ngModel[$scope.field];
|
||||
|
||||
$scope.$watch('ngModel[field]', updateFromModel);
|
||||
$scope.$watchCollection('date', updateFromView);
|
||||
$scope.$watchCollection('time', updateFromView);
|
||||
}
|
||||
|
||||
export default DateTimePickerController;
|
@ -20,70 +20,53 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* This controller acts as an adapter to permit getter-setter
|
||||
* functions to be used as ng-model arguments to controls,
|
||||
* such as the input-filter. This is supported natively in
|
||||
* Angular 1.3+ via `ng-model-options`, so this controller
|
||||
* should be made obsolete after any upgrade to Angular 1.3.
|
||||
*
|
||||
* It expects to find in scope a value `ngModel` which is a
|
||||
* function which, when called with no arguments, acts as a
|
||||
* getter, and when called with one argument, acts as a setter.
|
||||
*
|
||||
* It also publishes into the scope a value `getterSetter.value`
|
||||
* which is meant to be used as an assignable expression.
|
||||
*
|
||||
* This controller watches both of these; when one changes,
|
||||
* it will update the other's value to match. Because of this,
|
||||
* the `ngModel` function should be both stable and computationally
|
||||
* inexpensive, as it will be invoked often.
|
||||
*
|
||||
* Getter-setter style models can be preferable when there
|
||||
* is significant indirection between templates; "dotless"
|
||||
* expressions in `ng-model` can behave unexpectedly due to the
|
||||
* rules of scope, but dots are lost when passed in via `ng-model`
|
||||
* (so if a control is internally implemented using regular
|
||||
* form elements, it can't transparently pass through the `ng-model`
|
||||
* parameter it received.) Getter-setter functions are never the
|
||||
* target of a scope assignment and so avoid this problem.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param {Scope} $scope the controller's scope
|
||||
*/
|
||||
function GetterSetterController($scope) {
|
||||
|
||||
// Update internal assignable state based on changes
|
||||
// to the getter-setter function.
|
||||
function updateGetterSetter() {
|
||||
if (typeof $scope.ngModel === 'function') {
|
||||
$scope.getterSetter.value = $scope.ngModel();
|
||||
}
|
||||
}
|
||||
|
||||
// Update the external getter-setter based on changes
|
||||
// to the assignable state.
|
||||
function updateNgModel() {
|
||||
if (typeof $scope.ngModel === 'function') {
|
||||
$scope.ngModel($scope.getterSetter.value);
|
||||
}
|
||||
}
|
||||
|
||||
// Watch for changes to both expressions
|
||||
$scope.$watch("ngModel()", updateGetterSetter);
|
||||
$scope.$watch("getterSetter.value", updateNgModel);
|
||||
|
||||
// Publish an assignable field into scope.
|
||||
$scope.getterSetter = {};
|
||||
function GetterSetterController($scope) {
|
||||
|
||||
// Update internal assignable state based on changes
|
||||
// to the getter-setter function.
|
||||
function updateGetterSetter() {
|
||||
if (typeof $scope.ngModel === 'function') {
|
||||
$scope.getterSetter.value = $scope.ngModel();
|
||||
}
|
||||
|
||||
return GetterSetterController;
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// Update the external getter-setter based on changes
|
||||
// to the assignable state.
|
||||
function updateNgModel() {
|
||||
if (typeof $scope.ngModel === 'function') {
|
||||
$scope.ngModel($scope.getterSetter.value);
|
||||
}
|
||||
}
|
||||
|
||||
// Watch for changes to both expressions
|
||||
$scope.$watch("ngModel()", updateGetterSetter);
|
||||
$scope.$watch("getterSetter.value", updateNgModel);
|
||||
|
||||
// Publish an assignable field into scope.
|
||||
$scope.getterSetter = {};
|
||||
|
||||
}
|
||||
|
||||
export default GetterSetterController;
|
@ -23,97 +23,110 @@
|
||||
/**
|
||||
* Module defining ObjectInspectorController. Created by shale on 08/21/2015.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The ObjectInspectorController gets and formats the data for
|
||||
* the inspector display
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function ObjectInspectorController($scope, objectService) {
|
||||
$scope.primaryParents = [];
|
||||
$scope.contextutalParents = [];
|
||||
//$scope.isLink = false;
|
||||
/**
|
||||
* Module defining ObjectInspectorController. Created by shale on 08/21/2015.
|
||||
*/
|
||||
function ObjectInspectorController($scope, objectService) {
|
||||
$scope.primaryParents = [];
|
||||
$scope.contextutalParents = [];
|
||||
//$scope.isLink = false;
|
||||
|
||||
// Gets an array of the contextual parents/ancestors of the selected object
|
||||
function getContextualPath() {
|
||||
var currentObj = $scope.domainObject,
|
||||
currentParent,
|
||||
parents = [];
|
||||
// Gets an array of the contextual parents/ancestors of the selected object
|
||||
function getContextualPath() {
|
||||
var currentObj = $scope.domainObject,
|
||||
currentParent,
|
||||
parents = [];
|
||||
|
||||
currentParent = currentObj
|
||||
&& currentObj.hasCapability('context')
|
||||
&& currentObj.getCapability('context').getParent();
|
||||
currentParent = currentObj
|
||||
&& currentObj.hasCapability('context')
|
||||
&& currentObj.getCapability('context').getParent();
|
||||
|
||||
while (currentParent && currentParent.getModel().type !== 'root'
|
||||
&& currentParent.hasCapability('context')) {
|
||||
// Record this object
|
||||
parents.unshift(currentParent);
|
||||
while (currentParent && currentParent.getModel().type !== 'root'
|
||||
&& currentParent.hasCapability('context')) {
|
||||
// Record this object
|
||||
parents.unshift(currentParent);
|
||||
|
||||
// Get the next one up the tree
|
||||
currentObj = currentParent;
|
||||
currentParent = currentObj.getCapability('context').getParent();
|
||||
}
|
||||
|
||||
$scope.contextutalParents = parents;
|
||||
}
|
||||
|
||||
// Gets an array of the parents/ancestors of the selected object's
|
||||
// primary location (locational of original non-link)
|
||||
function getPrimaryPath(current) {
|
||||
var location;
|
||||
|
||||
// If this the the initial call of this recursive function
|
||||
if (!current) {
|
||||
current = $scope.domainObject;
|
||||
$scope.primaryParents = [];
|
||||
}
|
||||
|
||||
location = current.getModel().location;
|
||||
|
||||
if (location && location !== 'root') {
|
||||
objectService.getObjects([location]).then(function (obj) {
|
||||
var next = obj[location];
|
||||
|
||||
$scope.primaryParents.unshift(next);
|
||||
getPrimaryPath(next);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Gets the metadata for the selected object
|
||||
function getMetadata() {
|
||||
$scope.metadata = $scope.domainObject
|
||||
&& $scope.domainObject.hasCapability('metadata')
|
||||
&& $scope.domainObject.useCapability('metadata');
|
||||
}
|
||||
|
||||
// Set scope variables when the selected object changes
|
||||
$scope.$watch('domainObject', function () {
|
||||
$scope.isLink = $scope.domainObject
|
||||
&& $scope.domainObject.hasCapability('location')
|
||||
&& $scope.domainObject.getCapability('location').isLink();
|
||||
|
||||
if ($scope.isLink) {
|
||||
getPrimaryPath();
|
||||
getContextualPath();
|
||||
} else {
|
||||
$scope.primaryParents = [];
|
||||
getContextualPath();
|
||||
}
|
||||
|
||||
getMetadata();
|
||||
});
|
||||
|
||||
var mutation = $scope.domainObject.getCapability('mutation');
|
||||
var unlisten = mutation.listen(getMetadata);
|
||||
$scope.$on('$destroy', unlisten);
|
||||
// Get the next one up the tree
|
||||
currentObj = currentParent;
|
||||
currentParent = currentObj.getCapability('context').getParent();
|
||||
}
|
||||
|
||||
return ObjectInspectorController;
|
||||
$scope.contextutalParents = parents;
|
||||
}
|
||||
);
|
||||
|
||||
// Gets an array of the parents/ancestors of the selected object's
|
||||
// primary location (locational of original non-link)
|
||||
function getPrimaryPath(current) {
|
||||
var location;
|
||||
|
||||
// If this the the initial call of this recursive function
|
||||
if (!current) {
|
||||
current = $scope.domainObject;
|
||||
$scope.primaryParents = [];
|
||||
}
|
||||
|
||||
location = current.getModel().location;
|
||||
|
||||
if (location && location !== 'root') {
|
||||
objectService.getObjects([location]).then(function (obj) {
|
||||
var next = obj[location];
|
||||
|
||||
$scope.primaryParents.unshift(next);
|
||||
getPrimaryPath(next);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Gets the metadata for the selected object
|
||||
function getMetadata() {
|
||||
$scope.metadata = $scope.domainObject
|
||||
&& $scope.domainObject.hasCapability('metadata')
|
||||
&& $scope.domainObject.useCapability('metadata');
|
||||
}
|
||||
|
||||
// Set scope variables when the selected object changes
|
||||
$scope.$watch('domainObject', function () {
|
||||
$scope.isLink = $scope.domainObject
|
||||
&& $scope.domainObject.hasCapability('location')
|
||||
&& $scope.domainObject.getCapability('location').isLink();
|
||||
|
||||
if ($scope.isLink) {
|
||||
getPrimaryPath();
|
||||
getContextualPath();
|
||||
} else {
|
||||
$scope.primaryParents = [];
|
||||
getContextualPath();
|
||||
}
|
||||
|
||||
getMetadata();
|
||||
});
|
||||
|
||||
var mutation = $scope.domainObject.getCapability('mutation');
|
||||
var unlisten = mutation.listen(getMetadata);
|
||||
$scope.$on('$destroy', unlisten);
|
||||
}
|
||||
|
||||
export default ObjectInspectorController;
|
@ -20,145 +20,161 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
var ROOT_ID = "ROOT";
|
||||
var ROOT_ID = "ROOT";
|
||||
|
||||
/**
|
||||
* Controller for the domain object selector control.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param {ObjectService} objectService service from which to
|
||||
* read domain objects
|
||||
* @param $scope Angular scope for this controller
|
||||
*/
|
||||
function SelectorController(objectService, $scope) {
|
||||
var treeModel = {},
|
||||
listModel = {},
|
||||
previousSelected,
|
||||
self = this;
|
||||
/**
|
||||
* Controller for the domain object selector control.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param {ObjectService} objectService service from which to
|
||||
* read domain objects
|
||||
* @param $scope Angular scope for this controller
|
||||
*/
|
||||
function SelectorController(objectService, $scope) {
|
||||
var treeModel = {},
|
||||
listModel = {},
|
||||
previousSelected,
|
||||
self = this;
|
||||
|
||||
// For watch; look at the user's selection in the tree
|
||||
function getTreeSelection() {
|
||||
return treeModel.selectedObject;
|
||||
}
|
||||
// For watch; look at the user's selection in the tree
|
||||
function getTreeSelection() {
|
||||
return treeModel.selectedObject;
|
||||
}
|
||||
|
||||
// Store root object for subsequent exposure to template
|
||||
function storeRoot(objects) {
|
||||
self.rootObject = objects[ROOT_ID];
|
||||
}
|
||||
// Store root object for subsequent exposure to template
|
||||
function storeRoot(objects) {
|
||||
self.rootObject = objects[ROOT_ID];
|
||||
}
|
||||
|
||||
// Check that a selection is of the valid type
|
||||
function validateTreeSelection(selectedObject) {
|
||||
var type = selectedObject
|
||||
&& selectedObject.getCapability('type');
|
||||
// Check that a selection is of the valid type
|
||||
function validateTreeSelection(selectedObject) {
|
||||
var type = selectedObject
|
||||
&& selectedObject.getCapability('type');
|
||||
|
||||
// Delegate type-checking to the capability...
|
||||
if (!type || !type.instanceOf($scope.structure.type)) {
|
||||
treeModel.selectedObject = previousSelected;
|
||||
}
|
||||
|
||||
// Track current selection to restore it if an invalid
|
||||
// selection is made later.
|
||||
previousSelected = treeModel.selectedObject;
|
||||
}
|
||||
|
||||
// Update the right-hand list of currently-selected objects
|
||||
function updateList(ids) {
|
||||
function updateSelectedObjects(objects) {
|
||||
// Look up from the
|
||||
function getObject(id) {
|
||||
return objects[id];
|
||||
}
|
||||
|
||||
self.selectedObjects =
|
||||
ids.filter(getObject).map(getObject);
|
||||
}
|
||||
|
||||
// Look up objects by id, then populate right-hand list
|
||||
objectService.getObjects(ids).then(updateSelectedObjects);
|
||||
}
|
||||
|
||||
// Reject attempts to select objects of the wrong type
|
||||
$scope.$watch(getTreeSelection, validateTreeSelection);
|
||||
|
||||
// Make sure right-hand list matches underlying model
|
||||
$scope.$watchCollection(function () {
|
||||
return self.getField();
|
||||
}, updateList);
|
||||
|
||||
// Look up root object, then store it
|
||||
objectService.getObjects([ROOT_ID]).then(storeRoot);
|
||||
|
||||
this.$scope = $scope;
|
||||
this.selectedObjects = [];
|
||||
|
||||
// Expose tree/list model for use in template directly
|
||||
this.treeModel = treeModel;
|
||||
this.listModel = listModel;
|
||||
// Delegate type-checking to the capability...
|
||||
if (!type || !type.instanceOf($scope.structure.type)) {
|
||||
treeModel.selectedObject = previousSelected;
|
||||
}
|
||||
|
||||
// Set the value of the field being edited
|
||||
SelectorController.prototype.setField = function (value) {
|
||||
this.$scope.ngModel[this.$scope.field] = value;
|
||||
};
|
||||
|
||||
// Get the value of the field being edited
|
||||
SelectorController.prototype.getField = function () {
|
||||
return this.$scope.ngModel[this.$scope.field] || [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the root object to show in the left-hand tree.
|
||||
* @returns {DomainObject} the root object
|
||||
*/
|
||||
SelectorController.prototype.root = function () {
|
||||
return this.rootObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a domain object to the list of selected objects.
|
||||
* @param {DomainObject} the domain object to select
|
||||
*/
|
||||
SelectorController.prototype.select = function (domainObject) {
|
||||
var id = domainObject && domainObject.getId(),
|
||||
list = this.getField() || [];
|
||||
// Only select if we have a valid id,
|
||||
// and it isn't already selected
|
||||
if (id && list.indexOf(id) === -1) {
|
||||
this.setField(list.concat([id]));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a domain object from the list of selected objects.
|
||||
* @param {DomainObject} the domain object to select
|
||||
*/
|
||||
SelectorController.prototype.deselect = function (domainObject) {
|
||||
var id = domainObject && domainObject.getId(),
|
||||
list = this.getField() || [];
|
||||
// Only change if this was a valid id,
|
||||
// for an object which was already selected
|
||||
if (id && list.indexOf(id) !== -1) {
|
||||
// Filter it out of the current field
|
||||
this.setField(list.filter(function (otherId) {
|
||||
return otherId !== id;
|
||||
}));
|
||||
// Clear the current list selection
|
||||
delete this.listModel.selectedObject;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the currently-selected domain objects.
|
||||
* @returns {DomainObject[]} the current selection
|
||||
*/
|
||||
SelectorController.prototype.selected = function () {
|
||||
return this.selectedObjects;
|
||||
};
|
||||
|
||||
return SelectorController;
|
||||
// Track current selection to restore it if an invalid
|
||||
// selection is made later.
|
||||
previousSelected = treeModel.selectedObject;
|
||||
}
|
||||
);
|
||||
|
||||
// Update the right-hand list of currently-selected objects
|
||||
function updateList(ids) {
|
||||
function updateSelectedObjects(objects) {
|
||||
// Look up from the
|
||||
function getObject(id) {
|
||||
return objects[id];
|
||||
}
|
||||
|
||||
self.selectedObjects =
|
||||
ids.filter(getObject).map(getObject);
|
||||
}
|
||||
|
||||
// Look up objects by id, then populate right-hand list
|
||||
objectService.getObjects(ids).then(updateSelectedObjects);
|
||||
}
|
||||
|
||||
// Reject attempts to select objects of the wrong type
|
||||
$scope.$watch(getTreeSelection, validateTreeSelection);
|
||||
|
||||
// Make sure right-hand list matches underlying model
|
||||
$scope.$watchCollection(function () {
|
||||
return self.getField();
|
||||
}, updateList);
|
||||
|
||||
// Look up root object, then store it
|
||||
objectService.getObjects([ROOT_ID]).then(storeRoot);
|
||||
|
||||
this.$scope = $scope;
|
||||
this.selectedObjects = [];
|
||||
|
||||
// Expose tree/list model for use in template directly
|
||||
this.treeModel = treeModel;
|
||||
this.listModel = listModel;
|
||||
}
|
||||
|
||||
// Set the value of the field being edited
|
||||
SelectorController.prototype.setField = function (value) {
|
||||
this.$scope.ngModel[this.$scope.field] = value;
|
||||
};
|
||||
|
||||
// Get the value of the field being edited
|
||||
SelectorController.prototype.getField = function () {
|
||||
return this.$scope.ngModel[this.$scope.field] || [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the root object to show in the left-hand tree.
|
||||
* @returns {DomainObject} the root object
|
||||
*/
|
||||
SelectorController.prototype.root = function () {
|
||||
return this.rootObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a domain object to the list of selected objects.
|
||||
* @param {DomainObject} the domain object to select
|
||||
*/
|
||||
SelectorController.prototype.select = function (domainObject) {
|
||||
var id = domainObject && domainObject.getId(),
|
||||
list = this.getField() || [];
|
||||
// Only select if we have a valid id,
|
||||
// and it isn't already selected
|
||||
if (id && list.indexOf(id) === -1) {
|
||||
this.setField(list.concat([id]));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a domain object from the list of selected objects.
|
||||
* @param {DomainObject} the domain object to select
|
||||
*/
|
||||
SelectorController.prototype.deselect = function (domainObject) {
|
||||
var id = domainObject && domainObject.getId(),
|
||||
list = this.getField() || [];
|
||||
// Only change if this was a valid id,
|
||||
// for an object which was already selected
|
||||
if (id && list.indexOf(id) !== -1) {
|
||||
// Filter it out of the current field
|
||||
this.setField(list.filter(function (otherId) {
|
||||
return otherId !== id;
|
||||
}));
|
||||
// Clear the current list selection
|
||||
delete this.listModel.selectedObject;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the currently-selected domain objects.
|
||||
* @returns {DomainObject[]} the current selection
|
||||
*/
|
||||
SelectorController.prototype.selected = function () {
|
||||
return this.selectedObjects;
|
||||
};
|
||||
|
||||
export default SelectorController;
|
@ -20,294 +20,311 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
], function () {
|
||||
var TICK_SPACING_PX = 150;
|
||||
|
||||
var TICK_SPACING_PX = 150;
|
||||
/* format number as percent; 0.0-1.0 to "0%"-"100%" */
|
||||
function toPercent(p) {
|
||||
return (100 * p) + "%";
|
||||
}
|
||||
|
||||
/* format number as percent; 0.0-1.0 to "0%"-"100%" */
|
||||
function toPercent(p) {
|
||||
return (100 * p) + "%";
|
||||
}
|
||||
function clamp(value, low, high) {
|
||||
return Math.max(low, Math.min(high, value));
|
||||
}
|
||||
|
||||
function clamp(value, low, high) {
|
||||
return Math.max(low, Math.min(high, value));
|
||||
}
|
||||
|
||||
function copyBounds(bounds) {
|
||||
return {
|
||||
start: bounds.start,
|
||||
end: bounds.end
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller used by the `time-controller` template.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param $scope the Angular scope for this controller
|
||||
* @param {FormatService} formatService the service to user to format
|
||||
* domain values
|
||||
* @param {string} defaultFormat the format to request when no
|
||||
* format has been otherwise specified
|
||||
* @param {Function} now a function to return current system time
|
||||
*/
|
||||
function TimeRangeController($scope, $timeout, formatService, defaultFormat, now) {
|
||||
this.$scope = $scope;
|
||||
this.formatService = formatService;
|
||||
this.defaultFormat = defaultFormat;
|
||||
this.now = now;
|
||||
|
||||
this.tickCount = 2;
|
||||
this.innerMinimumSpan = 1000; // 1 second
|
||||
this.outerMinimumSpan = 1000; // 1 second
|
||||
this.initialDragValue = undefined;
|
||||
this.formatter = formatService.getFormat(defaultFormat);
|
||||
this.formStartChanged = false;
|
||||
this.formEndChanged = false;
|
||||
this.$timeout = $timeout;
|
||||
|
||||
this.$scope.ticks = [];
|
||||
|
||||
this.updateViewFromModel(this.$scope.ngModel);
|
||||
this.updateFormModel();
|
||||
|
||||
[
|
||||
'updateViewFromModel',
|
||||
'updateSpanWidth',
|
||||
'updateOuterStart',
|
||||
'updateOuterEnd',
|
||||
'updateFormat',
|
||||
'validateStart',
|
||||
'validateEnd',
|
||||
'onFormStartChange',
|
||||
'onFormEndChange'
|
||||
].forEach(function (boundFn) {
|
||||
this[boundFn] = this[boundFn].bind(this);
|
||||
}, this);
|
||||
|
||||
this.$scope.$watchCollection("ngModel", this.updateViewFromModel);
|
||||
this.$scope.$watch("spanWidth", this.updateSpanWidth);
|
||||
this.$scope.$watch("ngModel.outer.start", this.updateOuterStart);
|
||||
this.$scope.$watch("ngModel.outer.end", this.updateOuterEnd);
|
||||
this.$scope.$watch("parameters.format", this.updateFormat);
|
||||
this.$scope.$watch("formModel.start", this.onFormStartChange);
|
||||
this.$scope.$watch("formModel.end", this.onFormEndChange);
|
||||
}
|
||||
|
||||
TimeRangeController.prototype.formatTimestamp = function (ts) {
|
||||
return this.formatter.format(ts);
|
||||
function copyBounds(bounds) {
|
||||
return {
|
||||
start: bounds.start,
|
||||
end: bounds.end
|
||||
};
|
||||
}
|
||||
|
||||
TimeRangeController.prototype.updateTicks = function () {
|
||||
var i, p, ts, start, end, span;
|
||||
end = this.$scope.ngModel.outer.end;
|
||||
start = this.$scope.ngModel.outer.start;
|
||||
span = end - start;
|
||||
this.$scope.ticks = [];
|
||||
for (i = 0; i < this.tickCount; i += 1) {
|
||||
p = i / (this.tickCount - 1);
|
||||
ts = p * span + start;
|
||||
this.$scope.ticks.push(this.formatTimestamp(ts));
|
||||
/**
|
||||
* Controller used by the `time-controller` template.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param $scope the Angular scope for this controller
|
||||
* @param {FormatService} formatService the service to user to format
|
||||
* domain values
|
||||
* @param {string} defaultFormat the format to request when no
|
||||
* format has been otherwise specified
|
||||
* @param {Function} now a function to return current system time
|
||||
*/
|
||||
function TimeRangeController($scope, $timeout, formatService, defaultFormat, now) {
|
||||
this.$scope = $scope;
|
||||
this.formatService = formatService;
|
||||
this.defaultFormat = defaultFormat;
|
||||
this.now = now;
|
||||
|
||||
this.tickCount = 2;
|
||||
this.innerMinimumSpan = 1000; // 1 second
|
||||
this.outerMinimumSpan = 1000; // 1 second
|
||||
this.initialDragValue = undefined;
|
||||
this.formatter = formatService.getFormat(defaultFormat);
|
||||
this.formStartChanged = false;
|
||||
this.formEndChanged = false;
|
||||
this.$timeout = $timeout;
|
||||
|
||||
this.$scope.ticks = [];
|
||||
|
||||
this.updateViewFromModel(this.$scope.ngModel);
|
||||
this.updateFormModel();
|
||||
|
||||
[
|
||||
'updateViewFromModel',
|
||||
'updateSpanWidth',
|
||||
'updateOuterStart',
|
||||
'updateOuterEnd',
|
||||
'updateFormat',
|
||||
'validateStart',
|
||||
'validateEnd',
|
||||
'onFormStartChange',
|
||||
'onFormEndChange'
|
||||
].forEach(function (boundFn) {
|
||||
this[boundFn] = this[boundFn].bind(this);
|
||||
}, this);
|
||||
|
||||
this.$scope.$watchCollection("ngModel", this.updateViewFromModel);
|
||||
this.$scope.$watch("spanWidth", this.updateSpanWidth);
|
||||
this.$scope.$watch("ngModel.outer.start", this.updateOuterStart);
|
||||
this.$scope.$watch("ngModel.outer.end", this.updateOuterEnd);
|
||||
this.$scope.$watch("parameters.format", this.updateFormat);
|
||||
this.$scope.$watch("formModel.start", this.onFormStartChange);
|
||||
this.$scope.$watch("formModel.end", this.onFormEndChange);
|
||||
}
|
||||
|
||||
TimeRangeController.prototype.formatTimestamp = function (ts) {
|
||||
return this.formatter.format(ts);
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateTicks = function () {
|
||||
var i, p, ts, start, end, span;
|
||||
end = this.$scope.ngModel.outer.end;
|
||||
start = this.$scope.ngModel.outer.start;
|
||||
span = end - start;
|
||||
this.$scope.ticks = [];
|
||||
for (i = 0; i < this.tickCount; i += 1) {
|
||||
p = i / (this.tickCount - 1);
|
||||
ts = p * span + start;
|
||||
this.$scope.ticks.push(this.formatTimestamp(ts));
|
||||
}
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateSpanWidth = function (w) {
|
||||
this.tickCount = Math.max(Math.floor(w / TICK_SPACING_PX), 2);
|
||||
this.updateTicks();
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateViewForInnerSpanFromModel = function (
|
||||
ngModel
|
||||
) {
|
||||
var span = ngModel.outer.end - ngModel.outer.start;
|
||||
|
||||
// Expose readable dates for the knobs
|
||||
this.$scope.startInnerText = this.formatTimestamp(ngModel.inner.start);
|
||||
this.$scope.endInnerText = this.formatTimestamp(ngModel.inner.end);
|
||||
|
||||
// And positions for the knobs
|
||||
this.$scope.startInnerPct =
|
||||
toPercent((ngModel.inner.start - ngModel.outer.start) / span);
|
||||
this.$scope.endInnerPct =
|
||||
toPercent((ngModel.outer.end - ngModel.inner.end) / span);
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.defaultBounds = function () {
|
||||
var t = this.now();
|
||||
|
||||
return {
|
||||
start: t - 24 * 3600 * 1000, // One day
|
||||
end: t
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateViewFromModel = function (ngModel) {
|
||||
ngModel = ngModel || {};
|
||||
ngModel.outer = ngModel.outer || this.defaultBounds();
|
||||
ngModel.inner = ngModel.inner || copyBounds(ngModel.outer);
|
||||
|
||||
// Stick it back is scope (in case we just set defaults)
|
||||
this.$scope.ngModel = ngModel;
|
||||
|
||||
this.updateViewForInnerSpanFromModel(ngModel);
|
||||
this.updateTicks();
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.startLeftDrag = function () {
|
||||
this.initialDragValue = this.$scope.ngModel.inner.start;
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.startRightDrag = function () {
|
||||
this.initialDragValue = this.$scope.ngModel.inner.end;
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.startMiddleDrag = function () {
|
||||
this.initialDragValue = {
|
||||
start: this.$scope.ngModel.inner.start,
|
||||
end: this.$scope.ngModel.inner.end
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.toMillis = function (pixels) {
|
||||
var span =
|
||||
this.$scope.ngModel.outer.end - this.$scope.ngModel.outer.start;
|
||||
|
||||
return (pixels / this.$scope.spanWidth) * span;
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.leftDrag = function (pixels) {
|
||||
var delta = this.toMillis(pixels);
|
||||
this.$scope.ngModel.inner.start = clamp(
|
||||
this.initialDragValue + delta,
|
||||
this.$scope.ngModel.outer.start,
|
||||
this.$scope.ngModel.inner.end - this.innerMinimumSpan
|
||||
);
|
||||
this.updateViewFromModel(this.$scope.ngModel);
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.rightDrag = function (pixels) {
|
||||
var delta = this.toMillis(pixels);
|
||||
this.$scope.ngModel.inner.end = clamp(
|
||||
this.initialDragValue + delta,
|
||||
this.$scope.ngModel.inner.start + this.innerMinimumSpan,
|
||||
this.$scope.ngModel.outer.end
|
||||
);
|
||||
this.updateViewFromModel(this.$scope.ngModel);
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.middleDrag = function (pixels) {
|
||||
var delta = this.toMillis(pixels),
|
||||
edge = delta < 0 ? 'start' : 'end',
|
||||
opposite = delta < 0 ? 'end' : 'start';
|
||||
|
||||
// Adjust the position of the edge in the direction of drag
|
||||
this.$scope.ngModel.inner[edge] = clamp(
|
||||
this.initialDragValue[edge] + delta,
|
||||
this.$scope.ngModel.outer.start,
|
||||
this.$scope.ngModel.outer.end
|
||||
);
|
||||
// Adjust opposite knob to maintain span
|
||||
this.$scope.ngModel.inner[opposite] =
|
||||
this.$scope.ngModel.inner[edge]
|
||||
+ this.initialDragValue[opposite]
|
||||
- this.initialDragValue[edge];
|
||||
|
||||
this.updateViewFromModel(this.$scope.ngModel);
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateFormModel = function () {
|
||||
this.$scope.formModel = {
|
||||
start: ((this.$scope.ngModel || {}).outer || {}).start,
|
||||
end: ((this.$scope.ngModel || {}).outer || {}).end
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateOuterStart = function () {
|
||||
var ngModel = this.$scope.ngModel;
|
||||
|
||||
ngModel.inner.start =
|
||||
Math.max(ngModel.outer.start, ngModel.inner.start);
|
||||
ngModel.inner.end = Math.max(
|
||||
ngModel.inner.start + this.innerMinimumSpan,
|
||||
ngModel.inner.end
|
||||
);
|
||||
|
||||
this.updateFormModel();
|
||||
this.updateViewForInnerSpanFromModel(ngModel);
|
||||
this.updateTicks();
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateOuterEnd = function () {
|
||||
var ngModel = this.$scope.ngModel;
|
||||
|
||||
ngModel.inner.end =
|
||||
Math.min(ngModel.outer.end, ngModel.inner.end);
|
||||
ngModel.inner.start = Math.min(
|
||||
ngModel.inner.end - this.innerMinimumSpan,
|
||||
ngModel.inner.start
|
||||
);
|
||||
|
||||
this.updateFormModel();
|
||||
this.updateViewForInnerSpanFromModel(ngModel);
|
||||
this.updateTicks();
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateFormat = function (key) {
|
||||
this.formatter = this.formatService.getFormat(key || this.defaultFormat);
|
||||
this.updateViewForInnerSpanFromModel(this.$scope.ngModel);
|
||||
this.updateTicks();
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateBoundsFromForm = function () {
|
||||
var self = this;
|
||||
|
||||
//Allow Angular to trigger watches and determine whether values have changed.
|
||||
this.$timeout(function () {
|
||||
if (self.formStartChanged) {
|
||||
self.$scope.ngModel.outer.start =
|
||||
self.$scope.ngModel.inner.start =
|
||||
self.$scope.formModel.start;
|
||||
self.formStartChanged = false;
|
||||
}
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateSpanWidth = function (w) {
|
||||
this.tickCount = Math.max(Math.floor(w / TICK_SPACING_PX), 2);
|
||||
this.updateTicks();
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateViewForInnerSpanFromModel = function (
|
||||
ngModel
|
||||
) {
|
||||
var span = ngModel.outer.end - ngModel.outer.start;
|
||||
|
||||
// Expose readable dates for the knobs
|
||||
this.$scope.startInnerText = this.formatTimestamp(ngModel.inner.start);
|
||||
this.$scope.endInnerText = this.formatTimestamp(ngModel.inner.end);
|
||||
|
||||
// And positions for the knobs
|
||||
this.$scope.startInnerPct =
|
||||
toPercent((ngModel.inner.start - ngModel.outer.start) / span);
|
||||
this.$scope.endInnerPct =
|
||||
toPercent((ngModel.outer.end - ngModel.inner.end) / span);
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.defaultBounds = function () {
|
||||
var t = this.now();
|
||||
|
||||
return {
|
||||
start: t - 24 * 3600 * 1000, // One day
|
||||
end: t
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateViewFromModel = function (ngModel) {
|
||||
ngModel = ngModel || {};
|
||||
ngModel.outer = ngModel.outer || this.defaultBounds();
|
||||
ngModel.inner = ngModel.inner || copyBounds(ngModel.outer);
|
||||
|
||||
// Stick it back is scope (in case we just set defaults)
|
||||
this.$scope.ngModel = ngModel;
|
||||
|
||||
this.updateViewForInnerSpanFromModel(ngModel);
|
||||
this.updateTicks();
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.startLeftDrag = function () {
|
||||
this.initialDragValue = this.$scope.ngModel.inner.start;
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.startRightDrag = function () {
|
||||
this.initialDragValue = this.$scope.ngModel.inner.end;
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.startMiddleDrag = function () {
|
||||
this.initialDragValue = {
|
||||
start: this.$scope.ngModel.inner.start,
|
||||
end: this.$scope.ngModel.inner.end
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.toMillis = function (pixels) {
|
||||
var span =
|
||||
this.$scope.ngModel.outer.end - this.$scope.ngModel.outer.start;
|
||||
|
||||
return (pixels / this.$scope.spanWidth) * span;
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.leftDrag = function (pixels) {
|
||||
var delta = this.toMillis(pixels);
|
||||
this.$scope.ngModel.inner.start = clamp(
|
||||
this.initialDragValue + delta,
|
||||
this.$scope.ngModel.outer.start,
|
||||
this.$scope.ngModel.inner.end - this.innerMinimumSpan
|
||||
);
|
||||
this.updateViewFromModel(this.$scope.ngModel);
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.rightDrag = function (pixels) {
|
||||
var delta = this.toMillis(pixels);
|
||||
this.$scope.ngModel.inner.end = clamp(
|
||||
this.initialDragValue + delta,
|
||||
this.$scope.ngModel.inner.start + this.innerMinimumSpan,
|
||||
this.$scope.ngModel.outer.end
|
||||
);
|
||||
this.updateViewFromModel(this.$scope.ngModel);
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.middleDrag = function (pixels) {
|
||||
var delta = this.toMillis(pixels),
|
||||
edge = delta < 0 ? 'start' : 'end',
|
||||
opposite = delta < 0 ? 'end' : 'start';
|
||||
|
||||
// Adjust the position of the edge in the direction of drag
|
||||
this.$scope.ngModel.inner[edge] = clamp(
|
||||
this.initialDragValue[edge] + delta,
|
||||
this.$scope.ngModel.outer.start,
|
||||
this.$scope.ngModel.outer.end
|
||||
);
|
||||
// Adjust opposite knob to maintain span
|
||||
this.$scope.ngModel.inner[opposite] =
|
||||
this.$scope.ngModel.inner[edge]
|
||||
+ this.initialDragValue[opposite]
|
||||
- this.initialDragValue[edge];
|
||||
|
||||
this.updateViewFromModel(this.$scope.ngModel);
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateFormModel = function () {
|
||||
this.$scope.formModel = {
|
||||
start: ((this.$scope.ngModel || {}).outer || {}).start,
|
||||
end: ((this.$scope.ngModel || {}).outer || {}).end
|
||||
};
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateOuterStart = function () {
|
||||
var ngModel = this.$scope.ngModel;
|
||||
|
||||
ngModel.inner.start =
|
||||
Math.max(ngModel.outer.start, ngModel.inner.start);
|
||||
ngModel.inner.end = Math.max(
|
||||
ngModel.inner.start + this.innerMinimumSpan,
|
||||
ngModel.inner.end
|
||||
);
|
||||
|
||||
this.updateFormModel();
|
||||
this.updateViewForInnerSpanFromModel(ngModel);
|
||||
this.updateTicks();
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateOuterEnd = function () {
|
||||
var ngModel = this.$scope.ngModel;
|
||||
|
||||
ngModel.inner.end =
|
||||
Math.min(ngModel.outer.end, ngModel.inner.end);
|
||||
ngModel.inner.start = Math.min(
|
||||
ngModel.inner.end - this.innerMinimumSpan,
|
||||
ngModel.inner.start
|
||||
);
|
||||
|
||||
this.updateFormModel();
|
||||
this.updateViewForInnerSpanFromModel(ngModel);
|
||||
this.updateTicks();
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateFormat = function (key) {
|
||||
this.formatter = this.formatService.getFormat(key || this.defaultFormat);
|
||||
this.updateViewForInnerSpanFromModel(this.$scope.ngModel);
|
||||
this.updateTicks();
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.updateBoundsFromForm = function () {
|
||||
var self = this;
|
||||
|
||||
//Allow Angular to trigger watches and determine whether values have changed.
|
||||
this.$timeout(function () {
|
||||
if (self.formStartChanged) {
|
||||
self.$scope.ngModel.outer.start =
|
||||
self.$scope.ngModel.inner.start =
|
||||
self.$scope.formModel.start;
|
||||
self.formStartChanged = false;
|
||||
}
|
||||
|
||||
if (self.formEndChanged) {
|
||||
self.$scope.ngModel.outer.end =
|
||||
self.$scope.ngModel.inner.end =
|
||||
self.$scope.formModel.end;
|
||||
self.formEndChanged = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.onFormStartChange = function (
|
||||
newValue,
|
||||
oldValue
|
||||
) {
|
||||
if (!this.formStartChanged && newValue !== oldValue) {
|
||||
this.formStartChanged = true;
|
||||
if (self.formEndChanged) {
|
||||
self.$scope.ngModel.outer.end =
|
||||
self.$scope.ngModel.inner.end =
|
||||
self.$scope.formModel.end;
|
||||
self.formEndChanged = false;
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.onFormEndChange = function (
|
||||
newValue,
|
||||
oldValue
|
||||
) {
|
||||
if (!this.formEndChanged && newValue !== oldValue) {
|
||||
this.formEndChanged = true;
|
||||
}
|
||||
};
|
||||
TimeRangeController.prototype.onFormStartChange = function (
|
||||
newValue,
|
||||
oldValue
|
||||
) {
|
||||
if (!this.formStartChanged && newValue !== oldValue) {
|
||||
this.formStartChanged = true;
|
||||
}
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.validateStart = function (startValue) {
|
||||
return startValue
|
||||
<= this.$scope.formModel.end - this.outerMinimumSpan;
|
||||
};
|
||||
TimeRangeController.prototype.onFormEndChange = function (
|
||||
newValue,
|
||||
oldValue
|
||||
) {
|
||||
if (!this.formEndChanged && newValue !== oldValue) {
|
||||
this.formEndChanged = true;
|
||||
}
|
||||
};
|
||||
|
||||
TimeRangeController.prototype.validateEnd = function (endValue) {
|
||||
return endValue
|
||||
>= this.$scope.formModel.start + this.outerMinimumSpan;
|
||||
};
|
||||
TimeRangeController.prototype.validateStart = function (startValue) {
|
||||
return startValue
|
||||
<= this.$scope.formModel.end - this.outerMinimumSpan;
|
||||
};
|
||||
|
||||
return TimeRangeController;
|
||||
});
|
||||
TimeRangeController.prototype.validateEnd = function (endValue) {
|
||||
return endValue
|
||||
>= this.$scope.formModel.start + this.outerMinimumSpan;
|
||||
};
|
||||
|
||||
export default TimeRangeController;
|
@ -20,47 +20,56 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* A ToggleController is used to activate/deactivate things.
|
||||
* A common usage is for "twistie"
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function ToggleController() {
|
||||
this.state = false;
|
||||
function ToggleController() {
|
||||
this.state = false;
|
||||
|
||||
this.setState = this.setState.bind(this);
|
||||
}
|
||||
this.setState = this.setState.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current state of the toggle.
|
||||
* @return {boolean} true if active
|
||||
*/
|
||||
ToggleController.prototype.isActive = function () {
|
||||
return this.state;
|
||||
};
|
||||
/**
|
||||
* Get the current state of the toggle.
|
||||
* @return {boolean} true if active
|
||||
*/
|
||||
ToggleController.prototype.isActive = function () {
|
||||
return this.state;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set a new state for the toggle.
|
||||
* @return {boolean} true to activate
|
||||
*/
|
||||
ToggleController.prototype.setState = function (newState) {
|
||||
this.state = newState;
|
||||
};
|
||||
/**
|
||||
* Set a new state for the toggle.
|
||||
* @return {boolean} true to activate
|
||||
*/
|
||||
ToggleController.prototype.setState = function (newState) {
|
||||
this.state = newState;
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle the current state; activate if it is inactive,
|
||||
* deactivate if it is active.
|
||||
*/
|
||||
ToggleController.prototype.toggle = function () {
|
||||
this.state = !this.state;
|
||||
};
|
||||
/**
|
||||
* Toggle the current state; activate if it is inactive,
|
||||
* deactivate if it is active.
|
||||
*/
|
||||
ToggleController.prototype.toggle = function () {
|
||||
this.state = !this.state;
|
||||
};
|
||||
|
||||
return ToggleController;
|
||||
}
|
||||
);
|
||||
export default ToggleController;
|
@ -23,182 +23,170 @@
|
||||
/**
|
||||
* Module defining TreeNodeController. Created by vwoeltje on 11/10/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The TreeNodeController supports the tree node representation;
|
||||
* a tree node has a label for the current object as well as a
|
||||
* subtree which shows (and is not loaded until) the node is
|
||||
* expanded.
|
||||
*
|
||||
* This controller tracks the following, so that the tree node
|
||||
* template may update its state accordingly:
|
||||
*
|
||||
* * Whether or not the tree node has ever been expanded (this
|
||||
* is used to lazily load, exactly once, the subtree)
|
||||
* * Whether or not the node is currently the domain object
|
||||
* of navigation (this gets highlighted differently to
|
||||
* provide the user with visual feedback.)
|
||||
*
|
||||
* Additionally, this controller will automatically trigger
|
||||
* node expansion when this tree node's _subtree_ will contain
|
||||
* the navigated object (recursively, this becomes an
|
||||
* expand-to-show-navigated-object behavior.)
|
||||
*
|
||||
* Finally, if a `callback` property is passed in through the
|
||||
* `parameters` attribute of the `tree-node`, that callback
|
||||
* will be invoked whenever a user clicks in a manner which
|
||||
* would result in a selection. This callback is invoked
|
||||
* even if the selection does not change (if you are only
|
||||
* interested in changes, watch the `selectedObject` property
|
||||
* of the object passed in `ng-model` instead.)
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function TreeNodeController($scope, $timeout) {
|
||||
var self = this,
|
||||
selectedObject = ($scope.ngModel || {}).selectedObject;
|
||||
/**
|
||||
* Module defining TreeNodeController. Created by vwoeltje on 11/10/14.
|
||||
*/
|
||||
function TreeNodeController($scope, $timeout) {
|
||||
var self = this,
|
||||
selectedObject = ($scope.ngModel || {}).selectedObject;
|
||||
|
||||
// Look up the id for a domain object. A convenience
|
||||
// for mapping; additionally does some undefined-checking.
|
||||
function getId(obj) {
|
||||
return obj && obj.getId && obj.getId();
|
||||
}
|
||||
|
||||
// Verify that id paths are equivalent, staring at
|
||||
// index, ending at the end of the node path.
|
||||
function checkPath(nodePath, navPath, index) {
|
||||
index = index || 0;
|
||||
|
||||
// The paths overlap if we have made it past the
|
||||
// end of the node's path; otherwise, check the
|
||||
// id at the current index for equality and perform
|
||||
// a recursive step for subsequent ids in the paths,
|
||||
// until we exceed path length or hit a mismatch.
|
||||
return (index >= nodePath.length)
|
||||
|| ((navPath[index] === nodePath[index])
|
||||
&& checkPath(nodePath, navPath, index + 1));
|
||||
}
|
||||
|
||||
// Consider the currently-navigated object and update
|
||||
// parameters which support display.
|
||||
function checkSelection() {
|
||||
var nodeObject = $scope.domainObject,
|
||||
navObject = selectedObject,
|
||||
nodeContext = nodeObject
|
||||
&& nodeObject.getCapability('context'),
|
||||
navContext = navObject
|
||||
&& navObject.getCapability('context'),
|
||||
nodePath,
|
||||
navPath;
|
||||
|
||||
// Deselect; we will reselect below, iff we are
|
||||
// exactly at the end of the path.
|
||||
self.isSelectedFlag = false;
|
||||
|
||||
// Expand if necessary (if the navigated object will
|
||||
// be in this node's subtree)
|
||||
if (nodeContext && navContext) {
|
||||
// Get the paths as arrays of identifiers
|
||||
nodePath = nodeContext.getPath().map(getId);
|
||||
navPath = navContext.getPath().map(getId);
|
||||
|
||||
// Check to see if the node's path lies entirely
|
||||
// within the navigation path; otherwise, navigation
|
||||
// has happened in some other subtree.
|
||||
if (navPath.length >= nodePath.length
|
||||
&& checkPath(nodePath, navPath)) {
|
||||
|
||||
// nodePath is along the navPath; if it's
|
||||
// at the end of the path, highlight;
|
||||
// otherwise, expand.
|
||||
if (nodePath.length === navPath.length) {
|
||||
self.isSelectedFlag = true;
|
||||
} else { // node path is shorter: Expand!
|
||||
if ($scope.toggle) {
|
||||
$scope.toggle.setState(true);
|
||||
}
|
||||
|
||||
self.trackExpansion();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Callback for the selection updates; track the currently
|
||||
// navigated object and update display parameters as needed.
|
||||
function setSelection(object) {
|
||||
selectedObject = object;
|
||||
checkSelection();
|
||||
}
|
||||
|
||||
this.isSelectedFlag = false;
|
||||
this.hasBeenExpandedFlag = false;
|
||||
this.$timeout = $timeout;
|
||||
this.$scope = $scope;
|
||||
|
||||
// Listen for changes which will effect display parameters
|
||||
$scope.$watch("ngModel.selectedObject", setSelection);
|
||||
$scope.$watch("domainObject", checkSelection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the domain object represented by this node in the tree.
|
||||
* This will both update the `selectedObject` property in
|
||||
* the object passed in via `ng-model`, and will fire any `callback`
|
||||
* passed in via `parameters`.
|
||||
*/
|
||||
TreeNodeController.prototype.select = function () {
|
||||
if (this.$scope.ngModel) {
|
||||
this.$scope.ngModel.selectedObject =
|
||||
this.$scope.domainObject;
|
||||
}
|
||||
|
||||
if ((this.$scope.parameters || {}).callback) {
|
||||
this.$scope.parameters.callback(this.$scope.domainObject);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This method should be called when a node is expanded
|
||||
* to record that this has occurred, to support one-time
|
||||
* lazy loading of the node's subtree.
|
||||
*/
|
||||
TreeNodeController.prototype.trackExpansion = function () {
|
||||
var self = this;
|
||||
if (!self.hasBeenExpanded()) {
|
||||
// Run on a timeout; if a lot of expansion needs to
|
||||
// occur (e.g. if the selection is several nodes deep) we
|
||||
// want this to be spread across multiple digest cycles.
|
||||
self.$timeout(function () {
|
||||
self.hasBeenExpandedFlag = true;
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this not has ever been expanded.
|
||||
* @returns true if it has been expanded
|
||||
*/
|
||||
TreeNodeController.prototype.hasBeenExpanded = function () {
|
||||
return this.hasBeenExpandedFlag;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether or not the domain object represented by
|
||||
* this tree node should be highlighted.
|
||||
* An object will be highlighted if it matches
|
||||
* ngModel.selectedObject
|
||||
* @returns true if this should be highlighted
|
||||
*/
|
||||
TreeNodeController.prototype.isSelected = function () {
|
||||
return this.isSelectedFlag;
|
||||
};
|
||||
|
||||
return TreeNodeController;
|
||||
// Look up the id for a domain object. A convenience
|
||||
// for mapping; additionally does some undefined-checking.
|
||||
function getId(obj) {
|
||||
return obj && obj.getId && obj.getId();
|
||||
}
|
||||
);
|
||||
|
||||
// Verify that id paths are equivalent, staring at
|
||||
// index, ending at the end of the node path.
|
||||
function checkPath(nodePath, navPath, index) {
|
||||
index = index || 0;
|
||||
|
||||
// The paths overlap if we have made it past the
|
||||
// end of the node's path; otherwise, check the
|
||||
// id at the current index for equality and perform
|
||||
// a recursive step for subsequent ids in the paths,
|
||||
// until we exceed path length or hit a mismatch.
|
||||
return (index >= nodePath.length)
|
||||
|| ((navPath[index] === nodePath[index])
|
||||
&& checkPath(nodePath, navPath, index + 1));
|
||||
}
|
||||
|
||||
// Consider the currently-navigated object and update
|
||||
// parameters which support display.
|
||||
function checkSelection() {
|
||||
var nodeObject = $scope.domainObject,
|
||||
navObject = selectedObject,
|
||||
nodeContext = nodeObject
|
||||
&& nodeObject.getCapability('context'),
|
||||
navContext = navObject
|
||||
&& navObject.getCapability('context'),
|
||||
nodePath,
|
||||
navPath;
|
||||
|
||||
// Deselect; we will reselect below, iff we are
|
||||
// exactly at the end of the path.
|
||||
self.isSelectedFlag = false;
|
||||
|
||||
// Expand if necessary (if the navigated object will
|
||||
// be in this node's subtree)
|
||||
if (nodeContext && navContext) {
|
||||
// Get the paths as arrays of identifiers
|
||||
nodePath = nodeContext.getPath().map(getId);
|
||||
navPath = navContext.getPath().map(getId);
|
||||
|
||||
// Check to see if the node's path lies entirely
|
||||
// within the navigation path; otherwise, navigation
|
||||
// has happened in some other subtree.
|
||||
if (navPath.length >= nodePath.length
|
||||
&& checkPath(nodePath, navPath)) {
|
||||
|
||||
// nodePath is along the navPath; if it's
|
||||
// at the end of the path, highlight;
|
||||
// otherwise, expand.
|
||||
if (nodePath.length === navPath.length) {
|
||||
self.isSelectedFlag = true;
|
||||
} else { // node path is shorter: Expand!
|
||||
if ($scope.toggle) {
|
||||
$scope.toggle.setState(true);
|
||||
}
|
||||
|
||||
self.trackExpansion();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Callback for the selection updates; track the currently
|
||||
// navigated object and update display parameters as needed.
|
||||
function setSelection(object) {
|
||||
selectedObject = object;
|
||||
checkSelection();
|
||||
}
|
||||
|
||||
this.isSelectedFlag = false;
|
||||
this.hasBeenExpandedFlag = false;
|
||||
this.$timeout = $timeout;
|
||||
this.$scope = $scope;
|
||||
|
||||
// Listen for changes which will effect display parameters
|
||||
$scope.$watch("ngModel.selectedObject", setSelection);
|
||||
$scope.$watch("domainObject", checkSelection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the domain object represented by this node in the tree.
|
||||
* This will both update the `selectedObject` property in
|
||||
* the object passed in via `ng-model`, and will fire any `callback`
|
||||
* passed in via `parameters`.
|
||||
*/
|
||||
TreeNodeController.prototype.select = function () {
|
||||
if (this.$scope.ngModel) {
|
||||
this.$scope.ngModel.selectedObject =
|
||||
this.$scope.domainObject;
|
||||
}
|
||||
|
||||
if ((this.$scope.parameters || {}).callback) {
|
||||
this.$scope.parameters.callback(this.$scope.domainObject);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This method should be called when a node is expanded
|
||||
* to record that this has occurred, to support one-time
|
||||
* lazy loading of the node's subtree.
|
||||
*/
|
||||
TreeNodeController.prototype.trackExpansion = function () {
|
||||
var self = this;
|
||||
if (!self.hasBeenExpanded()) {
|
||||
// Run on a timeout; if a lot of expansion needs to
|
||||
// occur (e.g. if the selection is several nodes deep) we
|
||||
// want this to be spread across multiple digest cycles.
|
||||
self.$timeout(function () {
|
||||
self.hasBeenExpandedFlag = true;
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this not has ever been expanded.
|
||||
* @returns true if it has been expanded
|
||||
*/
|
||||
TreeNodeController.prototype.hasBeenExpanded = function () {
|
||||
return this.hasBeenExpandedFlag;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether or not the domain object represented by
|
||||
* this tree node should be highlighted.
|
||||
* An object will be highlighted if it matches
|
||||
* ngModel.selectedObject
|
||||
* @returns true if this should be highlighted
|
||||
*/
|
||||
TreeNodeController.prototype.isSelected = function () {
|
||||
return this.isSelectedFlag;
|
||||
};
|
||||
|
||||
export default TreeNodeController;
|
@ -23,51 +23,63 @@
|
||||
/**
|
||||
* Module defining ViewSwitcherController. Created by vwoeltje on 11/7/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Controller for the view switcher; populates and maintains a list
|
||||
* of applicable views for a represented domain object.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function ViewSwitcherController($scope, $timeout) {
|
||||
// If the view capability gets refreshed, try to
|
||||
// keep the same option chosen.
|
||||
function findMatchingOption(options, selected) {
|
||||
var i;
|
||||
/**
|
||||
* Module defining ViewSwitcherController. Created by vwoeltje on 11/7/14.
|
||||
*/
|
||||
function ViewSwitcherController($scope, $timeout) {
|
||||
// If the view capability gets refreshed, try to
|
||||
// keep the same option chosen.
|
||||
function findMatchingOption(options, selected) {
|
||||
var i;
|
||||
|
||||
if (selected) {
|
||||
for (i = 0; i < options.length; i += 1) {
|
||||
if (options[i].key === selected.key) {
|
||||
return options[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options[0];
|
||||
}
|
||||
|
||||
// Get list of views, read from capability
|
||||
function updateOptions(views) {
|
||||
if (Array.isArray(views)) {
|
||||
$timeout(function () {
|
||||
$scope.ngModel.selected = findMatchingOption(
|
||||
views,
|
||||
($scope.ngModel || {}).selected
|
||||
);
|
||||
}, 0);
|
||||
if (selected) {
|
||||
for (i = 0; i < options.length; i += 1) {
|
||||
if (options[i].key === selected.key) {
|
||||
return options[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Update view options when the in-scope results of using the
|
||||
// view capability change.
|
||||
$scope.$watch("view", updateOptions);
|
||||
}
|
||||
|
||||
return ViewSwitcherController;
|
||||
return options[0];
|
||||
}
|
||||
);
|
||||
|
||||
// Get list of views, read from capability
|
||||
function updateOptions(views) {
|
||||
if (Array.isArray(views)) {
|
||||
$timeout(function () {
|
||||
$scope.ngModel.selected = findMatchingOption(
|
||||
views,
|
||||
($scope.ngModel || {}).selected
|
||||
);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Update view options when the in-scope results of using the
|
||||
// view capability change.
|
||||
$scope.$watch("view", updateOptions);
|
||||
}
|
||||
|
||||
export default ViewSwitcherController;
|
@ -20,58 +20,66 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The `mct-click-elsewhere` directive will evaluate its
|
||||
* associated expression whenever a `mousedown` occurs anywhere
|
||||
* outside of the element that has the `mct-click-elsewhere`
|
||||
* directive attached. This is useful for dismissing popups
|
||||
* and the like.
|
||||
*/
|
||||
function MCTClickElsewhere($document) {
|
||||
function MCTClickElsewhere($document) {
|
||||
|
||||
// Link; install event handlers.
|
||||
function link(scope, element, attrs) {
|
||||
// Keep a reference to the body, to attach/detach
|
||||
// mouse event handlers; mousedown and mouseup cannot
|
||||
// only be attached to the element being linked, as the
|
||||
// mouse may leave this element during the drag.
|
||||
var body = $document.find('body');
|
||||
// Link; install event handlers.
|
||||
function link(scope, element, attrs) {
|
||||
// Keep a reference to the body, to attach/detach
|
||||
// mouse event handlers; mousedown and mouseup cannot
|
||||
// only be attached to the element being linked, as the
|
||||
// mouse may leave this element during the drag.
|
||||
var body = $document.find('body');
|
||||
|
||||
function clickBody(event) {
|
||||
var x = event.clientX,
|
||||
y = event.clientY,
|
||||
rect = element[0].getBoundingClientRect(),
|
||||
xMin = rect.left,
|
||||
xMax = xMin + rect.width,
|
||||
yMin = rect.top,
|
||||
yMax = yMin + rect.height;
|
||||
function clickBody(event) {
|
||||
var x = event.clientX,
|
||||
y = event.clientY,
|
||||
rect = element[0].getBoundingClientRect(),
|
||||
xMin = rect.left,
|
||||
xMax = xMin + rect.width,
|
||||
yMin = rect.top,
|
||||
yMax = yMin + rect.height;
|
||||
|
||||
if (x < xMin || x > xMax || y < yMin || y > yMax) {
|
||||
scope.$apply(function () {
|
||||
scope.$eval(attrs.mctClickElsewhere);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
body.on("mousedown", clickBody);
|
||||
scope.$on("$destroy", function () {
|
||||
body.off("mousedown", clickBody);
|
||||
if (x < xMin || x > xMax || y < yMin || y > yMax) {
|
||||
scope.$apply(function () {
|
||||
scope.$eval(attrs.mctClickElsewhere);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
// mct-drag only makes sense as an attribute
|
||||
restrict: "A",
|
||||
// Link function, to install event handlers
|
||||
link: link
|
||||
};
|
||||
}
|
||||
|
||||
return MCTClickElsewhere;
|
||||
body.on("mousedown", clickBody);
|
||||
scope.$on("$destroy", function () {
|
||||
body.off("mousedown", clickBody);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
// mct-drag only makes sense as an attribute
|
||||
restrict: "A",
|
||||
// Link function, to install event handlers
|
||||
link: link
|
||||
};
|
||||
}
|
||||
|
||||
export default MCTClickElsewhere;
|
@ -23,69 +23,75 @@
|
||||
/**
|
||||
* Module defining MCTContainer. Created by vwoeltje on 11/17/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* The mct-container is similar to the mct-include directive
|
||||
* insofar as it allows templates to be referenced by
|
||||
* symbolic keys instead of by URL. Unlike mct-include, it
|
||||
* supports transclusion.
|
||||
*
|
||||
* Unlike mct-include, mct-container accepts a key as a
|
||||
* plain string attribute, instead of as an Angular
|
||||
* expression.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function MCTContainer(containers) {
|
||||
var containerMap = {};
|
||||
/**
|
||||
* Module defining MCTContainer. Created by vwoeltje on 11/17/14.
|
||||
*/
|
||||
function MCTContainer(containers) {
|
||||
var containerMap = {};
|
||||
|
||||
// Initialize container map from extensions
|
||||
containers.forEach(function (container) {
|
||||
containerMap[container.key] = container;
|
||||
});
|
||||
// Initialize container map from extensions
|
||||
containers.forEach(function (container) {
|
||||
containerMap[container.key] = container;
|
||||
});
|
||||
|
||||
return {
|
||||
return {
|
||||
|
||||
// Allow only at the element level
|
||||
restrict: 'E',
|
||||
// Allow only at the element level
|
||||
restrict: 'E',
|
||||
|
||||
// Support transclusion
|
||||
transclude: true,
|
||||
// Support transclusion
|
||||
transclude: true,
|
||||
|
||||
// Create a new (non-isolate) scope
|
||||
scope: true,
|
||||
// Create a new (non-isolate) scope
|
||||
scope: true,
|
||||
|
||||
// Populate initial scope based on attributes requested
|
||||
// by the container definition
|
||||
link: function (scope, element, attrs) {
|
||||
var key = attrs.key,
|
||||
container = containerMap[key],
|
||||
alias = "container",
|
||||
copiedAttributes = {};
|
||||
// Populate initial scope based on attributes requested
|
||||
// by the container definition
|
||||
link: function (scope, element, attrs) {
|
||||
var key = attrs.key,
|
||||
container = containerMap[key],
|
||||
alias = "container",
|
||||
copiedAttributes = {};
|
||||
|
||||
if (container) {
|
||||
alias = container.alias || alias;
|
||||
(container.attributes || []).forEach(function (attr) {
|
||||
copiedAttributes[attr] = attrs[attr];
|
||||
});
|
||||
}
|
||||
if (container) {
|
||||
alias = container.alias || alias;
|
||||
(container.attributes || []).forEach(function (attr) {
|
||||
copiedAttributes[attr] = attrs[attr];
|
||||
});
|
||||
}
|
||||
|
||||
scope[alias] = copiedAttributes;
|
||||
},
|
||||
scope[alias] = copiedAttributes;
|
||||
},
|
||||
|
||||
template: function (element, attrs) {
|
||||
var key = attrs.key,
|
||||
container = containerMap[key];
|
||||
template: function (element, attrs) {
|
||||
var key = attrs.key,
|
||||
container = containerMap[key];
|
||||
|
||||
return container ? container.template : "";
|
||||
}
|
||||
};
|
||||
return container ? container.template : "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return MCTContainer;
|
||||
}
|
||||
);
|
||||
export default MCTContainer;
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user