<commit_before>'use strict';
/*global $, angular, ol, Mousetrap*/
/*jslint browser: true*/

// Initialization of angular root application
var derm_app = angular.module('DermApp', ['ui.bootstrap', 'ngSanitize', 'xml', 'ui.select']);
derm_app.value("ol", ol);

derm_app.config(function ($httpProvider, $logProvider) {
    $httpProvider.defaults.xsrfCookieName = 'girderToken';
    $httpProvider.defaults.xsrfHeaderName = 'Girder-Token';

    $logProvider.debugEnabled(true);
});

// Initialization of angular app controller with necessary scope variables. Inline declaration of external variables
// needed within the controller's scope. State variables (available between controllers using $rootScope). Necessary to
// put these in rootScope to handle pushed data via websocket service.
derm_app.controller('ApplicationController', ['$scope', '$rootScope', '$location', '$document', '$log', 'olViewer',
    function ($scope, $rootScope, $location, $document, $log, olViewer) {

        // global ready state variable
        $rootScope.applicationReady = false; // a hack to know when the rest has loaded (since ol3 won't init until dom does)
        $rootScope.imageviewer = undefined; // the ol3 viewer

        // initial layout
        $("#angular_id").height(window.innerHeight);
        $("#map").height(window.innerHeight);

        // main application, gives a bit of a delay before loading everything
        $document.ready(function () {
            $log.debug('DOM ready');
            $rootScope.imageviewer = new olViewer($('#map')[0]);
            $rootScope.applicationReady = true;

            updateLayout();
        });
    }
]);

derm_app.controller('UserController', ['$scope', '$http', '$log',
    function ($scope, $http, $log) {
        var apiUserUrl = '/api/v1/user/me';
        //$scope.user = {};
        $http.get(apiUserUrl).then(function (response) {
            $log.debug('Got user response', response);
            if (response.data) {
                $scope.user = response.data;
            } else {
                $scope.user = {
                    login: 'not logged in',
                    firstName: 'Anonymous',
                    lastName: ''
                };
            }
        });
    }
]);

