ASCU_ALL/Site/js/discret.js
2024-09-22 04:27:05 +05:00

327 lines
9.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var discret_table = $('#discret_table');
var filter_table = $('#filter_table');
var aply_filter = $('#aply_filter');
var change_filter = $('#change_filter');
var data_discret = null;
var data_discret_params = null;
var params_state_struct = null;
//Первая загрузка страницы
$(document).ready(
async function () {
show_load();
var flag_pasport_load = await get_url_params();
pasport_fill_label();
pasport_show_lable();
if (!flag_pasport_load) {
hide_load();
return;
}
if (!pasport_fill_date()) {
hide_load();
return;
}
show_menu();
pasport_show_date();
var ds = load_data_discret();
var dsp = load_data_discret_params();
var dsss = load_params_state_struct();
await Promise.all([ds, dsp, dsss]);
if (dsp)
fill_filter_discret();
if (ds)
fill_table_discret();
hide_load();
}
);
aply_filter.click(function () {
read_filter();
fill_table_discret();
});
var change_filter_flag = true;
change_filter.click(function () {
change_filter.empty();
if (change_filter_flag)
change_filter.append("Установить все");
else
change_filter.append("Снять все");
for (var i = 0; i < data_discret_params.length; i++) {
var check_label = filter_table.find('#discret_filter_id_' + data_discret_params[i].index);
if (change_filter_flag)
check_label.removeAttr('checked');
else
check_label.attr('checked', true);
}
change_filter_flag = !change_filter_flag;
});
async function load_data_discret() {
try {
var res = await $.ajax({
type: "POST",
url: 'https://vsmpo.mbucb.ru/api/date/getdiscret',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({
"vdp": pasport_data.numVDP,
"start": pasport_data.dStart,
"end": pasport_data.dEnd
})
});
data_discret = res.discret;
return true;
}
catch (err) {
data_discret = null;
alert("Ошибка загрузки дискретов.");
return false;
}
}
async function load_data_discret_params() {
try {
var name_vdp = "0" + pasport_data.numVDP;
name_vdp = name_vdp.substr(name_vdp.length - 2);
var res = await $.ajax({
type: "POST",
url: 'https://vsmpo.mbucb.ru/api/params/getdiscret',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({ "name": name_vdp })
});
data_discret_params = res.discret_params;
var i = 0;
while (i < data_discret_params.length) {
if (data_discret_params[i].skip) {
data_discret_params.splice(i, 1);
continue;
}
data_discret_params[i].show = true;
i++;
}
return true;
}
catch (err) {
data_discret_params = null;
alert("Ошибка загрузки структуры дискретов");
return false;
}
}
async function load_params_state_struct() {
try {
var res = await $.ajax({
type: "POST",
url: 'https://vsmpo.mbucb.ru/api/params/getstatestruct',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({})
});
params_state_struct = res.stateStruct;
return true;
}
catch (err) {
params_state_struct = null;
alert("Ошибка загрузки состояний");
return false;
}
}
function fill_table_discret() {
try {
discret_table.find('tbody').empty();
if (data_discret == undefined ||
data_discret == null ||
data_discret_params == undefined ||
data_discret_params == null)
return;
for (var i = 0; i < data_discret.length; i++) {
var state = data_discret_params.find(item => item.index == data_discret[i].index);
if (state == undefined || state == null || !state.show)
continue;
var state_idx = params_state_struct.find(item => item.name == state.stateStruct);
if (state_idx == undefined || state_idx == null) {
state_idx = {};
state_idx.color = "#ffffff";
state_idx.name = "Состояние №" + data_discret[i].state;
} else {
state_idx = state_idx.states.find(item => item.index == data_discret[i].state);
if (state_idx == undefined || state_idx == null) {
state_idx = {};
state_idx.color = "#ffffff";
state_idx.name = "Состояние №" + data_discret[i].state;
}
}
discret_table.find('tbody').append(
'<tr style="background-color : ' + state_idx.color + '20;">' +
'<td>' + (i + 1) +
'</td>' +
'<td>' + data_discret[i].index +
'</td>' +
'<td>' + data_discret[i].start +
'</td>' +
'<td>' + state.name +
'</td>' +
'<td>' + state_idx.name +
'</td>' +
'</tr>');
}
}
catch {
alert("Ошибка заполнения таблицы.");
}
}
function fill_filter_discret() {
filter_table.empty();
if (data_discret_params == undefined ||
data_discret_params == null)
return;
for (var i = 0; i < data_discret_params.length; i++) {
filter_table.append(
'<div class= "form-check">' +
'<input class="form-check-input" type="checkbox" value="' + data_discret_params[i].index +
'" id="discret_filter_id_' + data_discret_params[i].index + '" ' +
(data_discret_params[i].show ? 'checked' : '') + '>' +
'<label class="form-check-label" for="discret_filter_id_' + data_discret_params[i].index + '">' +
data_discret_params[i].index + ' ' + data_discret_params[i].name +
'</label></div>'
);
}
}
function read_filter() {
for (var i = 0; i < data_discret_params.length; i++) {
if (filter_table.find('#discret_filter_id_' + data_discret_params[i].index).is(':checked'))
data_discret_params[i].show = true;
else
data_discret_params[i].show = false;
}
}
function load_discret() {
$.ajax({
type:
"POST",
url:
'https://' +
//document.URL.split("/")[2] +
'vsmpo.mbucb.ru' +
'/api/discret/getdiscrets',
contentType:
"application/json; charset=utf-8",
dataType:
"json",
data:
JSON.stringify(
{
"vdp": pasport_data == null ? global_vdp : pasport_data.numVDP,
"start": pasport_data == null ? global_dStart : pasport_data.dStart,
"end": pasport_data == null ? global_dEnd : pasport_data.dEnd
}
),
failure:
function (errMsg) {
hide_load();
alert("Не смог зугрузить массив данных. \n" + errMsg.name + ":" + errMsg.message + "\n" + errMsg.stack);
},
success: function (date) {
if (
date === undefined ||
date.discrets === undefined ||
date.stateParams === undefined ||
date.discretParams === undefined
) {
alert("Неверные данные")
return;
}
for (var i = 0; i < date.discrets.length; i++) {
var discret_row = {};
discret_row.id = i + 1;
discret_row.index = date.discrets[i].index;
discret_row.name = "Дискрет №" + date.discrets[i].index;
discret_row.color = "#ffffff";
discret_row.state = "Неизвестный №" + date.discrets[i].state;
discret_row.date_time = date.discrets[i].start;
var discretParams = date.discretParams.find(item => item.index == date.discrets[i].index);
if (discretParams != undefined) {
discret_row.name = discretParams.name;
var stateParam =
date.stateParams.find(item =>
item.name == discretParams.stateStruct &&
item.states.find(item => item.index == date.discrets[i].state) != undefined
)
if (stateParam != undefined) {
var state_tmp = stateParam.states.find(item => item.index == date.discrets[i].state);
discret_row.state = state_tmp.name;
discret_row.color = state_tmp.color;
}
}
var discret_filter = {};
discret_filter.index = discret_row.index;
discret_filter.name = discret_row.name;
discret_filter.show = true;
if (local_filter.find(item => item.index == discret_filter.index) === undefined)
local_filter.push(discret_filter);
local_date.push(discret_row);
}
local_filter.sort(function (a, b) { return a.index - b.index; });
update_filter();
update_table();
hide_load();
}
});
}
function update_filter() {
filter_table.empty();
for (var i = 0; i < local_filter.length; i++) {
filter_table.append(
'<div class= "form-check">' +
'<input class="form-check-input" type="checkbox" value="' + local_filter[i].index +
'" id="discret_filter_id_' + local_filter[i].index + '" ' +
(local_filter[i].show ? 'checked' : '') + '>' +
'<label class="form-check-label" for="discret_filter_id_' + local_filter[i].index + '">' +
local_filter[i].index + ' ' + local_filter[i].name +
'</label></div>'
);
}
}
function update_table() {
discret_table.find('tbody').empty();
for (var i = 0; i < local_date.length; i++) {
var check = local_filter.find(item => item.index == local_date[i].index);
if (check != undefined && !check.show)
continue;
discret_table.find('tbody').append(
'<tr style="background-color : ' + local_date[i].color + '20;">' +
'<td>' + (i + 1) +
'</td>' +
'<td>' + local_date[i].index +
'</td>' +
'<td>' + local_date[i].date_time +
'</td>' +
'<td>' + local_date[i].name +
'</td>' +
'<td>' + local_date[i].state +
'</td>' +
'</tr>');
}
}