From 51c9328dfd325d3988d5dd2ce64be0ec83849e6c Mon Sep 17 00:00:00 2001 From: Deep Tailor Date: Tue, 23 Jun 2020 14:39:19 -0700 Subject: [PATCH] working new folder action --- src/MCT.js | 1 + .../newFolderAction/newFolderAction.js | 80 +++++++++++++++++++ src/plugins/newFolderAction/plugin.js | 30 +++++++ src/plugins/plugins.js | 7 +- 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 src/plugins/newFolderAction/newFolderAction.js create mode 100644 src/plugins/newFolderAction/plugin.js diff --git a/src/MCT.js b/src/MCT.js index f219368c97..7192db2ff0 100644 --- a/src/MCT.js +++ b/src/MCT.js @@ -268,6 +268,7 @@ define([ this.install(this.plugins.ConditionWidget()); this.install(this.plugins.URLTimeSettingsSynchronizer()); this.install(this.plugins.NotificationIndicator()); + this.install(this.plugins.NewFolderAction()); } MCT.prototype = Object.create(EventEmitter.prototype); diff --git a/src/plugins/newFolderAction/newFolderAction.js b/src/plugins/newFolderAction/newFolderAction.js new file mode 100644 index 0000000000..1c017d36af --- /dev/null +++ b/src/plugins/newFolderAction/newFolderAction.js @@ -0,0 +1,80 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2020, 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 uuid from 'uuid'; + +export default class NewFolderAction { + constructor(openmct) { + this.name = 'New Folder'; + this.key = 'newFolder'; + this.description = 'Create a new folder'; + this.cssClass = 'icon-folder'; + + this._openmct = openmct; + this._dialogService = openmct.$injector.get('dialogService'); + this._folderType = openmct.types.get('folder'); + this._dialogForm = { + name: "New Folder Name", + sections: [ + { + rows: [ + { + key: "name", + control: "textfield", + name: "Folder Name", + required: false + } + ] + } + ] + }; + } + invoke(objectPath) { + let domainObject = objectPath[0], + parentKeystring = this._openmct.objects.makeKeyString(domainObject.identifier), + composition = this._openmct.composition.get(domainObject); + + this._dialogService.getUserInput(this._dialogForm, {}).then((userInput) => { + let name = userInput.name, + identifier = { + key: uuid(), + namespace: domainObject.identifier.namespace + }, + objectModel = { + identifier, + type: 'folder', + location: parentKeystring + }; + + this._folderType.definition.initialize(objectModel); + objectModel.name = name; + + this._openmct.objects.mutate(objectModel, 'created', Date.now()); + composition.add(objectModel); + }); + } + appliesTo(objectPath) { + let domainObject = objectPath[0]; + + return domainObject.type === 'folder'; + } +} diff --git a/src/plugins/newFolderAction/plugin.js b/src/plugins/newFolderAction/plugin.js new file mode 100644 index 0000000000..21bf2c4ef9 --- /dev/null +++ b/src/plugins/newFolderAction/plugin.js @@ -0,0 +1,30 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2018, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +import NewFolderAction from './newFolderAction'; + +export default function () { + return function (openmct) { + openmct.on('start', () => { + openmct.contextMenu.registerAction(new NewFolderAction(openmct)); + }); + }; +} diff --git a/src/plugins/plugins.js b/src/plugins/plugins.js index 504aa89d8e..ab6b4c9e30 100644 --- a/src/plugins/plugins.js +++ b/src/plugins/plugins.js @@ -53,7 +53,8 @@ define([ './themes/maelstrom', './themes/snow', './URLTimeSettingsSynchronizer/plugin', - './notificationIndicator/plugin' + './notificationIndicator/plugin', + './newFolderAction/plugin' ], function ( _, UTCTimeSystem, @@ -87,7 +88,8 @@ define([ Maelstrom, Snow, URLTimeSettingsSynchronizer, - NotificationIndicator + NotificationIndicator, + NewFolderAction ) { var bundleMap = { LocalStorage: 'platform/persistence/local', @@ -198,6 +200,7 @@ define([ plugins.ConditionWidget = ConditionWidgetPlugin.default; plugins.URLTimeSettingsSynchronizer = URLTimeSettingsSynchronizer.default; plugins.NotificationIndicator = NotificationIndicator.default; + plugins.NewFolderAction = NewFolderAction.default; return plugins; });