94 lines
4.6 KiB
JavaScript
94 lines
4.6 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by mkumar1 on 05-02-2018.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('adminModule')
|
|
.controller('ReportsConfigurationController', ['$scope', 'configurationModel', 'adminConsoleConfigurationModel', '$q', '$httpParamSerializer', '$window',
|
|
function ($scope, configurationModel, adminConsoleConfigurationModel, $q, $httpParamSerializer, $window) {
|
|
$scope.reportsConfig = {
|
|
reportStartDatePicker: { open: false },
|
|
reportEndDatePicker: { open: false }
|
|
};
|
|
//Do not remove quotes around show-weeks here in order to fix JSCS. These quotes are required for datePickerOptions in angular UI
|
|
$scope.datePickerOptions = {
|
|
startingDay: configurationModel.getWeekStartingDay(),
|
|
'show-weeks': false
|
|
};
|
|
$scope.maxDate = new Date();
|
|
$scope.updateDateTime = function (type) {
|
|
console.log(type);
|
|
};
|
|
$scope.reportsData = _.cloneDeep($scope.displayData);
|
|
function initPaginate() {
|
|
$scope.pagination = {
|
|
totalItems: ($scope.reportsData.users && _.isArray($scope.reportsData.users)) ? $scope.reportsData.users.length : 0,
|
|
currentPage: 1,
|
|
numPerPage: 20
|
|
};
|
|
}
|
|
initPaginate();
|
|
$scope.paginate = function (value) {
|
|
var begin, end, index;
|
|
begin = ($scope.pagination.currentPage - 1) * $scope.pagination.numPerPage;
|
|
end = begin + $scope.pagination.numPerPage;
|
|
index = $scope.reportsData.users.indexOf(value);
|
|
return (begin <= index && index < end);
|
|
};
|
|
$scope.openDatePicker = function (identifier, calendar, event) {
|
|
if (identifier === 'start') {
|
|
$scope.reportsConfig.reportEndDatePicker.open = false;
|
|
}
|
|
else {
|
|
$scope.reportsConfig.reportStartDatePicker.open = false;
|
|
}
|
|
calendar.open = true;
|
|
event.stopPropagation();
|
|
};
|
|
function fetchReportData() {
|
|
var clientTypeParams = {
|
|
after_date: ($scope.reportsConfig.reportStartDate) ? moment($scope.reportsConfig.reportStartDate).startOf('day').valueOf() : '',
|
|
before_date: ($scope.reportsConfig.reportEndDate) ? moment($scope.reportsConfig.reportEndDate).endOf('day').valueOf() : '',
|
|
app_name: 'SmartIT'
|
|
};
|
|
var activeUsersParams = {
|
|
offset: 0,
|
|
after_date: ($scope.reportsConfig.reportStartDate) ? moment($scope.reportsConfig.reportStartDate).startOf('day').valueOf() : '',
|
|
app_name: 'SmartIT',
|
|
before_date: ($scope.reportsConfig.reportEndDate) ? moment($scope.reportsConfig.reportEndDate).endOf('day').valueOf() : '',
|
|
limit: 100,
|
|
sidx: '',
|
|
sord: 'asc'
|
|
};
|
|
$scope.dataLoading = true;
|
|
$q.all([adminConsoleConfigurationModel.getActiveUsers(activeUsersParams), adminConsoleConfigurationModel.getClientTypesUsage(clientTypeParams)]).then(function (reportData) {
|
|
$scope.reportsData = {
|
|
users: reportData[0],
|
|
clients: reportData[1]
|
|
};
|
|
initPaginate();
|
|
$scope.dataLoading = false;
|
|
});
|
|
}
|
|
$scope.getCustomReportData = function () {
|
|
fetchReportData();
|
|
};
|
|
$scope.clearReportDates = function () {
|
|
$scope.reportsConfig.reportStartDate = '';
|
|
$scope.reportsConfig.reportEndDate = '';
|
|
fetchReportData();
|
|
};
|
|
$scope.downloadCSV = function () {
|
|
var downloadParams = {
|
|
after_date: ($scope.reportsConfig.reportStartDate) ? moment($scope.reportsConfig.reportStartDate).startOf('day').valueOf() : '',
|
|
app_name: 'SmartIT',
|
|
before_date: ($scope.reportsConfig.reportEndDate) ? moment($scope.reportsConfig.reportEndDate).endOf('day').valueOf() : '',
|
|
include_client_types_usage: true
|
|
};
|
|
var downloadUrl = '/smartit/rest/reports/active_users_csv?' + $httpParamSerializer(downloadParams);
|
|
$window.open(downloadUrl, '_self', '');
|
|
};
|
|
}]);
|
|
})();
|