/**
* @ngdoc directives
* @name dashboard
* @module s4c.directives.dashboard.dashboard
*
* @description
* `dashboardController` Controller do módulo de dashboard da webview
*
*/
(function () {
'use strict';
dashboardController.$inject = [
'$scope',
'$http',
'API_ENDPOINT',
'$filter',
'$mdDialog',
'$interval',
'Preset',
'$sce',
'ParametrosS4C'
];
function dashboardController(
$scope,
$http,
API_ENDPOINT,
$filter,
$mdDialog,
$interval,
Preset,
$sce,
ParametrosS4C) {
$scope.res = $scope.$root.res;
/**
* Função usada pra ler arquivo
*
* @method readTextFile
*
* @param file {Object} Arquivo
* @param callback {Function} Função que será chamada no final da execução deste método
*
*
*/
function readTextFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4 && (rawFile.status == "200" || rawFile.status == 0)) {
callback(rawFile.responseText);
}
}
rawFile.send(null);
}
$scope.enderecos = [];
readTextFile("/s4c_dir/dashboardUrls.json", function (text) {
var data = JSON.parse(text);
$scope.enderecos.push(data.dashboard1);
$scope.enderecos.push(data.dashboard2);
$scope.enderecos.push(data.dashboard3);
$scope.index = 1;
$scope.endereco = $scope.enderecos[0];
if ($scope.endereco.indexOf('http://') == -1 && $scope.endereco.indexOf('https://') == -1) {
$scope.endereco = 'https://' + $scope.endereco;
}
$scope.endereco = $sce.trustAsResourceUrl($scope.endereco);
$interval(function () {
if ($scope.enderecos[$scope.index].indexOf('http://') == -1 && $scope.enderecos[$scope.index].indexOf('https://') == -1) {
$scope.enderecos[$scope.index] = 'https://' + $scope.enderecos[$scope.index];
}
$scope.endereco = $sce.trustAsResourceUrl($scope.enderecos[$scope.index]);
$scope.index++;
$scope.index = $scope.index % 3;
}, 10000);
});
angular.extend($scope, {
});
}
function s4cDashboard() {
return {
restrict: 'EA',
templateUrl: 'app/directives/dashboard/dashboard.html',
scope: {},
controller: dashboardController
};
}
angular.module('s4c.components.dashboard', [])
.directive('s4cDashboard', s4cDashboard);
})();