<commit_before>'use strict';

angular.module('subutai.monitoring.controller', [])
	.controller('MonitoringCtrl', MonitoringCtrl);

MonitoringCtrl.$inject = ['$scope', 'monitoringSrv', 'cfpLoadingBar', '$http', '$sce', 'ngDialog'];

function MonitoringCtrl($scope, monitoringSrv, cfpLoadingBar, $http, $sce, ngDialog) {

	var vm = this;

	cfpLoadingBar.start();
	angular.element(document).ready(function () {
		cfpLoadingBar.complete();
	});

	vm.currentType = 'environments';
	vm.isAdmin = false;

	vm.charts = [{}, {}, {}, {}];
	vm.environments = [];
	vm.containers = [];
	vm.hosts = [];
	vm.selectedEnvironment = '';
	vm.currentHost = '';
	vm.period = 1;
	vm.info = {};
	vm.p2pColor = false;
	vm.currentError = '';
	vm.parseOptions = {
		1: {labelStep: 10, valueStep: 1},
		6: {labelStep: 60, valueStep: 5},
		12: {labelStep: 120, valueStep: 10},
		24: {labelStep: 240, valueStep: 20},
		48: {labelStep: 480, valueStep: 40}
	};

	vm.statusTable = {
		"p2pStatuses": {
			"healthy": 0,
			"problems": 0,
			"notWork": 0,
		},
		"p2pUpdates": {
			"updated": 0,
			"normal": 0,
			"needUpdate": 0,
		}
	};

	vm.statusColors = [
		{"color": "#22b573", "text": "Already up-to-date", "status": "true", "statusText": "Healthy"},
		{"color": "#efc94c", "text": "Need update soon", "status": "WAIT", "statusText": "Problems"},
		{"color": "#c1272d", "text": "Update immediately", "status": "false", "statusText": "Not working"},
	];

	//functions
	vm.showContainers = showContainers;
	vm.setCurrentType = setCurrentType;
	vm.getServerData = getServerData;
	vm.initAccordeon = initAccordeon;
	vm.viewError = viewError;

	monitoringSrv.getEnvironments().success(function (data) {
		vm.environments = data;
	});

	function viewError(errorText) {
		vm.currentError = errorText;
		ngDialog.open({
			template: 'subutai-app/monitoring/partials/p2pErrorPopup.html',
			scope: $scope
		});
	}
	
	function getP2Pstatus() {
		monitoringSrv.getP2Pstatus().success (function (data) {
			vm.info = data.p2pList;
			for(var i = 0; i < vm.info.length; i++) {

				switch(vm.info[i].p2pStatus) {
					case 0:
						vm.statusTable.p2pStatuses.healthy++;
						break;
					case 1:
						vm.statusTable.p2pStatuses.problems++;
						vm.p2pColor = '#efc94c';
						break;
					case 2:
						vm.statusTable.p2pStatuses.notWork++;
						if(!vm.p2pColor || vm.p2pColor == '#efc94c') {
							vm.p2pColor = '#c1272d';
						}
						break;
					default:
						break;
				}

				switch(vm.info[i].p2pVersionCheck) {
					case 0:
						vm.statusTable.p2pUpdates.updated++;
						break;
					case 1:
						vm.statusTable.p2pUpdates.normal++;
						break;
					case 2:
						vm.statusTable.p2pUpdates.needUpdate++;
						break;
					default:
						break;
				}

			}
		});
		
	}
	getP2Pstatus();

	monitoringSrv.getResourceHosts().success(function (data) {
		vm.hosts = data;
		vm.currentHost = vm.hosts.length > 0 ? vm.hosts[0].id : '';
		monitoringSrv.isAdminCheck().success(function (data) {
			vm.environments = data;
			if(data == true || data == 'true') {
				vm.isAdmin = true;
				vm.currentType = 'peer';
				getServerData();
			}
		});
	});<commit_msg>fix #1482 (Hide admin-specific metrics from regular user) select env by default<commit_after>'use strict';

angular.module('subutai.monitoring.controller', [])
	.controller('MonitoringCtrl', MonitoringCtrl);

MonitoringCtrl.$inject = ['$scope', 'monitoringSrv', 'cfpLoadingBar', '$http', '$sce', 'ngDialog', '$timeout'];

function MonitoringCtrl($scope, monitoringSrv, cfpLoadingBar, $http, $sce, ngDialog, $timeout) {

	var vm = this;

	cfpLoadingBar.start();
	angular.element(document).ready(function () {
		cfpLoadingBar.complete();
	});

	vm.currentType = 'environments';
	vm.isAdmin = false;

	vm.charts = [{}, {}, {}, {}];
	vm.environments = [];
	vm.containers = [];
	vm.hosts = [];
	vm.selectedEnvironment = '';
	vm.currentHost = '';
	vm.period = 1;
	vm.info = {};
	vm.p2pColor = false;
	vm.currentError = '';
	vm.parseOptions = {
		1: {labelStep: 10, valueStep: 1},
		6: {labelStep: 60, valueStep: 5},
		12: {labelStep: 120, valueStep: 10},
		24: {labelStep: 240, valueStep: 20},
		48: {labelStep: 480, valueStep: 40}
	};

	vm.statusTable = {
		"p2pStatuses": {
			"healthy": 0,
			"problems": 0,
			"notWork": 0,
		},
		"p2pUpdates": {
			"updated": 0,
			"normal": 0,
			"needUpdate": 0,
		}
	};

	vm.statusColors = [
		{"color": "#22b573", "text": "Already up-to-date", "status": "true", "statusText": "Healthy"},
		{"color": "#efc94c", "text": "Need update soon", "status": "WAIT", "statusText": "Problems"},
		{"color": "#c1272d", "text": "Update immediately", "status": "false", "statusText": "Not working"},
	];

	//functions
	vm.showContainers = showContainers;
	vm.setCurrentType = setCurrentType;
	vm.getServerData = getServerData;
	vm.initAccordeon = initAccordeon;
	vm.viewError = viewError;

	monitoringSrv.getEnvironments().success(function (data) {
		vm.environments = data;
	});

	function viewError(errorText) {
		vm.currentError = errorText;
		ngDialog.open({
			template: 'subutai-app/monitoring/partials/p2pErrorPopup.html',
			scope: $scope
		});
	}
	
	function getP2Pstatus() {
		monitoringSrv.getP2Pstatus().success (function (data) {
			vm.info = data.p2pList;
			for(var i = 0; i < vm.info.length; i++) {

				switch(vm.info[i].p2pStatus) {
					case 0:
						vm.statusTable.p2pStatuses.healthy++;
						break;
					case 1:
						vm.statusTable.p2pStatuses.problems++;
						vm.p2pColor = '#efc94c';
						break;
					case 2:
						vm.statusTable.p2pStatuses.notWork++;
						if(!vm.p2pColor || vm.p2pColor == '#efc94c') {
							vm.p2pColor = '#c1272d';
						}
						break;
					default:
						break;
				}

				switch(vm.info[i].p2pVersionCheck) {
					case 0:
						vm.statusTable.p2pUpdates.updated++;
						break;
					case 1:
						vm.statusTable.p2pUpdates.normal++;
						break;
					case 2:
						vm.statusTable.p2pUpdates.needUpdate++;
						break;
					default:
						break;
				}

			}
		});
		
	}
	getP2Pstatus();

	monitoringSrv.getResourceHosts().success(function (data) {
		vm.hosts = data;
		monitoringSrv.isAdminCheck().success(function (data) {
			if(data == true || data == 'true') {
				vm.isAdmin = true;
				vm.currentType = 'peer';
				vm.currentHost = vm.hosts.length > 0 ? vm.hosts[0].id : '';
				getServerData();
			} else {
				$timeout(function() {
					setFirstEnvByDefault();
				}, 2000);
			}
		});
	});

	function setFirstEnvByDefault() {
		if(vm.environments.length > 0) {
			vm.selectedEnvironment = vm.environments[0].id;
			vm.containers = vm.environments[0].containers;
			if(vm.containers.length > 0) {
				vm.currentHost = vm.containers[0].id;
				getServerData();
			}
		}
	}
{'fraction_non_alphanumeric': 0.1774217697260069, 'fraction_numerical': 0.027099865249288816, 'mean_word_length': 3.3947368421052633, 'pattern_counts': {'":': 40, '<': 5, '<?xml version=': 0, '>': 7, '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': '7323502', 'n_tokens_mistral': 3040, 'n_tokens_neox': 2456, 'n_words': 444}