[Plots] #638 New plot display options
This commit is contained in:
57
platform/commonUI/regions/src/EditableRegionPolicy.js
Normal file
57
platform/commonUI/regions/src/EditableRegionPolicy.js
Normal file
@@ -0,0 +1,57 @@
|
||||
/*****************************************************************************
|
||||
* 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(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* A policy for determining whether a region part should be visible or
|
||||
* not, based on its editability and the current state of the domain
|
||||
* object .
|
||||
* @constructor
|
||||
* @implements {Policy}
|
||||
* @memberof platform/commonUI/regions
|
||||
*/
|
||||
function EditableRegionPolicy() {
|
||||
}
|
||||
|
||||
EditableRegionPolicy.prototype.allow = function (regionPart, domainObject) {
|
||||
if (!regionPart.modes){
|
||||
return true;
|
||||
}
|
||||
if (domainObject.getCapability('status').get('editing')){
|
||||
//If the domain object is in edit mode, only include a part
|
||||
// if it is marked editable
|
||||
return regionPart.modes.indexOf('edit') != -1;
|
||||
} else {
|
||||
//If the domain object is not in edit mode, return any parts
|
||||
// that are not explicitly marked editable
|
||||
return regionPart.modes.indexOf('browse') != -1;
|
||||
}
|
||||
};
|
||||
|
||||
return EditableRegionPolicy;
|
||||
}
|
||||
);
|
||||
94
platform/commonUI/regions/src/Region.js
Normal file
94
platform/commonUI/regions/src/Region.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/*****************************************************************************
|
||||
* 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,window*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @typeDef {object} PartContents
|
||||
* @property {string} key If the part is defined as a
|
||||
* representation, the key corresponding to the representation.
|
||||
* @memberOf platform/commonUI/regions
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typeDef {object} RegionPart
|
||||
* @property {string} name A unique name for this region part
|
||||
* @property {PartContents} content the details of the region part
|
||||
* being defined
|
||||
* @property {Array<string>} [modes] the modes that this region part
|
||||
* should be included in. Options are 'edit' and 'browse'. By
|
||||
* default, will be included in both. Inclusion of region parts is
|
||||
* determined by policies of category 'region'. By default, the
|
||||
* {EditableRegionPolicy} will be applied.
|
||||
* @memberOf platform/commonUI/regions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines the interface for a screen region. A screen region is a
|
||||
* section of the browse an edit screens for an object. Regions are
|
||||
* declared in object type definitions.
|
||||
* @memberOf platform/commonUI/regions
|
||||
* @abstract
|
||||
* @constructor
|
||||
*/
|
||||
function Region() {
|
||||
this.parts = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a part to this region.
|
||||
* @param {RegionPart} part the part to add
|
||||
* @param {number} [index] the position to insert the part. By default
|
||||
* will add to the end
|
||||
*/
|
||||
Region.prototype.addPart = function (part, index){
|
||||
if (index) {
|
||||
this.parts.splice(index, 0, part);
|
||||
} else {
|
||||
this.parts.push(part);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes a part from this region.
|
||||
* @param {RegionPart} part the part to add
|
||||
* @param {number} [index] the position to insert the part. By default
|
||||
* will add to the end
|
||||
*/
|
||||
Region.prototype.removePart = function (part){
|
||||
if (typeof part === 'number') {
|
||||
this.parts.splice(part, 1);
|
||||
} else if (typeof part === 'string'){
|
||||
this.parts
|
||||
}
|
||||
else {
|
||||
this.parts.splice(this.parts.indexOf(part), 1);
|
||||
}
|
||||
};
|
||||
|
||||
return Region;
|
||||
}
|
||||
);
|
||||
64
platform/commonUI/regions/src/RegionController.js
Normal file
64
platform/commonUI/regions/src/RegionController.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/*****************************************************************************
|
||||
* 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,Promise*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* The RegionController adds region data for a domain object's type
|
||||
* to the scope.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function RegionController($scope, policyService) {
|
||||
var domainObject = $scope.domainObject,
|
||||
typeCapability = domainObject.getCapability('type');
|
||||
|
||||
/**
|
||||
* TODO: Refactor this out, probably to a directive.
|
||||
* Or, alternatively, could have a regionCapability that returns
|
||||
* regions and parts filtered for applicability to current
|
||||
* object state.
|
||||
* @param regions
|
||||
* @returns {*}
|
||||
*/
|
||||
function filterParts(regions) {
|
||||
//Dupe so we're not modifying the type definition.
|
||||
var filteredRegions = {};
|
||||
for (var regionName in regions) {
|
||||
filteredRegions[regionName] = Object.create(regions[regionName]);
|
||||
filteredRegions[regionName].parts = regions[regionName].parts.filter(function(part){
|
||||
return policyService.allow('region', part, domainObject);
|
||||
});
|
||||
}
|
||||
return filteredRegions;
|
||||
}
|
||||
|
||||
$scope.regions = filterParts(typeCapability.getDefinition().regions);
|
||||
}
|
||||
|
||||
return RegionController;
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user