diff --git a/karma.conf.js b/karma.conf.js index 1ef8d86ed1..f2ba4d9753 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -106,7 +106,7 @@ module.exports = (config) => { }, specReporter: { maxLogLines: 5, - suppressErrorSummary: true, + suppressErrorSummary: false, suppressFailed: false, suppressPassed: false, suppressSkipped: true, diff --git a/platform/commonUI/dialog/res/templates/overlay-options.html b/platform/commonUI/dialog/res/templates/overlay-options.html index f32359c624..9dc0ed193d 100644 --- a/platform/commonUI/dialog/res/templates/overlay-options.html +++ b/platform/commonUI/dialog/res/templates/overlay-options.html @@ -20,7 +20,7 @@ at runtime from the About dialog for additional information. --> -
+
{{ngModel.dialog.title}}
{{ngModel.dialog.hint}}
diff --git a/platform/commonUI/edit/bundle.js b/platform/commonUI/edit/bundle.js index 4482231816..dc0299ce62 100644 --- a/platform/commonUI/edit/bundle.js +++ b/platform/commonUI/edit/bundle.js @@ -26,22 +26,12 @@ define([ "./src/controllers/EditObjectController", "./src/actions/EditAndComposeAction", "./src/actions/EditAction", - "./src/actions/PropertiesAction", "./src/actions/SaveAction", "./src/actions/SaveAndStopEditingAction", - "./src/actions/SaveAsAction", "./src/actions/CancelAction", "./src/policies/EditPersistableObjectsPolicy", "./src/representers/EditRepresenter", "./src/capabilities/EditorCapability", - "./src/creation/CreateMenuController", - "./src/creation/LocatorController", - "./src/creation/CreationPolicy", - "./src/creation/CreateActionProvider", - "./src/creation/CreationService", - "./res/templates/create/locator.html", - "./res/templates/create/create-button.html", - "./res/templates/create/create-menu.html", "./res/templates/library.html", "./res/templates/edit-object.html", "./res/templates/edit-action-buttons.html", @@ -52,22 +42,12 @@ define([ EditObjectController, EditAndComposeAction, EditAction, - PropertiesAction, SaveAction, SaveAndStopEditingAction, - SaveAsAction, CancelAction, EditPersistableObjectsPolicy, EditRepresenter, EditorCapability, - CreateMenuController, - LocatorController, - CreationPolicy, - CreateActionProvider, - CreationService, - locatorTemplate, - createButtonTemplate, - createMenuTemplate, libraryTemplate, editObjectTemplate, editActionButtonsTemplate, @@ -100,22 +80,6 @@ define([ "$location", "navigationService" ] - }, - { - "key": "CreateMenuController", - "implementation": CreateMenuController, - "depends": [ - "$scope" - ] - }, - { - "key": "LocatorController", - "implementation": LocatorController, - "depends": [ - "$scope", - "$timeout", - "objectService" - ] } ], "actions": [ @@ -137,22 +101,6 @@ define([ "group": "action", "priority": 10 }, - { - "key": "properties", - "category": [ - "contextual", - "view-control" - ], - "implementation": PropertiesAction, - "cssClass": "major icon-pencil", - "name": "Edit Properties...", - "group": "action", - "priority": 10, - "description": "Edit properties of this object.", - "depends": [ - "dialogService" - ] - }, { "key": "save-and-stop-editing", "category": "save", @@ -177,22 +125,6 @@ define([ "notificationService" ] }, - { - "key": "save-as", - "category": "save", - "implementation": SaveAsAction, - "name": "Save As...", - "cssClass": "icon-save labeled", - "description": "Save changes made to these objects.", - "depends": [ - "$injector", - "dialogService", - "copyService", - "notificationService", - "openmct" - ], - "priority": "mandatory" - }, { "key": "cancel", "category": "conclude-editing", @@ -210,10 +142,6 @@ define([ "category": "action", "implementation": EditPersistableObjectsPolicy, "depends": ["openmct"] - }, - { - "implementation": CreationPolicy, - "category": "creation" } ], "templates": [ @@ -243,42 +171,8 @@ define([ { "key": "topbar-edit", "template": topbarEditTemplate - }, - { - "key": "create-button", - "template": createButtonTemplate - }, - { - "key": "create-menu", - "template": createMenuTemplate, - "uses": [ - "action" - ] } ], - "components": [ - { - "key": "CreateActionProvider", - "provides": "actionService", - "type": "provider", - "implementation": CreateActionProvider, - "depends": [ - "typeService", - "policyService" - ] - }, - { - "key": "CreationService", - "provides": "creationService", - "type": "provider", - "implementation": CreationService, - "depends": [ - "$q", - "$log" - ] - } - - ], "representers": [ { "implementation": EditRepresenter, @@ -298,12 +192,6 @@ define([ ] } ], - "controls": [ - { - "key": "locator", - "template": locatorTemplate - } - ], "runs": [ { depends: [ diff --git a/platform/commonUI/edit/res/templates/create/create-button.html b/platform/commonUI/edit/res/templates/create/create-button.html deleted file mode 100644 index 5878c9bf97..0000000000 --- a/platform/commonUI/edit/res/templates/create/create-button.html +++ /dev/null @@ -1,30 +0,0 @@ - - -
- Create -
- -
diff --git a/platform/commonUI/edit/res/templates/create/create-menu.html b/platform/commonUI/edit/res/templates/create/create-menu.html deleted file mode 100644 index 2656ac4fd7..0000000000 --- a/platform/commonUI/edit/res/templates/create/create-menu.html +++ /dev/null @@ -1,45 +0,0 @@ - -
- - -
diff --git a/platform/commonUI/edit/res/templates/create/locator.html b/platform/commonUI/edit/res/templates/create/locator.html deleted file mode 100644 index 9a889d5d55..0000000000 --- a/platform/commonUI/edit/res/templates/create/locator.html +++ /dev/null @@ -1,29 +0,0 @@ - -
-
- - -
-
diff --git a/platform/commonUI/edit/src/actions/PropertiesAction.js b/platform/commonUI/edit/src/actions/PropertiesAction.js deleted file mode 100644 index 7d0e43ff77..0000000000 --- a/platform/commonUI/edit/src/actions/PropertiesAction.js +++ /dev/null @@ -1,98 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * Edit the properties of a domain object. Shows a dialog - * which should display a set of properties similar to that - * shown in the Create wizard. - */ -define( - ['./PropertiesDialog'], - function (PropertiesDialog) { - - /** - * Implements the "Edit Properties" action, which prompts the user - * to modify a domain object's properties. - * - * @param {DialogService} dialogService a service which will show the dialog - * @param {DomainObject} object the object to be edited - * @param {ActionContext} context the context in which this action is performed - * @memberof platform/commonUI/edit - * @implements {Action} - * @constructor - */ - function PropertiesAction(dialogService, context) { - this.domainObject = (context || {}).domainObject; - this.dialogService = dialogService; - } - - PropertiesAction.prototype.perform = function () { - var type = this.domainObject.getCapability('type'), - domainObject = this.domainObject, - dialogService = this.dialogService; - - // Update the domain object model based on user input - function updateModel(userInput, dialog) { - return domainObject.useCapability('mutation', function (model) { - dialog.updateModel(model, userInput); - }); - } - - function showDialog(objType) { - // Create a dialog object to generate the form structure, etc. - var dialog = - new PropertiesDialog(objType, domainObject.getModel()); - - // Show the dialog - return dialogService.getUserInput( - dialog.getFormStructure(), - dialog.getInitialFormValue() - ).then(function (userInput) { - // Update the model, if user input was provided - return userInput && updateModel(userInput, dialog); - }); - } - - return type && showDialog(type); - }; - - /** - * Filter this action for applicability against a given context. - * This will ensure that a domain object is present in the - * context. - */ - PropertiesAction.appliesTo = function (context, view, openmct) { - - let domainObject = (context || {}).domainObject; - - if (!domainObject || (domainObject.model && domainObject.model.locked)) { - return false; - } - - return openmct.objects.isPersistable(domainObject.id); - }; - - return PropertiesAction; - } - -); - diff --git a/platform/commonUI/edit/src/actions/PropertiesDialog.js b/platform/commonUI/edit/src/actions/PropertiesDialog.js deleted file mode 100644 index c3e2c4bcfb..0000000000 --- a/platform/commonUI/edit/src/actions/PropertiesDialog.js +++ /dev/null @@ -1,92 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - function () { - - /** - * Construct a new Properties dialog. - * - * @param {TypeImpl} type the type of domain object for which properties - * will be specified - * @param {DomainObject} the object for which properties will be set - * @memberof platform/commonUI/edit - * @constructor - */ - function PropertiesDialog(type, model) { - this.type = type; - this.model = model; - this.properties = type.getProperties(); - } - - /** - * Get sections provided by this dialog. - * @return {FormStructure} the structure of this form - */ - PropertiesDialog.prototype.getFormStructure = function () { - return { - name: "Edit " + this.model.name, - sections: [{ - name: "Properties", - rows: this.properties.map(function (property, index) { - // Property definition is same as form row definition - var row = JSON.parse(JSON.stringify(property.getDefinition())); - row.key = index; - - return row; - }).filter(function (row) { - // Only show properties which are editable - return row.control; - }) - }] - }; - }; - - /** - * Get the initial state of the form shown by this dialog - * (based on the object model) - * @returns {object} initial state of the form - */ - PropertiesDialog.prototype.getInitialFormValue = function () { - var model = this.model; - - // Start with initial values for properties - // Note that index needs to correlate to row.key - // from getFormStructure - return this.properties.map(function (property) { - return property.getValue(model); - }); - }; - - /** - * Update a domain object model based on the value of a form. - */ - PropertiesDialog.prototype.updateModel = function (model, formValue) { - // Update all properties - this.properties.forEach(function (property, index) { - property.setValue(model, formValue[index]); - }); - }; - - return PropertiesDialog; - } -); diff --git a/platform/commonUI/edit/src/actions/SaveAsAction.js b/platform/commonUI/edit/src/actions/SaveAsAction.js deleted file mode 100644 index 23e64c71cf..0000000000 --- a/platform/commonUI/edit/src/actions/SaveAsAction.js +++ /dev/null @@ -1,210 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define([ - '../creation/CreateWizard', - './SaveInProgressDialog' -], -function ( - CreateWizard, - SaveInProgressDialog -) { - - /** - * The "Save" action; the action triggered by clicking Save from - * Edit Mode. Exits the editing user interface and invokes object - * capabilities to persist the changes that have been made. - * @constructor - * @implements {Action} - * @memberof platform/commonUI/edit - */ - function SaveAsAction( - $injector, - dialogService, - copyService, - notificationService, - openmct, - context - ) { - this.domainObject = (context || {}).domainObject; - this.injectObjectService = function () { - this.objectService = $injector.get("objectService"); - }; - - this.dialogService = dialogService; - this.copyService = copyService; - this.notificationService = notificationService; - this.openmct = openmct; - } - - /** - * @private - */ - SaveAsAction.prototype.createWizard = function (parent) { - return new CreateWizard( - this.domainObject, - parent, - this.openmct - ); - }; - - /** - * @private - */ - SaveAsAction.prototype.getObjectService = function () { - // Lazily acquire object service (avoids cyclical dependency) - if (!this.objectService) { - this.injectObjectService(); - } - - return this.objectService; - }; - - /** - * Save changes and conclude editing. - * - * @returns {Promise} a promise that will be fulfilled when - * cancellation has completed - * @memberof platform/commonUI/edit.SaveAction# - */ - SaveAsAction.prototype.perform = function () { - return this.save(); - }; - - /** - * @private - */ - SaveAsAction.prototype.save = function () { - var self = this, - domainObject = this.domainObject, - dialog = new SaveInProgressDialog(this.dialogService); - - function doWizardSave(parent) { - var wizard = self.createWizard(parent); - - return self.dialogService - .getUserInput(wizard.getFormStructure(true), - wizard.getInitialFormValue()) - .then(wizard.populateObjectFromInput.bind(wizard), function (failureReason) { - return Promise.reject("user canceled"); - }); - } - - function showBlockingDialog(object) { - dialog.show(); - - return object; - } - - function hideBlockingDialog(object) { - dialog.hide(); - - return object; - } - - function fetchObject(objectId) { - return self.getObjectService().getObjects([objectId]).then(function (objects) { - return objects[objectId]; - }); - } - - function getParent(object) { - return fetchObject(object.getModel().location); - } - - function saveObject(object) { - //persist the object, which adds it to the transaction and then call editor.save - return object.getCapability("persistence").persist() - .then(() => { - return self.openmct.editor.save().then(() => { - return object; - }); - }); - } - - function addSavedObjectToParent(parent) { - return parent.getCapability("composition") - .add(domainObject) - .then(function (addedObject) { - return parent.getCapability("persistence").persist() - .then(function () { - return addedObject; - }); - }); - } - - function indexForSearch(addedObject) { - addedObject.useCapability('mutation', (model) => { - return model; - }); - - return addedObject; - } - - function onSuccess(object) { - self.notificationService.info("Save Succeeded"); - - return object; - } - - function onFailure(reason) { - hideBlockingDialog(); - if (reason !== "user canceled") { - self.notificationService.error("Save Failed"); - } - - throw reason; - } - - return getParent(domainObject) - .then(doWizardSave) - .then(showBlockingDialog) - .then(saveObject) - .then(getParent) - .then(addSavedObjectToParent) - .then((addedObject) => { - return fetchObject(addedObject.getId()); - }) - .then(indexForSearch) - .then(hideBlockingDialog) - .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 - */ - SaveAsAction.appliesTo = function (context) { - var domainObject = (context || {}).domainObject; - - return domainObject !== undefined - && domainObject.hasCapability('editor') - && domainObject.getCapability('editor').isEditContextRoot() - && domainObject.getModel().persisted === undefined; - }; - - return SaveAsAction; -} -); diff --git a/platform/commonUI/edit/src/creation/CreateAction.js b/platform/commonUI/edit/src/creation/CreateAction.js deleted file mode 100644 index 7903af296c..0000000000 --- a/platform/commonUI/edit/src/creation/CreateAction.js +++ /dev/null @@ -1,133 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * Module defining CreateAction. Created by vwoeltje on 11/10/14. - */ -define( - [], - function () { - - /** - * The Create Action is performed to create new instances of - * domain objects of a specific type. This is the action that - * is performed when a user uses the Create menu. - * - * @memberof platform/commonUI/browse - * @implements {Action} - * @constructor - * - * @param {Type} type the type of domain object to create - * @param {DomainObject} parent the domain object that should - * act as a container for the newly-created object - * (note that the user will have an opportunity to - * override this) - * @param {ActionContext} context the context in which the - * action is being performed - */ - function CreateAction(type, parent, context, openmct) { - this.metadata = { - key: 'create', - cssClass: type.getCssClass(), - name: type.getName(), - type: type.getKey(), - description: type.getDescription(), - context: context - }; - this.type = type; - this.parent = parent; - this.openmct = openmct; - } - - /** - * Create a new object of the given type. - * This will prompt for user input first. - */ - CreateAction.prototype.perform = function () { - var newModel = this.type.getInitialModel(), - openmct = this.openmct, - newObject; - - function onCancel() { - openmct.editor.cancel(); - } - - function isFirstViewEditable(domainObject, objectPath) { - let firstView = openmct.objectViews.get(domainObject, objectPath)[0]; - - return firstView && firstView.canEdit && firstView.canEdit(domainObject, objectPath); - } - - function navigateAndEdit(object) { - let objectPath = object.getCapability('context').getPath(), - url = '#/browse/' + objectPath - .slice(1) - .map(function (o) { - return o && openmct.objects.makeKeyString(o.getId()); - }) - .join('/'); - - function editObject() { - const path = objectPath.slice(-1).map(obj => { - const objNew = obj.getCapability('adapter').invoke(); - - return objNew; - }); - if (isFirstViewEditable(object.useCapability('adapter'), path)) { - openmct.editor.edit(); - } - } - - openmct.router.once('afterNavigation', editObject); - - openmct.router.navigate(url); - } - - newModel.type = this.type.getKey(); - newModel.location = this.parent.getId(); - newObject = this.parent.useCapability('instantiation', newModel); - - openmct.editor.edit(); - newObject.getCapability("action").perform("save-as").then(navigateAndEdit, onCancel); - // TODO: support editing object without saving object first. - // Which means we have to toggle createwizard afterwards. For now, - // We will disable this. - }; - - /** - * Metadata associated with a Create action. - * @typedef {ActionMetadata} CreateActionMetadata - * @property {string} type the key for the type of domain object - * to be created - */ - - /** - * Get metadata about this action. - * @returns {CreateActionMetadata} metadata about this action - */ - CreateAction.prototype.getMetadata = function () { - return this.metadata; - }; - - return CreateAction; - } -); diff --git a/platform/commonUI/edit/src/creation/CreateActionProvider.js b/platform/commonUI/edit/src/creation/CreateActionProvider.js deleted file mode 100644 index 005b7085df..0000000000 --- a/platform/commonUI/edit/src/creation/CreateActionProvider.js +++ /dev/null @@ -1,80 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * Module defining CreateActionProvider.js. Created by vwoeltje on 11/10/14. - */ -define( - ["./CreateAction"], - function (CreateAction) { - - /** - * The CreateActionProvider is an ActionProvider which introduces - * a Create action for each creatable domain object type. - * - * @memberof platform/commonUI/browse - * @constructor - * @implements {ActionService} - * - * @param {TypeService} typeService the type service, used to discover - * available types - * @param {DialogService} dialogService the dialog service, used by - * specific Create actions to get user input to populate the - * model of the newly-created domain object. - * @param {CreationService} creationService the creation service (also - * introduced in this bundle), responsible for handling actual - * object creation. - */ - function CreateActionProvider(typeService, policyService) { - this.typeService = typeService; - this.policyService = policyService; - } - - CreateActionProvider.prototype.getActions = function (actionContext) { - var context = actionContext || {}, - key = context.key, - destination = context.domainObject, - self = this; - - // We only provide Create actions, and we need a - // domain object to serve as the container for the - // newly-created object (although the user may later - // make a different selection) - if (key !== 'create' || !destination) { - return []; - } - - // Introduce one create action per type - return this.typeService.listTypes().filter(function (type) { - return self.policyService.allow("creation", type); - }).map(function (type) { - return new CreateAction( - type, - destination, - context - ); - }); - }; - - return CreateActionProvider; - } -); diff --git a/platform/commonUI/edit/src/creation/CreateMenuController.js b/platform/commonUI/edit/src/creation/CreateMenuController.js deleted file mode 100644 index 3fedf00193..0000000000 --- a/platform/commonUI/edit/src/creation/CreateMenuController.js +++ /dev/null @@ -1,57 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * Module defining CreateMenuController. Created by vwoeltje on 11/10/14. - */ -define( - [], - function () { - - /** - * Controller for the Create menu; maintains an up-to-date - * set of Create actions based on the currently-selected - * domain object. - * - * @memberof platform/commonUI/browse - * @constructor - */ - function CreateMenuController($scope) { - // Update the set of Create actions - function refreshActions() { - $scope.createActions = $scope.action - ? $scope.action.getActions('create') - : []; - } - - // Listen for new instances of the represented object's - // "action" capability. This is provided by the mct-representation - // for the Create button. - // A watch is needed here (instead of invoking action.getActions - // directly) because different action instances may be returned - // with each call. - $scope.$watch("action", refreshActions); - } - - return CreateMenuController; - } -); diff --git a/platform/commonUI/edit/src/creation/CreateWizard.js b/platform/commonUI/edit/src/creation/CreateWizard.js deleted file mode 100644 index 32cf99368b..0000000000 --- a/platform/commonUI/edit/src/creation/CreateWizard.js +++ /dev/null @@ -1,186 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - function () { - - /** - * A class for capturing user input data from an object creation - * dialog, and populating a domain object with that data. - * - * @param {DomainObject} domainObject the newly created object to - * populate with user input - * @param {DomainObject} parent the domain object to serve as - * the initial parent for the created object, in the dialog - * @memberof platform/commonUI/browse - * @constructor - */ - function CreateWizard(domainObject, parent, openmct) { - this.type = domainObject.getCapability('type'); - this.model = domainObject.getModel(); - this.domainObject = domainObject; - this.properties = this.type.getProperties(); - this.parent = parent; - this.openmct = openmct; - } - - /** - * Get the form model for this wizard; this is a description - * that will be rendered to an HTML form. See the - * platform/forms bundle - * @param {boolean} includeLocation if true, a 'location' section - * will be included that will allow the user to select the location - * of the newly created object, otherwise the .location property of - * the model will be used. - * @return {FormModel} formModel the form model to - * show in the create dialog - */ - CreateWizard.prototype.getFormStructure = function (includeLocation) { - var sections = [], - domainObject = this.domainObject, - self = this; - - function validateLocation(parent) { - return parent && self.openmct.composition.checkPolicy(parent.useCapability('adapter'), domainObject.useCapability('adapter')); - } - - sections.push({ - name: "Properties", - rows: this.properties.map(function (property, index) { - // Property definition is same as form row definition - var row = JSON.parse(JSON.stringify(property.getDefinition())); - - // Use index as the key into the formValue; - // this correlates to the indexing provided by - // getInitialFormValue - row.key = index; - - return row; - }).filter(function (row) { - // Only show rows which have defined controls - return row && row.control; - }) - }); - - // Ensure there is always a "save in" section - if (includeLocation) { - sections.push({ - name: 'Location', - cssClass: "grows", - rows: [{ - name: "Save In", - control: "locator", - validate: validateLocation.bind(this), - key: "createParent" - }] - }); - } - - return { - sections: sections, - name: "Create a New " + this.type.getName() - }; - }; - - /** - * Given some form input values and a domain object, populate the - * domain object used to create this wizard from the given form values. - * @param formValue - * @returns {DomainObject} - */ - CreateWizard.prototype.populateObjectFromInput = function (formValue) { - var parent = this.getLocation(formValue), - formModel = this.createModel(formValue); - - formModel.location = parent.getId(); - - this.updateNamespaceFromParent(parent); - - this.domainObject.useCapability("mutation", function () { - return formModel; - }); - - return this.domainObject; - }; - - /** @private */ - CreateWizard.prototype.updateNamespaceFromParent = function (parent) { - let childIdentifier = this.domainObject.useCapability('adapter').identifier; - let parentIdentifier = parent.useCapability('adapter').identifier; - childIdentifier.namespace = parentIdentifier.namespace; - this.domainObject.id = this.openmct.objects.makeKeyString(childIdentifier); - }; - - /** - * Get the initial value for the form being described. - * This will include the values for all properties described - * in the structure. - * - * @returns {object} the initial value of the form - */ - CreateWizard.prototype.getInitialFormValue = function () { - // Start with initial values for properties - var model = this.model, - formValue = this.properties.map(function (property) { - return property.getValue(model); - }); - - // Include the createParent - formValue.createParent = this.parent; - - return formValue; - }; - - /** - * Based on a populated form, get the domain object which - * should be used as a parent for the newly-created object. - * @private - * @return {DomainObject} - */ - CreateWizard.prototype.getLocation = function (formValue) { - return formValue.createParent || this.parent; - }; - - /** - * Create the domain object model for a newly-created object, - * based on user input read from a formModel. - * @private - * @return {object} the domain object model - */ - CreateWizard.prototype.createModel = function (formValue) { - // Clone - var newModel = JSON.parse(JSON.stringify(this.model)); - - // Always use the type from the type definition - newModel.type = this.type.getKey(); - - // Update all properties - this.properties.forEach(function (property, index) { - property.setValue(newModel, formValue[index]); - }); - - return newModel; - }; - - return CreateWizard; - } -); diff --git a/platform/commonUI/edit/src/creation/CreationService.js b/platform/commonUI/edit/src/creation/CreationService.js deleted file mode 100644 index 86d4c6df82..0000000000 --- a/platform/commonUI/edit/src/creation/CreationService.js +++ /dev/null @@ -1,107 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * Module defining CreateService. Created by vwoeltje on 11/10/14. - */ -define( - [], - function () { - - var NON_PERSISTENT_WARNING = - "Tried to create an object in non-persistent container."; - - /** - * The creation service is responsible for instantiating and - * persisting new domain objects. Handles all actual object - * mutation and persistence associated with domain object - * creation. - * @memberof platform/commonUI/browse - * @constructor - */ - function CreationService($q, $log) { - this.$q = $q; - this.$log = $log; - } - - /** - * Create a new domain object with the provided model, as - * a member of the provided parent domain object's composition. - * This parent will additionally determine which persistence - * space an object is created within (as it is possible to - * have multiple persistence spaces attached.) - * - * Note that the model passed in for object creation may be - * modified to attach additional initial properties associated - * with domain object creation. - * - * @param {object} model the model for the newly-created - * domain object - * @param {DomainObject} parent the domain object which - * should contain the newly-created domain object - * in its composition - * @return {Promise} a promise that will resolve when the domain - * object has been created - */ - CreationService.prototype.createObject = function (model, parent) { - var persistence = parent.getCapability("persistence"), - newObject = parent.useCapability("instantiation", model), - newObjectPersistence = newObject.getCapability("persistence"), - self = this; - - // Add the newly-created object's id to the parent's - // composition, so that it will subsequently appear - // as a child contained by that parent. - function addToComposition() { - var compositionCapability = parent.getCapability('composition'), - addResult = compositionCapability - && compositionCapability.add(newObject); - - return self.$q.when(addResult).then(function (result) { - if (!result) { - self.$log.error("Could not modify " + parent.getId()); - - return undefined; - } - - return persistence.persist().then(function () { - return result; - }); - }); - } - - // We need the parent's persistence capability to determine - // what space to create the new object's model in. - if (!persistence || !newObjectPersistence) { - self.$log.warn(NON_PERSISTENT_WARNING); - - return self.$q.reject(new Error(NON_PERSISTENT_WARNING)); - } - - // Persist the new object, then add it to composition. - return newObjectPersistence.persist().then(addToComposition); - }; - - return CreationService; - } -); - diff --git a/platform/commonUI/edit/src/creation/LocatorController.js b/platform/commonUI/edit/src/creation/LocatorController.js deleted file mode 100644 index 57ea8f7864..0000000000 --- a/platform/commonUI/edit/src/creation/LocatorController.js +++ /dev/null @@ -1,98 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - [], - function () { - - /** - * Controller for the "locator" control, which provides the - * user with the ability to select a domain object as the - * destination for a newly-created object in the Create menu. - * @memberof platform/commonUI/browse - * @constructor - */ - function LocatorController($scope, $timeout, objectService) { - // Populate values needed by the locator control. These are: - // * rootObject: The top-level object, since we want to show - // the full tree - // * treeModel: The model for the embedded tree representation, - // used for bi-directional object selection. - function setLocatingObject(domainObject, priorObject) { - var context = domainObject - && domainObject.getCapability("context"), - contextRoot = context && context.getRoot(); - - if (contextRoot && contextRoot !== $scope.rootObject) { - $scope.rootObject = undefined; - // Update the displayed tree on a timeout to avoid - // an infinite digest exception. - $timeout(function () { - $scope.rootObject = - (context && context.getRoot()) || $scope.rootObject; - }, 0); - } else if (!contextRoot && !$scope.rootObject) { - // Update the displayed tree on a timeout to avoid - // an infinite digest exception. - objectService.getObjects(['ROOT']) - .then(function (objects) { - $timeout(function () { - $scope.rootObject = objects.ROOT; - }, 0); - }); - } - - $scope.treeModel.selectedObject = domainObject; - $scope.ngModel[$scope.field] = domainObject; - - // Restrict which locations can be selected - if (domainObject - && $scope.structure - && $scope.structure.validate) { - if (!$scope.structure.validate(domainObject)) { - setLocatingObject(priorObject, undefined); - - return; - } - } - - // Set validity - if ($scope.ngModelController) { - $scope.ngModelController.$setValidity( - 'composition', - Boolean($scope.treeModel.selectedObject) - ); - } - } - - // Initial state for the tree's model - $scope.treeModel = - { selectedObject: $scope.ngModel[$scope.field] }; - - // Watch for changes from the tree - $scope.$watch("treeModel.selectedObject", setLocatingObject); - } - - return LocatorController; - } -); - diff --git a/platform/commonUI/edit/test/actions/PropertiesActionSpec.js b/platform/commonUI/edit/test/actions/PropertiesActionSpec.js deleted file mode 100644 index aa167373f2..0000000000 --- a/platform/commonUI/edit/test/actions/PropertiesActionSpec.js +++ /dev/null @@ -1,110 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ['../../src/actions/PropertiesAction'], - function (PropertiesAction) { - - describe("Properties action", function () { - var capabilities, model, object, context, input, dialogService, action, openmct; - - function mockPromise(value) { - return { - then: function (callback) { - return mockPromise(callback(value)); - } - }; - } - - beforeEach(function () { - openmct = { - objects: { - isPersistable: jasmine.createSpy('isPersistable') - } - }; - capabilities = { - type: { - getProperties: function () { - return []; - }, - hasFeature: jasmine.createSpy('hasFeature') - }, - mutation: jasmine.createSpy("mutation") - }; - model = {}; - input = {}; - object = { - getId: function () { - return 'test-id'; - }, - getCapability: function (k) { - return capabilities[k]; - }, - getModel: function () { - return model; - }, - useCapability: function (k, v) { - return capabilities[k](v); - }, - hasCapability: function () { - return true; - } - }; - context = { - someKey: "some value", - domainObject: object - }; - dialogService = { - getUserInput: function () { - return mockPromise(input); - } - }; - - capabilities.type.hasFeature.and.returnValue(true); - capabilities.mutation.and.returnValue(true); - - openmct.objects.isPersistable.and.returnValue(true); - - action = new PropertiesAction(dialogService, context); - }); - - it("mutates an object when performed", function () { - action.perform(); - expect(capabilities.mutation).toHaveBeenCalled(); - capabilities.mutation.calls.mostRecent().args[0]({}); - }); - - it("does not muate object upon cancel", function () { - input = undefined; - action.perform(); - expect(capabilities.mutation).not.toHaveBeenCalled(); - }); - - it("is only applicable when a domain object is in context", function () { - expect(PropertiesAction.appliesTo(context, undefined, openmct)).toBeTruthy(); - expect(PropertiesAction.appliesTo({}, undefined, openmct)).toBeFalsy(); - expect(openmct.objects.isPersistable).toHaveBeenCalled(); - }); - - }); - } -); diff --git a/platform/commonUI/edit/test/actions/PropertiesDialogSpec.js b/platform/commonUI/edit/test/actions/PropertiesDialogSpec.js deleted file mode 100644 index b870ac029c..0000000000 --- a/platform/commonUI/edit/test/actions/PropertiesDialogSpec.js +++ /dev/null @@ -1,80 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["../../src/actions/PropertiesDialog"], - function (PropertiesDialog) { - - describe("Properties dialog", function () { - - var type, properties, model, dialog; - - beforeEach(function () { - type = { - getProperties: function () { - return properties; - } - }; - model = { x: "initial value" }; - properties = ["x", "y", "z"].map(function (k) { - return { - getValue: function (m) { - return m[k]; - }, - setValue: function (m, v) { - m[k] = v; - }, - getDefinition: function () { - return { control: 'textfield '}; - } - }; - }); - - dialog = new PropertiesDialog(type, model); - }); - - it("provides sections based on type properties", function () { - expect(dialog.getFormStructure().sections[0].rows.length) - .toEqual(properties.length); - }); - - it("pulls initial values from object model", function () { - expect(dialog.getInitialFormValue()[0]) - .toEqual("initial value"); - }); - - it("populates models with form results", function () { - dialog.updateModel(model, [ - "new value", - "other new value", - 42 - ]); - expect(model).toEqual({ - x: "new value", - y: "other new value", - z: 42 - }); - }); - - }); - } -); diff --git a/platform/commonUI/edit/test/actions/SaveAsActionSpec.js b/platform/commonUI/edit/test/actions/SaveAsActionSpec.js deleted file mode 100644 index dcce37bfa4..0000000000 --- a/platform/commonUI/edit/test/actions/SaveAsActionSpec.js +++ /dev/null @@ -1,249 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["../../src/actions/SaveAsAction"], - function (SaveAsAction) { - - xdescribe("The Save As action", function () { - var mockDomainObject, - mockClonedObject, - mockEditorCapability, - mockActionCapability, - mockObjectService, - mockDialogService, - mockCopyService, - mockNotificationService, - mockParent, - actionContext, - capabilities = {}, - action; - - function noop() {} - - function mockPromise(value) { - return (value || {}).then ? value - : { - then: function (callback) { - return mockPromise(callback(value)); - }, - catch: function (callback) { - return mockPromise(callback(value)); - } - }; - } - - beforeEach(function () { - mockDomainObject = jasmine.createSpyObj( - "domainObject", - [ - "getCapability", - "hasCapability", - "getModel", - "getId" - ] - ); - mockDomainObject.hasCapability.and.returnValue(true); - mockDomainObject.getCapability.and.callFake(function (capability) { - return capabilities[capability]; - }); - mockDomainObject.getModel.and.returnValue({ - location: 'a', - persisted: undefined - }); - mockDomainObject.getId.and.returnValue(0); - - mockClonedObject = jasmine.createSpyObj( - "clonedObject", - [ - "getId" - ] - ); - mockClonedObject.getId.and.returnValue(1); - - mockParent = jasmine.createSpyObj( - "parentObject", - [ - "getCapability", - "hasCapability", - "getModel" - ] - ); - - mockEditorCapability = jasmine.createSpyObj( - "editor", - ["save", "finish", "isEditContextRoot"] - ); - mockEditorCapability.save.and.returnValue(mockPromise(true)); - mockEditorCapability.finish.and.returnValue(mockPromise(true)); - mockEditorCapability.isEditContextRoot.and.returnValue(true); - capabilities.editor = mockEditorCapability; - - mockActionCapability = jasmine.createSpyObj( - "action", - ["perform"] - ); - capabilities.action = mockActionCapability; - - mockObjectService = jasmine.createSpyObj( - "objectService", - ["getObjects"] - ); - mockObjectService.getObjects.and.returnValue(mockPromise({'a': mockParent})); - - mockDialogService = jasmine.createSpyObj( - "dialogService", - [ - "getUserInput", - "showBlockingMessage" - ] - ); - mockDialogService.getUserInput.and.returnValue(mockPromise(undefined)); - - mockCopyService = jasmine.createSpyObj( - "copyService", - [ - "perform" - ] - ); - mockCopyService.perform.and.returnValue(mockPromise(mockClonedObject)); - - mockNotificationService = jasmine.createSpyObj( - "notificationService", - [ - "info", - "error" - ] - ); - - actionContext = { - domainObject: mockDomainObject - }; - - action = new SaveAsAction( - undefined, - undefined, - mockDialogService, - mockCopyService, - mockNotificationService, - actionContext); - - spyOn(action, "getObjectService"); - action.getObjectService.and.returnValue(mockObjectService); - - spyOn(action, "createWizard"); - action.createWizard.and.returnValue({ - getFormStructure: noop, - getInitialFormValue: noop, - populateObjectFromInput: function () { - return mockDomainObject; - } - }); - - }); - - it("only applies to domain object with an editor capability", function () { - expect(SaveAsAction.appliesTo(actionContext)).toBe(true); - expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); - - mockDomainObject.hasCapability.and.returnValue(false); - mockDomainObject.getCapability.and.returnValue(undefined); - expect(SaveAsAction.appliesTo(actionContext)).toBe(false); - }); - - it("only applies to domain object that has not already been" - + " persisted", function () { - expect(SaveAsAction.appliesTo(actionContext)).toBe(true); - expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); - - mockDomainObject.getModel.and.returnValue({persisted: 0}); - expect(SaveAsAction.appliesTo(actionContext)).toBe(false); - }); - - it("uses the editor capability to save the object", function () { - mockEditorCapability.save.and.returnValue(Promise.resolve()); - - return action.perform().then(function () { - expect(mockEditorCapability.save).toHaveBeenCalled(); - }); - }); - - it("uses the editor capability to finish editing the object", function () { - return action.perform().then(function () { - expect(mockEditorCapability.finish.calls.count()).toBeGreaterThan(0); - }); - }); - - it("returns to browse after save", function () { - spyOn(action, "save"); - action.save.and.returnValue(mockPromise(mockDomainObject)); - action.perform(); - expect(mockActionCapability.perform).toHaveBeenCalledWith( - "navigate" - ); - }); - - it("prompts the user for object details", function () { - action.perform(); - expect(mockDialogService.getUserInput).toHaveBeenCalled(); - }); - - 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); - }); - - it("shows a blocking dialog indicating that saving is in progress", function () { - mockEditorCapability.save.and.returnValue(new Promise(function () {})); - action.perform(); - expect(mockDialogService.showBlockingMessage).toHaveBeenCalled(); - expect(mockDialogHandle.dismiss).not.toHaveBeenCalled(); - }); - - it("hides the blocking dialog after saving finishes", function () { - return action.perform().then(function () { - expect(mockDialogService.showBlockingMessage).toHaveBeenCalled(); - expect(mockDialogHandle.dismiss).toHaveBeenCalled(); - }); - }); - - it("notifies if saving succeeded", function () { - return action.perform().then(function () { - expect(mockNotificationService.info).toHaveBeenCalled(); - expect(mockNotificationService.error).not.toHaveBeenCalled(); - }); - }); - - it("notifies if saving failed", function () { - mockCopyService.perform.and.returnValue(Promise.reject("some failure reason")); - action.perform().then(function () { - expect(mockNotificationService.error).toHaveBeenCalled(); - expect(mockNotificationService.info).not.toHaveBeenCalled(); - }); - }); - }); - }); - } -); diff --git a/platform/commonUI/edit/test/creation/CreateActionProviderSpec.js b/platform/commonUI/edit/test/creation/CreateActionProviderSpec.js deleted file mode 100644 index eded353bc3..0000000000 --- a/platform/commonUI/edit/test/creation/CreateActionProviderSpec.js +++ /dev/null @@ -1,118 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * MCTRepresentationSpec. Created by vwoeltje on 11/6/14. - */ -define( - ["../../src/creation/CreateActionProvider"], - function (CreateActionProvider) { - - describe("The create action provider", function () { - var mockTypeService, - mockPolicyService, - mockCreationPolicy, - mockPolicyMap = {}, - mockTypes, - provider; - - function createMockType(name) { - var mockType = jasmine.createSpyObj( - "type" + name, - [ - "getKey", - "getGlyph", - "getCssClass", - "getName", - "getDescription", - "getProperties", - "getInitialModel", - "hasFeature" - ] - ); - mockType.hasFeature.and.returnValue(true); - mockType.getName.and.returnValue(name); - - return mockType; - } - - beforeEach(function () { - mockTypeService = jasmine.createSpyObj( - "typeService", - ["listTypes"] - ); - mockPolicyService = jasmine.createSpyObj( - "policyService", - ["allow"] - ); - - mockTypes = ["A", "B", "C"].map(createMockType); - - mockTypes.forEach(function (type) { - mockPolicyMap[type.getName()] = true; - }); - - mockCreationPolicy = function (type) { - return mockPolicyMap[type.getName()]; - }; - - mockPolicyService.allow.and.callFake(function (category, type) { - return Boolean(category === "creation" && mockCreationPolicy(type)); - }); - - mockTypeService.listTypes.and.returnValue(mockTypes); - - provider = new CreateActionProvider( - mockTypeService, - mockPolicyService - ); - }); - - it("exposes one create action per type", function () { - expect(provider.getActions({ - key: "create", - domainObject: {} - }).length).toEqual(3); - }); - - it("exposes no non-create actions", function () { - expect(provider.getActions({ - key: "somethingElse", - domainObject: {} - }).length).toEqual(0); - }); - - it("does not expose non-creatable types", function () { - // One of the types won't have the creation feature... - mockPolicyMap[mockTypes[0].getName()] = false; - // ...so it should have been filtered out. - expect(provider.getActions({ - key: "create", - domainObject: {} - }).length).toEqual(2); - // Make sure it was creation which was used to check - expect(mockPolicyService.allow) - .toHaveBeenCalledWith("creation", mockTypes[0]); - }); - }); - } -); diff --git a/platform/commonUI/edit/test/creation/CreateActionSpec.js b/platform/commonUI/edit/test/creation/CreateActionSpec.js deleted file mode 100644 index 9bc7957696..0000000000 --- a/platform/commonUI/edit/test/creation/CreateActionSpec.js +++ /dev/null @@ -1,186 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * MCTRepresentationSpec. Created by vwoeltje on 11/6/14. - */ -define( - ["../../src/creation/CreateAction"], - function (CreateAction) { - - xdescribe("The create action", function () { - var mockType, - mockParent, - mockContext, - mockDomainObject, - capabilities = {}, - mockEditAction, - action; - - function mockPromise(value) { - return { - then: function (callback) { - return mockPromise(callback(value)); - } - }; - } - - beforeEach(function () { - mockType = jasmine.createSpyObj( - "type", - [ - "getKey", - "getGlyph", - "getCssClass", - "getName", - "getDescription", - "getProperties", - "getInitialModel" - ] - ); - mockParent = jasmine.createSpyObj( - "domainObject", - [ - "getId", - "getModel", - "getCapability", - "useCapability" - ] - ); - mockDomainObject = jasmine.createSpyObj( - "domainObject", - [ - "getId", - "getModel", - "getCapability", - "hasCapability", - "useCapability" - ] - ); - mockDomainObject.hasCapability.and.callFake(function (name) { - return Boolean(capabilities[name]); - }); - mockDomainObject.getCapability.and.callFake(function (name) { - return capabilities[name]; - }); - - capabilities.action = jasmine.createSpyObj( - "actionCapability", - [ - "getActions", - "perform" - ] - ); - - capabilities.editor = jasmine.createSpyObj( - "editorCapability", - [ - "edit", - "save", - "finish" - ] - ); - - mockEditAction = jasmine.createSpyObj( - "editAction", - [ - "perform" - ] - ); - - mockContext = { - domainObject: mockParent - }; - mockParent.useCapability.and.returnValue(mockDomainObject); - - mockType.getKey.and.returnValue("test"); - mockType.getCssClass.and.returnValue("icon-telemetry"); - mockType.getDescription.and.returnValue("a test type"); - mockType.getName.and.returnValue("Test"); - mockType.getProperties.and.returnValue([]); - mockType.getInitialModel.and.returnValue({}); - - action = new CreateAction( - mockType, - mockParent, - mockContext - ); - }); - - it("exposes type-appropriate metadata", function () { - var metadata = action.getMetadata(); - - expect(metadata.name).toEqual("Test"); - expect(metadata.description).toEqual("a test type"); - expect(metadata.cssClass).toEqual("icon-telemetry"); - }); - - describe("the perform function", function () { - var promise = jasmine.createSpyObj("promise", ["then"]); - beforeEach(function () { - capabilities.action.getActions.and.returnValue([mockEditAction]); - }); - - it("uses the instantiation capability when performed", function () { - action.perform(); - expect(mockParent.useCapability).toHaveBeenCalledWith("instantiation", jasmine.any(Object)); - }); - - it("uses the edit action if available", function () { - action.perform(); - expect(mockEditAction.perform).toHaveBeenCalled(); - }); - - it("uses the save-as action if object does not have an edit action" - + " available", function () { - capabilities.action.getActions.and.returnValue([]); - capabilities.action.perform.and.returnValue(mockPromise(undefined)); - capabilities.editor.save.and.returnValue(promise); - action.perform(); - expect(capabilities.action.perform).toHaveBeenCalledWith("save-as"); - }); - - describe("uses to editor capability", function () { - beforeEach(function () { - capabilities.action.getActions.and.returnValue([]); - capabilities.action.perform.and.returnValue(promise); - capabilities.editor.save.and.returnValue(promise); - }); - - it("to save the edit if user saves dialog", function () { - action.perform(); - expect(promise.then).toHaveBeenCalled(); - promise.then.calls.mostRecent().args[0](); - expect(capabilities.editor.save).toHaveBeenCalled(); - }); - - it("to finish the edit if user cancels dialog", function () { - action.perform(); - promise.then.calls.mostRecent().args[1](); - expect(capabilities.editor.finish).toHaveBeenCalled(); - }); - }); - }); - - }); - } -); diff --git a/platform/commonUI/edit/test/creation/CreateMenuControllerSpec.js b/platform/commonUI/edit/test/creation/CreateMenuControllerSpec.js deleted file mode 100644 index 4a5298d343..0000000000 --- a/platform/commonUI/edit/test/creation/CreateMenuControllerSpec.js +++ /dev/null @@ -1,65 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * MCTRepresentationSpec. Created by vwoeltje on 11/6/14. - */ -define( - ["../../src/creation/CreateMenuController"], - function (CreateMenuController) { - - describe("The create menu controller", function () { - var mockScope, - mockActions, - controller; - - beforeEach(function () { - mockActions = jasmine.createSpyObj("action", ["getActions"]); - mockScope = jasmine.createSpyObj("$scope", ["$watch"]); - controller = new CreateMenuController(mockScope); - }); - - 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 create actions", function () { - mockScope.action = mockActions; - - mockActions.getActions.and.returnValue(["a", "b", "c"]); - - // Call the watch - mockScope.$watch.calls.mostRecent().args[1](); - - // Should have grouped and ungrouped actions in scope now - expect(mockScope.createActions.length).toEqual(3); - - // Make sure the right action type was requested - expect(mockActions.getActions).toHaveBeenCalledWith("create"); - }); - }); - } -); diff --git a/platform/commonUI/edit/test/creation/CreateWizardSpec.js b/platform/commonUI/edit/test/creation/CreateWizardSpec.js deleted file mode 100644 index 8fff4dc903..0000000000 --- a/platform/commonUI/edit/test/creation/CreateWizardSpec.js +++ /dev/null @@ -1,197 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * MCTRepresentationSpec. Created by vwoeltje on 11/6/14. - */ -define( - ["../../src/creation/CreateWizard"], - function (CreateWizard) { - - xdescribe("The create wizard", function () { - var mockType, - mockParent, - mockProperties, - mockPolicyService, - testModel, - mockDomainObject, - wizard; - - function createMockProperty(name) { - var mockProperty = jasmine.createSpyObj( - "property" + name, - ["getDefinition", "getValue", "setValue"] - ); - mockProperty.getDefinition.and.returnValue({ - control: "textfield" - }); - mockProperty.getValue.and.returnValue(name); - - return mockProperty; - } - - beforeEach(function () { - mockType = jasmine.createSpyObj( - "type", - [ - "getKey", - "getGlyph", - "getCssClass", - "getName", - "getDescription", - "getProperties", - "getInitialModel" - ] - ); - mockParent = jasmine.createSpyObj( - "domainObject", - [ - "getId", - "getModel", - "getCapability" - ] - ); - mockProperties = ["A", "B", "C"].map(createMockProperty); - mockPolicyService = jasmine.createSpyObj('policyService', ['allow']); - - testModel = { someKey: "some value" }; - - mockType.getKey.and.returnValue("test"); - mockType.getCssClass.and.returnValue("icon-telemetry"); - mockType.getDescription.and.returnValue("a test type"); - mockType.getName.and.returnValue("Test"); - mockType.getInitialModel.and.returnValue(testModel); - mockType.getProperties.and.returnValue(mockProperties); - - mockDomainObject = jasmine.createSpyObj( - 'domainObject', - ['getCapability', 'useCapability', 'getModel'] - ); - - //Mocking the getCapability('type') call - mockDomainObject.getCapability.and.returnValue(mockType); - mockDomainObject.useCapability.and.returnValue(); - mockDomainObject.getModel.and.returnValue(testModel); - - wizard = new CreateWizard( - mockDomainObject, - mockParent, - mockPolicyService - ); - }); - - it("creates a form model with a Properties section", function () { - expect(wizard.getFormStructure().sections[0].name) - .toEqual("Properties"); - }); - - it("adds one row per defined type property", function () { - // Three properties were defined in the mock type - expect(wizard.getFormStructure().sections[0].rows.length) - .toEqual(3); - }); - - it("interprets form data using type-defined properties", function () { - // Use key names from mock properties - wizard.createModel([ - "field 0", - "field 1", - "field 2" - ]); - - // Should have gotten a setValue call - mockProperties.forEach(function (mockProperty, i) { - expect(mockProperty.setValue).toHaveBeenCalledWith( - { - someKey: "some value", - type: 'test' - }, - "field " + i - ); - }); - }); - - it("looks up initial values from properties", function () { - var initialValue = wizard.getInitialFormValue(); - - expect(initialValue[0]).toEqual("A"); - expect(initialValue[1]).toEqual("B"); - expect(initialValue[2]).toEqual("C"); - - // Verify that expected argument was passed - mockProperties.forEach(function (mockProperty) { - expect(mockProperty.getValue) - .toHaveBeenCalledWith(testModel); - }); - }); - - it("populates the model on the associated object", function () { - var formValue = { - "A": "ValueA", - "B": "ValueB", - "C": "ValueC" - }, - compareModel = wizard.createModel(formValue); - //populateObjectFromInput adds a .location attribute that is not added by createModel. - compareModel.location = undefined; - wizard.populateObjectFromInput(formValue); - expect(mockDomainObject.useCapability).toHaveBeenCalledWith('mutation', jasmine.any(Function)); - expect(mockDomainObject.useCapability.calls.mostRecent().args[1]()).toEqual(compareModel); - }); - - it("validates selection types using policy", function () { - var mockDomainObj = jasmine.createSpyObj( - 'domainObject', - ['getCapability'] - ), - mockOtherType = jasmine.createSpyObj( - 'otherType', - ['getKey'] - ), - - //Create a form structure with location - structure = wizard.getFormStructure(true), - sections = structure.sections, - rows = structure.sections[sections.length - 1].rows, - locationRow = rows[rows.length - 1]; - - mockDomainObj.getCapability.and.returnValue(mockOtherType); - locationRow.validate(mockDomainObj); - - // Should check policy to see if the user-selected location - // can actually contain objects of this type - expect(mockPolicyService.allow).toHaveBeenCalledWith( - 'composition', - mockDomainObj, - mockDomainObject - ); - }); - - it("creates a form model without a location if not requested", function () { - expect(wizard.getFormStructure(false).sections.some(function (section) { - return section.name === 'Location'; - })).toEqual(false); - }); - - }); - } -); diff --git a/platform/commonUI/edit/test/creation/CreationServiceSpec.js b/platform/commonUI/edit/test/creation/CreationServiceSpec.js deleted file mode 100644 index 799474d24e..0000000000 --- a/platform/commonUI/edit/test/creation/CreationServiceSpec.js +++ /dev/null @@ -1,216 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * MCTRepresentationSpec. Created by vwoeltje on 11/6/14. - */ -define( - ["../../src/creation/CreationService"], - function (CreationService) { - - describe("The creation service", function () { - var mockQ, - mockLog, - mockParentObject, - mockNewObject, - mockMutationCapability, - mockPersistenceCapability, - mockCompositionCapability, - mockContextCapability, - mockCreationCapability, - mockCapabilities, - mockNewPersistenceCapability, - creationService; - - function mockPromise(value) { - return (value && value.then) ? value : { - then: function (callback) { - return mockPromise(callback(value)); - } - }; - } - - function mockReject(value) { - return { - then: function (callback, error) { - return mockPromise(error(value)); - } - }; - } - - beforeEach(function () { - mockQ = { - when: mockPromise, - reject: mockReject - }; - mockLog = jasmine.createSpyObj( - "$log", - ["error", "warn", "info", "debug"] - ); - mockParentObject = jasmine.createSpyObj( - "parentObject", - ["getId", "getCapability", "useCapability"] - ); - mockNewObject = jasmine.createSpyObj( - "newObject", - ["getId", "getCapability", "useCapability"] - ); - mockMutationCapability = jasmine.createSpyObj( - "mutation", - ["invoke"] - ); - mockPersistenceCapability = jasmine.createSpyObj( - "persistence", - ["persist", "getSpace"] - ); - mockCompositionCapability = jasmine.createSpyObj( - "composition", - ["invoke", "add"] - ); - mockContextCapability = jasmine.createSpyObj( - "context", - ["getPath"] - ); - mockCreationCapability = jasmine.createSpyObj( - "creation", - ["instantiate", "invoke"] - ); - mockCapabilities = { - mutation: mockMutationCapability, - persistence: mockPersistenceCapability, - composition: mockCompositionCapability, - context: mockContextCapability, - instantiation: mockCreationCapability - }; - mockNewPersistenceCapability = jasmine.createSpyObj( - "new-persistence", - ["persist", "getSpace"] - ); - - mockParentObject.getCapability.and.callFake(function (key) { - return mockCapabilities[key]; - }); - mockParentObject.useCapability.and.callFake(function (key, value) { - return mockCapabilities[key].invoke(value); - }); - mockParentObject.getId.and.returnValue('parentId'); - - mockNewObject.getId.and.returnValue('newId'); - mockNewObject.getCapability.and.callFake(function (c) { - return c === 'persistence' - ? mockNewPersistenceCapability : undefined; - }); - - mockPersistenceCapability.persist - .and.returnValue(mockPromise(true)); - mockNewPersistenceCapability.persist - .and.returnValue(mockPromise(true)); - - mockMutationCapability.invoke.and.returnValue(mockPromise(true)); - mockPersistenceCapability.getSpace.and.returnValue("testSpace"); - mockCompositionCapability.invoke.and.returnValue( - mockPromise([mockNewObject]) - ); - mockCompositionCapability.add.and.returnValue(mockPromise(true)); - mockCreationCapability.instantiate.and.returnValue(mockNewObject); - mockCreationCapability.invoke.and.callFake(function (model) { - return mockCreationCapability.instantiate(model); - }); - - creationService = new CreationService( - mockQ, - mockLog - ); - }); - - it("allows new objects to be created", function () { - var model = { someKey: "some value" }; - creationService.createObject(model, mockParentObject); - expect(mockCreationCapability.instantiate) - .toHaveBeenCalledWith(model); - }); - - it("adds new objects to the parent's composition", function () { - var model = { someKey: "some value" }; - creationService.createObject(model, mockParentObject); - - // Verify that a new ID was added - expect(mockCompositionCapability.add) - .toHaveBeenCalledWith(mockNewObject); - }); - - it("provides the newly-created object", function () { - var mockDomainObject = jasmine.createSpyObj( - 'newDomainObject', - ['getId', 'getModel', 'getCapability'] - ), - mockCallback = jasmine.createSpy('callback'); - - // Act as if the object had been created - mockCompositionCapability.add.and.callFake(function (id) { - mockDomainObject.getId.and.returnValue(id); - mockCompositionCapability.invoke - .and.returnValue(mockPromise([mockDomainObject])); - - return mockPromise(mockDomainObject); - }); - - // Should find it in the composition - creationService.createObject({}, mockParentObject) - .then(mockCallback); - - expect(mockCallback).toHaveBeenCalledWith(mockDomainObject); - - }); - - it("warns if parent has no persistence capability", function () { - // Callbacks - var success = jasmine.createSpy("success"), - failure = jasmine.createSpy("failure"); - - mockCapabilities.persistence = undefined; - creationService.createObject({}, mockParentObject).then( - success, - failure - ); - - // Should have warned and rejected the promise - expect(mockLog.warn).toHaveBeenCalled(); - expect(success).not.toHaveBeenCalled(); - expect(failure).toHaveBeenCalled(); - }); - - it("logs an error when mutation fails", function () { - // If mutation of the parent fails, we've lost the - // created object - this is an error. - var model = { someKey: "some value" }; - - mockCompositionCapability.add.and.returnValue(mockPromise(false)); - - creationService.createObject(model, mockParentObject); - - expect(mockLog.error).toHaveBeenCalled(); - }); - - }); - } -); diff --git a/platform/commonUI/edit/test/creation/LocatorControllerSpec.js b/platform/commonUI/edit/test/creation/LocatorControllerSpec.js deleted file mode 100644 index 615fb645e4..0000000000 --- a/platform/commonUI/edit/test/creation/LocatorControllerSpec.js +++ /dev/null @@ -1,171 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -/** - * MCTRepresentationSpec. Created by vwoeltje on 11/6/14. - */ -define( - ["../../src/creation/LocatorController"], - function (LocatorController) { - - describe("The locator controller", function () { - var mockScope, - mockTimeout, - mockDomainObject, - mockRootObject, - mockContext, - mockObjectService, - getObjectsPromise, - controller; - - beforeEach(function () { - mockScope = jasmine.createSpyObj( - "$scope", - ["$watch"] - ); - mockTimeout = jasmine.createSpy("$timeout"); - mockDomainObject = jasmine.createSpyObj( - "domainObject", - ["getCapability"] - ); - mockRootObject = jasmine.createSpyObj( - "rootObject", - ["getCapability"] - ); - mockContext = jasmine.createSpyObj( - "context", - ["getRoot"] - ); - mockObjectService = jasmine.createSpyObj( - "objectService", - ["getObjects"] - ); - getObjectsPromise = jasmine.createSpyObj( - "promise", - ["then"] - ); - - mockDomainObject.getCapability.and.returnValue(mockContext); - mockContext.getRoot.and.returnValue(mockRootObject); - mockObjectService.getObjects.and.returnValue(getObjectsPromise); - - mockScope.ngModel = {}; - mockScope.field = "someField"; - - controller = new LocatorController(mockScope, mockTimeout, mockObjectService); - }); - describe("when context is available", function () { - - beforeEach(function () { - mockContext.getRoot.and.returnValue(mockRootObject); - controller = new LocatorController(mockScope, mockTimeout, mockObjectService); - }); - - it("adds a treeModel to scope", function () { - expect(mockScope.treeModel).toBeDefined(); - }); - - it("watches for changes to treeModel", function () { - // This is what the embedded tree representation - // will be modifying. - expect(mockScope.$watch).toHaveBeenCalledWith( - "treeModel.selectedObject", - jasmine.any(Function) - ); - }); - - it("changes its own model on embedded model updates", function () { - // Need to pass on selection changes as updates to - // the control's value - mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); - mockTimeout.calls.mostRecent().args[0](); - expect(mockScope.ngModel.someField).toEqual(mockDomainObject); - expect(mockScope.rootObject).toEqual(mockRootObject); - - // Verify that the capability we expect to have been used - // was used. - expect(mockDomainObject.getCapability) - .toHaveBeenCalledWith("context"); - }); - - it("rejects changes which fail validation", function () { - mockScope.structure = { validate: jasmine.createSpy('validate') }; - mockScope.structure.validate.and.returnValue(false); - - // Pass selection change - mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); - mockTimeout.calls.mostRecent().args[0](); - - expect(mockScope.structure.validate).toHaveBeenCalled(); - // Change should have been rejected - expect(mockScope.ngModel.someField).not.toEqual(mockDomainObject); - }); - - it("treats a lack of a selection as invalid", function () { - mockScope.ngModelController = jasmine.createSpyObj( - 'ngModelController', - ['$setValidity'] - ); - - mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); - mockTimeout.calls.mostRecent().args[0](); - expect(mockScope.ngModelController.$setValidity) - .toHaveBeenCalledWith(jasmine.any(String), true); - - mockScope.$watch.calls.mostRecent().args[1](undefined); - mockTimeout.calls.mostRecent().args[0](); - expect(mockScope.ngModelController.$setValidity) - .toHaveBeenCalledWith(jasmine.any(String), false); - }); - }); - describe("when no context is available", function () { - var defaultRoot = "DEFAULT_ROOT"; - - beforeEach(function () { - mockContext.getRoot.and.returnValue(undefined); - getObjectsPromise.then.and.callFake(function (callback) { - callback({'ROOT': defaultRoot}); - }); - controller = new LocatorController(mockScope, mockTimeout, mockObjectService); - }); - - it("provides a default context where none is available", function () { - mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); - mockTimeout.calls.mostRecent().args[0](); - expect(mockScope.rootObject).toBe(defaultRoot); - }); - - it("does not issue redundant requests for the root object", function () { - mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); - mockTimeout.calls.mostRecent().args[0](); - mockScope.$watch.calls.mostRecent().args[1](undefined); - mockTimeout.calls.mostRecent().args[0](); - mockScope.$watch.calls.mostRecent().args[1](mockDomainObject); - mockTimeout.calls.mostRecent().args[0](); - expect(mockObjectService.getObjects.calls.count()) - .toEqual(1); - }); - - }); - }); - } -); diff --git a/platform/entanglement/bundle.js b/platform/entanglement/bundle.js index 591797ec1d..f4475d9a2e 100644 --- a/platform/entanglement/bundle.js +++ b/platform/entanglement/bundle.js @@ -21,25 +21,21 @@ *****************************************************************************/ define([ - "./src/actions/LinkAction", "./src/actions/SetPrimaryLocationAction", "./src/services/LocatingCreationDecorator", "./src/services/LocatingObjectDecorator", "./src/policies/CopyPolicy", "./src/policies/CrossSpacePolicy", "./src/capabilities/LocationCapability", - "./src/services/LinkService", "./src/services/CopyService", "./src/services/LocationService" ], function ( - LinkAction, SetPrimaryLocationAction, LocatingCreationDecorator, LocatingObjectDecorator, CopyPolicy, CrossSpacePolicy, LocationCapability, - LinkService, CopyService, LocationService ) { @@ -52,21 +48,6 @@ define([ "configuration": {}, "extensions": { "actions": [ - { - "key": "link", - "name": "Create Link", - "description": "Create Link to object in another location.", - "cssClass": "icon-link", - "category": "contextual", - "group": "action", - "priority": 7, - "implementation": LinkAction, - "depends": [ - "policyService", - "locationService", - "linkService" - ] - }, { "key": "locate", "name": "Set Primary Location", @@ -115,15 +96,6 @@ define([ } ], "services": [ - { - "key": "linkService", - "name": "Link Service", - "description": "Provides a service for linking objects", - "implementation": LinkService, - "depends": [ - "openmct" - ] - }, { "key": "copyService", "name": "Copy Service", diff --git a/platform/entanglement/src/services/LinkService.js b/platform/entanglement/src/services/LinkService.js deleted file mode 100644 index f6f45b4031..0000000000 --- a/platform/entanglement/src/services/LinkService.js +++ /dev/null @@ -1,71 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - function () { - - /** - * LinkService provides an interface for linking objects to additional - * locations. It also provides a method for determining if an object - * can be copied to a specific location. - * @constructor - * @memberof platform/entanglement - * @implements {platform/entanglement.AbstractComposeService} - */ - function LinkService(openmct) { - this.openmct = openmct; - } - - LinkService.prototype.validate = function (object, parentCandidate) { - if (!parentCandidate || !parentCandidate.getId) { - return false; - } - - if (parentCandidate.getId() === object.getId()) { - return false; - } - - if (!parentCandidate.hasCapability('composition')) { - return false; - } - - if (parentCandidate.getModel().composition.indexOf(object.getId()) !== -1) { - return false; - } - - return this.openmct.composition.checkPolicy(parentCandidate.useCapability('adapter'), object.useCapability('adapter')); - }; - - LinkService.prototype.perform = function (object, parentObject) { - if (!this.validate(object, parentObject)) { - throw new Error( - "Tried to link objects without validating first." - ); - } - - return parentObject.getCapability('composition').add(object); - }; - - return LinkService; - } -); - diff --git a/platform/entanglement/test/actions/LinkActionSpec.js b/platform/entanglement/test/actions/LinkActionSpec.js deleted file mode 100644 index f42cce799f..0000000000 --- a/platform/entanglement/test/actions/LinkActionSpec.js +++ /dev/null @@ -1,178 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - [ - '../../src/actions/LinkAction', - '../services/MockLinkService', - '../DomainObjectFactory' - ], - function (LinkAction, MockLinkService, domainObjectFactory) { - - describe("Link Action", function () { - - var linkAction, - policyService, - locationService, - locationServicePromise, - linkService, - context, - selectedObject, - selectedObjectContextCapability, - currentParent, - newParent; - - beforeEach(function () { - policyService = jasmine.createSpyObj( - 'policyService', - ['allow'] - ); - policyService.allow.and.returnValue(true); - - selectedObjectContextCapability = jasmine.createSpyObj( - 'selectedObjectContextCapability', - [ - 'getParent' - ] - ); - - selectedObject = domainObjectFactory({ - name: 'selectedObject', - model: { - name: 'selectedObject' - }, - capabilities: { - context: selectedObjectContextCapability - } - }); - - currentParent = domainObjectFactory({ - name: 'currentParent' - }); - - selectedObjectContextCapability - .getParent - .and.returnValue(currentParent); - - newParent = domainObjectFactory({ - name: 'newParent' - }); - - locationService = jasmine.createSpyObj( - 'locationService', - [ - 'getLocationFromUser' - ] - ); - - locationServicePromise = jasmine.createSpyObj( - 'locationServicePromise', - [ - 'then' - ] - ); - - locationService - .getLocationFromUser - .and.returnValue(locationServicePromise); - - linkService = new MockLinkService(); - }); - - describe("with context from context-action", function () { - beforeEach(function () { - context = { - domainObject: selectedObject - }; - - linkAction = new LinkAction( - policyService, - locationService, - linkService, - context - ); - }); - - it("initializes happily", function () { - expect(linkAction).toBeDefined(); - }); - - describe("when performed it", function () { - beforeEach(function () { - linkAction.perform(); - }); - - it("prompts for location", function () { - expect(locationService.getLocationFromUser) - .toHaveBeenCalledWith( - "Link selectedObject To a New Location", - "Link To", - jasmine.any(Function), - currentParent - ); - }); - - it("waits for location and handles cancellation by user", function () { - expect(locationServicePromise.then) - .toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function)); - }); - - it("links object to selected location", function () { - locationServicePromise - .then - .calls.mostRecent() - .args[0](newParent); - - expect(linkService.perform) - .toHaveBeenCalledWith(selectedObject, newParent); - }); - }); - }); - - describe("with context from drag-drop", function () { - beforeEach(function () { - context = { - selectedObject: selectedObject, - domainObject: newParent - }; - - linkAction = new LinkAction( - policyService, - locationService, - linkService, - context - ); - }); - - it("initializes happily", function () { - expect(linkAction).toBeDefined(); - }); - - it("performs link immediately", function () { - linkAction.perform(); - expect(linkService.perform) - .toHaveBeenCalledWith(selectedObject, newParent); - }); - }); - }); - } -); diff --git a/platform/entanglement/test/services/LinkServiceSpec.js b/platform/entanglement/test/services/LinkServiceSpec.js deleted file mode 100644 index 5d03a27127..0000000000 --- a/platform/entanglement/test/services/LinkServiceSpec.js +++ /dev/null @@ -1,215 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - [ - '../../src/services/LinkService', - '../DomainObjectFactory', - '../ControlledPromise' - ], - function (LinkService, domainObjectFactory, ControlledPromise) { - - xdescribe("LinkService", function () { - - var linkService, - mockPolicyService; - - beforeEach(function () { - mockPolicyService = jasmine.createSpyObj( - 'policyService', - ['allow'] - ); - mockPolicyService.allow.and.returnValue(true); - linkService = new LinkService(mockPolicyService); - }); - - describe("validate", function () { - - var object, - parentCandidate, - validate; - - beforeEach(function () { - object = domainObjectFactory({ - name: 'object' - }); - parentCandidate = domainObjectFactory({ - name: 'parentCandidate', - capabilities: { - composition: jasmine.createSpyObj( - 'composition', - ['invoke', 'add'] - ) - } - }); - validate = function () { - return linkService.validate(object, parentCandidate); - }; - }); - - it("does not allow invalid parentCandidate", function () { - parentCandidate = undefined; - expect(validate()).toBe(false); - parentCandidate = {}; - expect(validate()).toBe(false); - }); - - it("does not allow parent to be object", function () { - parentCandidate.id = object.id = 'abc'; - expect(validate()).toBe(false); - }); - - it("does not allow parent that contains object", function () { - object.id = 'abc'; - parentCandidate.id = 'xyz'; - parentCandidate.model.composition = ['abc']; - expect(validate()).toBe(false); - }); - - it("does not allow parents without composition", function () { - parentCandidate = domainObjectFactory({ - name: 'parentCandidate' - }); - object.id = 'abc'; - parentCandidate.id = 'xyz'; - parentCandidate.hasCapability.and.callFake(function (c) { - return c !== 'composition'; - }); - expect(validate()).toBe(false); - }); - - describe("defers to policyService", function () { - beforeEach(function () { - object.id = 'abc'; - object.capabilities.type = { type: 'object' }; - parentCandidate.id = 'xyz'; - parentCandidate.capabilities.type = { - type: 'parentCandidate' - }; - parentCandidate.model.composition = []; - }); - - it("calls policy service with correct args", function () { - validate(); - expect(mockPolicyService.allow).toHaveBeenCalledWith( - "composition", - parentCandidate, - object - ); - }); - - it("and returns false", function () { - mockPolicyService.allow.and.returnValue(true); - expect(validate()).toBe(true); - expect(mockPolicyService.allow).toHaveBeenCalled(); - }); - - it("and returns true", function () { - mockPolicyService.allow.and.returnValue(false); - expect(validate()).toBe(false); - expect(mockPolicyService.allow).toHaveBeenCalled(); - }); - }); - }); - - describe("perform", function () { - - var object, - linkedObject, - parentModel, - parentObject, - compositionPromise, - addPromise, - compositionCapability; - - beforeEach(function () { - compositionPromise = new ControlledPromise(); - addPromise = new ControlledPromise(); - compositionCapability = jasmine.createSpyObj( - 'compositionCapability', - ['invoke', 'add'] - ); - compositionCapability.invoke.and.returnValue(compositionPromise); - compositionCapability.add.and.returnValue(addPromise); - parentModel = { - composition: [] - }; - parentObject = domainObjectFactory({ - name: 'parentObject', - model: parentModel, - capabilities: { - mutation: { - invoke: function (mutator) { - mutator(parentModel); - - return new ControlledPromise(); - } - }, - composition: compositionCapability - } - }); - - object = domainObjectFactory({ - name: 'object', - id: 'xyz' - }); - - linkedObject = domainObjectFactory({ - name: 'object-link', - id: 'xyz' - }); - - }); - - it("adds to the parent's composition", function () { - expect(compositionCapability.add).not.toHaveBeenCalled(); - linkService.perform(object, parentObject); - expect(compositionCapability.add) - .toHaveBeenCalledWith(object); - }); - - it("returns object representing new link", function () { - var returnPromise, whenComplete; - returnPromise = linkService.perform(object, parentObject); - whenComplete = jasmine.createSpy('whenComplete'); - returnPromise.then(whenComplete); - - addPromise.resolve(linkedObject); - compositionPromise.resolve([linkedObject]); - expect(whenComplete).toHaveBeenCalledWith(linkedObject); - }); - - it("throws an error when performed on invalid inputs", function () { - function perform() { - linkService.perform(object, parentObject); - } - - spyOn(linkService, 'validate'); - linkService.validate.and.returnValue(true); - expect(perform).not.toThrow(); - linkService.validate.and.returnValue(false); - expect(perform).toThrow(); - }); - }); - }); - } -); diff --git a/platform/forms/README.md b/platform/forms/README.md deleted file mode 100644 index 1f0b7386ec..0000000000 --- a/platform/forms/README.md +++ /dev/null @@ -1,133 +0,0 @@ -# Overview - -This bundle contains a general implementation of forms in Open MCT. -This allows forms to be expressed using a reasonably concise declarative -syntax, and rendered as Angular templates in a consistent fashion. - -# Usage - -To include a form with a declarative definition, use the `mct-form` -directive, e.g.: - - - - -Using toolbars is similar: - - - - -The attributes utilized by this form are as follows: - -* `ng-model`: The object which should contain the full form input. Individual - fields in this model are bound to individual controls; the names used for - these fields are provided in the form structure (see below). -* `structure`: The structure of the form; e.g. sections, rows, their names, - and so forth. The value of this attribute should be an Angular expression. -* `name`: The name in the containing scope under which to publish form - "meta-state", e.g. `$valid`, `$dirty`, etc. This is as the behavior of - `ng-form`. Passed as plain text in the attribute. - -## Form structure - -A form's structure is described as a JavaScript object in the following form: - - { - "name": ... title to display for the form, as a string ..., - "sections": [ - { - "name": ... title to display for the section ..., - "rows": [ - { - "name": ... title to display for this row ..., - "control": ... symbolic key for the control ..., - "key": ... field name in ng-model ... - "pattern": ... optional, reg exp to match against ... - "required": ... optional boolean ... - "options": [ - "name": ... name to display (e.g. in a select) ..., - "value": ... value to store in the model ... - ] - }, - ... and other rows ... - ] - }, - ... and other sections ... - ] - } - -Note that `pattern` may be specified as a string, to simplify storing -for structures as JSON when necessary. The string should be given in -a form appropriate to pass to a `RegExp` constructor. - -## Toolbar structure - -A toolbar's structure is described similarly to forms, except that there -is no notion of rows; instead, there are `items`. - - { - "name": ... title to display for the form, as a string ..., - "sections": [ - { - "name": ... title to display for the section ..., - "items": [ - { - "name": ... title to display for this row ..., - "control": ... symbolic key for the control ..., - "key": ... field name in ng-model ... - "pattern": ... optional, reg exp to match against ... - "required": ... optional boolean ... - "options": [ - "name": ... name to display (e.g. in a select) ..., - "value": ... value to store in the model ... - ], - "disabled": ... true if control should be disabled ... - "size": ... size of the control (for textfields) ... - "click": ... function to invoke (for buttons) ... - "glyph": ... glyph to display (for buttons) ... - "text": ... text withiin control (for buttons) ... - }, - ... and other rows ... - ] - }, - ... and other sections ... - ] - } - -Note that `pattern` may be specified as a string, to simplify storing -for structures as JSON when necessary. The string should be given in -a form appropriate to pass to a `RegExp` constructor. - -## Adding controls - -These control types are included in the forms bundle: - -* `textfield`: A text input to enter plain text. -* `numberfield`: A text input to enter numbers. -* `select`: A drop-down list of options. -* `checkbox`: A box which may be checked/unchecked. -* `color`: A color picker. -* `button`: A button. -* `datetime`: An input for UTC date/time entry; gives result as a - UNIX timestamp, in milliseconds since start of 1970, UTC. - -New controls may be added as extensions of the `controls` category. -Extensions of this category have two properites: - -* `key`: The symbolic name for this control (matched against the - `control` field in rows of the form structure). -* `templateUrl`: The URL to the control's Angular template, relative - to the resources directory of the bundle which exposes the extension. - -Within the template for a control, the following variables will be -included in scope: - -* `ngModel`: The model where form input will be stored. Notably we - also need to look at `field` (see below) to determine which field - in the model should be modified. -* `ngRequired`: True if input is required. -* `ngPattern`: The pattern to match against (for text entry.) -* `options`: The options for this control, as passed from the - `options` property of an individual row. -* `field`: Name of the field in `ngModel` which will hold the value - for this control. diff --git a/platform/forms/bundle.js b/platform/forms/bundle.js deleted file mode 100644 index ac0394e91d..0000000000 --- a/platform/forms/bundle.js +++ /dev/null @@ -1,202 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define([ - "./src/MCTForm", - "./src/MCTControl", - "./src/MCTFileInput", - "./src/FileInputService", - "./src/controllers/AutocompleteController", - "./src/controllers/DateTimeController", - "./src/controllers/CompositeController", - "./src/controllers/ColorController", - "./src/controllers/DialogButtonController", - "./res/templates/controls/autocomplete.html", - "./res/templates/controls/checkbox.html", - "./res/templates/controls/datetime.html", - "./res/templates/controls/select.html", - "./res/templates/controls/textfield.html", - "./res/templates/controls/numberfield.html", - "./res/templates/controls/textarea.html", - "./res/templates/controls/button.html", - "./res/templates/controls/color.html", - "./res/templates/controls/composite.html", - "./res/templates/controls/menu-button.html", - "./res/templates/controls/dialog.html", - "./res/templates/controls/radio.html", - "./res/templates/controls/file-input.html" -], function ( - MCTForm, - MCTControl, - MCTFileInput, - FileInputService, - AutocompleteController, - DateTimeController, - CompositeController, - ColorController, - DialogButtonController, - autocompleteTemplate, - checkboxTemplate, - datetimeTemplate, - selectTemplate, - textfieldTemplate, - numberfieldTemplate, - textareaTemplate, - buttonTemplate, - colorTemplate, - compositeTemplate, - menuButtonTemplate, - dialogTemplate, - radioTemplate, - fileInputTemplate -) { - - return { - name: "platform/forms", - definition: { - "name": "MCT Forms", - "description": "Form generator; includes directive and some controls.", - "extensions": { - "directives": [ - { - "key": "mctForm", - "implementation": MCTForm - }, - { - "key": "mctControl", - "implementation": MCTControl, - "depends": [ - "templateLinker", - "controls[]" - ] - }, - { - "key": "mctFileInput", - "implementation": MCTFileInput, - "depends": [ - "fileInputService" - ] - } - ], - "controls": [ - { - "key": "autocomplete", - "template": autocompleteTemplate - }, - { - "key": "checkbox", - "template": checkboxTemplate - }, - { - "key": "radio", - "template": radioTemplate - }, - { - "key": "datetime", - "template": datetimeTemplate - }, - { - "key": "select", - "template": selectTemplate - }, - { - "key": "textfield", - "template": textfieldTemplate - }, - { - "key": "numberfield", - "template": numberfieldTemplate - }, - { - "key": "textarea", - "template": textareaTemplate - }, - { - "key": "button", - "template": buttonTemplate - }, - { - "key": "color", - "template": colorTemplate - }, - { - "key": "composite", - "template": compositeTemplate - }, - { - "key": "menu-button", - "template": menuButtonTemplate - }, - { - "key": "dialog-button", - "template": dialogTemplate - }, - { - "key": "file-input", - "template": fileInputTemplate - } - ], - "controllers": [ - { - "key": "AutocompleteController", - "implementation": AutocompleteController, - "depends": [ - "$scope", - "$element" - ] - }, - { - "key": "DateTimeController", - "implementation": DateTimeController, - "depends": [ - "$scope" - ] - }, - { - "key": "CompositeController", - "implementation": CompositeController - }, - { - "key": "ColorController", - "implementation": ColorController - }, - { - "key": "DialogButtonController", - "implementation": DialogButtonController, - "depends": [ - "$scope", - "dialogService" - ] - } - ], - "components": [ - { - "provides": "fileInputService", - "type": "provider", - "implementation": FileInputService - } - - ] - } - } - }; -}); diff --git a/platform/forms/res/templates/controls/autocomplete.html b/platform/forms/res/templates/controls/autocomplete.html deleted file mode 100644 index 8e37132e60..0000000000 --- a/platform/forms/res/templates/controls/autocomplete.html +++ /dev/null @@ -1,46 +0,0 @@ - - -
- - -
-
    -
  • - {{opt.name}} -
  • -
-
-
diff --git a/platform/forms/res/templates/controls/button.html b/platform/forms/res/templates/controls/button.html deleted file mode 100644 index e14f257157..0000000000 --- a/platform/forms/res/templates/controls/button.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - {{structure.text}} - - diff --git a/platform/forms/res/templates/controls/checkbox.html b/platform/forms/res/templates/controls/checkbox.html deleted file mode 100644 index 253d7f8b28..0000000000 --- a/platform/forms/res/templates/controls/checkbox.html +++ /dev/null @@ -1,28 +0,0 @@ - - diff --git a/platform/forms/res/templates/controls/color.html b/platform/forms/res/templates/controls/color.html deleted file mode 100644 index a3998f5ba0..0000000000 --- a/platform/forms/res/templates/controls/color.html +++ /dev/null @@ -1,57 +0,0 @@ - - diff --git a/platform/forms/res/templates/controls/composite.html b/platform/forms/res/templates/controls/composite.html deleted file mode 100644 index 7e88bc8031..0000000000 --- a/platform/forms/res/templates/controls/composite.html +++ /dev/null @@ -1,38 +0,0 @@ - - - -
- - - - {{item.name}} - -
-
-
diff --git a/platform/forms/res/templates/controls/datetime.html b/platform/forms/res/templates/controls/datetime.html deleted file mode 100644 index e571f044a0..0000000000 --- a/platform/forms/res/templates/controls/datetime.html +++ /dev/null @@ -1,83 +0,0 @@ - -
- -
- Date - Hour - Min - Sec - Timezone -
- - - -
- - - - - - - - - - - - - - UTC - -
-
- - -
diff --git a/platform/forms/res/templates/controls/dialog.html b/platform/forms/res/templates/controls/dialog.html deleted file mode 100644 index 0ea910746f..0000000000 --- a/platform/forms/res/templates/controls/dialog.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - diff --git a/platform/forms/res/templates/controls/file-input.html b/platform/forms/res/templates/controls/file-input.html deleted file mode 100644 index c780b2a330..0000000000 --- a/platform/forms/res/templates/controls/file-input.html +++ /dev/null @@ -1,30 +0,0 @@ - - - diff --git a/platform/forms/res/templates/controls/menu-button.html b/platform/forms/res/templates/controls/menu-button.html deleted file mode 100644 index 0d010a84aa..0000000000 --- a/platform/forms/res/templates/controls/menu-button.html +++ /dev/null @@ -1,39 +0,0 @@ - - diff --git a/platform/forms/res/templates/controls/numberfield.html b/platform/forms/res/templates/controls/numberfield.html deleted file mode 100644 index bb235e029c..0000000000 --- a/platform/forms/res/templates/controls/numberfield.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - diff --git a/platform/forms/res/templates/controls/radio.html b/platform/forms/res/templates/controls/radio.html deleted file mode 100644 index a6daab09ec..0000000000 --- a/platform/forms/res/templates/controls/radio.html +++ /dev/null @@ -1,29 +0,0 @@ - - diff --git a/platform/forms/res/templates/controls/select.html b/platform/forms/res/templates/controls/select.html deleted file mode 100644 index f95121d4f7..0000000000 --- a/platform/forms/res/templates/controls/select.html +++ /dev/null @@ -1,30 +0,0 @@ - -
- -
diff --git a/platform/forms/res/templates/controls/textarea.html b/platform/forms/res/templates/controls/textarea.html deleted file mode 100644 index f232040e6e..0000000000 --- a/platform/forms/res/templates/controls/textarea.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - diff --git a/platform/forms/res/templates/controls/textfield.html b/platform/forms/res/templates/controls/textfield.html deleted file mode 100644 index 18d4deda88..0000000000 --- a/platform/forms/res/templates/controls/textfield.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - diff --git a/platform/forms/res/templates/form.html b/platform/forms/res/templates/form.html deleted file mode 100644 index 9be1363a2c..0000000000 --- a/platform/forms/res/templates/form.html +++ /dev/null @@ -1,57 +0,0 @@ - -
- -

- {{section.name}} -

- -
- {{row.name}} -
-
-
- - -
-
-
-
-
diff --git a/platform/forms/src/FileInputService.js b/platform/forms/src/FileInputService.js deleted file mode 100644 index bdc3fd2c2a..0000000000 --- a/platform/forms/src/FileInputService.js +++ /dev/null @@ -1,96 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define(["zepto"], function ($) { - - /** - * The FileInputService provides an interface for triggering a file input. - * - * @constructor - * @memberof platform/forms - */ - function FileInputService() { - } - - /** - * Creates, triggers, and destroys a file picker element and returns a - * promise for an object containing the chosen file's name and contents. - * - * @returns {Promise} promise for an object containing file meta-data - */ - FileInputService.prototype.getInput = function (fileType) { - var input = this.newInput(); - var read = this.readFile; - var fileInfo = {}; - var file; - - return new Promise(function (resolve, reject) { - input.trigger("click"); - input.on('change', function (event) { - // eslint-disable-next-line no-invalid-this - file = this.files[0]; - input.remove(); - if (file) { - if (fileType && (!file.type || (file.type !== fileType))) { - reject("Incompatible file type"); - } - - read(file) - .then(function (contents) { - fileInfo.name = file.name; - fileInfo.body = contents; - resolve(fileInfo); - }, function () { - reject("File read error"); - }); - } - }); - }); - }; - - FileInputService.prototype.readFile = function (file) { - var fileReader = new FileReader(); - - return new Promise(function (resolve, reject) { - fileReader.onload = function (event) { - resolve(event.target.result); - }; - - fileReader.onerror = function () { - return reject(event.target.result); - }; - - fileReader.readAsText(file); - }); - }; - - FileInputService.prototype.newInput = function () { - var input = $(document.createElement('input')); - input.attr("type", "file"); - input.css("display", "none"); - $('body').append(input); - - return input; - }; - - return FileInputService; -}); diff --git a/platform/forms/src/MCTControl.js b/platform/forms/src/MCTControl.js deleted file mode 100644 index d6237bf9f2..0000000000 --- a/platform/forms/src/MCTControl.js +++ /dev/null @@ -1,103 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - [], - function () { - - /** - * The mct-control will dynamically include the control - * for a form element based on a symbolic key. Individual - * controls are defined under the extension category - * `controls`; this allows plug-ins to introduce new form - * control types while still making use of the form - * generator to ensure an overall consistent form style. - * @constructor - * @memberof platform/forms - */ - function MCTControl(templateLinker, controls) { - var controlMap = {}; - - // Prepopulate controlMap for easy look up by key - controls.forEach(function (control) { - controlMap[control.key] = control; - }); - - function link(scope, element, attrs, ngModelController) { - var changeTemplate = templateLinker.link(scope, element); - scope.$watch("key", function (key) { - changeTemplate(controlMap[key]); - }); - scope.ngModelController = ngModelController; - } - - return { - // Only show at the element level - restrict: "E", - - // ngOptions is terminal, so we need to be higher priority - priority: 1000, - - // Get the ngModelController, so that controls can set validity - require: '?ngModel', - - // Link function - link: link, - - // Pass through Angular's normal input field attributes - scope: { - // Used to choose which form control to use - key: "=", - - // Allow controls to trigger blur-like events - ngBlur: "&", - - // Allow controls to trigger blur-like events - ngMouseup: "&", - - // The state of the form value itself - ngModel: "=", - - // Enabled/disabled state - ngDisabled: "=", - - // Whether or not input is required - ngRequired: "=", - - // Pattern (for input fields) - ngPattern: "=", - - // Set of choices (if any) - options: "=", - - // Structure (subtree of Form Structure) - structure: "=", - - // Name, as in " 20 - ? fileName.substr(0, 20) + "..." - : fileName; - } - - function handleClick() { - fileInputService.getInput(scope.structure.type).then(function (result) { - setText(result.name); - scope.ngModel[scope.field] = result; - control.$setValidity("file-input", true); - scope.$digest(); - }, function () { - setText('Select File'); - control.$setValidity("file-input", false); - scope.$digest(); - }); - } - - control.$setValidity("file-input", false); - element.on('click', handleClick); - } - - return { - restrict: "A", - require: "^form", - link: link - }; - } - - return MCTFileInput; - } -); diff --git a/platform/forms/src/MCTForm.js b/platform/forms/src/MCTForm.js deleted file mode 100644 index dc8cd295c2..0000000000 --- a/platform/forms/src/MCTForm.js +++ /dev/null @@ -1,80 +0,0 @@ -/***************************************************************************** - * 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 bundle implements directives for displaying and handling forms for - * user input. - * @namespace platform/forms - */ -define( - ["./controllers/FormController", "../res/templates/form.html"], - function (FormController, formTemplate) { - - /** - * The mct-form directive allows generation of displayable - * forms based on a declarative description of the form's - * structure. - * - * This directive accepts three attributes: - * - * * `ng-model`: The model for the form; where user input - * where be stored. - * * `structure`: The declarative structure of the form. - * Describes what controls should be shown and where - * their values should be read/written in the model. - * * `name`: The name under which to expose the form's - * dirty/valid state. This is similar to ng-form's use - * of name, except this will be made available in the - * parent scope. - * - * @memberof platform/forms - * @constructor - */ - function MCTForm() { - return { - // Only show at the element level - restrict: "E", - - // Load the forms template - template: formTemplate, - - // Use FormController to populate/respond to changes in scope - controller: ['$scope', FormController], - - // Initial an isolate scope - scope: { - - // The model: Where form input will actually go - ngModel: "=", - - // Form structure; what sections/rows to show - structure: "=", - - // Name under which to publish the form - name: "@" - } - }; - } - - return MCTForm; - } -); diff --git a/platform/forms/src/controllers/AutocompleteController.js b/platform/forms/src/controllers/AutocompleteController.js deleted file mode 100644 index 5b129bc98e..0000000000 --- a/platform/forms/src/controllers/AutocompleteController.js +++ /dev/null @@ -1,140 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - [], - function () { - - /** - * Controller for the `autocomplete` form control. - * - * @memberof platform/forms - * @constructor - */ - function AutocompleteController($scope, $element) { - - var key = { - down: 40, - up: 38, - enter: 13 - }, - autocompleteInputElement = $element[0].getElementsByClassName('autocompleteInput')[0]; - - if ($scope.options[0].name) { - // If "options" include name, value pair - $scope.optionNames = $scope.options.map(function (opt) { - return opt.name; - }); - } else { - // If options is only an array of string. - $scope.optionNames = $scope.options; - } - - function fillInputWithIndexedOption() { - if ($scope.filteredOptions[$scope.optionIndex]) { - $scope.ngModel[$scope.field] = $scope.filteredOptions[$scope.optionIndex].name; - } - } - - function decrementOptionIndex() { - if ($scope.optionIndex === 0) { - $scope.optionIndex = $scope.filteredOptions.length; - } - - $scope.optionIndex--; - fillInputWithIndexedOption(); - } - - function incrementOptionIndex() { - if ($scope.optionIndex === $scope.filteredOptions.length - 1) { - $scope.optionIndex = -1; - } - - $scope.optionIndex++; - fillInputWithIndexedOption(); - } - - function fillInputWithString(string) { - $scope.hideOptions = true; - $scope.ngModel[$scope.field] = string; - } - - function showOptions(string) { - $scope.hideOptions = false; - $scope.filterOptions(string); - $scope.optionIndex = 0; - } - - $scope.keyDown = function ($event) { - if ($scope.filteredOptions) { - var keyCode = $event.keyCode; - switch (keyCode) { - case key.down: - incrementOptionIndex(); - break; - case key.up: - $event.preventDefault(); // Prevents cursor jumping back and forth - decrementOptionIndex(); - break; - case key.enter: - if ($scope.filteredOptions[$scope.optionIndex]) { - fillInputWithString($scope.filteredOptions[$scope.optionIndex].name); - } - } - } - }; - - $scope.filterOptions = function (string) { - $scope.hideOptions = false; - $scope.filteredOptions = $scope.optionNames.filter(function (option) { - return option.toLowerCase().indexOf(string.toLowerCase()) >= 0; - }).map(function (option, index) { - return { - optionId: index, - name: option - }; - }); - }; - - $scope.inputClicked = function () { - autocompleteInputElement.select(); - showOptions(autocompleteInputElement.value); - }; - - $scope.arrowClicked = function () { - autocompleteInputElement.select(); - showOptions(''); - }; - - $scope.fillInput = function (string) { - fillInputWithString(string); - }; - - $scope.optionMouseover = function (optionId) { - $scope.optionIndex = optionId; - }; - } - - return AutocompleteController; - - } -); diff --git a/platform/forms/src/controllers/ColorController.js b/platform/forms/src/controllers/ColorController.js deleted file mode 100644 index a692b39b11..0000000000 --- a/platform/forms/src/controllers/ColorController.js +++ /dev/null @@ -1,104 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - [], - function () { - - var BASE_COLORS = [ - [136, 32, 32], - [224, 64, 64], - [240, 160, 72], - [255, 248, 96], - [128, 240, 72], - [128, 248, 248], - [88, 144, 224], - [0, 72, 240], - [136, 80, 240], - [224, 96, 248] - ], - GRADIENTS = [0.75, 0.50, 0.25, -0.25, -0.50, -0.75], - GROUPS = []; - - function toWebColor(triplet) { - return '#' + triplet.map(function (v) { - return (v < 16 ? '0' : '') + v.toString(16); - }).join(''); - } - - function toGradient(triplet, value) { - return triplet.map(function (v) { - return Math.round(value > 0 - ? (v + (255 - v) * value) - : (v * (1 + value)) - ); - }); - } - - function initializeGroups() { - var group; - - // Ten grayscale colors - group = []; - while (group.length < 10) { - group.push(toWebColor([ - Math.round(28.3333 * group.length), - Math.round(28.3333 * group.length), - Math.round(28.3333 * group.length) - ])); - } - - GROUPS.push(group); - - // Ten basic colors - GROUPS.push(BASE_COLORS.map(toWebColor)); - - // ...and some gradients of those colors - group = []; - GRADIENTS.forEach(function (v) { - group = group.concat(BASE_COLORS.map(function (c) { - return toWebColor(toGradient(c, v)); - })); - }); - GROUPS.push(group); - } - - function ColorController() { - if (GROUPS.length === 0) { - initializeGroups(); - } - } - - /** - * Get groups of colors to display in a color picker. These are - * given as #-prefixed color strings, in a two-dimensional array. - * Each element of the array is a group of related colors (e.g. - * grayscale colors, web colors, gradients...) - * @returns {string[][]} groups of colors - */ - ColorController.prototype.groups = function () { - return GROUPS; - }; - - return ColorController; - } -); diff --git a/platform/forms/src/controllers/CompositeController.js b/platform/forms/src/controllers/CompositeController.js deleted file mode 100644 index efa07d2a85..0000000000 --- a/platform/forms/src/controllers/CompositeController.js +++ /dev/null @@ -1,62 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - [], - function () { - - /** - * The CompositeController supports the "composite" control type, - * which provides an array of other controls. It is used specifically - * to support validation when a particular row is not marked as - * required; in this case, empty input should be allowed, but partial - * input (where some but not all of the composite controls have been - * filled in) should be disallowed. This is enforced in the template - * by an ng-required directive, but that is supported by the - * isNonEmpty check that this controller provides. - * @memberof platform/forms - * @constructor - */ - function CompositeController() { - } - - // Check if an element is defined; the map step of isNonEmpty - function isDefined(element) { - return typeof element !== 'undefined'; - } - - /** - * Check if an array contains anything other than - * undefined elements. - * @param {Array} value the array to check - * @returns {boolean} true if any non-undefined - * element is in the array - * @memberof platform/forms.CompositeController# - */ - CompositeController.prototype.isNonEmpty = function (value) { - return Array.isArray(value) && value.some(isDefined); - }; - - return CompositeController; - - } -); diff --git a/platform/forms/src/controllers/DateTimeController.js b/platform/forms/src/controllers/DateTimeController.js deleted file mode 100644 index 4a41f2773f..0000000000 --- a/platform/forms/src/controllers/DateTimeController.js +++ /dev/null @@ -1,108 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["moment"], - function (moment) { - - var DATE_FORMAT = "YYYY-MM-DD"; - - /** - * Controller for the `datetime` form control. - * This is a composite control; it includes multiple - * input fields but outputs a single timestamp (in - * milliseconds since start of 1970) to the ngModel. - * - * @memberof platform/forms - * @constructor - */ - function DateTimeController($scope) { - - // Update the - function update() { - var date = $scope.datetime.date, - hour = $scope.datetime.hour, - min = $scope.datetime.min, - sec = $scope.datetime.sec, - fullDateTime = moment.utc(date, DATE_FORMAT) - .hour(hour || 0) - .minute(min || 0) - .second(sec || 0); - - if (fullDateTime.isValid()) { - $scope.ngModel[$scope.field] = fullDateTime.valueOf(); - } - - // If anything is complete, say so in scope; there are - // ng-required usages that will update off of this (to - // allow datetime to be optional while still permitting - // incomplete input) - $scope.partiallyComplete = - Object.keys($scope.datetime).some(function (key) { - return $scope.datetime[key]; - }); - - // Treat empty input as an undefined value - if (!$scope.partiallyComplete) { - $scope.ngModel[$scope.field] = undefined; - } - } - - function updateDateTime(value) { - var m; - if (value !== undefined) { - m = moment.utc(value); - $scope.datetime = { - date: m.format(DATE_FORMAT), - hour: m.format("H"), - min: m.format("m"), - sec: m.format("s") - }; - } else { - $scope.datetime = {}; - } - } - - // ...and update form values when actual field in model changes - $scope.$watch("ngModel[field]", updateDateTime); - - // Update value whenever any field changes. - $scope.$watch("datetime.date", update); - $scope.$watch("datetime.hour", update); - $scope.$watch("datetime.min", update); - $scope.$watch("datetime.sec", update); - - // Expose format string for placeholder - $scope.format = DATE_FORMAT; - - // Initialize forms values - updateDateTime( - ($scope.ngModel && $scope.field) - ? $scope.ngModel[$scope.field] : undefined - ); - } - - return DateTimeController; - - } -); - diff --git a/platform/forms/src/controllers/DialogButtonController.js b/platform/forms/src/controllers/DialogButtonController.js deleted file mode 100644 index 435b127b34..0000000000 --- a/platform/forms/src/controllers/DialogButtonController.js +++ /dev/null @@ -1,93 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ -define( - [], - function () { - - /** - * Controller for the `dialog-button` control type. Provides - * structure for a button (embedded via the template) which - * will show a dialog for editing a single property when clicked. - * @memberof platform/forms - * @constructor - * @param $scope the control's Angular scope - * @param {DialogService} dialogService service to use to prompt - * for user input - */ - function DialogButtonController($scope, dialogService) { - var self = this, - buttonForm; - - // Store the result of user input to the model - function storeResult(result) { - $scope.ngModel[$scope.field] = result[$scope.field]; - } - - // Prompt for user input - function showDialog() { - // Prepare initial state - var state = {}; - state[$scope.field] = $scope.ngModel[$scope.field]; - - // Show dialog, then store user input (if any) - dialogService.getUserInput(buttonForm, state).then(storeResult); - } - - // Refresh state based on structure for this control - function refreshStructure(structure) { - var row = Object.create(structure.dialog || {}); - - structure = structure || {}; - - // Add the key, to read back from that row - row.key = $scope.field; - - // Prepare the structure for the button itself - self.buttonStructure = {}; - self.buttonStructure.cssClass = structure.cssClass; - self.buttonStructure.name = structure.name; - self.buttonStructure.description = structure.description; - self.buttonStructure.click = showDialog; - - // Prepare the form; a single row - buttonForm = { - name: structure.title, - sections: [{ rows: [row] }] - }; - } - - $scope.$watch('structure', refreshStructure); - } - - /** - * Get the structure for an `mct-control` of type - * `button`; a dialog will be launched when this button - * is clicked. - * @returns dialog structure - */ - DialogButtonController.prototype.getButtonStructure = function () { - return this.buttonStructure; - }; - - return DialogButtonController; - } -); diff --git a/platform/forms/src/controllers/FormController.js b/platform/forms/src/controllers/FormController.js deleted file mode 100644 index eebae6e943..0000000000 --- a/platform/forms/src/controllers/FormController.js +++ /dev/null @@ -1,77 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - [], - function () { - - // Default ng-pattern; any non whitespace - var NON_WHITESPACE = /\S/; - - /** - * Controller for mct-form and mct-toolbar directives. - * @memberof platform/forms - * @constructor - */ - function FormController($scope) { - var regexps = []; - - // ng-pattern seems to want a RegExp, and not a - // string (despite what documentation says) but - // we want form structure to be JSON-expressible, - // so we make RegExp's from strings as-needed - function getRegExp(pattern) { - // If undefined, don't apply a pattern - if (!pattern) { - return NON_WHITESPACE; - } - - // Just echo if it's already a regexp - if (pattern instanceof RegExp) { - return pattern; - } - - // Otherwise, assume a string - // Cache for easy lookup later (so we don't - // creat a new RegExp every digest cycle) - if (!regexps[pattern]) { - regexps[pattern] = new RegExp(pattern); - } - - return regexps[pattern]; - } - - // Publish the form state under the requested - // name in the parent scope - $scope.$watch("mctForm", function (mctForm) { - if ($scope.name) { - $scope.$parent[$scope.name] = mctForm; - } - }); - - // Expose the regexp lookup - $scope.getRegExp = getRegExp; - } - - return FormController; - } -); diff --git a/platform/forms/test/FileInputServiceSpec.js b/platform/forms/test/FileInputServiceSpec.js deleted file mode 100644 index 014b6cc7d7..0000000000 --- a/platform/forms/test/FileInputServiceSpec.js +++ /dev/null @@ -1,74 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["../src/FileInputService"], - function (FileInputService) { - - describe("The FileInputService", function () { - var fileInputService, - mockInput; - - beforeEach(function () { - fileInputService = new FileInputService(); - mockInput = jasmine.createSpyObj('input', - [ - 'on', - 'trigger', - 'remove' - ] - ); - mockInput.on.and.callFake(function (event, changeHandler) { - changeHandler.apply(mockInput); - }); - spyOn(fileInputService, "newInput").and.returnValue( - mockInput - ); - - }); - - it("can read a file", function () { - mockInput.files = [new File(["file content"], "file name")]; - fileInputService.getInput().then(function (result) { - expect(result.name).toBe("file name"); - expect(result.body).toBe("file content"); - }); - - expect(mockInput.trigger).toHaveBeenCalledWith('click'); - expect(mockInput.remove).toHaveBeenCalled(); - }); - - it("catches file read errors", function () { - mockInput.files = ["GARBAGE"]; - fileInputService.getInput().then( - function (result) {}, - function (err) { - expect(err).toBe("File read error"); - } - ); - - expect(mockInput.trigger).toHaveBeenCalledWith('click'); - expect(mockInput.remove).toHaveBeenCalled(); - }); - }); - } -); diff --git a/platform/forms/test/MCTControlSpec.js b/platform/forms/test/MCTControlSpec.js deleted file mode 100644 index f7ff316e07..0000000000 --- a/platform/forms/test/MCTControlSpec.js +++ /dev/null @@ -1,92 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["../src/MCTControl"], - function (MCTControl) { - - describe("The mct-control directive", function () { - var testControls, - mockScope, - mockLinker, - mockChangeTemplate, - mctControl; - - beforeEach(function () { - testControls = [ - { - key: "abc", - bundle: { - path: "a", - resources: "b" - }, - templateUrl: "c/template.html" - }, - { - key: "xyz", - bundle: { - path: "x", - resources: "y" - }, - templateUrl: "z/template.html" - } - ]; - - mockScope = jasmine.createSpyObj("$scope", ["$watch"]); - mockLinker = jasmine.createSpyObj("templateLinker", ["link"]); - mockChangeTemplate = jasmine.createSpy('changeTemplate'); - mockLinker.link.and.returnValue(mockChangeTemplate); - - mctControl = new MCTControl(mockLinker, testControls); - }); - - it("is restricted to the element level", function () { - expect(mctControl.restrict).toEqual("E"); - }); - - it("watches its passed key to choose a template", function () { - mctControl.link(mockScope); - - expect(mockScope.$watch).toHaveBeenCalledWith( - "key", - jasmine.any(Function) - ); - }); - - it("changes its template dynamically", function () { - mctControl.link(mockScope); - - expect(mockChangeTemplate) - .not.toHaveBeenCalledWith(testControls[1]); - - mockScope.key = "xyz"; - mockScope.$watch.calls.mostRecent().args[1]("xyz"); - - // Should have communicated the template path to - // ng-include via the "inclusion" field in scope - expect(mockChangeTemplate) - .toHaveBeenCalledWith(testControls[1]); - }); - - }); - } -); diff --git a/platform/forms/test/MCTFileInputSpec.js b/platform/forms/test/MCTFileInputSpec.js deleted file mode 100644 index 3b05f7da57..0000000000 --- a/platform/forms/test/MCTFileInputSpec.js +++ /dev/null @@ -1,95 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["../src/MCTFileInput"], - function (MCTFileInput) { - - xdescribe("The mct-file-input directive", function () { - - var mockScope, - mockFileInputService, - mctFileInput, - element, - attrs, - control; - - beforeEach(function () { - attrs = []; - control = jasmine.createSpyObj('control', ['$setValidity']); - element = jasmine.createSpyObj('element', ['on', 'trigger']); - mockFileInputService = jasmine.createSpyObj('fileInputService', - ['getInput'] - ); - mockScope = jasmine.createSpyObj( - '$scope', - ['$watch'] - ); - - mockScope.structure = {text: 'Select File'}; - mockScope.field = "file-input"; - mockScope.ngModel = {"file-input": undefined}; - - element.on.and.callFake(function (event, clickHandler) { - clickHandler(); - }); - mockFileInputService.getInput.and.returnValue( - Promise.resolve({ - name: "file-name", - body: "file-body" - }) - ); - - mctFileInput = new MCTFileInput(mockFileInputService); - - return new Promise(function (resolve) { - mctFileInput.link(mockScope, element, attrs, control); - setTimeout(resolve, 100); - }); - }); - - it("is restricted to attributes", function () { - expect(mctFileInput.restrict).toEqual("A"); - }); - - it("changes button text to match file name", function () { - expect(element.on).toHaveBeenCalledWith( - 'click', - jasmine.any(Function) - ); - expect(mockScope.structure.text).toEqual("file-name"); - }); - - it("validates control on file selection", function () { - var calls = control.$setValidity.calls; - - expect(calls.count()).toBe(2); - expect(calls.all()[0].args).toEqual( - ['file-input', false] - ); - expect(calls.all()[1].args).toEqual( - ['file-input', true] - ); - }); - }); - } -); diff --git a/platform/forms/test/MCTFormSpec.js b/platform/forms/test/MCTFormSpec.js deleted file mode 100644 index 5145dfc009..0000000000 --- a/platform/forms/test/MCTFormSpec.js +++ /dev/null @@ -1,114 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["../src/MCTForm"], - function (MCTForm) { - - describe("The mct-form directive", function () { - var mockScope, - mctForm; - - function installController() { - var Controller = mctForm.controller[1]; - - return new Controller(mockScope); - } - - beforeEach(function () { - mockScope = jasmine.createSpyObj("$scope", ["$watch"]); - mockScope.$parent = {}; - mctForm = new MCTForm(); - }); - - it("is restricted to elements", function () { - expect(mctForm.restrict).toEqual("E"); - }); - - it("watches for changes in form by name", function () { - // mct-form needs to watch for the form by name - // in order to convey changes in $valid, $dirty, etc - // up to the parent scope. - installController(); - - expect(mockScope.$watch).toHaveBeenCalledWith( - "mctForm", - jasmine.any(Function) - ); - }); - - it("conveys form status to parent scope", function () { - var someState = { someKey: "some value" }; - mockScope.name = "someName"; - - installController(); - - mockScope.$watch.calls.mostRecent().args[1](someState); - - expect(mockScope.$parent.someName).toBe(someState); - }); - - it("allows strings to be converted to RegExps", function () { - // This is needed to support ng-pattern in the template - installController(); - - // Should have added getRegExp to the scope, - // to convert strings to regular expressions - expect(mockScope.getRegExp("^\\d+$")).toEqual(/^\d+$/); - }); - - it("returns the same regexp instance for the same string", function () { - // Don't want new instances each digest cycle, for performance - var strRegExp = "^[a-z]\\d+$", - regExp; - - // Add getRegExp to scope - installController(); - regExp = mockScope.getRegExp(strRegExp); - - // Same object instance each time... - expect(mockScope.getRegExp(strRegExp)).toBe(regExp); - expect(mockScope.getRegExp(strRegExp)).toBe(regExp); - }); - - it("passes RegExp objects through untouched", function () { - // Permit using forms to simply provide their own RegExp object - var regExp = /^\d+[a-d]$/; - - // Add getRegExp to scope - installController(); - - // Should have added getRegExp to the scope, - // to convert strings to regular expressions - expect(mockScope.getRegExp(regExp)).toBe(regExp); - }); - - it("passes a non-whitespace regexp when no pattern is defined", function () { - // If no pattern is supplied, ng-pattern should match anything - installController(); - expect(mockScope.getRegExp()).toEqual(/\S/); - expect(mockScope.getRegExp(undefined)).toEqual(/\S/); - }); - - }); - } -); diff --git a/platform/forms/test/controllers/AutocompleteControllerSpec.js b/platform/forms/test/controllers/AutocompleteControllerSpec.js deleted file mode 100644 index 12b0f560c4..0000000000 --- a/platform/forms/test/controllers/AutocompleteControllerSpec.js +++ /dev/null @@ -1,75 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define([ - "../../src/controllers/AutocompleteController", - "angular" -], function ( - AutocompleteController, - angular -) { - - describe("The autocomplete controller", function () { - var mockScope, - mockElement, - controller; - - beforeEach(function () { - mockScope = jasmine.createSpyObj("$scope", ["$watch"]); - mockScope.options = ['Asia/Dhaka', 'UTC', 'Toronto', 'Asia/Shanghai', 'Hotel California']; - mockScope.ngModel = [null, null, null, null, null]; - mockScope.field = 4; - mockElement = angular.element("
"); - controller = new AutocompleteController(mockScope, mockElement); - }); - - it("makes optionNames array equal to options if options is an array of string", function () { - expect(mockScope.optionNames).toEqual(mockScope.options); - }); - - it("filters options by returning array containing optionId and name", function () { - mockScope.filterOptions('Asia'); - var filteredOptions = [{ - optionId: 0, - name: 'Asia/Dhaka' - }, - { - optionId: 1, - name: 'Asia/Shanghai' - }]; - expect(mockScope.filteredOptions).toEqual(filteredOptions); - }); - - it("fills input with given string", function () { - var str = "UTC"; - mockScope.fillInput(str); - expect(mockScope.hideOptions).toEqual(true); - expect(mockScope.ngModel[mockScope.field]).toEqual(str); - }); - - it("sets a new optionIndex on mouse hover", function () { - mockScope.optionMouseover(1); - expect(mockScope.optionIndex).toEqual(1); - }); - - }); -}); diff --git a/platform/forms/test/controllers/ColorControllerSpec.js b/platform/forms/test/controllers/ColorControllerSpec.js deleted file mode 100644 index 373fc100e0..0000000000 --- a/platform/forms/test/controllers/ColorControllerSpec.js +++ /dev/null @@ -1,70 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["../../src/controllers/ColorController"], - function (ColorController) { - - var COLOR_REGEX = /^#[0-9a-fA-F]{6}$/; - - describe("The color picker's controller", function () { - var controller; - - beforeEach(function () { - controller = new ColorController(); - }); - - it("exposes groups of colors", function () { - var groups = controller.groups(); - - // Make sure that the groups array is non-empty - expect(Array.isArray(groups)).toBeTruthy(); - expect(groups.length).not.toEqual(0); - - groups.forEach(function (group) { - // Make sure each group is a non-empty array - expect(Array.isArray(group)).toBeTruthy(); - expect(group.length).not.toEqual(0); - // Make sure they're valid web colors - group.forEach(function (color) { - expect(COLOR_REGEX.test(color)).toBeTruthy(); - }); - }); - }); - - it("exposes unique colors", function () { - var count = 0, set = {}; - - // Count each color, and add them to the set - controller.groups().forEach(function (group) { - group.forEach(function (color) { - count += 1; - set[color] = true; - }); - }); - - // Size of set should be number of colors if all were unique - expect(Object.keys(set).length).toEqual(count); - }); - }); - } -); diff --git a/platform/forms/test/controllers/DateTimeControllerSpec.js b/platform/forms/test/controllers/DateTimeControllerSpec.js deleted file mode 100644 index add1f7e0ac..0000000000 --- a/platform/forms/test/controllers/DateTimeControllerSpec.js +++ /dev/null @@ -1,107 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["../../src/controllers/DateTimeController"], - function (DateTimeController) { - - describe("The date-time controller", function () { - var mockScope, - controller; - - beforeEach(function () { - mockScope = jasmine.createSpyObj("$scope", ["$watch"]); - controller = new DateTimeController(mockScope); - }); - - it("watches for changes in fields", function () { - ["date", "hour", "min", "sec"].forEach(function (fieldName) { - expect(mockScope.$watch).toHaveBeenCalledWith( - "datetime." + fieldName, - jasmine.any(Function) - ); - }); - }); - - it("converts date-time input into a timestamp", function () { - mockScope.ngModel = {}; - mockScope.field = "test"; - mockScope.datetime.date = "2014-11-28"; - mockScope.datetime.hour = 22; - mockScope.datetime.min = 55; - mockScope.datetime.sec = 13; - - mockScope.$watch.calls.mostRecent().args[1](); - - expect(mockScope.ngModel.test).toEqual(1417215313000); - }); - - it("reports when form input is partially complete", function () { - // This is needed to flag the control's state as invalid - // when it is partially complete without having it treated - // as required. - mockScope.ngModel = {}; - mockScope.field = "test"; - mockScope.datetime.date = "2014-11-28"; - mockScope.datetime.hour = 22; - mockScope.datetime.min = 55; - // mockScope.datetime.sec = 13; - - mockScope.$watch.calls.mostRecent().args[1](); - - expect(mockScope.partiallyComplete).toBeTruthy(); - }); - - it("reports 'undefined' for empty input", function () { - mockScope.ngModel = { test: 12345 }; - mockScope.field = "test"; - mockScope.$watch.calls.mostRecent().args[1](); - // Clear all inputs - mockScope.datetime = {}; - mockScope.$watch.calls.mostRecent().args[1](); - - // Should have cleared out the time stamp - expect(mockScope.ngModel.test).toBeUndefined(); - }); - - it("exposes date-time format for placeholder", function () { - expect(mockScope.format).toEqual(jasmine.any(String)); - expect(mockScope.format.length).toBeGreaterThan(0); - }); - it("initializes form fields with values from ng-model", function () { - mockScope.ngModel = { test: 1417215313000 }; - mockScope.field = "test"; - mockScope.$watch.calls.all().forEach(function (call) { - if (call.args[0] === 'ngModel[field]') { - call.args[1](mockScope.ngModel.test); - } - }); - expect(mockScope.datetime).toEqual({ - date: "2014-11-28", - hour: "22", - min: "55", - sec: "13" - }); - }); - }); - } -); diff --git a/platform/forms/test/controllers/DialogButtonControllerSpec.js b/platform/forms/test/controllers/DialogButtonControllerSpec.js deleted file mode 100644 index 1a270d4846..0000000000 --- a/platform/forms/test/controllers/DialogButtonControllerSpec.js +++ /dev/null @@ -1,135 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["../../src/controllers/DialogButtonController"], - function (DialogButtonController) { - - describe("A dialog button controller", function () { - var mockScope, - mockDialogService, - mockPromise, - testStructure, - controller; - - beforeEach(function () { - mockScope = jasmine.createSpyObj( - '$scope', - ['$watch'] - ); - mockDialogService = jasmine.createSpyObj( - 'dialogService', - ['getUserInput'] - ); - mockPromise = jasmine.createSpyObj( - 'promise', - ['then'] - ); - testStructure = { - name: "A Test", - cssClass: "icon-T", - description: "Test description", - control: "dialog-button", - title: "Test title", - dialog: { - "control": "textfield", - "name": "Inner control" - } - }; - - mockScope.field = "testKey"; - mockScope.ngModel = { testKey: "initial test value" }; - mockScope.structure = testStructure; - - mockDialogService.getUserInput.and.returnValue(mockPromise); - - controller = new DialogButtonController( - mockScope, - mockDialogService - ); - }); - - it("provides a structure for a button control", function () { - var buttonStructure; - - // Template is just a mct-control pointing to a button - // control, so this controller needs to set up all the - // logic for showing a dialog and collecting user input - // when that button gets clicked. - expect(mockScope.$watch).toHaveBeenCalledWith( - "structure", // As passed in via mct-control - jasmine.any(Function) - ); - - mockScope.$watch.calls.mostRecent().args[1](testStructure); - - buttonStructure = controller.getButtonStructure(); - expect(buttonStructure.cssClass).toEqual(testStructure.cssClass); - expect(buttonStructure.description).toEqual(testStructure.description); - expect(buttonStructure.name).toEqual(testStructure.name); - expect(buttonStructure.click).toEqual(jasmine.any(Function)); - }); - - it("shows a dialog when clicked", function () { - mockScope.$watch.calls.mostRecent().args[1](testStructure); - // Verify precondition - no dialog shown - expect(mockDialogService.getUserInput).not.toHaveBeenCalled(); - // Click! - controller.getButtonStructure().click(); - // Should have shown a dialog - expect(mockDialogService.getUserInput).toHaveBeenCalled(); - }); - - it("stores user input to the model", function () { - var key, input = {}; - // Show dialog, click... - mockScope.$watch.calls.mostRecent().args[1](testStructure); - controller.getButtonStructure().click(); - // Should be listening to 'then' - expect(mockPromise.then) - .toHaveBeenCalledWith(jasmine.any(Function)); - // Find the key that the dialog should return - key = mockDialogService.getUserInput.calls.mostRecent() - .args[0].sections[0].rows[0].key; - // Provide 'user input' - input[key] = "test user input"; - // Resolve the promise with it - mockPromise.then.calls.mostRecent().args[0](input); - // ... should have been placed into the model - expect(mockScope.ngModel.testKey).toEqual("test user input"); - }); - - it("supplies initial model state to the dialog", function () { - var key, state; - mockScope.$watch.calls.mostRecent().args[1](testStructure); - controller.getButtonStructure().click(); - // Find the key that the dialog should return - key = mockDialogService.getUserInput.calls.mostRecent() - .args[0].sections[0].rows[0].key; - // Get the initial state provided to the dialog - state = mockDialogService.getUserInput.calls.mostRecent().args[1]; - // Should have had value from ngModel stored to that key - expect(state[key]).toEqual("initial test value"); - }); - }); - } -); diff --git a/platform/forms/test/controllers/FormControllerSpec.js b/platform/forms/test/controllers/FormControllerSpec.js deleted file mode 100644 index ed1619ba0c..0000000000 --- a/platform/forms/test/controllers/FormControllerSpec.js +++ /dev/null @@ -1,87 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define( - ["../../src/controllers/FormController"], - function (FormController) { - - describe("The form controller", function () { - var mockScope, - controller; - - beforeEach(function () { - mockScope = jasmine.createSpyObj("$scope", ["$watch"]); - mockScope.$parent = {}; - controller = new FormController(mockScope); - }); - - it("watches for changes in form by name", function () { - expect(mockScope.$watch).toHaveBeenCalledWith( - "mctForm", - jasmine.any(Function) - ); - }); - - it("conveys form status to parent scope", function () { - var someState = { someKey: "some value" }; - mockScope.name = "someName"; - mockScope.$watch.calls.mostRecent().args[1](someState); - expect(mockScope.$parent.someName).toBe(someState); - }); - - it("allows strings to be converted to RegExps", function () { - // Should have added getRegExp to the scope, - // to convert strings to regular expressions - expect(mockScope.getRegExp("^\\d+$")).toEqual(/^\d+$/); - }); - - it("returns the same regexp instance for the same string", function () { - // Don't want new instances each digest cycle, for performance - var strRegExp = "^[a-z]\\d+$", - regExp; - - // Add getRegExp to scope - regExp = mockScope.getRegExp(strRegExp); - - // Same object instance each time... - expect(mockScope.getRegExp(strRegExp)).toBe(regExp); - expect(mockScope.getRegExp(strRegExp)).toBe(regExp); - }); - - it("passes RegExp objects through untouched", function () { - // Permit using forms to simply provide their own RegExp object - var regExp = /^\d+[a-d]$/; - - // Should have added getRegExp to the scope, - // to convert strings to regular expressions - expect(mockScope.getRegExp(regExp)).toBe(regExp); - }); - - it("passes a non-whitespace regexp when no pattern is defined", function () { - // If no pattern is supplied, ng-pattern should match anything - expect(mockScope.getRegExp()).toEqual(/\S/); - expect(mockScope.getRegExp(undefined)).toEqual(/\S/); - }); - - }); - } -); diff --git a/platform/import-export/README.md b/platform/import-export/README.md deleted file mode 100644 index e8d903ec68..0000000000 --- a/platform/import-export/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Import / Export Plugin -The Import/Export plugin allows objects to be exported as JSON files. This allows for sharing of objects between users -who are not using a shared persistence store. It also allows object trees to be backed up. Additionally, object trees -exported using this tool can then be exposed as read-only static root trees using the -[Static Root Plugin](../../src/plugins/staticRootPlugin/README.md). - -Upon installation it will add two new context menu actions to allow import and export of objects. Initiating the Export -action on an object will produce a JSON file that includes the object and all of its composed children. Selecting Import -on an object will allow the user to import a previously exported object tree as a child of the selected object. - -## Installation -```js -openmct.install(openmct.plugins.ImportExport()) -``` \ No newline at end of file diff --git a/platform/import-export/bundle.js b/platform/import-export/bundle.js deleted file mode 100644 index 8446ab27a1..0000000000 --- a/platform/import-export/bundle.js +++ /dev/null @@ -1,82 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define([ - "./src/actions/ExportAsJSONAction", - "./src/actions/ImportAsJSONAction" -], function ( - ExportAsJSONAction, - ImportAsJSONAction -) { - - return function ImportExportPlugin() { - return function (openmct) { - ExportAsJSONAction.prototype.appliesTo = function (context) { - return this.openmct.$injector.get('policyService') - .allow("creation", context.domainObject.getCapability("type") - ); - }; - - openmct.legacyRegistry.register("platform/import-export", { - "name": "Import-export plugin", - "description": "Allows importing / exporting of domain objects as JSON.", - "extensions": { - "actions": [ - { - "key": "export.JSON", - "name": "Export as JSON", - "implementation": ExportAsJSONAction, - "category": "contextual", - "cssClass": "icon-export", - "group": "json", - "priority": 2, - "depends": [ - "openmct", - "exportService", - "policyService", - "identifierService", - "typeService" - ] - }, - { - "key": "import.JSON", - "name": "Import from JSON", - "implementation": ImportAsJSONAction, - "category": "contextual", - "cssClass": "icon-import", - "group": "json", - "priority": 2, - "depends": [ - "exportService", - "identifierService", - "dialogService", - "openmct" - ] - } - ] - } - }); - - openmct.legacyRegistry.enable('platform/import-export'); - }; - }; -}); diff --git a/platform/import-export/src/actions/ExportAsJSONAction.js b/platform/import-export/src/actions/ExportAsJSONAction.js deleted file mode 100644 index ea299bad44..0000000000 --- a/platform/import-export/src/actions/ExportAsJSONAction.js +++ /dev/null @@ -1,202 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ - -define(['lodash'], function (_) { - - /** - * The ExportAsJSONAction is available from context menus and allows a user - * to export any creatable domain object as a JSON file. - * - * @implements {Action} - * @constructor - * @memberof platform/import-export - */ - function ExportAsJSONAction( - openmct, - exportService, - policyService, - identifierService, - typeService, - context - ) { - this.openmct = openmct; - this.root = {}; - this.tree = {}; - this.calls = 0; - this.context = context; - this.externalIdentifiers = []; - this.exportService = exportService; - this.policyService = policyService; - this.identifierService = identifierService; - this.typeService = typeService; - - this.idMap = {}; - } - - ExportAsJSONAction.prototype.perform = function () { - var root = this.context.domainObject.useCapability('adapter'); - this.root = this.copyObject(root); - var rootId = this.getId(this.root); - this.tree[rootId] = this.root; - - this.saveAs = function (completedTree) { - this.exportService.exportJSON( - completedTree, - {filename: this.root.name + '.json'} - ); - }; - - this.write(this.root); - }; - - /** - * Traverses object hierarchy and populates tree object with models and - * identifiers. - * - * @private - * @param {Object} parent - */ - ExportAsJSONAction.prototype.write = function (parent) { - this.calls++; - var composition = this.openmct.composition.get(parent); - - if (composition !== undefined) { - composition.load() - .then(function (children) { - children.forEach(function (child, index) { - // Only export if object is creatable - if (this.isCreatable(child)) { - // Prevents infinite export of self-contained objs - if (!Object.prototype.hasOwnProperty.call(this.tree, this.getId(child))) { - // If object is a link to something absent from - // tree, generate new id and treat as new object - if (this.isExternal(child, parent)) { - child = this.rewriteLink(child, parent); - } else { - this.tree[this.getId(child)] = child; - } - - this.write(child); - } - } - }.bind(this)); - this.calls--; - if (this.calls === 0) { - this.rewriteReferences(); - this.saveAs(this.wrapTree()); - } - }.bind(this)); - } else { - this.calls--; - if (this.calls === 0) { - this.rewriteReferences(); - this.saveAs(this.wrapTree()); - } - } - }; - - /** - * Exports an externally linked object as an entirely new object in the - * case where the original is not present in the exported tree. - * - * @private - */ - ExportAsJSONAction.prototype.rewriteLink = function (child, parent) { - this.externalIdentifiers.push(this.getId(child)); - var index = parent.composition.findIndex(id => { - return _.isEqual(child.identifier, id); - }); - var copyOfChild = this.copyObject(child); - copyOfChild.identifier.key = this.identifierService.generate(); - var newIdString = this.getId(copyOfChild); - var parentId = this.getId(parent); - - this.idMap[this.getId(child)] = newIdString; - copyOfChild.location = parentId; - parent.composition[index] = copyOfChild.identifier; - this.tree[newIdString] = copyOfChild; - this.tree[parentId].composition[index] = copyOfChild.identifier; - - return copyOfChild; - }; - - ExportAsJSONAction.prototype.copyObject = function (object) { - var jsonString = JSON.stringify(object); - - return JSON.parse(jsonString); - }; - - ExportAsJSONAction.prototype.isExternal = function (child, parent) { - if (child.location !== this.getId(parent) - && !Object.keys(this.tree).includes(child.location) - && this.getId(child) !== this.getId(this.root) - || this.externalIdentifiers.includes(this.getId(child))) { - - return true; - } - - return false; - }; - - /** - * Wraps root object for identification on reimport and wraps entire - * exported JSON construct for validation. - * - * @private - */ - ExportAsJSONAction.prototype.wrapTree = function () { - return { - "openmct": this.tree, - "rootId": this.getId(this.root) - }; - }; - - ExportAsJSONAction.prototype.isCreatable = function (domainObject) { - var type = this.typeService.getType(domainObject.type); - - return this.policyService.allow( - "creation", - type - ); - }; - - /** - * @private - */ - ExportAsJSONAction.prototype.getId = function (domainObject) { - return this.openmct.objects.makeKeyString(domainObject.identifier); - }; - - /** - * @private - */ - ExportAsJSONAction.prototype.rewriteReferences = function () { - var treeString = JSON.stringify(this.tree); - Object.keys(this.idMap).forEach(function (oldId) { - var newId = this.idMap[oldId]; - treeString = treeString.split(oldId).join(newId); - }.bind(this)); - this.tree = JSON.parse(treeString); - }; - - return ExportAsJSONAction; -}); diff --git a/platform/import-export/src/actions/ImportAsJSONAction.js b/platform/import-export/src/actions/ImportAsJSONAction.js deleted file mode 100644 index c510e605b7..0000000000 --- a/platform/import-export/src/actions/ImportAsJSONAction.js +++ /dev/null @@ -1,238 +0,0 @@ -/***************************************************************************** - * 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. - *****************************************************************************/ -define(['zepto', 'objectUtils'], function ($, objectUtils) { - - /** - * The ImportAsJSONAction is available from context menus and allows a user - * to import a previously exported domain object into any domain object - * that has the composition capability. - * - * @implements {Action} - * @constructor - * @memberof platform/import-export - */ - function ImportAsJSONAction( - exportService, - identifierService, - dialogService, - openmct, - context - ) { - - this.openmct = openmct; - this.context = context; - this.exportService = exportService; - this.dialogService = dialogService; - this.identifierService = identifierService; - this.instantiate = openmct.$injector.get("instantiate"); - } - - ImportAsJSONAction.prototype.perform = function () { - this.dialogService.getUserInput(this.getFormModel(), {}) - .then(function (form) { - var objectTree = form.selectFile.body; - if (this.validateJSON(objectTree)) { - this.importObjectTree(JSON.parse(objectTree)); - } else { - this.displayError(); - } - }.bind(this)); - }; - - ImportAsJSONAction.prototype.importObjectTree = function (objTree) { - var parent = this.context.domainObject; - var namespace = parent.useCapability('adapter').identifier.namespace; - - var tree = this.generateNewIdentifiers(objTree, namespace); - var rootId = tree.rootId; - - var rootModel = tree.openmct[rootId]; - delete rootModel.persisted; - - var rootObj = this.instantiate(rootModel, rootId); - var newStyleParent = parent.useCapability('adapter'); - var newStyleRootObj = rootObj.useCapability('adapter'); - - if (this.openmct.composition.checkPolicy(newStyleParent, newStyleRootObj)) { - // Instantiate all objects in tree with their newly generated ids, - // adding each to its rightful parent's composition - rootObj.getCapability("location").setPrimaryLocation(parent.getId()); - this.deepInstantiate(rootObj, tree.openmct, []); - parent.getCapability("composition").add(rootObj); - } else { - var dialog = this.openmct.overlays.dialog({ - iconClass: 'alert', - message: "We're sorry, but you cannot import that object type into this object.", - buttons: [ - { - label: "Ok", - emphasis: true, - callback: function () { - dialog.dismiss(); - } - } - ] - }); - } - }; - - ImportAsJSONAction.prototype.deepInstantiate = function (parent, tree, seen) { - // Traverses object tree, instantiates all domain object w/ new IDs and - // adds to parent's composition - if (parent.hasCapability("composition")) { - var parentModel = parent.getModel(); - var newObj; - - seen.push(parent.getId()); - - parentModel.composition.forEach(function (childId) { - let keystring = this.openmct.objects.makeKeyString(childId); - - if (!tree[keystring] || seen.includes(keystring)) { - return; - } - - let newModel = tree[keystring]; - delete newModel.persisted; - - newObj = this.instantiate(newModel, keystring); - newObj.getCapability("location") - .setPrimaryLocation(tree[keystring].location); - this.deepInstantiate(newObj, tree, seen); - }, this); - } - }; - - ImportAsJSONAction.prototype.generateNewIdentifiers = function (tree, namespace) { - // For each domain object in the file, generate new ID, replace in tree - Object.keys(tree.openmct).forEach(function (domainObjectId) { - let newId = { - namespace: namespace, - key: this.identifierService.generate() - }; - - let oldId = objectUtils.parseKeyString(domainObjectId); - - tree = this.rewriteId(oldId, newId, tree); - }, this); - - return tree; - }; - - ImportAsJSONAction.prototype.getKeyString = function (identifier) { - return this.openmct.objects.makeKeyString(identifier); - }; - - /** - * Rewrites all instances of a given id in the tree with a newly generated - * replacement to prevent collision. - * - * @private - */ - ImportAsJSONAction.prototype.rewriteId = function (oldId, newId, tree) { - let newIdKeyString = this.openmct.objects.makeKeyString(newId); - let oldIdKeyString = this.openmct.objects.makeKeyString(oldId); - tree = JSON.stringify(tree).replace(new RegExp(oldIdKeyString, 'g'), newIdKeyString); - - return JSON.parse(tree, (key, value) => { - if (value !== undefined - && value !== null - && Object.prototype.hasOwnProperty.call(value, 'key') - && Object.prototype.hasOwnProperty.call(value, 'namespace') - && value.key === oldId.key - && value.namespace === oldId.namespace) { - return newId; - } else { - return value; - } - }); - }; - - ImportAsJSONAction.prototype.getFormModel = function () { - return { - name: "Import as JSON", - sections: [ - { - name: "Import A File", - rows: [ - { - name: 'Select File', - key: 'selectFile', - control: 'file-input', - required: true, - text: 'Select File...' - } - ] - } - ] - }; - }; - - ImportAsJSONAction.prototype.validateJSON = function (jsonString) { - var json; - try { - json = JSON.parse(jsonString); - } catch (e) { - return false; - } - - if (!json.openmct || !json.rootId) { - return false; - } - - return true; - }; - - ImportAsJSONAction.prototype.displayError = function () { - var dialog, - model = { - title: "Invalid File", - actionText: "The selected file was either invalid JSON or was " - + "not formatted properly for import into Open MCT.", - severity: "error", - options: [ - { - label: "Ok", - callback: function () { - dialog.dismiss(); - } - } - ] - }; - dialog = this.dialogService.showBlockingMessage(model); - }; - - ImportAsJSONAction.appliesTo = function (context, view, openmct) { - let domainObject = (context || {}).domainObject; - - if (!domainObject || (domainObject.model && domainObject.model.locked)) { - return false; - } - - let isPersistable = openmct.objects.isPersistable(domainObject.id); - let hasComposition = domainObject.hasCapability('composition'); - - return hasComposition && isPersistable; - }; - - return ImportAsJSONAction; -}); diff --git a/src/MCT.js b/src/MCT.js index c70c96b3b2..7857493f21 100644 --- a/src/MCT.js +++ b/src/MCT.js @@ -46,7 +46,10 @@ define([ './plugins/licenses/plugin', './plugins/remove/plugin', './plugins/move/plugin', + './plugins/linkAction/plugin', './plugins/duplicate/plugin', + './plugins/importFromJSONAction/plugin', + './plugins/exportAsJSONAction/plugin', 'vue' ], function ( EventEmitter, @@ -74,7 +77,10 @@ define([ LicensesPlugin, RemoveActionPlugin, MoveActionPlugin, + LinkActionPlugin, DuplicateActionPlugin, + ImportFromJSONAction, + ExportAsJSONAction, Vue ) { /** @@ -254,6 +260,7 @@ define([ this.priority = api.PriorityAPI; this.router = new ApplicationRouter(this); + this.forms = new api.FormsAPI.default(this); this.branding = BrandingAPI.default; @@ -270,14 +277,17 @@ define([ this.install(LicensesPlugin.default()); this.install(RemoveActionPlugin.default()); this.install(MoveActionPlugin.default()); + this.install(LinkActionPlugin.default()); this.install(DuplicateActionPlugin.default()); + this.install(ExportAsJSONAction.default()); + this.install(ImportFromJSONAction.default()); + this.install(this.plugins.FormActions.default()); this.install(this.plugins.FolderView()); this.install(this.plugins.Tabs()); this.install(ImageryPlugin.default()); this.install(this.plugins.FlexibleLayout()); this.install(this.plugins.GoToOriginalAction()); this.install(this.plugins.OpenInNewTabAction()); - this.install(this.plugins.ImportExport()); this.install(this.plugins.WebPage()); this.install(this.plugins.Condition()); this.install(this.plugins.ConditionWidget()); diff --git a/src/adapter/actions/LegacyContextMenuAction.js b/src/adapter/actions/LegacyContextMenuAction.js index eef1c93561..58b4dcca03 100644 --- a/src/adapter/actions/LegacyContextMenuAction.js +++ b/src/adapter/actions/LegacyContextMenuAction.js @@ -21,7 +21,7 @@ *****************************************************************************/ import _ from 'lodash'; const INSIDE_EDIT_PATH_BLACKLIST = ["copy", "follow", "link", "locate", "move", "link"]; -const OUTSIDE_EDIT_PATH_BLACKLIST = ["copy", "follow", "properties", "move", "link", "remove", "locate"]; +const OUTSIDE_EDIT_PATH_BLACKLIST = ["copy", "follow", "move", "link", "remove", "locate"]; export default class LegacyContextMenuAction { constructor(openmct, LegacyAction) { diff --git a/src/api/api.js b/src/api/api.js index b2734125ca..b6e4af91f6 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -21,44 +21,47 @@ *****************************************************************************/ define([ - './time/TimeAPI', - './objects/ObjectAPI', - './composition/CompositionAPI', - './types/TypeRegistry', - './telemetry/TelemetryAPI', - './indicators/IndicatorAPI', - './notifications/NotificationAPI', - './Editor', - './menu/MenuAPI', './actions/ActionsAPI', + './composition/CompositionAPI', + './Editor', + './forms/FormsAPI', + './indicators/IndicatorAPI', + './menu/MenuAPI', + './notifications/NotificationAPI', + './objects/ObjectAPI', + './priority/PriorityAPI', './status/StatusAPI', - './priority/PriorityAPI' + './telemetry/TelemetryAPI', + './time/TimeAPI', + './types/TypeRegistry' ], function ( - TimeAPI, - ObjectAPI, - CompositionAPI, - TypeRegistry, - TelemetryAPI, - IndicatorAPI, - NotificationAPI, - EditorAPI, - MenuAPI, ActionsAPI, + CompositionAPI, + EditorAPI, + FormsAPI, + IndicatorAPI, + MenuAPI, + NotificationAPI, + ObjectAPI, + PriorityAPI, StatusAPI, - PriorityAPI + TelemetryAPI, + TimeAPI, + TypeRegistry ) { return { - TimeAPI: TimeAPI.default, - ObjectAPI: ObjectAPI, - CompositionAPI: CompositionAPI, - TypeRegistry: TypeRegistry, - TelemetryAPI: TelemetryAPI, - IndicatorAPI: IndicatorAPI, - NotificationAPI: NotificationAPI.default, - EditorAPI: EditorAPI, - MenuAPI: MenuAPI.default, ActionsAPI: ActionsAPI.default, + CompositionAPI: CompositionAPI, + EditorAPI: EditorAPI, + FormsAPI: FormsAPI, + IndicatorAPI: IndicatorAPI, + MenuAPI: MenuAPI.default, + NotificationAPI: NotificationAPI.default, + ObjectAPI: ObjectAPI, + PriorityAPI: PriorityAPI.default, StatusAPI: StatusAPI.default, - PriorityAPI: PriorityAPI.default + TelemetryAPI: TelemetryAPI, + TimeAPI: TimeAPI.default, + TypeRegistry: TypeRegistry }; }); diff --git a/src/api/forms/FormController.js b/src/api/forms/FormController.js new file mode 100644 index 0000000000..a1cadcaeb5 --- /dev/null +++ b/src/api/forms/FormController.js @@ -0,0 +1,93 @@ +import AutoCompleteField from './components/controls/AutoCompleteField.vue'; +import ClockDisplayFormatField from './components/controls/ClockDisplayFormatField.vue'; +import Datetime from './components/controls/Datetime.vue'; +import FileInput from './components/controls/FileInput.vue'; +import Locator from './components/controls/Locator.vue'; +import NumberField from './components/controls/NumberField.vue'; +import SelectField from './components/controls/SelectField.vue'; +import TextAreaField from './components/controls/TextAreaField.vue'; +import TextField from './components/controls/TextField.vue'; + +import Vue from 'vue'; + +export const DEFAULT_CONTROLS_MAP = { + 'autocomplete': AutoCompleteField, + 'composite': ClockDisplayFormatField, + 'datetime': Datetime, + 'file-input': FileInput, + 'locator': Locator, + 'numberfield': NumberField, + 'select': SelectField, + 'textarea': TextAreaField, + 'textfield': TextField +}; + +export default class FormControl { + constructor(openmct) { + this.openmct = openmct; + this.controls = {}; + + this._addDefaultFormControls(); + } + + addControl(controlName, controlViewProvider) { + const control = this.controls[controlName]; + if (control) { + console.warn(`Error: provided form control '${controlName}', already exists`); + + return; + } + + this.controls[controlName] = controlViewProvider; + } + + getControl(controlName) { + const control = this.controls[controlName]; + if (!control) { + console.error(`Error: form control '${controlName}', does not exist`); + } + + return control; + } + + /** + * @private + */ + _addDefaultFormControls() { + Object.keys(DEFAULT_CONTROLS_MAP).forEach(control => { + const controlViewProvider = this._getControlViewProvider(control); + this.addControl(control, controlViewProvider); + }); + } + + /** + * @private + */ + _getControlViewProvider(control) { + const self = this; + + return { + show(element, model, onChange) { + const rowComponent = new Vue({ + el: element, + components: { + FormControlComponent: DEFAULT_CONTROLS_MAP[control] + }, + provide: { + openmct: self.openmct + }, + data() { + return { + model, + onChange + }; + }, + template: `` + }); + + return rowComponent; + } + }; + } +} + diff --git a/src/api/forms/FormsAPI.js b/src/api/forms/FormsAPI.js new file mode 100644 index 0000000000..a455500b9e --- /dev/null +++ b/src/api/forms/FormsAPI.js @@ -0,0 +1,185 @@ +/***************************************************************************** + * 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 FormController from './FormController'; +import FormProperties from './components/FormProperties.vue'; + +import Vue from 'vue'; + +export default class FormsAPI { + constructor(openmct) { + this.openmct = openmct; + this.formController = new FormController(openmct); + } + + /** + * Control View Provider definition for a form control + * @typedef ControlViewProvider + * @property {function} show a function renders view in place of given element + * This function accepts element, model and onChange function + * element - html element (place holder) to render a row view + * model - row data for rendering name, value etc for given row type + * onChange - an onChange event callback funtion to keep track of any change in value + * @property {function} destroy a callback function when a vue component gets destroyed + */ + + /** + * Create a new form control definition with a formControlViewProvider + * this formControlViewProvider is used inside form overlay to show/render a form row + * + * @public + * @param {String} controlName a form structure, array of section + * @param {ControlViewProvider} controlViewProvider + */ + addNewFormControl(controlName, controlViewProvider) { + this.formController.addControl(controlName, controlViewProvider); + } + + /** + * Get a ControlViewProvider for a given/stored form controlName + * + * @public + * @param {String} controlName a form structure, array of section + * @return {ControlViewProvider} + */ + getFormControl(controlName) { + return this.formController.getControl(controlName); + } + + /** + * Section definition for formStructure + * @typedef Section + * @property {object} name Name of the section to display on Form + * @property {string} cssClass class name for styling section + * @property {array} rows collection of rows inside a section + */ + + /** + * Row definition for Section + * @typedef Row + * @property {string} control represents type of row to render + * eg:autocomplete,composite,datetime,file-input,locator,numberfield,select,textarea,textfield + * @property {string} cssClass class name for styling this row + * @property {module:openmct.DomainObject} domainObject object to be used by row + * @property {string} key id for this row + * @property {string} name Name of the row to display on Form + * @property {module:openmct.DomainObject} parent parent object to be used by row + * @property {boolean} required is this row mandatory + * @property {function} validate a function to validate this row on any changes + */ + + /** + * Show form inside an Overlay dialog with given form structure + * + * @public + * @param {Array
} formStructure a form structure, array of section + * @param {Object} options + * @property {HTMLElement} element Parent Element to render a Form + * @property {function} onChange a callback function when any changes detected + * @property {function} onSave a callback function when form is submitted + * @property {function} onDismiss a callback function when form is dismissed + */ + showForm(formStructure, { + element, + onChange + } = {}) { + const changes = {}; + let overlay; + let onDismiss; + let onSave; + + const promise = new Promise((resolve, reject) => { + onSave = onFormSave(resolve); + onDismiss = onFormDismiss(reject); + }); + + const vm = new Vue({ + components: { FormProperties }, + provide: { + openmct: this.openmct + }, + data() { + return { + formStructure, + onChange: onFormPropertyChange, + onDismiss, + onSave + }; + }, + template: '' + }).$mount(); + + const formElement = vm.$el; + if (element) { + element.append(formElement); + } else { + overlay = this.openmct.overlays.overlay({ + element: vm.$el, + size: 'small', + onDestroy: () => vm.$destroy() + }); + } + + function onFormPropertyChange(data) { + if (onChange) { + onChange(data); + } + + if (data.model) { + const property = data.model.property; + let key = data.model.key; + + if (property && property.length) { + key = property.join('.'); + } + + changes[key] = data.value; + } + } + + function onFormDismiss(dismiss) { + return () => { + if (element) { + formElement.remove(); + } else { + overlay.dismiss(); + } + + if (dismiss) { + dismiss(); + } + }; + } + + function onFormSave(save) { + return () => { + overlay.dismiss(); + + if (save) { + save(changes); + } + }; + } + + return promise; + } +} diff --git a/src/api/forms/components/FormProperties.vue b/src/api/forms/components/FormProperties.vue new file mode 100644 index 0000000000..9c4e7d1db7 --- /dev/null +++ b/src/api/forms/components/FormProperties.vue @@ -0,0 +1,137 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/FormRow.vue b/src/api/forms/components/FormRow.vue new file mode 100644 index 0000000000..c69c81c8af --- /dev/null +++ b/src/api/forms/components/FormRow.vue @@ -0,0 +1,146 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/AutoCompleteField.vue b/src/api/forms/components/controls/AutoCompleteField.vue new file mode 100644 index 0000000000..9f495fb9f7 --- /dev/null +++ b/src/api/forms/components/controls/AutoCompleteField.vue @@ -0,0 +1,181 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/ClockDisplayFormatField.vue b/src/api/forms/components/controls/ClockDisplayFormatField.vue new file mode 100644 index 0000000000..9f83e7a668 --- /dev/null +++ b/src/api/forms/components/controls/ClockDisplayFormatField.vue @@ -0,0 +1,66 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/Composite.vue b/src/api/forms/components/controls/Composite.vue new file mode 100644 index 0000000000..4e72ed34b2 --- /dev/null +++ b/src/api/forms/components/controls/Composite.vue @@ -0,0 +1,57 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/CompositeItem.vue b/src/api/forms/components/controls/CompositeItem.vue new file mode 100644 index 0000000000..cb107f9cb7 --- /dev/null +++ b/src/api/forms/components/controls/CompositeItem.vue @@ -0,0 +1,75 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/Datetime.vue b/src/api/forms/components/controls/Datetime.vue new file mode 100644 index 0000000000..ed4a0c1d04 --- /dev/null +++ b/src/api/forms/components/controls/Datetime.vue @@ -0,0 +1,169 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/FileInput.vue b/src/api/forms/components/controls/FileInput.vue new file mode 100644 index 0000000000..664720f539 --- /dev/null +++ b/src/api/forms/components/controls/FileInput.vue @@ -0,0 +1,100 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/Locator.vue b/src/api/forms/components/controls/Locator.vue new file mode 100644 index 0000000000..d027885516 --- /dev/null +++ b/src/api/forms/components/controls/Locator.vue @@ -0,0 +1,56 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/NumberField.vue b/src/api/forms/components/controls/NumberField.vue new file mode 100644 index 0000000000..0f2d982d48 --- /dev/null +++ b/src/api/forms/components/controls/NumberField.vue @@ -0,0 +1,63 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/SelectField.vue b/src/api/forms/components/controls/SelectField.vue new file mode 100644 index 0000000000..8ffbcfca5a --- /dev/null +++ b/src/api/forms/components/controls/SelectField.vue @@ -0,0 +1,64 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/TextAreaField.vue b/src/api/forms/components/controls/TextAreaField.vue new file mode 100644 index 0000000000..83e24745a9 --- /dev/null +++ b/src/api/forms/components/controls/TextAreaField.vue @@ -0,0 +1,62 @@ +/***************************************************************************** +* 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. +*****************************************************************************/ + + + + diff --git a/src/api/forms/components/controls/TextField.vue b/src/api/forms/components/controls/TextField.vue new file mode 100644 index 0000000000..60eaa3c931 --- /dev/null +++ b/src/api/forms/components/controls/TextField.vue @@ -0,0 +1,61 @@ +/***************************************************************************** + * 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. + *****************************************************************************/ + + + + diff --git a/platform/commonUI/edit/src/creation/CreationPolicy.js b/src/exporters/JSONExporter.js similarity index 72% rename from platform/commonUI/edit/src/creation/CreationPolicy.js rename to src/exporters/JSONExporter.js index 5a4895f5ac..4baa718c47 100644 --- a/platform/commonUI/edit/src/creation/CreationPolicy.js +++ b/src/exporters/JSONExporter.js @@ -20,24 +20,15 @@ * at runtime from the About dialog for additional information. *****************************************************************************/ -define( - [], - function () { +import {saveAs} from 'file-saver/FileSaver'; - /** - * A policy for determining whether objects of a given type can be - * created. - * @constructor - * @implements {Policy} - * @memberof platform/commonUI/browse - */ - function CreationPolicy() { - } - - CreationPolicy.prototype.allow = function (type) { - return type.hasFeature("creation"); - }; - - return CreationPolicy; +class JSONExporter { + export(obj, options) { + let filename = (options && options.filename) || "test-export.json"; + let jsonText = JSON.stringify(obj); + let blob = new Blob([jsonText], {type: "application/json"}); + saveAs(blob, filename); } -); +} + +export default JSONExporter; diff --git a/src/installDefaultBundles.js b/src/installDefaultBundles.js index b858d57462..3328232e46 100644 --- a/src/installDefaultBundles.js +++ b/src/installDefaultBundles.js @@ -35,7 +35,6 @@ const DEFAULTS = [ 'platform/containment', 'platform/exporters', 'platform/telemetry', - 'platform/forms', 'platform/identity', 'platform/persistence/aggregator', 'platform/policy', @@ -73,7 +72,6 @@ define([ '../platform/entanglement/bundle', '../platform/exporters/bundle', '../platform/features/static-markup/bundle', - '../platform/forms/bundle', '../platform/framework/bundle', '../platform/framework/src/load/Bundle', '../platform/identity/bundle', diff --git a/src/plugins/condition/components/inspector/ConditionalStylesView.vue b/src/plugins/condition/components/inspector/ConditionalStylesView.vue index 851796e7f4..062ac9f35e 100644 --- a/src/plugins/condition/components/inspector/ConditionalStylesView.vue +++ b/src/plugins/condition/components/inspector/ConditionalStylesView.vue @@ -101,12 +101,12 @@