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
frame: $scope.frame or @scope.frame
socialView: annotator.socialView
ongoingHighlightSwitch: false
model: {}
model: session
search:
facets: SEARCH_FACETS
values: SEARCH_VALUES
......@@ -62,7 +62,6 @@ class App
angular.extend annotator.options.Store, options
session.$promise.then (data) ->
angular.extend $scope.model, data
unless data.personas?.length
$scope.initUpdater()
$scope.reloadAnnotations()
......
......@@ -64,9 +64,14 @@ class SessionProvider
($q, $resource, baseURI, flash) ->
actions = {}
_process = (response) ->
data = response.data
process = (data, headersGetter) ->
# Parse as json
data = angular.fromJson data
# Lift response data
model = data.model
model.errors = data.errors
model.reason = data.reason
# bw compat
if angular.isObject(data.persona)
......@@ -85,19 +90,12 @@ class SessionProvider
csrfToken = model.csrf
delete model.csrf
# Lift the model object so it becomes the response data.
# Return the response or a rejected response.
if data.status is 'failure'
$q.reject(data)
else
model
# Return the model
model
for name, options of ACTION_OPTION
actions[name] = angular.extend {}, options, @options
actions[name].interceptor =
response: _process
responseError: _process
actions[name].transformResponse = process
$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