Compare commits

...

11 Commits

9 changed files with 220 additions and 10 deletions

View File

@ -32,6 +32,7 @@ define([
'./policies/AdapterCompositionPolicy',
'./policies/AdaptedViewPolicy',
'./runs/AlternateCompositionInitializer',
'./runs/SelectingNavigationListener',
'text!./templates/adapted-view-template.html'
], function (
legacyRegistry,
@ -45,6 +46,7 @@ define([
AdapterCompositionPolicy,
AdaptedViewPolicy,
AlternateCompositionInitializer,
SelectingNavigationListener,
adaptedViewTemplate
) {
legacyRegistry.register('src/adapter', {
@ -121,6 +123,10 @@ define([
{
implementation: AlternateCompositionInitializer,
depends: ["openmct"]
},
{
implementation: SelectingNavigationListener,
depends: ["navigationService", "openmct"]
}
],
views: [

View File

@ -29,8 +29,9 @@ define([], function () {
}
var domainObject = legacyObject.useCapability('adapter');
var providers = openmct.mainViews.get(domainObject);
$scope.view = providers[0] && providers[0].view(domainObject);
var context = { item: domainObject };
var providers = openmct.mainViews.get(context);
$scope.view = providers[0] && providers[0].view(context);
}
$scope.$watch('domainObject', refresh);

View File

@ -0,0 +1,34 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
define([], function () {
function SelectingNavigationListener(navigationService, openmct) {
var selection = openmct.selection;
navigationService.addListener(function (legacyObject) {
var domainObject = legacyObject.useCapability('adapter');
selection.clear();
selection.add({ item: domainObject });
});
}
return SelectingNavigationListener;
});

View File

@ -0,0 +1,53 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
define(['./InspectorView'], function (InspectorView) {
function InspectorController(selection, region, registry) {
this.selection = selection;
this.region = region;
this.registry = registry;
this.active = false;
this.onChange = this.onChange.bind(this);
}
InspectorController.prototype.onChange = function (context) {
var view = new InspectorView(this.registry, context)
this.region.show(view);
};
InspectorController.prototype.activate = function () {
if (!this.active) {
this.selection.on('change', this.onChange);
this.active = true;
}
};
InspectorController.prototype.deactivate = function () {
if (this.active) {
this.selection.off('change', this.onChange);
this.active = false;
}
};
return InspectorController;
});

View File

@ -0,0 +1,55 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
define([
'text!./inspector-panel.html',
'zepto',
'lodash'
], function (inspectorTemplate, $, _) {
var TEMPLATE = _.template(inspectorTemplate);
function InspectorPanelView(provider, context) {
this.provider = provider;
this.context = context;
}
InspectorPanelView.prototype.show = function (element) {
var html = TEMPLATE(this.provider.metadata(this.context));
var $elements = $(html);
var innerRegion = $elements.find('.inner-region')[0];
$(element).append($elements);
this.destroy();
this.view = this.provider.view(this.context);
this.view.show(innerRegion);
};
InspectorPanelView.prototype.destroy = function () {
if (this.view) {
this.view.destroy();
this.view = undefined;
}
};
return InspectorPanelView;
});

View File

@ -0,0 +1,55 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
define(['zepto', './InspectorPanelView'], function ($, InspectorPanelView) {
function InspectorView(registry, context) {
this.registry = registry;
this.context = context;
this.views = [];
}
InspectorView.prototype.show = function (element) {
var providers = this.registry.get(this.context);
var $ul = $('<ul></ul>');
this.destroy();
this.views = providers.map(function (provider) {
return new InspectorPanelView(provider, this.context);
}.bind(this));
$(element).append($ul);
this.views.foreEach(function (view) {
view.show($ul[0]);
});
};
InspectorView.prototype.destroy = function () {
this.views.forEach(function (view) {
view.destroy();
});
this.views = [];
};
return InspectorView;
});

View File

@ -0,0 +1,4 @@
<li>
<em class="t-inspector-part-header"><%- name %></em>
<div class="inner-region"></div>
</li>

View File

@ -30,7 +30,7 @@ define(['zepto'], function ($) {
var $element = $(htmlElement);
var contextManager = this.contextManager;
var selection = this.selection;
var path = contextManager.path(item, htmlElement);
var context = contextManager.context(item, htmlElement);
function select() {
selection.add(path);
@ -40,7 +40,7 @@ define(['zepto'], function ($) {
var selected = selection.primary();
$element.toggleClass(
'selected',
selected && path.matches(selected)
!!selected && (selected.element === htmlElement)
);
}

View File

@ -34,13 +34,14 @@ define([], function () {
/**
* @private for platform-internal use
* @param {*} item the object to be viewed
* @param {module:openmct.Context} context the view's context,
* which includes the item being viewed
* @returns {module:openmct.ViewProvider[]} any providers
* which can provide views of this object
*/
ViewRegistry.prototype.get = function (item) {
ViewRegistry.prototype.get = function (context) {
return this.providers.filter(function (provider) {
return provider.canView(item);
return provider.canView(context);
});
};
@ -105,8 +106,8 @@ define([], function () {
*
* @method canView
* @memberof module:openmct.ViewProvider#
* @param {module:openmct.DomainObject} domainObject the domain object
* to be viewed
* @param {module:openmct.Context} context the view's context,
* which includes the item being viewed
* @returns {boolean} true if this domain object can be viewed using
* this provider
*/
@ -122,7 +123,8 @@ define([], function () {
*
* @method view
* @memberof module:openmct.ViewProvider#
* @param {*} object the object to be viewed
* @param {module:openmct.Context} context the view's context,
* which includes the item being viewed
* @returns {module:openmct.View} a view of this domain object
*/