Commit 205efe04 authored by Sean Hammond's avatar Sean Hammond

Don't use vm.annotation.group

The templates read vm.group() (which returns domainModel.group) and never write
any group, so vm.annotation.group just isn't needed.

The controller modifies domainModel.group is the focused group changes while
creating a new annotation.

vm.annotation.group is still there, we just don't use it anymore, in the future
we should not copy it into vm.annotation at all.
parent 9cce6a0b
......@@ -297,11 +297,11 @@ function AnnotationController(
if (isNew(domainModel)) {
var newGroup = groups.focused().id;
var isShared = permissions.isShared(
vm.annotation.permissions, vm.annotation.group);
vm.annotation.permissions, domainModel.group);
if (isShared) {
vm.annotation.permissions = permissions.shared(newGroup);
}
vm.annotation.group = newGroup;
domainModel.group = newGroup;
}
if (drafts.get(domainModel)) {
......@@ -482,7 +482,7 @@ function AnnotationController(
* @returns {Object} The full group object associated with the annotation.
*/
vm.group = function() {
return groups.get(vm.annotation.group);
return groups.get(domainModel.group);
};
/**
......@@ -547,7 +547,7 @@ function AnnotationController(
*/
vm.isShared = function() {
return permissions.isShared(
vm.annotation.permissions, vm.annotation.group);
vm.annotation.permissions, domainModel.group);
};
// Save on Meta + Enter or Ctrl + Enter.
......@@ -679,7 +679,7 @@ function AnnotationController(
if (privacy === 'private') {
vm.annotation.permissions = permissions.private();
} else if (privacy === 'shared') {
vm.annotation.permissions = permissions.shared(vm.annotation.group);
vm.annotation.permissions = permissions.shared(domainModel.group);
}
};
......
......@@ -1506,14 +1506,18 @@ describe('annotation.js', function() {
// annotation.
annotation.id = null;
var controller = createDirective(annotation).controller;
fakeGroups.get = sandbox.stub().returns({id: 'new-group'});
// Change the currently focused group.
fakeGroups.focused = sinon.stub().returns({id: 'new-group'});
$rootScope.$broadcast(events.GROUP_FOCUSED);
var group = controller.group().id;
assert.isTrue(fakeGroups.get.calledOnce);
assert.isTrue(fakeGroups.get.calledWithExactly('new-group'));
assert.equal(
controller.annotation.group,
'new-group',
group, 'new-group',
'It should update the group ID in the view model when the focused ' +
'group changes.');
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment