Files
admin-php-module/web/controllers/terminals.js
miroman-afk fb46c8e739 v.2.27
Fixed reports
2023-05-02 15:21:54 +03:00

183 lines
4.4 KiB
JavaScript

(function () {
'use strict';
angular
.module('app')
.controller('TerminalsCtrl', TerminalsCtrl);
TerminalsCtrl.$inject = ['$scope', 'smartRequest', 'Notification'];
function TerminalsCtrl($scope, smartRequest, Notification) {
$scope.terminals = [];
$scope.tasks = [];
$scope.printers = [];
$scope.settings = {
sizes: [56, 80],
speeds: [4800, 9600, 19200, 38400, 57600, 115200],
types: ['COM', 'LAN', 'Windows'],
com_ports: ['COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', 'COM10']
};
$scope.terminal_id = 0;
$scope.active_tasks = [];
$scope.terminalLogs = [];
$scope.update = function () {
smartRequest.get('v1/settings?method=terminals', function (data) {
$scope.terminals = data.terminals;
});
};
$scope.update();
$scope.onLicence = function (key, active) {
if (active === false) {
smartRequest.post('licence/reject', {
'key': key
},
function () {
$scope.update();
},
function () {
$scope.update();
});
}
else {
smartRequest.post('licence/apply', {
'key': key
},
function () {
$scope.update();
},
function () {
$scope.update();
});
}
};
$scope.isTaskActive = function (task) {
for (var i = 0; i < $scope.active_tasks.length; i++) {
if (task.code == $scope.active_tasks[i].code) {
return false;
}
}
return true;
};
$scope.editTerminal = function (id) {
$scope.terminal_id = id;
smartRequest.get('settings/update/list', function (data) {
for (var i = 0; i < data.update_list.length; i++) {
data.update_list[i].active = false;
data.update_list[i].period = parseInt(data.update_list[i].default);
}
$scope.all_tasks = data.update_list;
});
smartRequest.get('settings/update/active?terminal=' + id, function (data) {
for (var i = 0; i < data.update_list.length; i++) {
data.update_list[i].active = true;
data.update_list[i].period = parseInt(data.update_list[i].period);
}
$scope.active_tasks = data.update_list;
$('#edit-terminal').modal();
});
};
$scope.getEquipment = function (id) {
smartRequest.get('v1/equipment?terminal=' + id, function (data) {
$scope.printers = data.printers;
$scope.groups = data.printer_groups;
$scope.terminal_id = id;
});
$('#equipment').modal();
};
$scope.updateEquipment = function (printer) {
smartRequest.post('v1/printers', {
terminal: $scope.terminal_id,
id: printer.id,
name: printer.name,
ip_address: printer.ip,
com_port: printer.com_port,
type: printer.type,
speed: printer.speed,
group: printer.printer_group,
template: printer.template,
size: printer.size,
driver: printer.driver,
more: printer.more
}, function(data) {
Notification.success('Данные принтера сохранены');
});
};
$scope.updateFiscal = function (fiscal) {
smartRequest.post('v1/fiscals', {
terminal: $scope.terminal_id,
pass: fiscal.password,
ip: fiscal.ip
}, function(data) {
Notification.success('Данные ФР изменены');
});
};
$scope.addTask = function () {
smartRequest.get('settings/equipment/task?terminal=' + $scope.terminal_id, function (data) {
Notification.success('Задача запушена');
});
};
$scope.objectHasProperty = function (object, name) {
return object.hasOwnProperty(name);
};
$scope.changeTask = function (task) {
if (task.active) {
smartRequest.post('settings/update/enable', {
terminal: $scope.terminal_id,
task: task.code,
period: task.period
});
}
else {
smartRequest.post('settings/update/disable', {
terminal: $scope.terminal_id,
task: task.code
});
}
};
$scope.changePeriod = function (task) {
if (task.active) {
smartRequest.post('settings/update/enable', {
terminal: $scope.terminal_id,
task: task.code,
period: task.period
});
}
};
$scope.runTask = function (task) {
smartRequest.post('settings/update/force', {
terminal: $scope.terminal_id,
task: task.code
}, function (data) {
Notification.success('Задача запущена');
});
};
$scope.showLogs = function (terminal_key) {
smartRequest.get('settings/terminal/logs?terminal=' + terminal_key, function (data) {
$scope.terminalLogs = data.logs;
$('#logs').modal();
});
};
}
})();