mirror of
https://github.com/nasa/openmct.git
synced 2025-05-31 06:31:04 +00:00
[Tree] Begin separating out TreeView
This commit is contained in:
parent
3b0a3733b4
commit
ece8f7fded
32
platform/commonUI/general/res/templates/tree/node.html
Normal file
32
platform/commonUI/general/res/templates/tree/node.html
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<li>
|
||||||
|
<span
|
||||||
|
class="tree-item menus-to-left"
|
||||||
|
ng-class="{selected: treeNode.isSelected()}"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class='ui-symbol view-control flex-elem'
|
||||||
|
ng-class="{ 'has-children': model.composition !== undefined, expanded: toggle.isActive() }"
|
||||||
|
ng-click="toggle.toggle(); treeNode.trackExpansion()"
|
||||||
|
>
|
||||||
|
</span>
|
||||||
|
<mct-representation
|
||||||
|
class="rep-object-label"
|
||||||
|
key="'label'"
|
||||||
|
mct-object="domainObject"
|
||||||
|
parameters="{suppressMenuOnEdit: true}"
|
||||||
|
ng-click="treeNode.select()"
|
||||||
|
>
|
||||||
|
</mct-representation>
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="tree-item-subtree"
|
||||||
|
ng-show="toggle.isActive()"
|
||||||
|
ng-if="model.composition !== undefined"
|
||||||
|
>
|
||||||
|
<mct-representation key="'subtree'"
|
||||||
|
ng-model="ngModel"
|
||||||
|
parameters="parameters"
|
||||||
|
mct-object="treeNode.hasBeenExpanded() && domainObject">
|
||||||
|
</mct-representation>
|
||||||
|
</span>
|
||||||
|
</li>
|
@ -22,39 +22,19 @@
|
|||||||
/*global define*/
|
/*global define*/
|
||||||
|
|
||||||
define([
|
define([
|
||||||
'text!../../res/templates/subtree.html'
|
'text!../../res/templates/subtree.html',
|
||||||
], function (subtreeTemplate) {
|
'text!../../res/templates/tree/node.html'
|
||||||
function MCTTreeController($scope, $element) {
|
], function (subtreeTemplate, nodeTemplate) {
|
||||||
var ul = elem.filter('ul'),
|
function MCTTreeController($scope, $element, $compile) {
|
||||||
|
var ul = $element.filter('ul'),
|
||||||
|
makeNode = $compile(nodeTemplate),
|
||||||
activeObject,
|
activeObject,
|
||||||
unlisten;
|
unlisten;
|
||||||
|
|
||||||
function addNodes(domainObjects) {
|
|
||||||
domainObjects.forEach(function (addNode));
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadComposition(domainObject) {
|
|
||||||
activeObject = domainObject;
|
|
||||||
ul.empty();
|
|
||||||
if (domainObject.hasCapability('composition')) {
|
|
||||||
// TODO: Add pending indicator
|
|
||||||
domainObject.useCapability('composition')
|
|
||||||
.then(addNodes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeObject(domainObject) {
|
|
||||||
if (unlisten) {
|
|
||||||
unlisten();
|
|
||||||
}
|
|
||||||
|
|
||||||
unlisten = domainObject.getCapability('mutation')
|
$scope.$watch('mctObject', changeObject);
|
||||||
.listen(loadComposition);
|
|
||||||
|
|
||||||
loadComposition(domainObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
scope.$watch('mctObject', changeObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function MCTTree() {
|
function MCTTree() {
|
||||||
@ -63,11 +43,12 @@ define([
|
|||||||
controller: [
|
controller: [
|
||||||
'$scope',
|
'$scope',
|
||||||
'$element',
|
'$element',
|
||||||
|
'$compile',
|
||||||
MCTTreeController
|
MCTTreeController
|
||||||
],
|
],
|
||||||
require: [ "mctTree" ],
|
require: [ "mctTree" ],
|
||||||
scope: { mctObject: "=" },
|
scope: { mctObject: "=" },
|
||||||
template: subtreeTemplate
|
template: ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
0
platform/commonUI/general/src/ui/TreeNodeView.js
Normal file
0
platform/commonUI/general/src/ui/TreeNodeView.js
Normal file
98
platform/commonUI/general/src/ui/TreeView.js
Normal file
98
platform/commonUI/general/src/ui/TreeView.js
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define([
|
||||||
|
'angular'
|
||||||
|
], function (angular, TreeNodeView) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var $ = angular.element.bind(angular);
|
||||||
|
|
||||||
|
function TreeView() {
|
||||||
|
this.ul = $('<ul>');
|
||||||
|
this.ul.addClass('tree');
|
||||||
|
this.nodeViews = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
TreeView.prototype.setSize = function (sz) {
|
||||||
|
var nodeView;
|
||||||
|
|
||||||
|
while (this.nodeViews.length < sz) {
|
||||||
|
nodeView = new TreeNodeView();
|
||||||
|
this.nodeViews.push(nodeView);
|
||||||
|
this.ul.append($(nodeView.elements()));
|
||||||
|
}
|
||||||
|
|
||||||
|
while (this.nodeViews.length > sz) {
|
||||||
|
nodeView = this.nodeViews.pop();
|
||||||
|
$(nodeView.elements()).remove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TreeView.prototype.loadComposition = function (domainObject) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
function addNode(domainObject, index) {
|
||||||
|
self.nodeViews[index].model(domainObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addNodes(domainObjects) {
|
||||||
|
if (domainObject === self.activeObject) {
|
||||||
|
self.setSize(domainObjects.length);
|
||||||
|
domainObjects.forEach(addNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Add pending indicator
|
||||||
|
domainObject.useCapability('composition')
|
||||||
|
.then(addNodes);
|
||||||
|
};
|
||||||
|
|
||||||
|
TreeView.prototype.model = function (domainObject) {
|
||||||
|
if (this.unlisten) {
|
||||||
|
this.unlisten();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.activeObject = domainObject;
|
||||||
|
this.ul.empty();
|
||||||
|
|
||||||
|
if (domainObject && domainObject.hasCapability('composition')) {
|
||||||
|
this.unlisten = domainObject.getCapability('mutation')
|
||||||
|
.listen(this.loadComposition.bind(this));
|
||||||
|
this.loadComposition(domainObject);
|
||||||
|
} else {
|
||||||
|
this.setSize(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @returns {HTMLElement[]}
|
||||||
|
*/
|
||||||
|
TreeView.prototype.elements = function () {
|
||||||
|
return this.ul;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
return TreeView;
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user