From 703abe36c9130ed8d24e28257f108dc6ff6680ed Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Mon, 20 Aug 2018 13:20:58 -0700 Subject: [PATCH] tree loads composition Expose legacy types in new API tree navigation --- src/MCT.js | 20 +++++- src/adapter/vue-adapter/main-adapter.js | 2 +- src/api/types/Type.js | 26 +++++++ src/api/types/TypeRegistry.js | 8 +++ src/ui/components/layout/Layout.vue | 46 ------------- src/ui/components/layout/MctTree.vue | 92 ------------------------- src/ui/components/layout/mct-tree.vue | 24 +++++-- src/ui/components/layout/tree-item.vue | 61 ++++++++++++++-- 8 files changed, 128 insertions(+), 151 deletions(-) delete mode 100644 src/ui/components/layout/MctTree.vue diff --git a/src/MCT.js b/src/MCT.js index ef121726c3..dc6e250e3b 100644 --- a/src/MCT.js +++ b/src/MCT.js @@ -281,6 +281,14 @@ define([ this.legacyExtension('types', legacyDefinition); }.bind(this)); + // TODO: move this to adapter bundle. + this.legacyExtension('runs', { + depends: ['types[]'], + implementation: (types) => { + this.types.importLegacyTypes(types); + } + }); + this.objectViews.getAllProviders().forEach(function (p) { this.legacyExtension('views', { key: p.key, @@ -313,8 +321,18 @@ define([ var startPromise = new Main().run(this.legacyRegistry) .then(function (angular) { this.$angular = angular; + // OpenMCT Object provider doesn't operate properly unless + // something has depended upon objectService. Cool, right? + this.$injector.get('objectService'); + console.log('Rendering app layout.'); - var appLayout = new Vue(Layout.default); + + var appLayout = new Vue({ + mixins: [Layout.default], + provide: { + openmct: this + } + }); domElement.appendChild(appLayout.$mount().$el); console.log('Attaching adapter'); diff --git a/src/adapter/vue-adapter/main-adapter.js b/src/adapter/vue-adapter/main-adapter.js index 3db6fa80d1..4ff6fc2767 100644 --- a/src/adapter/vue-adapter/main-adapter.js +++ b/src/adapter/vue-adapter/main-adapter.js @@ -108,8 +108,8 @@ define([ angular.element(this.layout.$refs.mainContainer), this.templateMap["browseObject"] ); + document.title = object.getModel().name; this.scheduleDigest(); - } idsForObject(domainObject) { diff --git a/src/api/types/Type.js b/src/api/types/Type.js index a3ef4c174f..8ede9a25ea 100644 --- a/src/api/types/Type.js +++ b/src/api/types/Type.js @@ -32,6 +32,9 @@ define(function () { */ function Type(definition) { this.definition = definition; + if (definition.key) { + this.key = definition.key; + } } /** @@ -70,5 +73,28 @@ define(function () { return def; }; + /** + * Create a type definition from a legacy definition. + */ + Type.definitionFromLegacyDefinition = function (legacyDefinition) { + let definition = {}; + definition.name = legacyDefinition.name; + definition.cssClass = legacyDefinition.cssClass; + definition.description = legacyDefinition.description; + definition.form = legacyDefinition.properties; + if (legacyDefinition.model) { + definition.initialize = function (model) { + for (let [k, v] of Object.entries(legacyDefinition.model)) { + model[k] = JSON.parse(JSON.stringify(v)); + } + } + } + if (Array.isArray(legacyDefinition.creatable) && 'creation' in legacyDefinition.creatable) { + definition.creatable = true; + } + + return definition; + } + return Type; }); diff --git a/src/api/types/TypeRegistry.js b/src/api/types/TypeRegistry.js index 4e1920bc8b..d6fa9b50b7 100644 --- a/src/api/types/TypeRegistry.js +++ b/src/api/types/TypeRegistry.js @@ -98,6 +98,14 @@ define(['./Type'], function (Type) { return this.types[typeKey]; }; + TypeRegistry.prototype.importLegacyTypes = function (types) { + types.filter((t) => !this.get(t.key)) + .forEach((type) => { + let def = Type.definitionFromLegacyDefinition(type); + this.addType(type.key, def); + }); + } + return TypeRegistry; }); diff --git a/src/ui/components/layout/Layout.vue b/src/ui/components/layout/Layout.vue index 03cf8bc455..35ae3f0684 100644 --- a/src/ui/components/layout/Layout.vue +++ b/src/ui/components/layout/Layout.vue @@ -139,52 +139,6 @@ import pane from '../controls/pane.vue'; export default { - data () { - return { - treeRoots: [ - { - id: 'r1', - name: 'Root 1', - children: [ - { - id: 'r1c1', - name: 'r1c1' - }, - { - id: 'r1c2', - name: 'r1c2' - }, - { - id: 'r1c3', - name: 'r1c3' - }, - ] - },{ - id: 'r2', - name: 'Root 2', - children: [ - { - id: 'r2c1', - name: 'r2c1', - children: [ - { - id: 'r2c1c1', - name: 'r2c1c1' - } - ] - } - ] - },{ - id: 'r3', - name: 'Root 3' - } - ] - } - }, - methods: { - navigateTo(path, openmct) { - } - }, components: { MctInspector, MctMain, diff --git a/src/ui/components/layout/MctTree.vue b/src/ui/components/layout/MctTree.vue deleted file mode 100644 index f64204a528..0000000000 --- a/src/ui/components/layout/MctTree.vue +++ /dev/null @@ -1,92 +0,0 @@ - - - - - diff --git a/src/ui/components/layout/mct-tree.vue b/src/ui/components/layout/mct-tree.vue index 15851c5e46..a0655a95aa 100644 --- a/src/ui/components/layout/mct-tree.vue +++ b/src/ui/components/layout/mct-tree.vue @@ -1,8 +1,8 @@ @@ -74,7 +74,23 @@ import treeItem from './tree-item.vue' export default { - props: ['nodes'], + data() { + return { + children: [] + }; + }, + inject: ['openmct'], + mounted: function () { + this.openmct.objects.get('ROOT') + .then(root => this.openmct.composition.get(root).load()) + .then(children => this.children = children.map((c) => { + return { + id: this.openmct.objects.makeKeyString(c.identifier), + object: c, + path: [c.identifier] + }; + })) + }, name: 'mct-tree', components: { treeItem diff --git a/src/ui/components/layout/tree-item.vue b/src/ui/components/layout/tree-item.vue index 548bc42790..75ff662b3a 100644 --- a/src/ui/components/layout/tree-item.vue +++ b/src/ui/components/layout/tree-item.vue @@ -2,16 +2,18 @@
  • - - {{ node.name }} - + + {{ node.object.name }} +