{"size": 2470, "ext": "js", "max_stars_repo_path": "www/addons/mod/feedback/controllers/attempt.js", "max_stars_repo_name": "JosAlbert/ap", "max_stars_repo_stars_event_min_datetime": "2018-02-16T23:02:01.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-16T23:02:06.000Z", "max_issues_repo_path": "www/addons/mod/feedback/controllers/attempt.js", "max_issues_repo_name": "JosAlbert/ap", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "www/addons/mod/feedback/controllers/attempt.js", "max_forks_repo_name": "JosAlbert/ap", "max_forks_repo_forks_event_min_datetime": "2016-05-26T10:15:17.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-07T10:59:57.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 39.2063492063, "max_line_length": 125, "alphanum_fraction": 0.6198380567}
// (C) Copyright 2015 Martin Dougiamas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

angular.module('mm.addons.mod_feedback')

/**
 * Feedback attempt review controller.
 *
 * @module mm.addons.mod_feedback
 * @ngdoc controller
 * @name mmaModFeedbackAttemptCtrl
 */
.controller('mmaModFeedbackAttemptCtrl', function($scope, $stateParams, $mmaModFeedback, $mmUtil, $q, $mmText, $ionicHistory,
            $mmaModFeedbackHelper, mmaModFeedbackComponent) {

    var feedbackId = $stateParams.feedbackid || 0;

    $scope.attempt = $stateParams.attempt || false;
    $scope.component = mmaModFeedbackComponent;
    $scope.componentId = $stateParams.moduleid;

    // Convenience function to get feedback data.
    function fetchFeedbackAttemptData() {
        return $mmaModFeedback.getItems(feedbackId).then(function(items) {
            // Add responses and format items.
            $scope.items = items.items.map(function(item) {
                if (item.typ == 'label') {
                    item.submittedValue = $mmText.replacePluginfileUrls(item.presentation, item.itemfiles);
                } else {
                    for (var x in $scope.attempt.responses) {
                        if ($scope.attempt.responses[x].id == item.id) {
                            item.submittedValue = $scope.attempt.responses[x].printval;
                            delete $scope.attempt.responses[x];
                            break;
                        }
                    }
                }
                return $mmaModFeedbackHelper.getItemForm(item, true);
            });

        }).catch(function(message) {
            $mmUtil.showErrorModalDefault(message, 'mm.course.errorgetmodule', true);
            // Some call failed on first fetch, go back.
            $ionicHistory.goBack();
            return $q.reject();
        }).finally(function(){
            $scope.feedbackLoaded = true;
        });
    }

    fetchFeedbackAttemptData();
});