Commit 07fc65c6 authored by Randall Leeds's avatar Randall Leeds Committed by Aron Carroll

Change session interceptor to a transform

The difference is that, while both get to intercept and handle the
response, only the transform can change the result that updates the
resource instance.

In this way, it's not necessary to copy the response data onto the
scope anymore because the object is updated properly in place rather
than being updated with the wrapped response containing the csrf
token and flash messages and other parasession data.
parent 52a71489
...@@ -48,7 +48,7 @@ class App ...@@ -48,7 +48,7 @@ class App
frame: $scope.frame or @scope.frame frame: $scope.frame or @scope.frame
socialView: annotator.socialView socialView: annotator.socialView
ongoingHighlightSwitch: false ongoingHighlightSwitch: false
model: {} model: session
search: search:
facets: SEARCH_FACETS facets: SEARCH_FACETS
values: SEARCH_VALUES values: SEARCH_VALUES
...@@ -62,7 +62,6 @@ class App ...@@ -62,7 +62,6 @@ class App
angular.extend annotator.options.Store, options angular.extend annotator.options.Store, options
session.$promise.then (data) -> session.$promise.then (data) ->
angular.extend $scope.model, data
unless data.personas?.length unless data.personas?.length
$scope.initUpdater() $scope.initUpdater()
$scope.reloadAnnotations() $scope.reloadAnnotations()
......
...@@ -64,9 +64,14 @@ class SessionProvider ...@@ -64,9 +64,14 @@ class SessionProvider
($q, $resource, baseURI, flash) -> ($q, $resource, baseURI, flash) ->
actions = {} actions = {}
_process = (response) -> process = (data, headersGetter) ->
data = response.data # Parse as json
data = angular.fromJson data
# Lift response data
model = data.model model = data.model
model.errors = data.errors
model.reason = data.reason
# bw compat # bw compat
if angular.isObject(data.persona) if angular.isObject(data.persona)
...@@ -85,19 +90,12 @@ class SessionProvider ...@@ -85,19 +90,12 @@ class SessionProvider
csrfToken = model.csrf csrfToken = model.csrf
delete model.csrf delete model.csrf
# Lift the model object so it becomes the response data. # Return the model
# Return the response or a rejected response.
if data.status is 'failure'
$q.reject(data)
else
model model
for name, options of ACTION_OPTION for name, options of ACTION_OPTION
actions[name] = angular.extend {}, options, @options actions[name] = angular.extend {}, options, @options
actions[name].interceptor = actions[name].transformResponse = process
response: _process
responseError: _process
$resource("#{baseURI}app", {}, actions).load() $resource("#{baseURI}app", {}, actions).load()
] ]
......
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