 ]
 
 
-ctlrs.controller 'SessionDetailCtrl', ['$rootScope', '$scope', '$stateParams',
-  'ControllerHelper', 'Subject', 'Session', 'Image',
-  ($rootScope, $scope, $stateParams, ControllerHelper, Subject, Session, Image) ->
-    $rootScope.project = $stateParams.project
-    # Compose a subject from the route parameters.
-    subject =
-      project: $stateParams.project or 'QIN'
-      collection: _.str.capitalize($stateParams.collection)
-      number: parseInt($stateParams.subject)
-
-    # Compose a session from the route parameters.
-    session =
-      subject: subject
-      number: parseInt($stateParams.session)
-      detail: $stateParams.detail
+ctlrs.controller 'SessionDetailCtrl', ['$rootScope', '$scope',
+  'session', 'detail', 'Image', 'ControllerHelper', 'Helpers',
+  ($rootScope, $scope, session, detail, Image, ControllerHelper, Helpers) ->
+    # Capture the current project.
+    $rootScope.project = session.subject.project
 
     # TODO - refactor the chart formatting cruft below into a
     # directive a la the modeling charts.


# The controller helper methods.
ctlrs.factory 'ControllerHelper', ['$location', ($location) ->
  # Fetches a parent object's detail and apply the given
  # action function.
  getDetail: (obj, resource, action) ->
    resource.detail(id: obj.detail).$promise
      .then (detail) ->
        if action
          action(detail, obj)
        obj

  # Copies the given source object properties into the
  # destination object.
  copyContent: (source, dest) ->
    # Copy the detail properties into the parent object.
    srcProps = Object.getOwnPropertyNames(source)
    destProps = Object.getOwnPropertyNames(dest)
    fields = _.difference(srcProps, destProps)
    for field in fields
      dest[field] = source[field]

  # Replaces the browser URL search parameters to include at most
  # a non-default project, since all other search parameters are
  # redundant.

        formatItem(key, data[key]) for key in _.keys(data)

      # Copy the fetched detail into the session.
      Helpers.copyContent(detail, session)
      
      # Add the registration.
      # TODO - handle more than one registration?
      session.registration = session.registrations[0]
      
      # Add the intensity graph parameters.
      session.graphData = intensityGraphData(
        Scan: session.scan.intensity.intensities
