Commit cc2ac9a3 authored by Nick Stenning's avatar Nick Stenning

Use new feature client for dynamic feature toggling

Our first attempt at integrating feature flags with the frontend
required a rebuild and redeploy of the extension, which somewhat
defeats the purpose of feature flags. This commit wires up the new
feature client introduced in the preceding commits, allowing feature
toggles to update behaviour of already-deployed clients.
parent 5e1ebc60
...@@ -5,19 +5,24 @@ module.exports = class AppController ...@@ -5,19 +5,24 @@ module.exports = class AppController
this.$inject = [ this.$inject = [
'$controller', '$document', '$location', '$rootScope', '$route', '$scope', '$controller', '$document', '$location', '$rootScope', '$route', '$scope',
'$window', '$window',
'auth', 'drafts', 'identity', 'auth', 'drafts', 'features', 'identity',
'permissions', 'streamer', 'annotationUI', 'permissions', 'streamer', 'annotationUI',
'annotationMapper', 'threading' 'annotationMapper', 'threading'
] ]
constructor: ( constructor: (
$controller, $document, $location, $rootScope, $route, $scope, $controller, $document, $location, $rootScope, $route, $scope,
$window, $window,
auth, drafts, identity, auth, drafts, features, identity,
permissions, streamer, annotationUI, permissions, streamer, annotationUI,
annotationMapper, threading annotationMapper, threading
) -> ) ->
$controller('AnnotationUIController', {$scope}) $controller('AnnotationUIController', {$scope})
# Allow all child scopes to look up feature flags as:
#
# if ($scope.feature('foo')) { ... }
$scope.feature = features.flagEnabled
$scope.auth = auth $scope.auth = auth
isFirstRun = $location.search().hasOwnProperty('firstrun') isFirstRun = $location.search().hasOwnProperty('firstrun')
......
...@@ -78,6 +78,8 @@ setupStreamer = [ ...@@ -78,6 +78,8 @@ setupStreamer = [
$http.defaults.headers.common['X-Client-Id'] = clientId $http.defaults.headers.common['X-Client-Id'] = clientId
] ]
setupFeatures = ['features', (features) -> features.fetch()]
module.exports = angular.module('h', [ module.exports = angular.module('h', [
'angulartics' 'angulartics'
'angulartics.google.analytics' 'angulartics.google.analytics'
...@@ -128,6 +130,7 @@ module.exports = angular.module('h', [ ...@@ -128,6 +130,7 @@ module.exports = angular.module('h', [
.service('bridge', require('./bridge')) .service('bridge', require('./bridge'))
.service('crossframe', require('./cross-frame')) .service('crossframe', require('./cross-frame'))
.service('drafts', require('./drafts')) .service('drafts', require('./drafts'))
.service('features', require('./features'))
.service('flash', require('./flash')) .service('flash', require('./flash'))
.service('formRespond', require('./form-respond')) .service('formRespond', require('./form-respond'))
.service('host', require('./host')) .service('host', require('./host'))
...@@ -155,6 +158,7 @@ module.exports = angular.module('h', [ ...@@ -155,6 +158,7 @@ module.exports = angular.module('h', [
.config(configureRoutes) .config(configureRoutes)
.config(configureTemplates) .config(configureTemplates)
.run(setupFeatures)
.run(setupCrossFrame) .run(setupCrossFrame)
.run(setupStreamer) .run(setupStreamer)
.run(setupHost) .run(setupHost)
...@@ -11,6 +11,7 @@ describe 'AppController', -> ...@@ -11,6 +11,7 @@ describe 'AppController', ->
fakeAnnotationUI = null fakeAnnotationUI = null
fakeAuth = null fakeAuth = null
fakeDrafts = null fakeDrafts = null
fakeFeatures = null
fakeIdentity = null fakeIdentity = null
fakeLocation = null fakeLocation = null
fakeParams = null fakeParams = null
...@@ -54,6 +55,11 @@ describe 'AppController', -> ...@@ -54,6 +55,11 @@ describe 'AppController', ->
discard: sandbox.spy() discard: sandbox.spy()
} }
fakeFeatures = {
fetch: sandbox.spy()
flagEnabled: sandbox.stub().returns(false)
}
fakeIdentity = { fakeIdentity = {
watch: sandbox.spy() watch: sandbox.spy()
request: sandbox.spy() request: sandbox.spy()
...@@ -97,6 +103,7 @@ describe 'AppController', -> ...@@ -97,6 +103,7 @@ describe 'AppController', ->
$provide.value 'annotationUI', fakeAnnotationUI $provide.value 'annotationUI', fakeAnnotationUI
$provide.value 'auth', fakeAuth $provide.value 'auth', fakeAuth
$provide.value 'drafts', fakeDrafts $provide.value 'drafts', fakeDrafts
$provide.value 'features', fakeFeatures
$provide.value 'identity', fakeIdentity $provide.value 'identity', fakeIdentity
$provide.value '$location', fakeLocation $provide.value '$location', fakeLocation
$provide.value '$routeParams', fakeParams $provide.value '$routeParams', fakeParams
......
<div class="tab-pane" title="Notifications"> <div ng-if="feature('notification')" class="tab-pane" title="Notifications">
<form class="account-form form" name="notificationsForm"> <form class="account-form form" name="notificationsForm">
<p class="form-description">Receive notification emails when:</p> <p class="form-description">Receive notification emails when:</p>
<div class="form-field form-checkbox-list"> <div class="form-field form-checkbox-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