<commit_before>angular.module("dashboard", []).controller("DashboardController", ["$http", function DashboardController($http) {
    this.projectList = [];
    this.currentProjectId = "";
    this.currentProject = null;
    this.plotList = [];
    this.currentPlot = null;
    this.currentSamples = [];
    this.userSamples = {};

    // FIXME: Implement this endpoint: get-all-projects -> project_list.json
    this.getProjectList = function () {
        $http.get("get-all-projects")
            .then(function successCallback(response) {
                this.projectList = response.data;
                this.initialize();
            }, function errorCallback(response) {
                console.log(response);
                alert("Error retrieving the project list. See console for details.");
            });
    };

    this.getProjectById = function (projectId) {
        return this.projectList.find(
            function (project) {
                return project.id == projectId;
            }
        );
    };

    this.initialize = function () {
        if (this.projectList.length == 0) {
            // Load the projectList
            this.getProjectList();
        } else {
            // Load the currentProject
            this.currentProjectId = document.getElementById("initial-project-id").value;
            this.currentProject = this.getProjectById(parseInt(this.currentProjectId));

            // Initialize the base map and show the selected project's boundary
            map_utils.digital_globe_base_map({div_name: "image-analysis-pane",
                                              center_coords: [102.0, 17.0],
                                              zoom_level: 5});
            map_utils.set_current_imagery(this.currentProject.imagery);
            map_utils.draw_polygon(this.currentProject.boundary);
        }
    };

    this.switchProject = function () {
        var newProject = this.getProjectById(parseInt(this.currentProjectId));
        if (newProject) {
            this.currentProject = newProject;
            this.currentPlot = null;
            this.currentSamples = [];
            this.userSamples = {};
            map_utils.remove_plot_layer();
            map_utils.remove_sample_layer();
            map_utils.disable_selection();
            utils.enable_element("new-plot-button");
            utils.disable_element("flag-plot-button");
            utils.disable_element("save-values-button");
            map_utils.set_current_imagery(newProject.imagery);
            map_utils.draw_polygon(newProject.boundary);
        }
    };

    // FIXME: Implement this endpoint: get-project-plots projectId -> plot_data_<projectId>.json
    this.getPlotData = function (projectId) {
        $http.post("get-project-plots",
                   {project_id: projectId})
            .then(function successCallback(response) {
                this.plotList = response.data;
                this.loadRandomPlot();
                this.plotList = [];
            }, function errorCallback(response) {
                console.log(response);
                alert("Error retrieving plot data. See console for details.");
            });
    };

    this.loadRandomPlot = function () {
        if (this.plotList.length == 0) {
            this.getPlotData(parseInt(this.currentProjectId));
        } else {
            var randomIndex = Math.floor(Math.random() * this.plotList.length);
            var newPlot = this.plotList[randomIndex].plot;
            var newSamples = this.plotList[randomIndex].samples;
            this.currentPlot = newPlot;
            this.currentSamples = newSamples;
            this.userSamples = {};
            utils.disable_element("new-plot-button");
            utils.enable_element("flag-plot-button");
            utils.disable_element("save-values-button");
            map_utils.draw_buffer(newPlot.center, newPlot.radius);
            map_utils.draw_points(newSamples);
            window.open("geo-dash?title=" + this.currentProject.name
                        + "&pid=" + this.currentProjectId
                        + "&aoi=[" + map_utils.get_view_extent()
                        + "]&daterange=&bcenter=" + newPlot.center
                        + "&bradius=" + newPlot.radius,
                        "_geo-dash");
        };

    this.setCurrentValue = function (sampleValue) {
        var selectedFeatures = map_utils.get_selected_samples();
        if (selectedFeatures && selectedFeatures.getLength() > 0) {
            selectedFeatures.forEach(
                function (sample) {
                    this.userSamples[sample.get("sample_id")] = sampleValue.id;
                    map_utils.highlight_sample(sample, sampleValue.color);
                },
                this // necessary to pass outer scope into function<commit_msg>Fixing a syntax error introduced by the previous commit.<commit_after>angular.module("dashboard", []).controller("DashboardController", ["$http", function DashboardController($http) {
    this.projectList = [];
    this.currentProjectId = "";
    this.currentProject = null;
    this.plotList = [];
    this.currentPlot = null;
    this.currentSamples = [];
    this.userSamples = {};

    // FIXME: Implement this endpoint: get-all-projects -> project_list.json
    this.getProjectList = function () {
        $http.get("get-all-projects")
            .then(function successCallback(response) {
                this.projectList = response.data;
                this.initialize();
            }, function errorCallback(response) {
                console.log(response);
                alert("Error retrieving the project list. See console for details.");
            });
    };

    this.getProjectById = function (projectId) {
        return this.projectList.find(
            function (project) {
                return project.id == projectId;
            }
        );
    };

    this.initialize = function () {
        if (this.projectList.length == 0) {
            // Load the projectList
            this.getProjectList();
        } else {
            // Load the currentProject
            this.currentProjectId = document.getElementById("initial-project-id").value;
            this.currentProject = this.getProjectById(parseInt(this.currentProjectId));

            // Initialize the base map and show the selected project's boundary
            map_utils.digital_globe_base_map({div_name: "image-analysis-pane",
                                              center_coords: [102.0, 17.0],
                                              zoom_level: 5});
            map_utils.set_current_imagery(this.currentProject.imagery);
            map_utils.draw_polygon(this.currentProject.boundary);
        }
    };

    this.switchProject = function () {
        var newProject = this.getProjectById(parseInt(this.currentProjectId));
        if (newProject) {
            this.currentProject = newProject;
            this.currentPlot = null;
            this.currentSamples = [];
            this.userSamples = {};
            map_utils.remove_plot_layer();
            map_utils.remove_sample_layer();
            map_utils.disable_selection();
            utils.enable_element("new-plot-button");
            utils.disable_element("flag-plot-button");
            utils.disable_element("save-values-button");
            map_utils.set_current_imagery(newProject.imagery);
            map_utils.draw_polygon(newProject.boundary);
        }
    };

    // FIXME: Implement this endpoint: get-project-plots projectId -> plot_data_<projectId>.json
    this.getPlotData = function (projectId) {
        $http.post("get-project-plots",
                   {project_id: projectId})
            .then(function successCallback(response) {
                this.plotList = response.data;
                this.loadRandomPlot();
                this.plotList = [];
            }, function errorCallback(response) {
                console.log(response);
                alert("Error retrieving plot data. See console for details.");
            });
    };

    this.loadRandomPlot = function () {
        if (this.plotList.length == 0) {
            this.getPlotData(parseInt(this.currentProjectId));
        } else {
            var randomIndex = Math.floor(Math.random() * this.plotList.length);
            var newPlot = this.plotList[randomIndex].plot;
            var newSamples = this.plotList[randomIndex].samples;
            this.currentPlot = newPlot;
            this.currentSamples = newSamples;
            this.userSamples = {};
            utils.disable_element("new-plot-button");
            utils.enable_element("flag-plot-button");
            utils.disable_element("save-values-button");
            map_utils.draw_buffer(newPlot.center, newPlot.radius);
            map_utils.draw_points(newSamples);
            window.open("geo-dash?title=" + this.currentProject.name
                        + "&pid=" + this.currentProjectId
                        + "&aoi=[" + map_utils.get_view_extent()
                        + "]&daterange=&bcenter=" + newPlot.center
                        + "&bradius=" + newPlot.radius,
                        "_geo-dash");
        }
    };

    this.setCurrentValue = function (sampleValue) {
        var selectedFeatures = map_utils.get_selected_samples();
        if (selectedFeatures && selectedFeatures.getLength() > 0) {
            selectedFeatures.forEach(
                function (sample) {
                    this.userSamples[sample.get("sample_id")] = sampleValue.id;
                    map_utils.highlight_sample(sample, sampleValue.color);
                },
                this // necessary to pass outer scope into function
{'fraction_non_alphanumeric': 0.11272241077856629, 'fraction_numerical': 0.0022626761287668413, 'mean_word_length': 1.9139946059334731, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3820592', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2422, 'n_words': 409}