Commit 449d4cfc authored by Sheetal Umesh Kumar's avatar Sheetal Umesh Kumar Committed by GitHub

Merge pull request #316 from hypothesis/annotation-viewer-component

Convert AnnotationViewerController to a component
parents 55cc1f0f 84b78431
...@@ -62,8 +62,7 @@ function configureLocation($locationProvider) { ...@@ -62,8 +62,7 @@ function configureLocation($locationProvider) {
function configureRoutes($routeProvider) { function configureRoutes($routeProvider) {
$routeProvider.when('/a/:id', $routeProvider.when('/a/:id',
{ {
controller: 'AnnotationViewerController', template: '<annotation-viewer-content search="search"></annotation-viewer-content>',
template: require('./templates/annotation_viewer_content.html'),
reloadOnSearch: false, reloadOnSearch: false,
resolve: resolve, resolve: resolve,
}); });
...@@ -128,8 +127,6 @@ module.exports = angular.module('h', [ ...@@ -128,8 +127,6 @@ module.exports = angular.module('h', [
'ngRaven', 'ngRaven',
]) ])
.controller('AnnotationViewerController', require('./annotation-viewer-controller'))
// The root component for the application // The root component for the application
.directive('hypothesisApp', require('./directive/app')) .directive('hypothesisApp', require('./directive/app'))
...@@ -137,6 +134,7 @@ module.exports = angular.module('h', [ ...@@ -137,6 +134,7 @@ module.exports = angular.module('h', [
.component('annotation', require('./components/annotation').component) .component('annotation', require('./components/annotation').component)
.component('annotationShareDialog', require('./components/annotation-share-dialog')) .component('annotationShareDialog', require('./components/annotation-share-dialog'))
.component('annotationThread', require('./components/annotation-thread')) .component('annotationThread', require('./components/annotation-thread'))
.component('annotationViewerContent', require('./components/annotation-viewer-content'))
.component('dropdownMenuBtn', require('./components/dropdown-menu-btn')) .component('dropdownMenuBtn', require('./components/dropdown-menu-btn'))
.component('excerpt', require('./components/excerpt')) .component('excerpt', require('./components/excerpt'))
.component('groupList', require('./components/group-list')) .component('groupList', require('./components/group-list'))
......
'use strict'; 'use strict';
var angular = require('angular');
/** /**
* Fetch all annotations in the same thread as `id`. * Fetch all annotations in the same thread as `id`.
* *
...@@ -25,27 +23,25 @@ function fetchThread(store, id) { ...@@ -25,27 +23,25 @@ function fetchThread(store, id) {
} }
// @ngInject // @ngInject
function AnnotationViewerController ( function AnnotationViewerContentController (
$location, $routeParams, $scope, $location, $routeParams, annotationUI, rootThread, streamer, store,
annotationUI, rootThread, streamer, store, streamFilter, annotationMapper streamFilter, annotationMapper
) { ) {
var self = this;
annotationUI.setAppIsSidebar(false); annotationUI.setAppIsSidebar(false);
var id = $routeParams.id; var id = $routeParams.id;
// Provide no-ops until these methods are moved elsewere. They only apply this.search.update = function (query) {
// to annotations loaded into the stream.
$scope.focus = angular.noop;
$scope.search.update = function (query) {
$location.path('/stream').search('q', query); $location.path('/stream').search('q', query);
}; };
annotationUI.subscribe(function () { annotationUI.subscribe(function () {
$scope.rootThread = rootThread.thread(annotationUI.getState()); self.rootThread = rootThread.thread(annotationUI.getState());
}); });
$scope.setCollapsed = function (id, collapsed) { this.setCollapsed = function (id, collapsed) {
annotationUI.setCollapsed(id, collapsed); annotationUI.setCollapsed(id, collapsed);
}; };
...@@ -77,4 +73,11 @@ function AnnotationViewerController ( ...@@ -77,4 +73,11 @@ function AnnotationViewerController (
}); });
} }
module.exports = AnnotationViewerController; module.exports = {
controller: AnnotationViewerContentController,
controllerAs: 'vm',
bindings: {
search: '<',
},
template: require('../templates/annotation_viewer_content.html'),
};
...@@ -30,32 +30,20 @@ function FakeStore(annots) { ...@@ -30,32 +30,20 @@ function FakeStore(annots) {
}; };
} }
describe('AnnotationViewerController', function () { describe('annotationViewerContent', function () {
before(function () { before(function () {
angular.module('h', []) angular.module('h', [])
.controller('AnnotationViewerController', .component('annotationViewerContent',
require('../annotation-viewer-controller')); require('../annotation-viewer-content'));
}); });
beforeEach(angular.mock.module('h')); beforeEach(angular.mock.module('h'));
// Return the $controller service from Angular.
function getControllerService() {
var $controller;
angular.mock.inject(function (_$controller_) {
$controller = _$controller_;
});
return $controller;
}
function createController(opts) { function createController(opts) {
var locals = { var locals = {
$location: {}, $location: {},
$routeParams: { id: 'test_annotation_id' }, $routeParams: { id: 'test_annotation_id' },
$scope: {
search: {},
},
annotationUI: { annotationUI: {
setAppIsSidebar: sinon.stub(), setAppIsSidebar: sinon.stub(),
setCollapsed: sinon.stub(), setCollapsed: sinon.stub(),
...@@ -84,7 +72,14 @@ describe('AnnotationViewerController', function () { ...@@ -84,7 +72,14 @@ describe('AnnotationViewerController', function () {
loadAnnotations: sinon.spy(), loadAnnotations: sinon.spy(),
}, },
}; };
locals.ctrl = getControllerService()('AnnotationViewerController', locals);
var $componentController;
angular.mock.inject(function (_$componentController_) {
$componentController = _$componentController_;
});
locals.ctrl = $componentController('annotationViewerContent', locals, {
search: {},
});
return locals; return locals;
} }
......
<thread-list <thread-list
on-change-collapsed="setCollapsed(id, collapsed)" on-change-collapsed="vm.setCollapsed(id, collapsed)"
on-force-visible="forceVisible(thread)" on-force-visible="vm.forceVisible(thread)"
show-document-info="true" show-document-info="true"
thread="rootThread"> thread="vm.rootThread">
</thread-list> </thread-list>
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