mirror of
https://github.com/nasa/openmct.git
synced 2025-06-06 01:11:41 +00:00
[Layout] Add LayoutController
Add a controller for Layouts to choose frame positions. WTD-535.
This commit is contained in:
parent
7b1c275dee
commit
4db2febbb3
@ -8,7 +8,8 @@
|
|||||||
"name": "Layout",
|
"name": "Layout",
|
||||||
"glyph": "L",
|
"glyph": "L",
|
||||||
"type": "layout",
|
"type": "layout",
|
||||||
"templateUrl": "templates/layout.html"
|
"templateUrl": "templates/layout.html",
|
||||||
|
"uses": [ "composition" ]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"representations": [
|
"representations": [
|
||||||
@ -17,6 +18,13 @@
|
|||||||
"templateUrl": "templates/frame.html"
|
"templateUrl": "templates/frame.html"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"controllers": [
|
||||||
|
{
|
||||||
|
"key": "LayoutController",
|
||||||
|
"implementation": "LayoutController.js",
|
||||||
|
"depends": [ "$scope" ]
|
||||||
|
}
|
||||||
|
],
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"key": "layout",
|
"key": "layout",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<div class="frame frame-template abs" ng-controller="ViewSwitcherController">
|
<div class="frame frame-template abs">
|
||||||
<div class="bar abs object-header object-top-bar">
|
<div class="bar abs object-header object-top-bar">
|
||||||
<div class="title left abs">
|
<div class="title left abs">
|
||||||
<mct-representation key="'node'"
|
<mct-representation key="'node'"
|
||||||
@ -6,10 +6,10 @@
|
|||||||
</mct-representation>
|
</mct-representation>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-bar right abs">
|
<div class="btn-bar right abs">
|
||||||
<mct-include key="'switcher'"
|
<mct-representation key="'switcher'"
|
||||||
ng-model="switcher"
|
ng-model="representation"
|
||||||
ng-if="switcher.options.length > 0">
|
mct-object="domainObject">
|
||||||
</mct-include>
|
</mct-representation>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="abs object-holder">
|
<div class="abs object-holder">
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
<div style="width: 100%; height: 100%;">
|
<div style="width: 100%; height: 100%;"
|
||||||
|
ng-controller="LayoutController as controller">
|
||||||
|
|
||||||
<span style="left: 45px; width: 360px; top: 60px; height: 240px">
|
<div class='frame child-frame panel abs'
|
||||||
|
ng-repeat="childObject in composition"
|
||||||
|
ng-style="controller.getFrameStyle(childObject.getId())">
|
||||||
|
|
||||||
|
<div class="frame child-frame holder contents abs">
|
||||||
<mct-representation key="'frame'"
|
<mct-representation key="'frame'"
|
||||||
mct-object="domainObject">
|
mct-object="childObject">
|
||||||
</mct-representation>
|
</mct-representation>
|
||||||
</span>
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
59
platform/features/layout/src/LayoutController.js
Normal file
59
platform/features/layout/src/LayoutController.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var DEFAULT_DIMENSIONS = [ 4, 2 ];
|
||||||
|
|
||||||
|
function LayoutController($scope) {
|
||||||
|
var width = 16,
|
||||||
|
height = 16,
|
||||||
|
positions = {};
|
||||||
|
|
||||||
|
function convertPosition(position, dimensions) {
|
||||||
|
return {
|
||||||
|
left: (width * position[0]) + 'px',
|
||||||
|
top: (width * position[1]) + 'px',
|
||||||
|
width: (width * dimensions[0]) + 'px',
|
||||||
|
height: (height * dimensions[1]) + 'px'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function defaultPosition(index) {
|
||||||
|
return convertPosition([index, index], DEFAULT_DIMENSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
function lookupPanels(model) {
|
||||||
|
var configuration =
|
||||||
|
((model || {}).configuration || {}).layout || {};
|
||||||
|
|
||||||
|
// Clear prior positions
|
||||||
|
positions = {};
|
||||||
|
|
||||||
|
// Update width/height that we are tracking
|
||||||
|
|
||||||
|
// Pull values from panels field
|
||||||
|
|
||||||
|
// Add defaults where needed
|
||||||
|
((model || {}).composition || []).forEach(function (id, i) {
|
||||||
|
positions[id] = positions[id] || defaultPosition(i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$scope.$watch("model", lookupPanels);
|
||||||
|
|
||||||
|
return {
|
||||||
|
getFrameStyle: function (id) {
|
||||||
|
return positions[id];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return LayoutController;
|
||||||
|
}
|
||||||
|
);
|
Loading…
x
Reference in New Issue
Block a user