Compare commits

...

11 Commits

Author SHA1 Message Date
Charles Hacskaylo
6ba00486e2 [Frontend] Markup and CSS tweaks
Fixes #1280
Added margin-bottom to .l-inspector-part;
Added class to edit-notes.html;
2017-03-20 10:01:44 -07:00
Evan O'Hara
8e04286e48 [EditNotes] Testing EditNotesCtrl/EditNotesService
Simple test cases added for new classes.

https://github.com/nasa/openmct/issues/1280
2017-03-19 09:28:04 -07:00
Evan O'Hara
9b66d82947 [EditNotes] Revised tests for existing classes
SaveAction and SaveAndStopEditingAction simply needed dependencies
for EditNotesService.  InspectorRegion now expects 3 regions instead
of 1.

https://github.com/nasa/openmct/issues/1280
2017-03-19 09:24:15 -07:00
Evan O'Hara
2432aa238f [EditNotes] Updated the bundle for edit/bundle
The bundle has been updated to reflect the new dependencies.

https://github.com/nasa/openmct/issues/1280
2017-03-19 09:10:39 -07:00
Evan O'Hara
a05a908a7d [EditNotes] SaveAction now calls SaveNotes
SaveAction and SaveAndStopEditingAction now depend on EditNotesService
to allow the saving of the new notes property when these actions are
clicked.

https://github.com/nasa/openmct/issues/1280
2017-03-19 09:09:08 -07:00
Evan O'Hara
56ffab3c66 [EditNotes] Controller updates EditNotesService
EditNotesController now keeps the EditNotesService up to date with
any input the user enters into the textbox.

https://github.com/nasa/openmct/issues/1280
2017-03-19 09:07:37 -07:00
Evan O'Hara
1c1e773932 [EditNotes] Created the EditNotesService
Created the EditNotesService.js to allow for communication between
SaveAction and EditNotesController.

https://github.com/nasa/openmct/issues/1280
2017-03-19 09:06:06 -07:00
Evan O'Hara
bdf2fc4f3d [EditNotes] Added new regions to InspectorRegion
https://github.com/nasa/openmct/issues/1280
2017-03-19 08:41:44 -07:00
Evan O'Hara
113b2d5af3 [EditNotes] Created a new edit-notes region
Created a new edit-notes.html and a corresponding EditNotesController
to be used to replace the notes region when in edit mode.

https://github.com/nasa/openmct/issues/1280
2017-03-19 08:40:11 -07:00
Evan O'Hara
f618259904 [EditNotes] Separated notes from object-properties
Separated notes from object-properties to allow it to be hidden in
edit mode.  A new region will be added for the editable version.

https://github.com/nasa/openmct/issues/1280
2017-03-19 08:30:17 -07:00
Evan O'Hara
4cc37ea108 [EditNotes] Separated notes property to new region
Separated the notes property into a new region in order to allow it to
be hidden when in edit mode.  An editable template will take its place
in edit mode.

https://github.com/nasa/openmct/issues/1280
2017-03-19 08:19:11 -07:00
16 changed files with 454 additions and 9 deletions

View File