derm_app.controller('AnnotationTool', ['$scope', '$rootScope', '$timeout', '$sanitize', '$http', '$modal', '$log',
    function ($scope, $rootScope, $timeout, $sanitize, $http, $modal, $log) {
        $scope.annotation_model = {};
        $scope.annotation_options = undefined;

        $scope.selected_annotation = undefined;
        $scope.hover_annotation = undefined;

        $scope.certaintyModel = 'definite';

        $scope.showReview = false;
        $scope.filterval = '';

        $scope.formatter = new ol.format.GeoJSON();

        $rootScope.showingSegmentation = true;

        $rootScope.$watch('applicationReady', function () {
            if ($rootScope.applicationReady) {
                $scope.loadTasklist();
            }
        });

        $scope.selected = function () {
            $log.debug("selected", $scope.annotation_model);
        };

        $scope.loadTasklist = function () {
            var urlvals = window.location.pathname.split('/');
            var annotation_item_id = urlvals[urlvals.length - 1];
            $scope.annotation_item_id = annotation_item_id;

            var annotation_detail_url = '/api/v1/annotation/' + annotation_item_id;

            $http.get(annotation_detail_url).success(function (data) {
                //data.segmentation_info; // unused
                $scope.phase = 'Phase 2';
                $scope.current_image = data.image;
                $scope.annotation_options = data.variables;

                var segmentation_url = '/api/v1/item/' + $scope.current_image._id + '/segmentation';
                $rootScope.showingSegmentation = true;
                $rootScope.imageviewer.loadPainting(segmentation_url);
                $scope.task_start = Date.now(); // global start time for this task
            });
        };

        $scope.hasValidTile = function (_id) {
            if (_id in $scope.annotation_model) {
                var tiles = $scope.annotation_model[_id];
                for (var i=0;i<tiles.length;i++) {
                    if (tiles[i] > 0)
                    {
                        return true;
                    }
                }
            }<commit_msg>Clean up "loadTasklist" function in phase 2<commit_after>'use strict';
/*global $, angular, ol, Mousetrap*/
/*jslint browser: true*/

// Initialization of angular root application
var derm_app = angular.module('DermApp', ['ui.bootstrap', 'ngSanitize', 'xml', 'ui.select']);
derm_app.value("ol", ol);

derm_app.config(function ($httpProvider, $logProvider) {
    $httpProvider.defaults.xsrfCookieName = 'girderToken';
    $httpProvider.defaults.xsrfHeaderName = 'Girder-Token';

    $logProvider.debugEnabled(true);
});

// Initialization of angular app controller with necessary scope variables. Inline declaration of external variables
// needed within the controller's scope. State variables (available between controllers using $rootScope). Necessary to
// put these in rootScope to handle pushed data via websocket service.
derm_app.controller('ApplicationController', ['$scope', '$rootScope', '$location', '$document', '$log', 'olViewer',
    function ($scope, $rootScope, $location, $document, $log, olViewer) {

        // global ready state variable
        $rootScope.applicationReady = false; // a hack to know when the rest has loaded (since ol3 won't init until dom does)
        $rootScope.imageviewer = undefined; // the ol3 viewer

        // initial layout
        $("#angular_id").height(window.innerHeight);
        $("#map").height(window.innerHeight);

        // main application, gives a bit of a delay before loading everything
        $document.ready(function () {
            $log.debug('DOM ready');
            $rootScope.imageviewer = new olViewer($('#map')[0]);
            $rootScope.applicationReady = true;

            updateLayout();
        });
    }
]);

derm_app.controller('UserController', ['$scope', '$http', '$log',
    function ($scope, $http, $log) {
        var apiUserUrl = '/api/v1/user/me';
        //$scope.user = {};
        $http.get(apiUserUrl).then(function (response) {
            $log.debug('Got user response', response);
            if (response.data) {
                $scope.user = response.data;
            } else {
                $scope.user = {
                    login: 'not logged in',
                    firstName: 'Anonymous',
                    lastName: ''
                };
            }
        });
    }
]);

derm_app.controller('AnnotationTool', ['$scope', '$rootScope', '$timeout', '$sanitize', '$http', '$modal', '$log',
    function ($scope, $rootScope, $timeout, $sanitize, $http, $modal, $log) {
        $scope.annotation_model = {};
        $scope.annotation_options = undefined;

        $scope.selected_annotation = undefined;
        $scope.hover_annotation = undefined;

        $scope.certaintyModel = 'definite';
        $scope.phase = 'Phase 2';

        $scope.showReview = false;
        $scope.filterval = '';

        $scope.formatter = new ol.format.GeoJSON();

        $rootScope.showingSegmentation = true;

        $rootScope.$watch('applicationReady', function () {
            if ($rootScope.applicationReady) {
                loadAnnotationTask();
            }
        });

        $scope.selected = function () {
            $log.debug("selected", $scope.annotation_model);
        };

        function loadAnnotationTask () {
            var urlvals = window.location.pathname.split('/');
            var annotation_item_id = urlvals[urlvals.length - 1];
            $scope.annotation_item_id = annotation_item_id;

            var annotation_detail_url = '/api/v1/annotation/' + annotation_item_id;

            $http.get(annotation_detail_url).success(function (data) {
                //data.segmentation_info; // unused
                $scope.current_image = data.image;
                $scope.annotation_options = data.variables;

                var segmentation_url = '/api/v1/item/' + $scope.current_image._id + '/segmentation';
                $rootScope.showingSegmentation = true;
                $rootScope.imageviewer.loadPainting(segmentation_url);
                $scope.task_start = Date.now(); // global start time for this task
            });
        }

        $scope.hasValidTile = function (_id) {
            if (_id in $scope.annotation_model) {
                var tiles = $scope.annotation_model[_id];
                for (var i=0;i<tiles.length;i++) {
                    if (tiles[i] > 0)
                    {
                        return true;
                    }
                }
            }
{'fraction_non_alphanumeric': 0.13486953575059302, 'fraction_numerical': 0.0023720772619451034, 'mean_word_length': 2.2056480811006516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2535991', 'n_tokens_mistral': 2468, 'n_tokens_neox': 2358, 'n_words': 542}