Commit 39c18023 authored by Robert Knight's avatar Robert Knight

Remove AnnotationUIController

All of the functionality in this module is either unused or duplicated
elsewhere:

 * The $scope.{selectedAnnotations, focusedAnnotations,
   selectedAnnotationsCount} properties were unused.

   Note that there is a very similarly named `selectedAnnotationCount`
   scope property defined in `WidgetController` which _is_ used

 * The ANNOTATION_DELETED event handler duplicated another one in
   root-thread.js
parent b7e3b350
'use strict';
var events = require('./events');
/** Watch the UI state and update scope properties. */
// @ngInject
function AnnotationUIController($rootScope, $scope, annotationUI) {
annotationUI.subscribe(function () {
var state = annotationUI.getState();
$scope.selectedAnnotations = state.selectedAnnotationMap;
if (state.selectedAnnotationMap) {
$scope.selectedAnnotationsCount =
Object.keys(state.selectedAnnotationMap).length;
} else {
$scope.selectedAnnotationsCount = 0;
}
$scope.focusedAnnotations = state.focusedAnnotationMap;
});
$scope.$on(events.ANNOTATION_DELETED, function (event, annotation) {
annotationUI.removeSelectedAnnotation(annotation.id);
});
}
module.exports = AnnotationUIController;
......@@ -23,11 +23,10 @@ function authStateFromUserID(userid) {
// @ngInject
module.exports = function AppController(
$controller, $document, $location, $rootScope, $route, $scope,
$document, $location, $rootScope, $route, $scope,
$window, annotationUI, auth, drafts, features, frameSync, groups,
serviceUrl, session, settings, streamer
) {
$controller('AnnotationUIController', {$scope: $scope});
// This stores information about the current user's authentication status.
// When the controller instantiates we do not yet know if the user is
......
......@@ -122,7 +122,6 @@ module.exports = angular.module('h', [
'ngRaven',
])
.controller('AnnotationUIController', require('./annotation-ui-controller'))
.controller('AnnotationViewerController', require('./annotation-viewer-controller'))
.controller('StreamController', require('./stream-controller'))
.controller('WidgetController', require('./widget-controller'))
......
'use strict';
var angular = require('angular');
var annotationUIFactory = require('../annotation-ui');
describe('AnnotationUIController', function () {
var $scope;
var $rootScope;
var annotationUI;
var sandbox;
before(function () {
angular.module('h', [])
.controller('AnnotationUIController',
require('../annotation-ui-controller'));
});
beforeEach(angular.mock.module('h'));
beforeEach(angular.mock.inject(function ($controller, _$rootScope_) {
sandbox = sinon.sandbox.create();
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
$scope.search = {};
annotationUI = annotationUIFactory($rootScope, {});
$controller('AnnotationUIController', {
$scope: $scope,
annotationUI: annotationUI,
});
}));
afterEach(function () {
sandbox.restore();
});
it('updates the view when the selection changes', function () {
annotationUI.selectAnnotations(['1','2']);
assert.deepEqual($scope.selectedAnnotations, { 1: true, 2: true });
});
it('updates the selection counter when the selection changes', function () {
annotationUI.selectAnnotations(['1','2']);
assert.deepEqual($scope.selectedAnnotationsCount, 2);
});
it('clears the selection when no annotations are selected', function () {
annotationUI.selectAnnotations([]);
assert.deepEqual($scope.selectedAnnotations, null);
assert.deepEqual($scope.selectedAnnotationsCount, 0);
});
it('updates the focused annotations when the focus map changes', function () {
annotationUI.focusAnnotations(['1', '2']);
assert.deepEqual($scope.focusedAnnotations, { 1: true, 2: true });
});
describe('on annotationDeleted', function () {
it('removes the deleted annotation from the selection', function () {
annotationUI.selectAnnotations(['1']);
$rootScope.$broadcast('annotationDeleted', { id: 1 });
assert.equal(annotationUI.getState().selectedAnnotationMap, null);
});
});
});
......@@ -45,8 +45,7 @@ describe('AppController', function () {
}));
angular.module('h', [])
.controller('AppController', AppController)
.controller('AnnotationUIController', angular.noop);
.controller('AppController', AppController);
});
beforeEach(angular.mock.module('h'));
......
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