@@ -40,6 +40,7 @@ define([
"text!./res/templates/back-arrow.html",
"text!./res/templates/items/items.html",
"text!./res/templates/browse/object-properties.html",
"text!./res/templates/browse/object-notes.html",
"text!./res/templates/browse/inspector-region.html",
'legacyRegistry'
], function (
@@ -62,6 +63,7 @@ define([
backArrowTemplate,
itemsTemplate,
objectPropertiesTemplate,
objectNotesTemplate,
inspectorRegionTemplate,
legacyRegistry
) {
@@ -190,6 +192,10 @@ define([
"key": "object-properties",
"template": objectPropertiesTemplate
},
{
"key": "object-notes",
"template": objectNotesTemplate
},
{
"key": "inspector-region",
"template": inspectorRegionTemplate
@@ -226,7 +232,7 @@ define([
"$window"
],
"group": "windowing",
"cssClass": "icon-new-window",
"cssclass": "icon-new-window",
"priority": "preferred"
},
{
@@ -241,7 +247,7 @@ define([
{
"key": "items",
"name": "Items",
"cssClass": "icon-thumbs-strip",
"cssclass": "icon-thumbs-strip",
"description": "Grid of available items",
"template": itemsTemplate,
"uses": [

View File

@@ -0,0 +1,33 @@
<!--
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.
-->
<div ng-controller="ObjectInspectorController as controller">
<ul class="flex-elem grows l-inspector-part">
<li>
<em class="t-inspector-part-header" title="Notes.">Notes</em>
<div class="value"
ng-repeat="data in metadata"
ng-if="data.name === 'Notes'">
{{ data.value }}
</div>
</li>
</ul>
</div>

View File

@@ -25,7 +25,8 @@
<em class="t-inspector-part-header">Properties</em>
<div class="inspector-properties"
ng-repeat="data in metadata"
ng-class="{ first:$index === 0 }">
ng-class="{ first:$index === 0 }"
ng-if="data.name !== 'Notes'">
<div class="label">{{ data.name }}</div>
<div class="value">{{ data.value }}</div>
</div>

View File

@@ -59,7 +59,25 @@ define(
key: 'object-properties'
}
};
var notesRegion = {
name: 'notes',
title: 'Notes Region',
modes: ['browse'],
content: {
key: 'object-notes'
}
};
var editNotesRegion = {
name: 'editNotes',
title: 'Edit Notes Region',
modes: ['edit'],
content: {
key: 'edit-notes'
}
};
this.addRegion(new Region(metadataRegion), 0);
this.addRegion(new Region(notesRegion), 1);
this.addRegion(new Region(editNotesRegion), 1);
};
return InspectorRegion;

View File

@@ -35,7 +35,7 @@ define(
});
it("creates default region parts", function () {
expect(inspectorRegion.regions.length).toBe(1);
expect(inspectorRegion.regions.length).toBe(3);
});
});

View File

@@ -23,6 +23,7 @@
define([
"./src/controllers/EditActionController",
"./src/controllers/EditPanesController",
"./src/controllers/EditNotesController",
"./src/controllers/ElementsController",
"./src/controllers/EditObjectController",
"./src/actions/EditAndComposeAction",
@@ -41,6 +42,7 @@ define([
"./src/representers/EditToolbarRepresenter",
"./src/capabilities/EditorCapability",
"./src/capabilities/TransactionCapabilityDecorator",
"./src/services/EditNotesService",
"./src/services/TransactionManager",
"./src/services/TransactionService",
"./src/creation/CreateMenuController",
@@ -55,12 +57,14 @@ define([
"text!./res/templates/library.html",
"text!./res/templates/edit-object.html",
"text!./res/templates/edit-action-buttons.html",
"text!./res/templates/edit-notes.html",
"text!./res/templates/elements.html",
"text!./res/templates/topbar-edit.html",
'legacyRegistry'
], function (
EditActionController,
EditPanesController,
EditNotesController,
ElementsController,
EditObjectController,
EditAndComposeAction,
@@ -79,6 +83,7 @@ define([
EditToolbarRepresenter,
EditorCapability,
TransactionCapabilityDecorator,
EditNotesService,
TransactionManager,
TransactionService,
CreateMenuController,
@@ -93,6 +98,7 @@ define([
libraryTemplate,
editObjectTemplate,
editActionButtonsTemplate,
editNotesTemplate,
elementsTemplate,
topbarEditTemplate,
legacyRegistry
@@ -115,6 +121,14 @@ define([
"$scope"
]
},
{
"key": "EditNotesController",
"implementation": EditNotesController,
"depends": [
"$scope",
"editNotesService"
]
},
{
"key": "ElementsController",
"implementation": ElementsController,
@@ -199,7 +213,8 @@ define([
"description": "Save changes made to these objects.",
"depends": [
"dialogService",
"notificationService"
"notificationService",
"editNotesService"
]
},
{
@@ -211,7 +226,8 @@ define([
"description": "Save changes made to these objects.",
"depends": [
"dialogService",
"notificationService"
"notificationService",
"editNotesService"
]
},
{
@@ -289,6 +305,10 @@ define([
"action"
]
},
{
"key": "edit-notes",
"template": editNotesTemplate
},
{
"key": "edit-elements",
"template": elementsTemplate,
@@ -415,6 +435,10 @@ define([
"depends": [
"transactionService"
]
},
{
"key": "editNotesService",
"implementation": EditNotesService
}
]
}

View File

@@ -0,0 +1,27 @@
<!--
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.
-->
<div ng-controller="EditNotesController" class="flex-elem l-flex-col holder grows l-inspector-part">
<em class="t-inspector-part-header" title="Notes">Notes</em>
<span class="field control l-textarea-sm">
<textarea ng-model="notes"></textarea>
</span>
</div>

View File

@@ -34,11 +34,13 @@ define(
function SaveAction(
dialogService,
notificationService,
editNotesService,
context
) {
this.domainObject = (context || {}).domainObject;
this.dialogService = dialogService;
this.notificationService = notificationService;
this.editNotesService = editNotesService;
}
/**
@@ -58,6 +60,8 @@ define(
// used to insulate underlying objects from changes made
// during editing.
function doSave() {
//First save the notes
self.editNotesService.saveNotes(domainObject);
return domainObject.getCapability("editor").save();
}

View File

@@ -34,12 +34,14 @@ define(
function SaveAndStopEditingAction(
dialogService,
notificationService,
editNotesService,
context
) {
this.context = context;
this.domainObject = (context || {}).domainObject;
this.dialogService = dialogService;
this.notificationService = notificationService;
this.editNotesService = editNotesService;
}
/**
@@ -51,7 +53,7 @@ define(
*/
SaveAndStopEditingAction.prototype.perform = function () {
var domainObject = this.domainObject,
saveAction = new SaveAction(this.dialogService, this.notificationService, this.context);
saveAction = new SaveAction(this.dialogService, this.notificationService, this.editNotesService, this.context);
function closeEditor() {
return domainObject.getCapability("editor").finish();

View File

@@ -0,0 +1,60 @@
/**
* Created by EvansDesktop on 2/15/2017.
*/
/*****************************************************************************
* 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(
[],
function () {
/**
* The EditNotesController prepares the edit-notes view for display
* and keeps the editNotesService updated with user input.
* @constructor
*/
function EditNotesController($scope, editNotesService) {
this.editNotesService = editNotesService;
this.properties = $scope.domainObject.useCapability('metadata');
function locateNotesValueInDomainObject(properties) {
var notesValue;
properties.forEach(function(property){
if (property.name === 'Notes'){
notesValue = property.value;
}
});
return notesValue;
}
function sendNotesToController(value){
editNotesService.updateNotesFromController(value);
}
$scope.notes = locateNotesValueInDomainObject(this.properties);
$scope.$watch('notes', sendNotesToController);
}
return EditNotesController;
}
);

View File

@@ -0,0 +1,79 @@
/*****************************************************************************
* 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([],
function () {
/**
* The EditNotesService is responsible for handling communication
* between SaveAction and the EditNotesController as well as persisting
* the notes when a SaveAction is called
*
* @memberof platform/commonUI/edit
* @constructor
*/
function EditNotesService() {
}
/**
* Keeps the EditNotesService in sync with the EditNotesController
* @param (string) value passed in by the EditNotesController
*/
EditNotesService.prototype.updateNotesFromController = function (value) {
this.notes = value;
};
/**
* Updates the notes property in a domain object model based on
* a value given by the edit notes controller.
* @param (DomainObject) The active domainObject that we want to
* mutate
*/
EditNotesService.prototype.saveNotes = function (domainObject) {
if (this.notes != null) {
var type = domainObject.getCapability('type'),
properties = type.getProperties(),
notes = this.notes;
function getNotesIndex() {
var notesIndex;
properties.forEach(function (property, index) {
if (property.getDefinition().key === 'notes') {
notesIndex = index;
}
});
return notesIndex;
}
var notesIndex = getNotesIndex();
// Make sure the object has a notes property before mutation
if (notesIndex != null)
return domainObject.useCapability('mutation', function (model) {
properties[notesIndex].setValue(model, notes);
});
}
};
return EditNotesService;
}
);

View File

@@ -31,6 +31,7 @@ define(
actionContext,
mockDialogService,
mockNotificationService,
mockEditNotesService,
mockActionCapability,
capabilities = {},
action;
@@ -81,6 +82,11 @@ define(
["info", "error"]
);
mockEditNotesService = jasmine.createSpyObj(
"editNotesService",
["saveNotes"]
);
mockDomainObject.hasCapability.andReturn(true);
mockDomainObject.getCapability.andCallFake(function (capability) {
return capabilities[capability];
@@ -89,7 +95,7 @@ define(
mockEditorCapability.save.andReturn(mockPromise(true));
mockEditorCapability.isEditContextRoot.andReturn(true);
action = new SaveAction(mockDialogService, mockNotificationService, actionContext);
action = new SaveAction(mockDialogService, mockNotificationService, mockEditNotesService, actionContext);
});
it("only applies to domain object with an editor capability", function () {

View File

@@ -37,6 +37,7 @@ define(
actionContext,
dialogService,
notificationService,
editNotesService,
mockActionCapability,
capabilities = {},
action;
@@ -86,6 +87,11 @@ define(
["info", "error"]
);
editNotesService = jasmine.createSpyObj(
"editNotesService",
["saveNotes"]
);
mockDomainObject.hasCapability.andReturn(true);
mockDomainObject.getCapability.andCallFake(function (capability) {
return capabilities[capability];
@@ -94,7 +100,7 @@ define(
mockEditorCapability.save.andReturn(mockPromise(true));
mockEditorCapability.isEditContextRoot.andReturn(true);
action = new SaveAndStopEditingAction(dialogService, notificationService, actionContext);
action = new SaveAndStopEditingAction(dialogService, notificationService, editNotesService, actionContext);
});

View File

@@ -0,0 +1,78 @@
/*****************************************************************************
* 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(
["../../src/controllers/EditNotesController"],
function (EditNotesController) {
describe("The Edit Notes controller", function () {
var mockScope,
mockDomainObject,
mockEditNotesService,
controller;
// Utility function; look for a $watch on scope and fire it
function fireWatch(expr, value) {
mockScope.$watch.calls.forEach(function (call) {
if (call.args[0] === expr) {
call.args[1](value);
}
});
}
beforeEach(function () {
mockScope = jasmine.createSpyObj(
"$scope",
["$watch"]
);
mockDomainObject = jasmine.createSpyObj(
"domainObject",
["useCapability"]
);
mockEditNotesService = jasmine.createSpyObj(
"editNotesService",
["updateNotesFromController"]
);
mockScope.domainObject = mockDomainObject;
mockDomainObject.useCapability.andReturn([{
name: "Notes",
value: "Initial Notes"
}]);
controller = new EditNotesController(
mockScope,
mockEditNotesService
);
});
it("keeps the edit notes service updated on the user input", function () {
var newNotes = "Updated Notes";
mockScope.notes = newNotes;
fireWatch("notes", newNotes);
expect(mockEditNotesService.updateNotesFromController).toHaveBeenCalledWith(newNotes);
});
});
}
);

View File

@@ -0,0 +1,100 @@
/*****************************************************************************
* 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(
['../../src/services/EditNotesService'],
function (EditNotesService) {
describe("The Edit Notes Service", function () {
var editNotesService,
mockProperties,
mockDomainObject,
mockType;
beforeEach(function () {
mockDomainObject = jasmine.createSpyObj(
'domainObject',
[
'getCapability',
'useCapability'
]
);
mockType = jasmine.createSpyObj(
'type',
['getProperties']
);
mockDomainObject.getCapability.andReturn(mockType);
editNotesService = new EditNotesService();
});
describe("With a valid domain object", function () {
beforeEach(function() {
mockProperties = [
{key: "x", value: "xyz"},
{key: "y", value: "xyz"},
{key: "notes", value: "xyz"}
].map(function (k) {
return {
getDefinition: function () {
return k;
}
};
});
mockType.getProperties.andReturn(mockProperties);
});
it("mutates an object when saved", function () {
var updatedNotes = "updated notes";
editNotesService.updateNotesFromController(updatedNotes);
editNotesService.saveNotes(mockDomainObject);
expect(mockDomainObject.useCapability).toHaveBeenCalled();
});
});
describe("With an invalid domain object", function () {
beforeEach(function() {
mockProperties = [
{key: "x", value: "xyz"},
{key: "y", value: "xyz"}
].map(function (k) {
return {
getDefinition: function () {
return k.key;
}
};
});
mockType.getProperties.andReturn(mockProperties);
});
it("does not perform a mutation if the domainObject has no notes field", function () {
var updatedNotes = "updated notes";
editNotesService.updateNotesFromController(updatedNotes);
editNotesService.saveNotes(mockDomainObject);
expect(mockDomainObject.useCapability).not.toHaveBeenCalled();
});
});
});
});

View File

@@ -52,6 +52,7 @@
}
.l-inspector-part {
box-sizing: border-box;
margin-bottom: $interiorMarginLg;
padding-right: $interiorMargin;
.tree .form {
margin-left: $treeVCW + $interiorMarginLg;