<commit_before>/*
Copyright (c) 2014-2016 cloudover.io ltd.

This file is part of cloudover.coreCluster project.

cloudover.coreCluster is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

window.app.controller('HomeCtrl', function ($scope, $location, $http) {
    if (!$.cookie('core_token')) {
        document.location = 'login.html';
    }
    request('/api/template/capabilities/', {token: $.cookie("core_token")}, function(caps) {
        request('/api/template/get_list/', {token: $.cookie("core_token")}, function(templ) {
            $scope.templates = [];
            for (i = 0; i < templ.length; i++) {
                $scope.templates.push({});
                $scope.templates[i].caps = caps[templ[i]["id"]];
                $scope.templates[i].id = templ[i]["id"];
                $scope.templates[i].name = templ[i]["name"];
            }
            $scope.$apply();
        });
    }, quiet=true);

    request('/api/storage/capabilities/', {token: $.cookie("core_token")}, function(caps) {
        $scope.storage = (caps/1024).toFixed(2);
        $scope.$apply();
    }, quiet=true);

    request('/user/user/get_quota/', {login: $.cookie("core_login"), pw_hash: $.cookie("core_hash")}, function(r) {
        $scope = angular.element($("#view")).scope();
        $scope.$apply();

        var ctx = $("#memory").get(0).getContext("2d");
        var c = new Chart(ctx).Doughnut([
            {
                value: r['memory_used'],
                color: '#33ff88'
            },
            {
                value: r['memory_quota'] - r['memory_used'],
                color: '#dddddd'
            }
        ]);
        var ctx = $("#cpu").get(0).getContext("2d");
        var c = new Chart(ctx).Doughnut([
            {
                value: r['cpu_used'],
                color: '#ff6633'
            },
            {
                value: r['cpu_quota'] - r['cpu_used'],
                color: '#dddddd'
            }
        ]);
        var ctx = $("#storage").get(0).getContext("2d");
        var c = new Chart(ctx).Doughnut([
            {
                value: (r['storage_used']/1024/1024/1024).toFixed(2),
                color: '#ffbb33'
            },
            {
                value: (r['storage_quota']/1024/1024/1024 - r['storage_used']/1024/1024/1024).toFixed(2),
                color: '#dddddd'
            }
        ]);
    });

    // Thunder Script
    request('/api/api/list_api_modules/', {token: $.cookie("core_token")}, function(objs) {
        if (objs.indexOf('thunderscript.views.api') > 0) {
            $scope.thunder = true;

            $.ajax({
                type: 'GET',
                url: 'http://cloudover.io/thunder/raw/',
                complete: function(xhr, status) {
                    console.debug(xhr);
                    var scripts = xhr.responseText.split("\n");
                    var lookups = [];

                    for (i = 0; i < scripts.length; i++) {<commit_msg>https<commit_after>/*
Copyright (c) 2014-2016 cloudover.io ltd.

This file is part of cloudover.coreCluster project.

cloudover.coreCluster is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

window.app.controller('HomeCtrl', function ($scope, $location, $http) {
    if (!$.cookie('core_token')) {
        document.location = 'login.html';
    }
    request('/api/template/capabilities/', {token: $.cookie("core_token")}, function(caps) {
        request('/api/template/get_list/', {token: $.cookie("core_token")}, function(templ) {
            $scope.templates = [];
            for (i = 0; i < templ.length; i++) {
                $scope.templates.push({});
                $scope.templates[i].caps = caps[templ[i]["id"]];
                $scope.templates[i].id = templ[i]["id"];
                $scope.templates[i].name = templ[i]["name"];
            }
            $scope.$apply();
        });
    }, quiet=true);

    request('/api/storage/capabilities/', {token: $.cookie("core_token")}, function(caps) {
        $scope.storage = (caps/1024).toFixed(2);
        $scope.$apply();
    }, quiet=true);

    request('/user/user/get_quota/', {login: $.cookie("core_login"), pw_hash: $.cookie("core_hash")}, function(r) {
        $scope = angular.element($("#view")).scope();
        $scope.$apply();

        var ctx = $("#memory").get(0).getContext("2d");
        var c = new Chart(ctx).Doughnut([
            {
                value: r['memory_used'],
                color: '#33ff88'
            },
            {
                value: r['memory_quota'] - r['memory_used'],
                color: '#dddddd'
            }
        ]);
        var ctx = $("#cpu").get(0).getContext("2d");
        var c = new Chart(ctx).Doughnut([
            {
                value: r['cpu_used'],
                color: '#ff6633'
            },
            {
                value: r['cpu_quota'] - r['cpu_used'],
                color: '#dddddd'
            }
        ]);
        var ctx = $("#storage").get(0).getContext("2d");
        var c = new Chart(ctx).Doughnut([
            {
                value: (r['storage_used']/1024/1024/1024).toFixed(2),
                color: '#ffbb33'
            },
            {
                value: (r['storage_quota']/1024/1024/1024 - r['storage_used']/1024/1024/1024).toFixed(2),
                color: '#dddddd'
            }
        ]);
    });

    // Thunder Script
    request('/api/api/list_api_modules/', {token: $.cookie("core_token")}, function(objs) {
        if (objs.indexOf('thunderscript.views.api') > 0) {
            $scope.thunder = true;

            $.ajax({
                type: 'GET',
                url: 'https://cloudover.io/thunder/raw/',
                complete: function(xhr, status) {
                    console.debug(xhr);
                    var scripts = xhr.responseText.split("\n");
                    var lookups = [];

                    for (i = 0; i < scripts.length; i++) {
{'fraction_non_alphanumeric': 0.15960028551034974, 'fraction_numerical': 0.02027123483226267, 'mean_word_length': 1.92282019190655, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, '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': '2714190', 'n_tokens_mistral': 2147, 'n_tokens_neox': 1998, 'n_words': 480}