[Plots] #638 added onchange handling in order to synchronize forms with domain object model.
Fixed failing test Added tests jslint errors Minor refactoring of layout bundle revert layout/bundle.json
This commit is contained in:
@@ -295,7 +295,7 @@ define([
|
||||
"provides": "typeService",
|
||||
"type": "decorator",
|
||||
"implementation": TypeRegionDecorator
|
||||
},
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
|
||||
@@ -62,7 +62,7 @@ define(
|
||||
}
|
||||
};
|
||||
this.addPart(metadataPart, 0);
|
||||
}
|
||||
};
|
||||
|
||||
return InspectorRegion;
|
||||
}
|
||||
|
||||
@@ -29,16 +29,17 @@ define(
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Adds default screen regions to Type definitions. Screen regions
|
||||
* are sections of the browse and edit view of an object that can be
|
||||
* customized on a per-type basis. Within {@link Region}s are {@link RegionPart}s.
|
||||
* Policies can be used to decide which parts are visible or not based on object state.
|
||||
* Adds default browse screen regions to Type definitions. Screen
|
||||
* regions are sections of the browse and edit view of an object
|
||||
* that can be customized on a per-type basis. Within
|
||||
* {@link Region}s are {@link RegionPart}s. Policies can be used to
|
||||
* decide which parts are visible or not based on object state.
|
||||
* @memberOf platform/commonUI/regions
|
||||
* @see {@link Region}, {@link RegionPart}, {@link EditableRegionPolicy}
|
||||
* @constructor
|
||||
*/
|
||||
function TypeRegionDecorator(typeService) {
|
||||
this.typeService = typeService
|
||||
this.typeService = typeService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,11 +33,11 @@ define(
|
||||
var inspectorRegion;
|
||||
|
||||
beforeEach(function () {
|
||||
inspectorRegion = new InspectorRegion;
|
||||
inspectorRegion = new InspectorRegion();
|
||||
});
|
||||
|
||||
it("creates default region parts", function () {
|
||||
expect(inspectorRegion.parts().length).toBe(2);
|
||||
expect(inspectorRegion.parts.length).toBe(1);
|
||||
});
|
||||
|
||||
});
|
||||
70
platform/commonUI/browse/test/TypeRegionDecoratorSpec.js
Normal file
70
platform/commonUI/browse/test/TypeRegionDecoratorSpec.js
Normal file
@@ -0,0 +1,70 @@
|
||||
/*****************************************************************************
|
||||
* 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,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
/**
|
||||
* MCTIncudeSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
define(
|
||||
["../src/TypeRegionDecorator"],
|
||||
function (TypeRegionDecorator) {
|
||||
"use strict";
|
||||
|
||||
describe("The type region decorator", function () {
|
||||
var typeRegionDecorator,
|
||||
mockTypeService,
|
||||
mockType,
|
||||
mockTypeDefinition;
|
||||
|
||||
beforeEach(function () {
|
||||
mockTypeDefinition = {};
|
||||
|
||||
mockType = jasmine.createSpyObj('type', [
|
||||
'getDefinition'
|
||||
]);
|
||||
mockType.getDefinition.andReturn(mockTypeDefinition);
|
||||
|
||||
mockTypeService = jasmine.createSpyObj('typeService', [
|
||||
'listTypes',
|
||||
'getType'
|
||||
]);
|
||||
mockTypeService.getType.andReturn(mockType);
|
||||
mockTypeService.listTypes.andReturn([mockType]);
|
||||
|
||||
typeRegionDecorator = new TypeRegionDecorator(mockTypeService);
|
||||
});
|
||||
|
||||
it("decorates individual type definitions with basic inspector" +
|
||||
" region", function () {
|
||||
typeRegionDecorator.getType('someType');
|
||||
expect(mockTypeDefinition.regions).toBeDefined();
|
||||
});
|
||||
|
||||
it("decorates all type definitions with basic inspector" +
|
||||
" region", function () {
|
||||
typeRegionDecorator.listTypes();
|
||||
expect(mockTypeDefinition.regions).toBeDefined();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -23,6 +23,7 @@
|
||||
ng-controller="DateTimeFieldController">
|
||||
<input type="text"
|
||||
ng-model="textValue"
|
||||
ng-change="structure.onchange(ngModel[field])"
|
||||
ng-blur="restoreTextValue(); ngBlur()"
|
||||
ng-class="{
|
||||
error: textInvalid ||
|
||||
|
||||
@@ -44,11 +44,11 @@ define(
|
||||
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;
|
||||
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 regionPart.modes.indexOf('browse') !== -1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -74,17 +74,19 @@ define(
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param {RegionPart | number | strnig} part The region part to
|
||||
* remove. If a number, will remove the part at that index. If a
|
||||
* string, will remove the part with the matching name. If an
|
||||
* object, will attempt to remove that object from the Region
|
||||
*/
|
||||
Region.prototype.removePart = function (part){
|
||||
if (typeof part === 'number') {
|
||||
this.parts.splice(part, 1);
|
||||
} else if (typeof part === 'string'){
|
||||
this.parts
|
||||
}
|
||||
else {
|
||||
this.parts = this.parts.filter(function(thisPart) {
|
||||
return thisPart.name !== part;
|
||||
});
|
||||
} else {
|
||||
this.parts.splice(this.parts.indexOf(part), 1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,22 +37,19 @@ define(
|
||||
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.
|
||||
* Filters region parts to only those allowed by region policies
|
||||
* @param regions
|
||||
* @returns {*}
|
||||
* @returns {{}}
|
||||
*/
|
||||
function filterParts(regions) {
|
||||
//Dupe so we're not modifying the type definition.
|
||||
var filteredRegions = {};
|
||||
for (var regionName in regions) {
|
||||
Object.keys(regions).forEach(function(regionName) {
|
||||
filteredRegions[regionName] = Object.create(regions[regionName]);
|
||||
filteredRegions[regionName].parts = regions[regionName].parts.filter(function(part){
|
||||
filteredRegions[regionName].parts = (regions[regionName].parts || []).filter(function(part){
|
||||
return policyService.allow('region', part, domainObject);
|
||||
});
|
||||
}
|
||||
});
|
||||
return filteredRegions;
|
||||
}
|
||||
|
||||
|
||||
75
platform/commonUI/regions/test/EditableRegionPolicySpec.js
Normal file
75
platform/commonUI/regions/test/EditableRegionPolicySpec.js
Normal file
@@ -0,0 +1,75 @@
|
||||
/*****************************************************************************
|
||||
* 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,describe,it,expect,beforeEach,waitsFor,jasmine */
|
||||
|
||||
define(
|
||||
['../src/EditableRegionPolicy'],
|
||||
function (EditableRegionPolicy) {
|
||||
"use strict";
|
||||
|
||||
describe("The editable region policy ", function () {
|
||||
|
||||
var editableRegionPolicy,
|
||||
mockDomainObject,
|
||||
mockStatusCapability,
|
||||
mockBrowseRegionPart = {
|
||||
modes: 'browse'
|
||||
},
|
||||
mockEditRegionPart = {
|
||||
modes: 'edit'
|
||||
},
|
||||
mockAllModesRegionPart = {};
|
||||
|
||||
beforeEach(function(){
|
||||
editableRegionPolicy = new EditableRegionPolicy();
|
||||
|
||||
mockStatusCapability = jasmine.createSpyObj("statusCapability", [
|
||||
"get"
|
||||
]);
|
||||
mockDomainObject = jasmine.createSpyObj("domainObject", [
|
||||
"getCapability"
|
||||
]);
|
||||
mockDomainObject.getCapability.andReturn(mockStatusCapability);
|
||||
});
|
||||
|
||||
it("includes only browse region parts for object not in edit mode", function() {
|
||||
mockStatusCapability.get.andReturn(false);
|
||||
expect(editableRegionPolicy.allow(mockBrowseRegionPart, mockDomainObject)).toBe(true);
|
||||
expect(editableRegionPolicy.allow(mockEditRegionPart, mockDomainObject)).toBe(false);
|
||||
});
|
||||
|
||||
it("includes only edit region parts for object in edit mode", function() {
|
||||
mockStatusCapability.get.andReturn(true);
|
||||
expect(editableRegionPolicy.allow(mockBrowseRegionPart, mockDomainObject)).toBe(false);
|
||||
expect(editableRegionPolicy.allow(mockEditRegionPart, mockDomainObject)).toBe(true);
|
||||
});
|
||||
|
||||
it("includes region parts with no mode specification", function() {
|
||||
mockStatusCapability.get.andReturn(false);
|
||||
expect(editableRegionPolicy.allow(mockAllModesRegionPart, mockDomainObject)).toBe(true);
|
||||
mockStatusCapability.get.andReturn(true);
|
||||
expect(editableRegionPolicy.allow(mockAllModesRegionPart, mockDomainObject)).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
82
platform/commonUI/regions/test/RegionControllerSpec.js
Normal file
82
platform/commonUI/regions/test/RegionControllerSpec.js
Normal file
@@ -0,0 +1,82 @@
|
||||
/*****************************************************************************
|
||||
* 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,describe,it,expect,beforeEach,waitsFor,jasmine */
|
||||
|
||||
define(
|
||||
['../src/RegionController'],
|
||||
function (RegionController) {
|
||||
"use strict";
|
||||
|
||||
describe("The region controller ", function () {
|
||||
var mockScope,
|
||||
mockDomainObject,
|
||||
mockTypeCapability,
|
||||
mockTypeDefinition,
|
||||
mockPolicyService,
|
||||
controller;
|
||||
|
||||
beforeEach(function(){
|
||||
mockTypeDefinition = {
|
||||
regions:
|
||||
{
|
||||
'regionOne': {
|
||||
'parts': [
|
||||
{'name': 'Part One'},
|
||||
{'name': 'Part Two'}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mockTypeCapability = jasmine.createSpyObj('typeCapability', [
|
||||
'getDefinition'
|
||||
]);
|
||||
mockTypeCapability.getDefinition.andReturn(mockTypeDefinition);
|
||||
|
||||
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
||||
'getCapability'
|
||||
]);
|
||||
mockDomainObject.getCapability.andReturn(mockTypeCapability);
|
||||
|
||||
mockPolicyService = jasmine.createSpyObj('policyService', [
|
||||
'allow'
|
||||
]);
|
||||
|
||||
mockScope = {
|
||||
domainObject: mockDomainObject
|
||||
};
|
||||
});
|
||||
|
||||
it("filters out regions disallowed by region policy", function() {
|
||||
mockPolicyService.allow.andReturn(false);
|
||||
controller = new RegionController(mockScope, mockPolicyService);
|
||||
expect(mockScope.regions.regionOne.parts.length).toBe(0);
|
||||
});
|
||||
|
||||
it("does not filter out regions allowed by region policy", function() {
|
||||
mockPolicyService.allow.andReturn(true);
|
||||
controller = new RegionController(mockScope, mockPolicyService);
|
||||
expect(mockScope.regions.regionOne.parts.length).toBe(2);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
107
platform/commonUI/regions/test/RegionSpec.js
Normal file
107
platform/commonUI/regions/test/RegionSpec.js
Normal file
@@ -0,0 +1,107 @@
|
||||
/*****************************************************************************
|
||||
* 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,describe,it,expect,beforeEach,waitsFor,jasmine */
|
||||
|
||||
define(
|
||||
['../src/Region'],
|
||||
function (Region) {
|
||||
"use strict";
|
||||
|
||||
describe("The region class ", function () {
|
||||
|
||||
var region,
|
||||
part2 = {'name': 'part2'};
|
||||
|
||||
beforeEach(function(){
|
||||
region = new Region();
|
||||
region.parts = [
|
||||
{name: 'part1'},
|
||||
{name: 'part3'},
|
||||
{name: 'part4'}
|
||||
];
|
||||
});
|
||||
|
||||
it("adding a region part at a specified index adds it in that" +
|
||||
" position", function() {
|
||||
|
||||
region.addPart(part2, 1);
|
||||
|
||||
expect(region.parts.length).toBe(4);
|
||||
expect(region.parts[1]).toBe(part2);
|
||||
});
|
||||
|
||||
it("adding a region part without an index adds it at the end", function() {
|
||||
var partN = {'name': 'partN'};
|
||||
|
||||
region.addPart(partN);
|
||||
|
||||
expect(region.parts.length).toBe(4);
|
||||
expect(region.parts[region.parts.length-1]).toBe(partN);
|
||||
});
|
||||
|
||||
describe("removing a region part", function(){
|
||||
var partName = "part2";
|
||||
|
||||
beforeEach(function(){
|
||||
region.parts = [
|
||||
{name: 'part1'},
|
||||
part2,
|
||||
{name: 'part3'},
|
||||
{name: 'part4'}
|
||||
];
|
||||
});
|
||||
|
||||
it("with a string matches on region part" +
|
||||
" name", function() {
|
||||
expect(region.parts.length).toBe(4);
|
||||
expect(region.parts.indexOf(part2)).toBe(1);
|
||||
|
||||
region.removePart(partName);
|
||||
|
||||
expect(region.parts.length).toBe(3);
|
||||
expect(region.parts.indexOf(part2)).toBe(-1);
|
||||
});
|
||||
|
||||
it("with a number removes by index", function() {
|
||||
expect(region.parts.length).toBe(4);
|
||||
expect(region.parts.indexOf(part2)).toBe(1);
|
||||
|
||||
region.removePart(1);
|
||||
|
||||
expect(region.parts.length).toBe(3);
|
||||
expect(region.parts.indexOf(part2)).toBe(-1);
|
||||
});
|
||||
|
||||
|
||||
it("with object matches that object", function() {
|
||||
expect(region.parts.length).toBe(4);
|
||||
expect(region.parts.indexOf(part2)).toBe(1);
|
||||
|
||||
region.removePart(part2);
|
||||
|
||||
expect(region.parts.length).toBe(3);
|
||||
expect(region.parts.indexOf(part2)).toBe(-1);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,3 +0,0 @@
|
||||
[
|
||||
"InspectorRegion"
|
||||
]
|
||||
Reference in New Issue
Block a user