Додан моніторінг застосунку
Додани веб компоненти карточок територій та повідомлень
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
<span>Розташування:</span>
|
||||
<p id="stand-info-title">--</p>
|
||||
</div>
|
||||
<div>
|
||||
<div id="stand-info-block-geo" >
|
||||
<span>Геолокація:</span>
|
||||
<a id="stand-info-geo" target="_blank">--</a>
|
||||
</div>
|
||||
|
||||
@@ -23,14 +23,23 @@ const Stand_card = {
|
||||
|
||||
info: {
|
||||
list: [],
|
||||
sheeps: [],
|
||||
|
||||
async setHTML() {
|
||||
const url = `${CONFIG.api}stand/${Stand_card.id}`;
|
||||
this.list = await Stand_card.loadAPI(url);
|
||||
this.list = await Stand_card.loadAPI(`${CONFIG.api}stand/${Stand_card.id}`);
|
||||
this.sheeps = await Stand_card.loadAPI(`${CONFIG.api}sheeps/list/stand`);
|
||||
|
||||
|
||||
document.getElementById('stand-info-title').innerText = this.list.title;
|
||||
document.getElementById('stand-info-geo').innerHTML = 'Відкрити Google Maps';
|
||||
document.getElementById('stand-info-geo').href = `https://www.google.com/maps?q=${this.list.geo[0]},${this.list.geo[1]}`;
|
||||
|
||||
if(this.list.geo[0]>0){
|
||||
document.getElementById('stand-info-geo').innerHTML = 'Відкрити Google Maps';
|
||||
document.getElementById('stand-info-geo').href = `https://www.google.com/maps?q=${this.list.geo[0]},${this.list.geo[1]}`;
|
||||
document.getElementById('stand-info-block-geo').style.display = "";
|
||||
} else {
|
||||
document.getElementById('stand-info-block-geo').style.display = "none";
|
||||
}
|
||||
|
||||
document.getElementById('stand-info-image').setAttribute('src', '');
|
||||
|
||||
Stand_card.schedule.setHTML();
|
||||
@@ -42,7 +51,7 @@ const Stand_card = {
|
||||
update(msg) {
|
||||
const { type, data, user } = msg;
|
||||
const el = document.getElementById(`name-${data?.id}`);
|
||||
if (!el) return; // если элемент не найден — выходим
|
||||
if (!el) return; // якщо елемент не знайдено - виходимо
|
||||
|
||||
const isSelf = user.id == USER.id;
|
||||
|
||||
@@ -56,7 +65,7 @@ const Stand_card = {
|
||||
break;
|
||||
|
||||
case "stand_unlocking":
|
||||
// Разблокируем только если событие от другого пользователя
|
||||
// Розблокуємо лише якщо подія від іншого користувача
|
||||
if (!isSelf) {
|
||||
el.style.border = "";
|
||||
el.style.backgroundColor = "";
|
||||
@@ -70,18 +79,18 @@ const Stand_card = {
|
||||
const sid = data.sheep_id;
|
||||
const sname = data.sheep_name ?? "";
|
||||
|
||||
// Менеджеру показываем весь список
|
||||
// Менеджеру показуємо весь перелік
|
||||
if (USER.possibilities.can_manager_stand && Array.isArray(Sheeps?.sheeps_list?.list)) {
|
||||
el.innerHTML = "";
|
||||
|
||||
// пустой вариант
|
||||
// порожній варіант
|
||||
el.appendChild(Object.assign(document.createElement("option"), {
|
||||
value: "",
|
||||
textContent: " "
|
||||
}));
|
||||
|
||||
// заполняем всех овечек
|
||||
Sheeps.sheeps_list.list.forEach(s => {
|
||||
// заповнюємо всіх овечок
|
||||
Stand_card.info.sheeps.forEach(s => {
|
||||
const opt = document.createElement("option");
|
||||
opt.value = s.id;
|
||||
opt.textContent = s.name;
|
||||
@@ -91,7 +100,7 @@ const Stand_card = {
|
||||
|
||||
el.removeAttribute("disabled");
|
||||
} else {
|
||||
// Обычное поведение для обычных пользователей
|
||||
// Звичайна поведінка для звичайних користувачів
|
||||
if (sid == USER.id) {
|
||||
el.innerHTML = `<option value=""></option><option selected value="${USER.id}">${USER.name}</option>`;
|
||||
el.removeAttribute("disabled");
|
||||
@@ -130,7 +139,7 @@ const Stand_card = {
|
||||
}
|
||||
};
|
||||
|
||||
if (Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||
if (navigator.onLine && Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||
Cloud.socket.send(JSON.stringify(message));
|
||||
} else {
|
||||
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
||||
@@ -152,7 +161,7 @@ const Stand_card = {
|
||||
}
|
||||
};
|
||||
|
||||
if (Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||
if (navigator.onLine && Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||
Cloud.socket.send(JSON.stringify(message));
|
||||
} else {
|
||||
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
||||
@@ -177,14 +186,14 @@ const Stand_card = {
|
||||
};
|
||||
|
||||
if (USER.possibilities.can_manager_stand) {
|
||||
const pos = Sheeps.sheeps_list.list.map(e => e.id).indexOf(Number(sheep_id));
|
||||
const pos = Stand_card.info.sheeps.map(e => e.id).indexOf(Number(sheep_id));
|
||||
if (pos != -1) {
|
||||
let name = Sheeps.sheeps_list.list[pos].name;
|
||||
let name = Stand_card.info.sheeps[pos].name;
|
||||
message.data.sheep_name = name;
|
||||
}
|
||||
}
|
||||
|
||||
if (Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||
if (navigator.onLine && Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||
Cloud.socket.send(JSON.stringify(message));
|
||||
} else {
|
||||
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
||||
@@ -272,10 +281,10 @@ const Stand_card = {
|
||||
textContent: " "
|
||||
}));
|
||||
|
||||
// если есть права менеджера — добавляем всех пользователей
|
||||
if (USER.possibilities.can_manager_stand && Array.isArray(Sheeps?.sheeps_list?.list)) {
|
||||
Sheeps.sheeps_list.list.sort((a, b) => a.name.localeCompare(b.name, 'uk'));
|
||||
Sheeps.sheeps_list.list.forEach(s => {
|
||||
// якщо є права менеджера - додаємо всіх користувачів
|
||||
if (USER.possibilities.can_manager_stand && Array.isArray(Stand_card.info.sheeps)) {
|
||||
Stand_card.info.sheeps.sort((a, b) => a.name.localeCompare(b.name, 'uk'));
|
||||
Stand_card.info.sheeps.forEach(s => {
|
||||
const option = document.createElement("option");
|
||||
option.value = s.id;
|
||||
option.textContent = s.name;
|
||||
@@ -283,7 +292,7 @@ const Stand_card = {
|
||||
select.appendChild(option);
|
||||
});
|
||||
} else {
|
||||
// если есть владелец — показываем его
|
||||
// якщо є власник - показуємо його
|
||||
const opt = document.createElement("option");
|
||||
if (sheep.sheep_id) {
|
||||
opt.value = sheep.sheep_id;
|
||||
@@ -296,13 +305,13 @@ const Stand_card = {
|
||||
select.appendChild(opt);
|
||||
}
|
||||
|
||||
// если занят другим пользователем — блокируем
|
||||
// якщо зайнятий іншим користувачем - блокуємо
|
||||
if (sheep.sheep_id && sheep.sheep_id !== USER.id && !USER.possibilities.can_manager_stand) {
|
||||
select.disabled = true;
|
||||
select.value = sheep.sheep_id;
|
||||
}
|
||||
|
||||
// --- обработчики ---
|
||||
// --- обробники ---
|
||||
select.addEventListener("mousedown", () => Stand_card.cloud.mess.locking({ id: sheep.id }));
|
||||
select.addEventListener("change", () => Stand_card.cloud.mess.update({ sheep_id: select.value, id: sheep.id }));
|
||||
select.addEventListener("blur", () => Stand_card.cloud.mess.unlocking({ id: sheep.id }));
|
||||
@@ -347,7 +356,7 @@ const Stand_card = {
|
||||
if (USER.possibilities.can_add_stand) {
|
||||
const btn = Object.assign(document.createElement("button"), {
|
||||
id: "stand-new-button",
|
||||
textContent: "Додати стенд(и)",
|
||||
textContent: "Додати день",
|
||||
onclick: () => Stand_card.addStand()
|
||||
});
|
||||
fragment.appendChild(btn);
|
||||
@@ -407,12 +416,14 @@ const Stand_card = {
|
||||
.then(response => {
|
||||
if (response.status == 200) {
|
||||
console.log({ 'setPack': 'ok' });
|
||||
button.innerText = "Стенд(и) додано";
|
||||
button.innerText = "День додано";
|
||||
Notifier.success('День додано');
|
||||
|
||||
return response.json()
|
||||
} else {
|
||||
console.log('err');
|
||||
button.innerText = "Помилка запису";
|
||||
Notifier.error('Помилка додавання');
|
||||
|
||||
return
|
||||
}
|
||||
@@ -423,16 +434,12 @@ const Stand_card = {
|
||||
Stand_card.schedule.setHTML();
|
||||
|
||||
setTimeout(() => {
|
||||
button.innerText = "Додати стенд(и)";
|
||||
button.innerText = "Додати день";
|
||||
}, 3000);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
button.innerText = "Помилка запису";
|
||||
})
|
||||
},
|
||||
|
||||
edit({ sheep_id, stand_id }) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user