<commit_before>/* global gapi, console, require, angular, document */
/* jslint node: true */

"use strict";

var name = "dash.controllers";
var dependencyMap = require("../dependency-map").add(name);
var constants = require("../../server/utilities/constants");

var _ = require("lodash");

var controller = ($scope, socket, $state, gapi) => {
    gapi.isAuthorized()
        .done(
            (response) => {
                console.log("authed:", response);
            },
            (error) => {
                // not authed; rock and roll!
                console.log("to login", error); 
                $state.go("login");
            }
        );
    
    $scope.dashboards = [];
    $scope.dashboard = undefined;
    $scope.dashboardComponents = [];
    
    $scope.getComponentsForDashboard = (dashboard) => {
        if (dashboard === undefined) {
            console.error("No dashboard provided. Cannot fetch components for board that is not present.");
            return;
        }
        
        // set active dashboard
        $scope.dashboard = dashboard;
        // fetch components for the dashboard
        socket.emit(
            "dash.get.dashboard.components", 
            dashboard.rows_component_ids, 
            (socket, resultingComponents) => {
                console.log("Components for Active dashboard", resultingComponents);
                // backend sorts and makes sure the resulting components are already ready for use
                $scope.dashboardComponents = resultingComponents;
            });   
    };
    
    $scope.getDashboards = () => {
        socket.emit("dash.get.dashboard", {}, (socket, result) => {    
            $scope.dashboards = result;

            if ($scope.dashboards.length > 0) {
                $scope.getComponentsForDashboard($scope.dashboards[0]);
            }
        });
    };
    
   $scope.getDashboards();
};
controller.$inject = [ "$scope", "socket", "$state", "gapi" ];
controller.controllerName = "DashboardController";

var configuration = ($stateProvider) => {
    $stateProvider.state("dashboard", {
        templateUrl: "/public/html/dashboard/dashboard-view.html",
        url: "/dashboard",
        controller: controller
    });
};
configuration.$inject = [ "$stateProvider" ];

angular
    .module(name)<commit_msg>Querying with email<commit_after>/* global gapi, console, require, angular, document */
/* jslint node: true */

"use strict";

var name = "dash.controllers";
var dependencyMap = require("../dependency-map").add(name);
var constants = require("../../server/utilities/constants");

var _ = require("lodash");

var controller = ($rootScope, $scope, socket, $state, gapi) => {   
    $scope.dashboards = [];
    $scope.dashboard = undefined;
    $scope.dashboardComponents = [];
    
    $scope.getComponentsForDashboard = (dashboard) => {
        if (dashboard === undefined) {
            console.error("No dashboard provided. Cannot fetch components for board that is not present.");
            return;
        }
        
        // set active dashboard
        $scope.dashboard = dashboard;
        // fetch components for the dashboard
        socket.emit(
            "dash.get.dashboard.components", 
            dashboard.rows_component_ids, 
            (socket, resultingComponents) => {
                console.log("Components for Active dashboard", resultingComponents);
                // backend sorts and makes sure the resulting components are already ready for use
                $scope.dashboardComponents = resultingComponents;
            });   
    };

    $scope.getDashboards = user => {
        socket.emit("dash.get.dashboard", user, (socket, result) => {    
            $scope.dashboards = result;

            if ($scope.dashboards.length > 0) {
                $scope.getComponentsForDashboard($scope.dashboards[0]);
            }
        });
    };

    var removeEmptyListener = socket.on("dash.get.dashboard.empty", () => {
        // TODO show message to the user that they should contact their contact person about this
        console.log("No dashboards available for user");
    });
    
    $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams) => {
        console.log("Removing socket.on listeners..");
        removeEmptyListener();
    });

    gapi.isAuthorized()
        .done(user => {
            console.log("authed:", user);
            $scope.getDashboards(user);
        },
        error => {
            // The user has not logged in
            $state.go("login");
        });
};
controller.$inject = [ "$rootScope", "$scope", "socket", "$state", "gapi" ];
controller.controllerName = "DashboardController";

var configuration = ($stateProvider) => {
    $stateProvider.state("dashboard", {
        templateUrl: "/public/html/dashboard/dashboard-view.html",
        url: "/dashboard",
        controller: controller
    });
};
configuration.$inject = [ "$stateProvider" ];

angular
    .module(name)
{'fraction_non_alphanumeric': 0.1389111289031225, 'fraction_numerical': 0.0008006405124099279, 'mean_word_length': 2.244805194805195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2352750', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1306, 'n_words': 303}