'use strict';

angular.module('ddsApp').controller('TraceCtrl', function($scope, $http, $stateParams) {
    $scope.investigation = {
        situationId: $stateParams.situationId,
    };

    $scope.toggle = function(name) {
        $scope.trace[name].isOpen = ! $scope.trace[name].isOpen;
    };

    $scope.refreshView = function() {
        if ($scope.rawData.requestedCalculations.length == 1) {
            $scope.investigation.root = $scope.rawData.requestedCalculations[0];
        }
        _.forEach($scope.trace, function(value) {
            value.isOpen = false;
        });
        $scope.name = $scope.investigation.root;
        $scope.trace[$scope.name].isOpen = true;
    };

    if (! $scope.investigation.situationId) {
        return;
    }

    $http.get('/api/situations/' + $scope.investigation.situationId + '/openfisca-trace')
    .then(function(response) {
        $scope.rawData = response.data;
        $scope.rawData.requestedCalculations.sort();
        $scope.trace = $scope.rawData.trace;
    }, function(error) {
        $scope.error = error;
    });
});

@@ -1013,16 +1013,222 @@
 a.trace;
+%0A%0A        var variables = Object.keys($scope.trace);%0A        variables.forEach(function(variable) %7B%0A            $scope.trace%5Bvariable%5D.dependencies = _.uniq($scope.trace%5Bvariable%5D.dependencies);%0A        %7D);
 %0A    %7D, 

Remove duplicates in tracer dependencies #745