Додана сторінка "Стенд"

Додане повідомлення про оновлення застосунку
Оновлен Service Worker
Перероблен WebSocket APІ
This commit is contained in:
2025-10-19 00:55:30 +03:00
parent 6ec6523d71
commit 3f08f3f6c9
46 changed files with 2651 additions and 2691 deletions

View File

@@ -41,7 +41,9 @@ const Auth = {
if (USER.possibilities.can_add_schedule) document.getElementById("li-schedule").style.display = "";
if (USER.possibilities.can_manager_territory) document.getElementById("li-territory").style.display = "";
if (USER.possibilities.can_view_stand) document.getElementById("li-stand").style.display = "";
document.getElementById("li-options").style.display = "";
Cloud.start();
});
}
}

View File

@@ -17,4 +17,6 @@
<option value="large">Великий</option>
</select>
</div>
<button onclick="Options.logout()">Вийти з облікового запису</button>
</div>

View File

@@ -1,13 +1,14 @@
const Options = {
init: async () => {
async init() {
let html = await fetch('/lib/pages/options/index.html').then((response) => response.text());
app.innerHTML = html;
await Options.optionPush.init();
Options.optionFont.init();
},
optionPush: {
init: async () => {
async init() {
const element = document.getElementById("page-options-notifications");
const permission = await Notification.requestPermission();
@@ -25,7 +26,8 @@ const Options = {
element.checked = false;
}
},
edit: (state) => {
edit(state) {
if (state) {
webPush.init();
} else {
@@ -33,8 +35,9 @@ const Options = {
}
}
},
optionFont: {
init: () => {
init() {
const element = document.getElementById("page-options-fontSize");
let fontSize = localStorage.getItem("fontSize")
@@ -43,9 +46,15 @@ const Options = {
element.value = fontSize;
},
edit: (mode) => {
edit(mode) {
localStorage.setItem("fontSize", mode);
applyFontMode(mode);
}
},
logout() {
localStorage.removeItem("uuid");
window.location.reload();
}
}

View File

@@ -53,4 +53,16 @@
justify-content: space-between;
cursor: pointer;
margin: 5px 0;
}
.page-options>button {
border-radius: var(--border-radius);
background: var(--PrimaryColor);
color: var(--PrimaryColorText);
width: 100%;
height: 40px;
font-size: var(--FontSize3);
font-weight: 400;
margin: 20px 0;
text-transform: uppercase;
}

View File

@@ -27,144 +27,142 @@ let Sheeps_icon = [
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path d="M 14 12 C 12.896 12 12 12.896 12 14 C 12 15.104 12.896 16 14 16 L 15.492188 16 C 11.397556 20.243092 9 25.992059 9 32 C 9 39.62 12.760547 46.729531 19.060547 51.019531 C 20.970547 52.319531 23.249688 53 25.679688 53 L 38.330078 53 C 40.750078 53 43.039219 52.309766 44.949219 51.009766 C 51.239219 46.719766 55 39.62 55 32 C 55 25.992059 52.602444 20.243092 48.507812 16 L 50 16 C 51.104 16 52 15.104 52 14 C 52 12.896 51.104 12 50 12 L 14 12 z M 21.75 16 L 42.25 16 C 44.971669 17.740083 47.142531 20.078247 48.642578 22.791016 L 46.380859 23.695312 C 42.871859 25.098312 38.961906 25.213578 35.378906 24.017578 L 29.582031 22.085938 C 25.319031 20.664938 20.646828 20.726672 16.423828 22.263672 L 15.460938 22.613281 C 16.956883 19.976859 19.088528 17.701597 21.75 16 z M 23.042969 25.064453 C 24.826219 25.040328 26.612906 25.312359 28.316406 25.880859 L 34.113281 27.8125 C 36.165281 28.4965 38.300547 28.837891 40.435547 28.837891 C 42.961547 28.837891 45.486234 28.358203 47.865234 27.408203 L 50.1875 26.480469 C 50.715092 28.239658 51 30.092368 51 32 C 51 38.29 47.899219 44.170938 42.699219 47.710938 C 41.459219 48.550938 39.950078 49 38.330078 49 L 25.679688 49 C 24.059687 49 22.550547 48.560938 21.310547 47.710938 C 16.110547 44.170938 13 38.3 13 32 C 13 30.484897 13.183421 29.005425 13.519531 27.578125 L 17.791016 26.023438 C 19.480516 25.409438 21.259719 25.088578 23.042969 25.064453 z M 34.5 32 C 31.548188 32 29.139763 33.869393 27.722656 35.292969 L 25.199219 33.400391 C 24.469219 32.852391 23.464953 32.8685 22.751953 33.4375 C 22.039953 34.0065 21.802781 34.986359 22.175781 35.818359 C 22.537781 36.624359 22.900281 37.607 22.988281 38 C 22.901281 38.393 22.537781 39.375641 22.175781 40.181641 C 21.802781 41.013641 22.039953 41.9935 22.751953 42.5625 C 23.116953 42.8545 23.558 43 24 43 C 24.422 43 24.843219 42.866609 25.199219 42.599609 L 27.722656 40.707031 C 29.139763 42.130607 31.548188 44 34.5 44 C 38.979 44 42.258187 39.670734 42.617188 39.177734 C 43.128188 38.475734 43.128188 37.524266 42.617188 36.822266 C 42.258188 36.329266 38.979 32 34.5 32 z M 34.5 36 C 35.908 36 37.346078 37.048 38.330078 38 C 37.345078 38.953 35.908 40 34.5 40 C 33.092 40 31.655922 38.953 30.669922 38 C 31.655922 37.047 33.092 36 34.5 36 z"/></svg>'
]
const SheepsEvents = (() => {
let initialized = false;
const SheepsEvents = {
initialized: false,
return {
init: () => {
if (initialized) return;
init() {
if (this.initialized) return;
const sheepEditorForm = document.getElementById("sheep-editor");
const sheepEditorButton = document.getElementById('sheep-editor-button');
sheepEditorForm.addEventListener("submit", async (event) => {
event.preventDefault();
const sheepEditorForm = document.getElementById("sheep-editor");
const sheepEditorButton = document.getElementById('sheep-editor-button');
sheepEditorForm.addEventListener("submit", async (event) => {
event.preventDefault();
const form = event.target;
const formData = new FormData(form);
const uuidValue = form.elements["uuid"].value;
const sheep = Sheeps.sheeps_list.list.find(item => item.uuid === uuidValue);
const form = event.target;
const formData = new FormData(form);
const uuidValue = form.elements["uuid"].value;
const sheep = Sheeps.sheeps_list.list.find(item => item.uuid === uuidValue);
if (!sheep) {
console.error("Sheep not found for uuid:", uuidValue);
return;
}
if (!sheep) {
console.error("Sheep not found for uuid:", uuidValue);
return;
}
sheep.name = form.elements["name"].value;
sheep.group_id = Number(formData.get("group_id"));
sheep.appointment = formData.get("appointment");
sheep.mode = formData.get("mode");
sheep.mode_title = ["Користувач", "Модератор", "Адміністратор"][sheep.mode] || "Користувач";
sheep.name = form.elements["name"].value;
sheep.group_id = Number(formData.get("group_id"));
sheep.appointment = formData.get("appointment");
sheep.mode = formData.get("mode");
sheep.mode_title = ["Користувач", "Модератор", "Адміністратор"][sheep.mode] || "Користувач";
const permKeys = [
"can_view_sheeps",
"can_view_schedule",
"can_view_stand",
"can_view_territory",
"can_add_sheeps",
"can_add_territory",
"can_manager_territory",
"can_add_stand",
"can_manager_stand",
"can_add_schedule"
];
for (const key of permKeys) {
sheep.possibilities[key] = form.elements[key].checked;
}
const permKeys = [
"can_view_sheeps",
"can_view_schedule",
"can_view_stand",
"can_view_territory",
"can_add_sheeps",
"can_add_territory",
"can_manager_territory",
"can_add_stand",
"can_manager_stand",
"can_add_schedule"
];
for (const key of permKeys) {
sheep.possibilities[key] = form.elements[key].checked;
}
sheepEditorButton.innerText = "Зачекайте...";
sheepEditorButton.innerText = "Зачекайте...";
try {
const uuid = localStorage.getItem('uuid');
const URL = `${CONFIG.api}sheep`;
const response = await fetch(URL, {
method: 'PUT',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
},
body: JSON.stringify(sheep)
});
try {
const uuid = localStorage.getItem('uuid');
const URL = `${CONFIG.api}sheep`;
const response = await fetch(URL, {
method: 'PUT',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
},
body: JSON.stringify(sheep)
});
if (response.ok) {
sheepEditorButton.innerText = "Успішно збережено";
const data = await response.json();
console.log(data);
if (response.ok) {
sheepEditorButton.innerText = "Успішно збережено";
const data = await response.json();
console.log(data);
Sheeps.sheeps_list.list = [];
await Sheeps.sheeps_list.setHTML();
Sheeps.sheeps_list.list = [];
await Sheeps.sheeps_list.setHTML();
setTimeout(() => {
sheepEditorButton.innerText = "Зберегти";
}, 3000);
} else {
console.error('Помилка збереження');
sheepEditorButton.innerText = "Помилка збереження";
}
} catch (err) {
console.error(err);
setTimeout(() => {
sheepEditorButton.innerText = "Зберегти";
}, 3000);
} else {
console.error('Помилка збереження');
sheepEditorButton.innerText = "Помилка збереження";
}
});
} catch (err) {
console.error(err);
sheepEditorButton.innerText = "Помилка збереження";
}
});
const sheepAddedsForm = document.getElementById("sheep-addeds");
const sheepAddedsButton = document.getElementById('sheep-addeds-button');
sheepAddedsForm.addEventListener("submit", async (event) => {
event.preventDefault();
const sheepAddedsForm = document.getElementById("sheep-addeds");
const sheepAddedsButton = document.getElementById('sheep-addeds-button');
sheepAddedsForm.addEventListener("submit", async (event) => {
event.preventDefault();
const form = event.target;
const formData = new FormData(form);
const data = Object.fromEntries(formData.entries());
const form = event.target;
const formData = new FormData(form);
const data = Object.fromEntries(formData.entries());
sheepAddedsButton.innerText = "Зачекайте...";
sheepAddedsButton.innerText = "Зачекайте...";
try {
const uuid = localStorage.getItem('uuid');
const URL = `${CONFIG.api}sheep`;
const response = await fetch(URL, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
},
body: JSON.stringify(data)
});
try {
const uuid = localStorage.getItem('uuid');
const URL = `${CONFIG.api}sheep`;
const response = await fetch(URL, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
},
body: JSON.stringify(data)
});
if (response.ok) {
sheepAddedsButton.innerText = "Вісника додано";
const data = await response.json();
console.log(data);
if (response.ok) {
sheepAddedsButton.innerText = "Вісника додано";
const data = await response.json();
console.log(data);
Sheeps.sheeps_list.list = [];
Sheeps.sheeps_list.list = [];
const randomNumber = Math.floor(Math.random() * Sheeps_icon.length);
const randomNumber = Math.floor(Math.random() * Sheeps_icon.length);
Sheeps.addeds.close();
await Sheeps.editor.setHTML(data.uuid, randomNumber);
Sheeps.addeds.close();
await Sheeps.editor.setHTML(data.id, randomNumber);
setTimeout(() => {
sheepAddedsButton.innerText = "Додати";
}, 3000);
} else {
console.error('Помилка додавання');
sheepAddedsButton.innerText = "Помилка додавання";
}
} catch (err) {
console.error(err);
setTimeout(() => {
sheepAddedsButton.innerText = "Додати";
}, 3000);
} else {
console.error('Помилка додавання');
sheepAddedsButton.innerText = "Помилка додавання";
}
});
} catch (err) {
console.error(err);
sheepAddedsButton.innerText = "Помилка додавання";
}
});
initialized = true;
}
this.initialized = true;
}
})();
};
const Sheeps = {
init: async (id) => {
let html = await fetch('/lib/pages/sheeps/index.html').then((response) => response.text());
app.innerHTML = html;
Sheeps.sheeps_list.setHTML();
await Sheeps.sheeps_list.setHTML();
if (id) Sheeps.editor.setHTML(id);
SheepsEvents.init();
@@ -196,6 +194,8 @@ const Sheeps = {
? Sheeps.sheeps_list.list
: await Sheeps.sheeps_list.loadAPI();
Sheeps.sheeps_list.list.sort((a, b) => a.group_id - b.group_id);
let block_sheeps = document.getElementById('block-sheeps-list');
let butt_add = USER.possibilities.can_add_sheeps ? `
@@ -245,7 +245,7 @@ const Sheeps = {
if (search_value && !element.name.toLowerCase().includes(search_value)) {
continue; // пропустить, если имя не содержит строку поиска
}
html += `
<div class="card-profile" onclick="Sheeps.editor.setHTML('${element.id}')" name="sheep_${element.id}">
${Sheeps_icon[element.group_id]}
@@ -386,11 +386,13 @@ const Sheeps = {
sheep_editor_can_view_territory.checked = sheep.possibilities.can_view_territory;
if (USER.possibilities.can_manager_territory) {
document.getElementById('editor-blocks-territory').style.display = "";
document.getElementById('editor-blocks-territory').style.display = "none";
document.getElementById(`editor-blocks-territory`).innerHTML = "<summary>Території вісника</summary>";
Sheeps.territory.house(id);
Sheeps.territory.homestead(id);
}
if (USER.mode == 2) {
document.getElementById('editor-blocks-territory').style.display = "";
document.getElementById('sheep-editor-button').style.display = "";
sheep_editor_mode.disabled = false;
} else {
@@ -462,5 +464,69 @@ const Sheeps = {
search_value = value?.trim()?.toLowerCase() || "";
Sheeps.sheeps_list.setHTML(search_value);
}
},
territory: {
async loadAPI(URL) {
const uuid = localStorage.getItem("uuid");
const res = await fetch(URL, {
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
});
return await res.json();
},
async house(id) {
const URL = `${CONFIG.api}house/list?mode=admin&sheep_id=${id}`;
const list = await Sheeps.territory.loadAPI(URL);
if ((USER.possibilities.can_view_territory || USER.mode == 2) && list.length > 0){
document.getElementById('editor-blocks-territory').style.display = "";
Sheeps.territory.renderCards(list, "house");
}
},
async homestead(id) {
const URL = `${CONFIG.api}homestead/list?mode=admin&sheep_id=${id}`;
const list = await Sheeps.territory.loadAPI(URL);
if ((USER.possibilities.can_view_territory || USER.mode == 2) && list.length > 0){
document.getElementById('editor-blocks-territory').style.display = "";
Sheeps.territory.renderCards(list, "homestead");
}
},
renderCards: (list, type) => {
const container = document.getElementById(`editor-blocks-territory`);
const fragment = document.createDocumentFragment();
for (const el of list) {
const card = document.createElement("div");
card.innerHTML = `
<div id="title">
<h1>${el.title} ${el.number}</h1>
<a href="/territory/manager/${type}/${el.id}" title="Редактор квартир" data-route>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30">
<path d="M24 2H14c-.55 0-1 .45-1 1v4l3.6 2.7c.25.19.4.49.4.8V14h8V3C25 2.45 24.55 2 24 2zM15.5 7C15.22 7 15 6.78 15 6.5v-2C15 4.22 15.22 4 15.5 4h2C17.78 4 18 4.22 18 4.5v2C18 6.78 17.78 7 17.5 7h-1.17H15.5zM23 4.5v2C23 6.78 22.78 7 22.5 7h-2C20.22 7 20 6.78 20 6.5v-2C20 4.22 20.22 4 20.5 4h2C22.78 4 23 4.22 23 4.5zM22.5 12h-2c-.28 0-.5-.22-.5-.5v-2C20 9.22 20.22 9 20.5 9h2C22.78 9 23 9.22 23 9.5v2C23 11.78 22.78 12 22.5 12zM1 11.51V27c0 .55.45 1 1 1h12c.55 0 1-.45 1-1V11.51c0-.32-.16-.62-.42-.81l-6-4.28C8.41 6.29 8.2 6.23 8 6.23S7.59 6.29 7.42 6.42l-6 4.28C1.16 10.89 1 11.19 1 11.51zM6.5 20h-2C4.22 20 4 19.78 4 19.5v-2C4 17.22 4.22 17 4.5 17h2C6.78 17 7 17.22 7 17.5v2C7 19.78 6.78 20 6.5 20zM7 22.5v2C7 24.78 6.78 25 6.5 25h-2C4.22 25 4 24.78 4 24.5v-2C4 22.22 4.22 22 4.5 22h2C6.78 22 7 22.22 7 22.5zM6.5 15h-2C4.22 15 4 14.78 4 14.5v-2C4 12.22 4.22 12 4.5 12h2C6.78 12 7 12.22 7 12.5v2C7 14.78 6.78 15 6.5 15zM9.5 17h2c.28 0 .5.22.5.5v2c0 .28-.22.5-.5.5h-2C9.22 20 9 19.78 9 19.5v-2C9 17.22 9.22 17 9.5 17zM9 14.5v-2C9 12.22 9.22 12 9.5 12h2c.28 0 .5.22.5.5v2c0 .28-.22.5-.5.5h-2C9.22 15 9 14.78 9 14.5zM9.5 22h2c.28 0 .5.22.5.5v2c0 .28-.22.5-.5.5h-2C9.22 25 9 24.78 9 24.5v-2C9 22.22 9.22 22 9.5 22zM17 17v10c0 .55.45 1 1 1h10c.55 0 1-.45 1-1V17c0-.55-.45-1-1-1H18C17.45 16 17 16.45 17 17zM19.5 18h2c.28 0 .5.22.5.5v2c0 .28-.22.5-.5.5h-2c-.28 0-.5-.22-.5-.5v-2C19 18.22 19.22 18 19.5 18zM27 18.5v2c0 .28-.22.5-.5.5h-2c-.28 0-.5-.22-.5-.5v-2c0-.28.22-.5.5-.5h2C26.78 18 27 18.22 27 18.5zM26.5 26h-2c-.28 0-.5-.22-.5-.5v-2c0-.28.22-.5.5-.5h2c.28 0 .5.22.5.5v2C27 25.78 26.78 26 26.5 26zM19.5 23h2c.28 0 .5.22.5.5v2c0 .28-.22.5-.5.5h-2c-.28 0-.5-.22-.5-.5v-2C19 23.22 19.22 23 19.5 23z"></path>
</svg>
</a>
</div>
<!--
<div>
<h1>Територія видана:</h1>
<h2>02.07.2025</h2>
</div>
<div>
<h1>Варто забрати:</h1>
<h2>01.11.2025</h2>
</div> -->
`;
fragment.appendChild(card);
}
container.appendChild(fragment);
}
}
}

View File

@@ -552,17 +552,17 @@
align-items: flex-start;
margin: 10px;
padding: 10px;
min-height: 100px;
min-height: 30px;
justify-content: center;
position: relative;
border-radius: calc(var(--border-radius) - 5px - 6px);
border-radius: calc(var(--border-radius) - 5px - 6px);
}
#editor-blocks-territory>div>#title {
display: flex;
align-items: center;
height: 30px;
margin-bottom: 10px;
/* margin-bottom: 10px; */
justify-content: space-between;
}
@@ -595,14 +595,14 @@
}
#editor-blocks-territory>div>#title>a>svg {
width: 25px;
height: 25px;
width: 20px;
height: 20px;
fill: var(--PrimaryColorText);
}
#editor-blocks-territory>div>div {
display: flex;
margin-bottom: 10px;
/* margin-bottom: 10px; */
flex-direction: row;
align-items: center;
width: 100%;

View File

@@ -6,277 +6,14 @@
<summary>Інформація про стенд</summary>
<div>
<span>Розташування:</span>
<p id="stand-info-title">Тест</p>
<p id="stand-info-title">--</p>
</div>
<div>
<span>Геолокація:</span>
<p id="stand-info-geo"></p>
<a id="stand-info-geo">--</a>
</div>
<img id="stand-info-image" src="" />
</details>
<div id="stand-schedule">
<!-- <div class="block-day" id="day-0">
<h3>08.08.2025 • Пʼятниця</h3>
<div>
<span id="time">09:00-10:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">10:00-11:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">11:00-12:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">12:00-13:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">14:00-15:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">15:00-16:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">16:00-17:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">17:00-18:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
</div>
<div class="block-day" id="day-1">
<h3>11.08.2025 • Понеділок</h3>
<div>
<span id="time">09:00-10:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">10:00-11:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">11:00-12:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">12:00-13:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">14:00-15:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">15:00-16:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">16:00-17:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">17:00-18:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
</div> -->
</div>
<div id="stand-schedule"></div>
</div>

View File

@@ -1,123 +1,541 @@
const Stand_card = {
schedule: [],
init: async (id) => {
id: null,
async init(id) {
let html = await fetch('/lib/pages/stand/card/index.html').then((response) => response.text());
app.innerHTML = html;
let listDate = [1, 4];
Stand_card.id = id;
function generateAvailableDates() {
let select = document.getElementById("dateSelect");
select.innerHTML = "";
this.info.setHTML();
},
let today = new Date();
today.setHours(0, 0, 0, 0);
let months = [today.getMonth(), today.getMonth() + 1];
let year = today.getFullYear();
async loadAPI(url) {
const uuid = localStorage.getItem("uuid");
const response = await fetch(url, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
});
return await response.json();
},
months.forEach(month => {
let date = new Date(year, month, 1);
while (date.getMonth() === month) {
if (date >= today) {
let day = date.getDay();
if (listDate.includes(day)) {
let option = document.createElement("option");
option.value = date.toISOString().split("T")[0];
option.textContent = date.toLocaleDateString("uk-UA", {
weekday: "long", year: "numeric", month: "long", day: "numeric"
});
select.appendChild(option);
info: {
list: [],
async setHTML() {
const url = `${CONFIG.api}stand/${Stand_card.id}`;
this.list = await Stand_card.loadAPI(url);
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]}`;
document.getElementById('stand-info-image').setAttribute('src', '');
Stand_card.schedule.setHTML();
}
},
// Робота з WebSocket
cloud: {
update(msg) {
const { type, data, user } = msg;
const el = document.getElementById(`name-${data?.id}`);
if (!el) return; // если элемент не найден — выходим
const isSelf = user.id == USER.id;
switch (type) {
case "stand_locking":
if (!isSelf) {
el.disabled = true;
el.style.border = "2px solid var(--PrimaryColor)";
el.style.backgroundColor = "#EAFF0024";
}
break;
case "stand_unlocking":
// Разблокируем только если событие от другого пользователя
if (!isSelf) {
el.style.border = "";
el.style.backgroundColor = "";
}
if ((!isSelf && !el.value) || USER.possibilities.can_manager_stand) {
el.removeAttribute("disabled");
}
break;
case "stand_update": {
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 => {
const opt = document.createElement("option");
opt.value = s.id;
opt.textContent = s.name;
if (s.id == sid) opt.selected = true;
el.appendChild(opt);
});
el.removeAttribute("disabled");
} else {
// Обычное поведение для обычных пользователей
if (sid == USER.id) {
el.innerHTML = `<option value=""></option><option selected value="${USER.id}">${USER.name}</option>`;
el.removeAttribute("disabled");
} else if (!sid) {
el.innerHTML = `<option value=""></option><option value="${USER.id}">${USER.name}</option>`;
el.removeAttribute("disabled");
} else {
el.innerHTML = `<option value="${sid}">${sname}</option>`;
el.disabled = true;
}
}
date.setDate(date.getDate() + 1);
}
});
}
// generateAvailableDates();
Stand_card.generator();
el.style.border = "";
el.style.backgroundColor = "";
break;
}
default:
return;
}
},
// update(msg) {
// console.log(msg.type, msg.data.id);
// if (msg.type == "stand_locking") {
// const id = msg.data.id;
// const el = document.getElementById(`name-${id}`);
// if (msg.user.id != USER.id) {
// el.disabled = true;
// el.style.border = "2px solid var(--PrimaryColor);"
// el.style.backgroundColor = "red"
// }
// } else if (msg.type == "stand_unlocking") {
// const id = msg.data.id;
// const el = document.getElementById(`name-${id}`);
// if (msg.user.id != USER.id || !msg.data.sheep_id) {
// el.style.border = "";
// el.style.backgroundColor = ""
// el.removeAttribute('disabled');
// }
// } else if (msg.type == "stand_update") {
// const id = msg.data.id;
// const el = document.getElementById(`name-${id}`);
// if (msg.data.sheep_id == USER.id) {
// el.innerHTML = `<option value=""></option><option selected value="${USER.id}">${USER.name}</option>`;
// el.removeAttribute('disabled');
// } else if (msg.data.sheep_id == "" || msg.data.sheep_id == null || msg.data.sheep_id == USER.id) {
// el.innerHTML = `<option value=""></option><option value="${USER.id}">${USER.name}</option>`;
// el.removeAttribute('disabled');
// } else {
// el.innerHTML = `<option value="${msg.data.sheep_id}">${msg.data.sheep_name}</option>`;
// el.disabled = true;
// }
// el.style.border = "";
// el.style.backgroundColor = ""
// } else return;
// },
mess: {
locking({ id }) {
const message = {
event: 'message',
user: {
name: USER.name,
id: USER.id
},
type: "stand_locking",
data: {
id: id,
stand_id: Stand_card.id,
sheep_name: null
}
};
if (Cloud.socket?.readyState === WebSocket.OPEN) {
Cloud.socket.send(JSON.stringify(message));
} else {
if (confirm("З'єднання розірвано! Перепідключитись?")) {
Cloud.start();
}
}
},
unlocking({ id }) {
const message = {
event: 'message',
user: {
name: USER.name,
id: USER.id
},
type: "stand_unlocking",
data: {
id: id,
stand_id: Stand_card.id
}
};
if (Cloud.socket?.readyState === WebSocket.OPEN) {
Cloud.socket.send(JSON.stringify(message));
} else {
if (confirm("З'єднання розірвано! Перепідключитись?")) {
Cloud.start();
}
}
},
update({ sheep_id, id }) {
const message = {
event: 'message',
user: {
name: USER.name,
id: USER.id
},
type: "stand_update",
data: {
id: id,
stand_id: Stand_card.id,
sheep_id: sheep_id,
sheep_name: null
}
};
if (USER.possibilities.can_manager_stand) {
const pos = Sheeps.sheeps_list.list.map(e => e.id).indexOf(Number(sheep_id));
if (pos != -1) {
let name = Sheeps.sheeps_list.list[pos].name;
message.data.sheep_name = name;
}
}
if (Cloud.socket?.readyState === WebSocket.OPEN) {
Cloud.socket.send(JSON.stringify(message));
} else {
if (confirm("З'єднання розірвано! Перепідключитись?")) {
Cloud.start();
}
}
}
},
},
generator: () => {
let block_schedule = document.getElementById('stand-schedule');
let html = "";
schedule: {
list: [],
async setHTML() {
const block = document.getElementById('stand-schedule');
block.innerHTML = '';
let stand = {
id: 1,
title: "Універсам",
geo: { lat: 0, lng: 0 },
hour_start: 9,
hour_end: 14,
quantity_sheep: 2,
week_days: [0, 2, 4, 6],
processing_time: 0.5,
updated_at: null
}
const url = `${CONFIG.api}stand/schedule/list/${Stand_card.id}`;
this.list = Stand_card.grouped(await Stand_card.loadAPI(url));
Stand_card.schedule = [];
const fragment = document.createDocumentFragment();
// Кількість годин служіння
let stand_length = (stand.hour_end - stand.hour_start) / stand.processing_time;
const createSelect = (sheep) => {
const select = document.createElement("select");
select.id = `name-${sheep.id}`;
for (let z = 0; z < stand.week_days.length; z++) {
Stand_card.schedule.push([]);
// пустой option
select.appendChild(Object.assign(document.createElement("option"), {
value: "",
textContent: " "
}));
let date = new Date();
date.setDate(date.getDate() + stand.week_days[z]);
let dayName = date.toLocaleDateString('uk-UA', { weekday: 'long' });
html += `
<div class="block-day" id="day-${z}">
<h3>${date.toLocaleDateString()}${dayName}</h3>
`;
let stand_date = 1 + stand.week_days[z];
for (let i = 0; i < stand_length; i++) {
let time_now = stand.hour_start + (stand.processing_time * i);
let timeFormat = (a) => a > 9 ? a : `0${a}`;
function formatTime(hours) {
let h = Math.floor(hours);
let m = (hours % 1 === 0.5) ? "30" : "00";
let hh = h.toString().padStart(2, "0");
return `${hh}:${m}`;
}
html += `
<div id="hour-${z}-${i}">
<span class="time">${formatTime(time_now)}-${formatTime(time_now + stand.processing_time)}</span>
`;
for (let q = 0; q < stand.quantity_sheep; q++) {
html += `
<select id="name">
<option value=""></option>
<option value="Test">Test</option>
</select>
`;
Stand_card.schedule[z].push({
id: (i + z) * stand.quantity_sheep + q,
hour: stand.hour_start + (stand.processing_time * i),
number_sheep: q,
date: stand_date,
sheep_id: null,
stand_id: stand.id,
updated_at: Date.now()
// если есть права менеджера — добавляем всех пользователей
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 => {
const option = document.createElement("option");
option.value = s.id;
option.textContent = s.name;
if (s.id === sheep.sheep_id) option.selected = true;
select.appendChild(option);
});
} else {
// если есть владелец — показываем его
const opt = document.createElement("option");
if (sheep.sheep_id) {
opt.value = sheep.sheep_id;
opt.textContent = sheep.sheep_name ?? USER.name;
opt.selected = sheep.sheep_id === USER.id;
} else {
opt.value = USER.id;
opt.textContent = USER.name;
}
select.appendChild(opt);
}
html += `</div>`; // закриваємо hour
// если занят другим пользователем — блокируем
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 }));
return select;
};
this.list.forEach((day, dayIndex) => {
const timestamp = day[0][0].date;
const dayDiv = Object.assign(document.createElement("div"), {
className: "block-day",
id: `day-${dayIndex}`
});
dayDiv.appendChild(Object.assign(document.createElement("h3"), {
textContent: `${formattedDate(timestamp)}${formattedDayName(timestamp)}`
}));
day.forEach((hour, hourIndex) => {
const hourDiv = Object.assign(document.createElement("div"), {
id: `hour-${dayIndex}-${hourIndex}`
});
hourDiv.appendChild(Object.assign(document.createElement("span"), {
className: "time",
textContent: `${Stand_card.formatTime(hour[0].hour)}-${Stand_card.formatTime(hour[0].hour + Stand_card.info.list.processing_time)}`
}));
hour.forEach(sheep => hourDiv.appendChild(createSelect(sheep)));
dayDiv.appendChild(hourDiv);
});
fragment.appendChild(dayDiv);
});
// кнопка добавления
if (USER.possibilities.can_add_stand) {
const btn = Object.assign(document.createElement("button"), {
id: "stand-new-button",
textContent: "Додати стенд(и)",
onclick: () => Stand_card.addStand()
});
fragment.appendChild(btn);
}
html += `</div>`; // закриваємо day
block.appendChild(fragment);
}
// async setHTML() {
// const block_schedule = document.getElementById('stand-schedule');
// block_schedule.innerHTML = '';
// const url = `${CONFIG.api}stand/schedule/list/${Stand_card.id}`;
// this.list = Stand_card.grouped(await Stand_card.loadAPI(url));
// let dayIndex = 0;
// for (const day of this.list) {
// const timestamp = day[0][0].date;
// const dayDiv = document.createElement("div");
// dayDiv.className = "block-day";
// dayDiv.id = `day-${dayIndex}`;
// const header = document.createElement("h3");
// header.textContent = `${formattedDate(timestamp)} • ${formattedDayName(timestamp)}`;
// dayDiv.appendChild(header);
// let hourIndex = 0;
// for (const hour of day) {
// const hourDiv = document.createElement("div");
// hourDiv.id = `hour-${dayIndex}-${hourIndex}`;
// const span = document.createElement("span");
// span.className = "time";
// span.textContent = `${Stand_card.formatTime(hour[0].hour)}-${Stand_card.formatTime(hour[0].hour + Stand_card.info.list.processing_time)}`;
// hourDiv.appendChild(span);
// for (const sheep of hour) {
// const select = document.createElement("select");
// select.id = `name-${sheep.id}`;
// const emptyOption = document.createElement("option");
// emptyOption.value = "";
// emptyOption.textContent = " ";
// select.appendChild(emptyOption);
// if (sheep.sheep_id && sheep.sheep_id == USER.id) {
// const opt = document.createElement("option");
// opt.value = USER.id;
// opt.textContent = USER.name;
// opt.selected = true;
// select.appendChild(opt);
// // --- Обработчики событий ---
// select.addEventListener("focus", () => {
// // пользователь начал взаимодействие → блокируем
// Stand_card.cloud.mess.locking({ id: sheep.id });
// });
// select.addEventListener("blur", () => {
// // пользователь ушёл → разблокируем
// Stand_card.cloud.mess.unlocking({ id: sheep.id });
// });
// select.addEventListener("change", () => {
// // пользователь выбрал что-то → обновляем
// Stand_card.cloud.mess.update({ sheep_id: select.value, id: sheep.id });
// });
// } else if (sheep.sheep_id && sheep.sheep_id != USER.id) {
// const opt = document.createElement("option");
// opt.value = sheep.sheep_id;
// opt.textContent = sheep.sheep_name;
// opt.selected = true;
// select.appendChild(opt);
// // --- Обработчики событий ---
// select.addEventListener("focus", () => {
// // пользователь начал взаимодействие → блокируем
// Stand_card.cloud.mess.locking({ id: sheep.id });
// });
// select.addEventListener("blur", () => {
// // пользователь ушёл → разблокируем
// Stand_card.cloud.mess.unlocking({ id: sheep.id });
// });
// select.addEventListener("change", () => {
// // пользователь выбрал что-то → обновляем
// Stand_card.cloud.mess.update({ sheep_id: select.value, id: sheep.id });
// });
// select.disabled = true;
// } else {
// const opt = document.createElement("option");
// opt.value = USER.id;
// opt.textContent = USER.name;
// select.appendChild(opt);
// // --- Обработчики событий ---
// select.addEventListener("focus", () => {
// // пользователь начал взаимодействие → блокируем
// Stand_card.cloud.mess.locking({ id: sheep.id });
// });
// select.addEventListener("blur", () => {
// // пользователь ушёл → разблокируем
// Stand_card.cloud.mess.unlocking({ id: sheep.id });
// });
// select.addEventListener("change", () => {
// // пользователь выбрал что-то → обновляем
// Stand_card.cloud.mess.update({ sheep_id: select.value, id: sheep.id });
// });
// }
// hourDiv.appendChild(select);
// }
// dayDiv.appendChild(hourDiv);
// hourIndex++;
// }
// block_schedule.appendChild(dayDiv);
// dayIndex++;
// }
// if (USER.possibilities.can_add_stand) {
// const btn = document.createElement("button");
// btn.id = "stand-new-button";
// btn.onclick = () => Stand_card.addStand();
// btn.textContent = "Додати стенд(и)";
// block_schedule.appendChild(btn);
// }
// }
},
grouped(list) {
const groupedByDate = {};
for (const item of list) {
if (!groupedByDate[item.date]) groupedByDate[item.date] = [];
groupedByDate[item.date].push(item);
}
document.getElementById('stand-info-title').innerText = Stand_card.title;
document.getElementById('stand-info-geo').innerHTML = '';
document.getElementById('stand-info-image').setAttribute('src', '');
const result = Object.values(groupedByDate).map(dateGroup => {
const groupedByHour = [];
let currentGroup = [];
let lastHour = null;
for (const item of dateGroup) {
if (item.hour !== lastHour) {
if (currentGroup.length > 0) groupedByHour.push(currentGroup);
currentGroup = [];
lastHour = item.hour;
}
currentGroup.push(item);
}
if (currentGroup.length > 0) groupedByHour.push(currentGroup);
return groupedByHour;
});
return result;
},
formatTime(hours) {
let h = Math.floor(hours);
let m = (hours % 1 === 0.5) ? "30" : "00";
let hh = h.toString().padStart(2, "0");
return `${hh}:${m}`;
},
async addStand() {
const button = document.getElementById('stand-new-button');
const uuid = localStorage.getItem('uuid');
const URL = `${CONFIG.api}stand/schedule/${Stand_card.id}`;
await fetch(URL, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
})
.then(response => {
if (response.status == 200) {
console.log({ 'setPack': 'ok' });
button.innerText = "Стенд(и) додано";
return response.json()
} else {
console.log('err');
button.innerText = "Помилка запису";
return
}
})
.then(data => {
console.log(data);
Stand_card.schedule.setHTML();
setTimeout(() => {
button.innerText = "Додати стенд(и)";
}, 3000);
})
.catch(err => {
console.log(err);
button.innerText = "Помилка запису";
})
},
edit({ sheep_id, stand_id }) {
block_schedule.innerHTML = html;
}
}

View File

@@ -73,7 +73,7 @@
#stand-schedule {
width: 100%;
min-height: calc(100vh - 40px - 50px);
/* min-height: calc(100vh - 40px - 50px); */
height: fit-content;
margin: 0 10px 15px;
border-radius: var(--border-radius);
@@ -137,6 +137,9 @@
background-color: var(--ColorThemes0);
color: var(--ColorThemes3);
}
#stand-schedule>.block-day div select:disabled {
opacity: 0.9 !important;
}
#stand-schedule>.block-day div:nth-child(2n) {
background: var(--ColorThemes0);
@@ -145,4 +148,17 @@
#stand-schedule>.block-day div:nth-child(2n) select {
background-color: var(--ColorThemes2);
}
#stand-schedule> #stand-new-button{
border-radius: 6px;
background: var(--PrimaryColor);
color: var(--PrimaryColorText);
width: calc(100% - 20px);
height: 40px;
font-size: var(--FontSize3);
font-weight: 400;
margin: 10px;
text-transform: uppercase;
cursor: pointer;
}

View File

@@ -0,0 +1,115 @@
<div class="page-stand-constructor">
<form id="stand-constructor-form">
<h1>Створення місця розташування стенду</h1>
<div>
<label for="info-title">Назва стенду</label>
<input type="text" id="info-title" name="title" required />
</div>
<div>
<label for="info-quantity_sheep"
>Кількість вісників, що можуть стояти одночасно</label
>
<select id="info-quantity_sheep" name="quantity_sheep" required>
<option value="2" selected>2 вісника</option>
<option value="3">3 вісника</option>
<option value="4">4 вісника</option>
<option value="5">5 вісників</option>
<option value="6">6 вісників</option>
</select>
</div>
<div>
<label>Години початку та кінця служіння</label>
<div class="geo-inputs">
<input
type="number"
id="info-hour_start"
name="hour_start"
required
placeholder="10"
min="5",
step="1"
/>
<input
type="number"
id="info-hour_end"
name="hour_end"
required
placeholder="16"
max="22",
step="1"
/>
</div>
</div>
<div>
<label>Локація розташування</label>
<div class="geo-inputs">
<input
type="number"
id="info-geo_lat"
name="geo_lat"
required
placeholder="49.5601856455014",
step="0.01"
/>
<input
type="number"
id="info-geo_lng"
name="geo_lng"
required
placeholder="25.625626212730406",
step="0.01"
/>
</div>
</div>
<div>
<label for="info-processing_time">Час тривалості зміни вісників</label>
<select id="info-processing_time" name="processing_time" required>
<option value="0.5">30 хвилин</option>
<option value="1" selected>1 година</option>
<option value="2">2 години</option>
<option value="3">3 години</option>
</select>
</div>
<div>
<label>Дні встановлення стенду</label>
<div class="week-days">
<div class="option checkbox">
<input class="custom-checkbox" id="day-0" name="day-0" type="checkbox" />
<label for="day-0""> Понеділок: </label>
</div>
<div class="option checkbox">
<input class="custom-checkbox" id="day-1" name="day-1" type="checkbox" />
<label for="day-1"> Вівторок: </label>
</div>
<div class="option checkbox">
<input class="custom-checkbox" id="day-2" name="day-2" type="checkbox" />
<label for="day-2"> Середа: </label>
</div>
<div class="option checkbox">
<input class="custom-checkbox" id="day-3" name="day-3" type="checkbox" />
<label for="day-3"> Четвер: </label>
</div>
<div class="option checkbox">
<input class="custom-checkbox" id="day-4" name="day-4" type="checkbox" />
<label for="day-4"> Пʼятниця: </label>
</div>
<div class="option checkbox">
<input class="custom-checkbox" id="day-5" name="day-5" type="checkbox" />
<label for="day-5"> Субота: </label>
</div>
<div class="option checkbox">
<input class="custom-checkbox" id="day-6" name="day-6" type="checkbox" />
<label for="day-6"> Неділя: </label>
</div>
</div>
</div>
<button type="submit" id="stand-constructor-button">Зберегти</button>
</form>
</div>

View File

@@ -0,0 +1,75 @@
const Stand_constructor = {
init: async () => {
let html = await fetch('/lib/pages/stand/constructor/index.html').then((response) => response.text());
app.innerHTML = html;
const form = document.getElementById('stand-constructor-form');
form.addEventListener('submit', (event) => {
event.preventDefault();
let values = {
"title": document.getElementById('info-title').value,
"quantity_sheep": Number(document.getElementById('info-quantity_sheep').value),
"hour_start": Number(document.getElementById('info-hour_start').value),
"hour_end": Number(document.getElementById('info-hour_end').value),
"geo": [Number(document.getElementById('info-geo_lat').value), Number(document.getElementById('info-geo_lng').value)],
"processing_time": Number(document.getElementById('info-processing_time').value)
};
const checkboxes = form.querySelectorAll('input[type="checkbox"][name^="day-"]');
let week_days = () => {
let a = [];
for (const key in checkboxes) {
const element = checkboxes[key];
if(element.checked) a.push(Number((element.name).replace("day-", "")))
}
return a
}
values.week_days = week_days();
console.log(values);
Stand_constructor.save(values);
});
},
async save(values) {
const button = document.getElementById('stand-constructor-button');
const uuid = localStorage.getItem('uuid');
const URL = `${CONFIG.api}stand/list`;
await fetch(URL, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
},
body: JSON.stringify(values)
})
.then(response => {
if (response.status == 200) {
console.log({ 'setPack': 'ok' });
button.innerText = "Стенд додано";
return response.json()
} else {
console.log('err');
button.innerText = "Помилка запису";
return
}
})
.then(data => {
console.log(data);
Router.navigate(`/stand/card/${data.id}`);
setTimeout(() => {
button.innerText = "Зберегти";
}, 3000);
})
.catch(err => {
console.log(err);
button.innerText = "Помилка запису";
})
}
}

View File

@@ -0,0 +1,120 @@
.page-stand-constructor {
width: calc(100% - 40px);
display: flex;
flex-direction: column;
align-items: stretch;
margin: 20px 20px 0 20px;
}
.page-stand-constructor>form {
border-radius: 10px;
width: calc(100% - 40px);
display: flex;
flex-direction: column;
align-items: stretch;
margin-bottom: 20px;
background: var(--ColorThemes1);
color: var(--ColorThemes3);
border: 1px solid var(--ColorThemes2);
box-shadow: var(--shadow-l1);
padding: 0 20px;
position: relative;
}
.page-stand-constructor>form>h1 {
width: calc(100% - 40px);
color: var(--ColorThemes3);
border-radius: var(--border-radius);
font-size: var(--FontSize5);
font-weight: 300;
padding: 20px 0;
position: relative;
}
.page-stand-constructor>form>div {
width: 100%;
display: flex;
margin: 20px 0;
align-items: flex-start;
flex-direction: column;
}
.page-stand-constructor>form>div>label {
display: flex;
justify-content: center;
flex-direction: column;
font-size: var(--FontSize1);
font-weight: 500;
margin-bottom: 5px;
}
.page-stand-constructor>form>div>select {
width: 100%;
min-width: 140px;
padding: 0 5px;
border-radius: calc(var(--border-radius) - 5px - 4px);
height: 30px;
background-color: var(--ColorThemes0);
color: var(--ColorThemes3);
}
.page-stand-constructor>form>div>input,
.page-stand-constructor>form>div>div>input {
width: calc(100% - 10px);
min-width: 140px;
padding: 0 5px;
border-radius: 6px;
height: 30px;
background: var(--ColorThemes0);
color: var(--ColorThemes3);
font-size: var(--FontSize2);
}
.page-stand-constructor>form>div>.geo-inputs {
width: 100%;
display: flex;
justify-content: space-between;
}
.page-stand-constructor>form>div>.geo-inputs>input {
width: calc(50% - 15px);
}
.page-stand-constructor>form>div>.week-days {
background: var(--ColorThemes0);
border-radius: calc(var(--border-radius) - 5px - 4px);
width: calc(100% - 15px);
padding: 0 5px 0 10px;
}
.page-stand-constructor>form>div>.week-days>div {
margin: 10px 0;
width: 100%;
font-size: var(--FontSize3);
}
.page-stand-constructor>form>div>.week-days>div>.custom-checkbox+label {
font-size: var(--FontSize4);
font-weight: 400;
width: 100%;
display: flex;
align-items: center;
user-select: none;
flex-direction: row-reverse;
justify-content: space-between;
cursor: pointer;
margin: 5px 0;
}
.page-stand-constructor>form>button {
border-radius: 6px;
background: var(--PrimaryColor);
color: var(--PrimaryColorText);
width: 100%;
height: 40px;
font-size: var(--FontSize3);
font-weight: 400;
margin: 20px 0;
text-transform: uppercase;
}

View File

@@ -0,0 +1,282 @@
<div class="page-stand">
<!-- <label for="dateSelect">Виберіть дату:</label>
<select id="dateSelect"></select> -->
<details id="stand-info">
<summary>Інформація про стенд</summary>
<div>
<span>Розташування:</span>
<p id="stand-info-title">Тест</p>
</div>
<div>
<span>Геолокація:</span>
<p id="stand-info-geo"></p>
</div>
<img id="stand-info-image" src="" />
</details>
<div id="stand-schedule">
<!-- <div class="block-day" id="day-0">
<h3>08.08.2025 • Пʼятниця</h3>
<div>
<span id="time">09:00-10:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">10:00-11:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">11:00-12:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">12:00-13:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">14:00-15:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">15:00-16:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">16:00-17:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">17:00-18:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
</div>
<div class="block-day" id="day-1">
<h3>11.08.2025 • Понеділок</h3>
<div>
<span id="time">09:00-10:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">10:00-11:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">11:00-12:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">12:00-13:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">14:00-15:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">15:00-16:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">16:00-17:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
<div>
<span id="time">17:00-18:00</span>
<select id="name_1">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_2">
<option value=""></option>
<option value="Test">Test</option>
</select>
<select id="name_3">
<option value=""></option>
<option value="Test">Test</option>
</select>
</div>
</div> -->
</div>
</div>

View File

@@ -1,3 +1,25 @@
<div class="page-stand-list">
<div class="buttons-list" id="buttons-list">
<a
href="/stand/constructor"
data-route
id="constructorButton"
style="display: none"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">
<path
d="M 14.5 4 C 12.015 4 10 6.015 10 8.5 L 10 39.5 C 10 41.985 12.015 44 14.5 44 L 22.042969 44 C 22.079969 43.749 22.138516 43.502672 22.228516 43.263672 L 22.283203 43.285156 C 22.353203 42.961156 23.236422 40.161109 23.982422 37.787109 C 24.272422 36.865109 24.779891 36.029703 25.462891 35.345703 L 33.904297 27 L 27.5 27 C 26.672 27 26 26.328 26 25.5 L 26 16 L 38 16 L 38 23.054688 C 38.72 22.587688 39.4975 22.254422 40.3125 22.107422 C 40.5365 22.067422 40.769 22.062922 41 22.044922 L 41 14.5 C 41 13.672 40.328 13 39.5 13 L 34 13 L 34 8.5 C 34 6.015 31.985 4 29.5 4 L 14.5 4 z M 30.5 18 A 1.50015 1.50015 0 1 0 30.5 21 L 33.5 21 A 1.50015 1.50015 0 1 0 33.5 18 L 30.5 18 z M 41.498047 24 C 41.224047 24.001 40.946969 24.025172 40.667969 24.076172 C 39.783969 24.235172 38.939563 24.696156 38.226562 25.410156 L 26.427734 37.208984 C 26.070734 37.565984 25.807969 38.011141 25.667969 38.494141 L 24.097656 43.974609 C 24.025656 44.164609 23.993 44.365406 24 44.566406 C 24.013 44.929406 24.155594 45.288406 24.433594 45.566406 C 24.710594 45.843406 25.067688 45.986 25.429688 46 C 25.630688 46.007 25.834391 45.975344 26.025391 45.902344 L 31.505859 44.332031 C 31.988859 44.192031 32.431062 43.930266 32.789062 43.572266 L 44.589844 31.773438 C 45.303844 31.060437 45.764828 30.216031 45.923828 29.332031 C 45.973828 29.053031 45.997047 28.775953 45.998047 28.501953 C 46.001047 27.307953 45.540687 26.179312 44.679688 25.320312 C 43.820687 24.460313 42.692047 23.998 41.498047 24 z M 22 35 C 22.828 35 23.5 35.672 23.5 36.5 C 23.5 37.328 22.828 38 22 38 C 21.172 38 20.5 37.328 20.5 36.5 C 20.5 35.672 21.172 35 22 35 z"
/>
</svg>
<span>Конструктор</span>
</a>
</div>
<details open>
<summary>
<span>Доступні стенди</span>
</summary>
<div id="list"></div>
</details>
</div>

View File

@@ -1,6 +1,53 @@
const Stand_list = {
list: [],
init: async () => {
let html = await fetch('/lib/pages/stand/list/index.html').then((response) => response.text());
app.innerHTML = html;
Stand_list.setHTML();
if (USER.possibilities.can_add_stand) {
document.getElementById("buttons-list").style.display = "flex";
document.getElementById("constructorButton").style.display = "";
}
},
loadAPI: async function (url) {
const uuid = localStorage.getItem("uuid");
const response = await fetch(url, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
});
Stand_list.list = await response.json();
return Stand_list.list;
},
setHTML: async function () {
const block_list = document.getElementById('list');
const url = `${CONFIG.api}stand/list`;
let list = this.list.length > 0 ? this.list : await this.loadAPI(url);
let html = "";
for (const element of list) {
html += this.renderCard({ element });
}
block_list.innerHTML = html;
},
renderCard: ({ element }) => {
return `
<div class="card">
<div class="contents">
<div class="info">
<div>
<p>${element.title}</p>
</div>
</div>
</div>
<a href="/stand/card/${element.id}" data-route></a>
</div>
`;
},
}

View File

@@ -2,6 +2,243 @@
width: calc(100% - 40px);
display: flex;
flex-direction: column;
align-items: center;
align-items: stretch;
margin: 20px 20px 0 20px;
}
.page-stand-list>.buttons-list {
padding: 10px;
margin-bottom: 40px;
background: var(--ColorThemes1);
color: var(--ColorThemes3);
border: 1px solid var(--ColorThemes2);
box-shadow: var(--shadow-l1);
border-radius: var(--border-radius);
overflow: auto;
display: none;
}
.page-stand-list>.buttons-list>button,
.page-stand-list>.buttons-list>a {
cursor: pointer;
border-radius: calc(var(--border-radius) - 5px);
padding: 0 10px;
margin-right: 20px;
min-width: fit-content;
min-height: 40px;
background: var(--PrimaryColor);
display: flex;
align-items: center;
justify-content: center;
}
.page-stand-list>.buttons-list>button>span,
.page-stand-list>.buttons-list>a>span {
color: var(--PrimaryColorText);
font-size: var(--FontSize3);
font-weight: normal;
}
.page-stand-list>.buttons-list>button>svg,
.page-stand-list>.buttons-list>a>svg {
width: 20px;
height: 20px;
fill: var(--PrimaryColorText);
margin-right: 10px;
}
.page-stand-list>.list-controls {
padding: 10px;
margin: 0px 0 10px 0;
background: var(--ColorThemes1);
color: var(--ColorThemes3);
border: 1px solid var(--ColorThemes2);
box-shadow: var(--shadow-l1);
border-radius: var(--border-radius);
overflow: auto;
display: flex;
}
.page-stand-list>.list-controls select {
min-width: 140px;
height: 30px;
background-color: var(--ColorThemes2);
border: 1px solid var(--ColorThemes0);
box-shadow: var(--shadow-l1);
color: var(--ColorThemes3);
font-size: var(--FontSize1);
cursor: pointer;
padding: 0 5px;
margin-right: 10px;
border-radius: calc(var(--border-radius) - 5px - 2px);
}
.page-stand-list details {
border-radius: var(--border-radius);
width: 100%;
display: flex;
flex-direction: column;
align-items: stretch;
margin-bottom: 10px;
background: var(--ColorThemes1);
color: var(--ColorThemes3);
border: 1px solid var(--ColorThemes2);
box-shadow: var(--shadow-l1);
}
.page-stand-list>details[disabled] summary,
.page-stand-list>details.disabled summary {
pointer-events: none;
user-select: none;
}
.page-stand-list>details summary::-webkit-details-marker,
.page-stand-list>details summary::marker {
display: none;
content: "";
}
.page-stand-list summary {
width: calc(100% - 40px);
cursor: pointer;
color: var(--ColorThemes3);
border-radius: var(--border-radius);
font-size: var(--FontSize5);
font-weight: 300;
padding: 20px;
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
}
.page-stand-list #list {
width: 100%;
margin: 0;
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-content: flex-start;
justify-content: center;
overflow-y: auto;
align-items: flex-start;
transition: .3s ease;
}
.page-stand-list .card {
position: relative;
width: 300px;
height: 200px;
background-color: var(--ColorThemes2);
margin: 0px 10px 20px 10px;
overflow: hidden;
cursor: pointer;
border-radius: calc(var(--border-radius) - 5px);
}
@media (max-width: 2300px) {
.page-stand-list .card {
width: calc((100% / 5) - 40px);
}
}
@media (max-width: 1960px) {
.page-stand-list .card {
width: calc((100% / 4) - 40px);
}
}
@media (max-width: 1640px) {
.page-stand-list .card {
width: calc((100% / 3) - 40px);
}
}
@media (max-width: 1280px) {
.page-stand-list .card {
width: calc((100% / 2) - 40px);
}
}
@media (max-width: 650px) {
.page-stand-list .card {
width: 100%;
}
}
@media(hover: hover) {
.page-stand-list .card:hover {
opacity: 0.8;
}
}
.page-stand-list .card>i {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
z-index: 1;
filter: blur(2px);
/* background-repeat: round; */
background-size: cover;
background-position: center;
background-color: var(--PrimaryColor);
}
.page-stand-list .card>a {
position: absolute;
width: 100%;
height: 100%;
z-index: 10;
}
.page-stand-list .card>.contents {
position: absolute;
z-index: 2;
background: rgb(64 64 64 / 0.7);
width: 100%;
height: 100%;
font-size: 40px;
font-weight: 500;
color: #fff;
display: flex;
flex-direction: column;
align-items: stretch;
justify-content: space-between;
}
.page-stand-list .card>.contents>.info {
margin: 10px;
}
.page-stand-list .card>.contents>.info>div {
width: 100%;
height: 35px;
display: flex;
background: var(--ColorThemes0);
align-items: center;
justify-content: center;
font-size: var(--FontSize1);
color: var(--ColorThemes3);
border-radius: calc(var(--border-radius) - 5px - 4px);
position: relative;
overflow: hidden;
}
.page-stand-list .card>.contents>.info>div>span {
color: var(--ColorThemes3);
font-size: var(--FontSize3);
font-weight: 300;
z-index: 2;
}
.page-stand-list .card>.contents>.info>div>p {
color: var(--ColorThemes3);
font-size: var(--FontSize3);
font-weight: 400;
padding: 10px;
z-index: 2;
}

View File

@@ -0,0 +1,123 @@
const Stand = {
schedule: [],
init: async () => {
let html = await fetch('/lib/pages/stand/index.html').then((response) => response.text());
app.innerHTML = html;
let listDate = [1, 4];
function generateAvailableDates() {
let select = document.getElementById("dateSelect");
select.innerHTML = "";
let today = new Date();
today.setHours(0, 0, 0, 0);
let months = [today.getMonth(), today.getMonth() + 1];
let year = today.getFullYear();
months.forEach(month => {
let date = new Date(year, month, 1);
while (date.getMonth() === month) {
if (date >= today) {
let day = date.getDay();
if (listDate.includes(day)) {
let option = document.createElement("option");
option.value = date.toISOString().split("T")[0];
option.textContent = date.toLocaleDateString("uk-UA", {
weekday: "long", year: "numeric", month: "long", day: "numeric"
});
select.appendChild(option);
}
}
date.setDate(date.getDate() + 1);
}
});
}
// generateAvailableDates();
Stand.generator();
},
generator: () => {
let block_schedule = document.getElementById('stand-schedule');
let html = "";
let stand = {
id: 1,
title: "Універсам",
geo: { lat: 0, lng: 0 },
hour_start: 9,
hour_end: 14,
quantity_sheep: 2,
week_days: [0, 2, 4, 6],
processing_time: 0.5,
updated_at: null
}
Stand.schedule = [];
// Кількість годин служіння
let stand_length = (stand.hour_end - stand.hour_start) / stand.processing_time;
for (let z = 0; z < stand.week_days.length; z++) {
Stand.schedule.push([]);
let date = new Date();
date.setDate(date.getDate() + stand.week_days[z]);
let dayName = date.toLocaleDateString('uk-UA', { weekday: 'long' });
html += `
<div class="block-day" id="day-${z}">
<h3>${date.toLocaleDateString()}${dayName}</h3>
`;
let stand_date = 1 + stand.week_days[z];
for (let i = 0; i < stand_length; i++) {
let time_now = stand.hour_start + (stand.processing_time * i);
let timeFormat = (a) => a > 9 ? a : `0${a}`;
function formatTime(hours) {
let h = Math.floor(hours);
let m = (hours % 1 === 0.5) ? "30" : "00";
let hh = h.toString().padStart(2, "0");
return `${hh}:${m}`;
}
html += `
<div id="hour-${z}-${i}">
<span class="time">${formatTime(time_now)}-${formatTime(time_now + stand.processing_time)}</span>
`;
for (let q = 0; q < stand.quantity_sheep; q++) {
html += `
<select id="name">
<option value=""></option>
<option value="Test">Test</option>
</select>
`;
Stand.schedule[z].push({
id: (i + z) * stand.quantity_sheep + q,
hour: stand.hour_start + (stand.processing_time * i),
number_sheep: q,
date: stand_date,
sheep_id: null,
stand_id: stand.id,
updated_at: Date.now()
});
}
html += `</div>`; // закриваємо hour
}
html += `</div>`; // закриваємо day
}
document.getElementById('stand-info-title').innerText = stand.title;
document.getElementById('stand-info-geo').innerHTML = '';
document.getElementById('stand-info-image').setAttribute('src', '');
block_schedule.innerHTML = html;
}
}

View File

@@ -0,0 +1,148 @@
.page-stand {
width: calc(100% - 40px);
display: flex;
flex-direction: column;
align-items: center;
margin: 20px 20px 0 20px;
}
.page-stand details {
border-radius: var(--border-radius);
width: 100%;
display: flex;
flex-direction: column;
align-items: stretch;
margin-bottom: 20px;
background: var(--ColorThemes1);
color: var(--ColorThemes3);
border: 1px solid var(--ColorThemes2);
box-shadow: var(--shadow-l1);
}
.page-stand summary {
width: calc(100% - 40px);
cursor: pointer;
color: var(--ColorThemes3);
border-radius: var(--border-radius);
font-size: var(--FontSize5);
font-weight: 300;
padding: 20px;
position: relative;
}
#stand-info div {
display: flex;
flex-direction: row;
display: flex;
flex-direction: row;
padding: 10px;
color: var(--ColorThemes3);
align-items: center;
}
#stand-info div span {
opacity: 0.8;
font-weight: 400;
font-size: var(--FontSize2);
margin-right: 5px;
}
#stand-info div p {
font-weight: 300;
font-size: var(--FontSize4);
}
#stand-info img {
position: relative;
display: inline-block;
width: calc(100% - 20px);
border-radius: calc(var(--border-radius) - 8px);
margin: 10px;
height: auto;
aspect-ratio: 16 / 9;
background-color: #f2e5c9;
}
#stand-info img::before {
content: "Приклад розташування";
display: block;
color: #555;
text-align: center;
padding: 10px;
}
#stand-schedule {
width: 100%;
min-height: calc(100vh - 40px - 50px);
height: fit-content;
margin: 0 10px 15px;
border-radius: var(--border-radius);
display: flex;
flex-direction: column;
overflow: hidden;
background: var(--ColorThemes1);
color: var(--ColorThemes3);
border: 1px solid var(--ColorThemes2);
box-shadow: var(--shadow-l1);
transition: all .2sease 0s;
}
#stand-schedule>.block-day {
display: flex;
flex-direction: column;
width: calc(100% - 20px);
margin: 10px;
padding: 10px 0;
border: 1px solid var(--PrimaryColor);
background-color: var(--ColorThemes2);
border: 1px solid var(--ColorThemes0);
min-height: 100px;
justify-content: center;
position: relative;
border-radius: calc(var(--border-radius) - 5px);
overflow-x: auto;
}
#stand-schedule>.block-day h3 {
font-size: 17px;
font-weight: 500;
padding: 10px;
text-transform: capitalize;
width: calc(100% - 20px);
text-align: center;
}
#stand-schedule>.block-day div {
display: flex;
flex-direction: row;
padding: 5px 0;
margin: 0 10px;
align-items: center;
min-width: calc(100% - 20px);
width: fit-content;
}
#stand-schedule>.block-day div span {
min-width: 85px;
padding: 0 5px;
}
#stand-schedule>.block-day div select {
width: 100%;
min-width: 140px;
padding: 0 5px;
margin: 0 5px;
border-radius: calc(var(--border-radius) - 5px - 4px);
height: 30px;
background-color: var(--ColorThemes0);
color: var(--ColorThemes3);
}
#stand-schedule>.block-day div:nth-child(2n) {
background: var(--ColorThemes0);
border-radius: 8px;
}
#stand-schedule>.block-day div:nth-child(2n) select {
background-color: var(--ColorThemes2);
}

View File

@@ -3,9 +3,6 @@ let map_card;
const Territory_card = {
// Глобальні змінні стану
id: null,
socket: null,
reconnectTimeout: null,
reconnectAttempts: 0,
listEntrances: [],
listApartment: [],
listBuilding: [],
@@ -28,11 +25,6 @@ const Territory_card = {
app.innerHTML = html;
Territory_card.id = Id;
// Закриваємо старий WebSocket
if (this.socket) this.socket.close(1000, "Перезапуск з'єднання");
// this.cloud.start(makeid(6));
this.cloud.start()
// Якщо це сторінка будинку, отримуємо під’їзди та стартуємо WebSocket
if (type === "house") {
const controls = document.getElementById('page-card-controls');
@@ -45,6 +37,13 @@ const Territory_card = {
this.getHomestead.map({});
}
const ids = ['cloud_1', 'cloud_2', 'cloud_3'];
ids.forEach((id, idx) => {
const el = document.getElementById(id);
if(!el) return;
el.setAttribute('data-state', ['sync', 'ok', 'err'].indexOf(Cloud.status) === idx ? 'active' : '');
});
// Додаємо обробник закриття попапу
const popup = document.getElementById('card-new-date');
if (!popup.dataset.listenerAdded) {
@@ -59,71 +58,6 @@ const Territory_card = {
// Робота з WebSocket
cloud: {
start() {
const uuid = localStorage.getItem("uuid");
const ws = new WebSocket(CONFIG.wss, uuid);
Territory_card.socket = ws;
ws.onopen = () => {
console.log("[WebSocket] З'єднання встановлено");
Territory_card.cloud.setStatus('ok');
ws.send(JSON.stringify({
event: 'connection',
id: getTimeInSeconds(),
date: getTimeInSeconds(),
uuid,
user: {
name: USER.name,
id: USER.id
},
data: {}
}));
Territory_card.reconnectAttempts = 0;
clearTimeout(Territory_card.reconnectTimeout);
};
ws.onmessage = (e) => {
const data = JSON.parse(e.data);
if (data.event === 'connection' && data.user.id !== USER.id) {
console.log(`Новий користувач: ${data.user}`);
}
if (data.event === 'message') {
Territory_card.cloud.update(data);
}
};
ws.onclose = () => {
console.warn("[WebSocket] З'єднання розірвано");
Territory_card.cloud.setStatus('err');
Territory_card.reconnectAttempts++;
if (Territory_card.reconnectAttempts <= 5) {
Territory_card.reconnectTimeout = setTimeout(() => {
Territory_card.getEntrances({ update: true });
Territory_card.cloud.start();
}, 1000);
} else {
if (confirm("З'єднання розірвано! Перепідключитись?")) {
Territory_card.reconnectAttempts = 0;
Territory_card.getEntrances({ update: true });
Territory_card.cloud.start();
}
}
};
ws.onerror = (err) => {
console.error("[WebSocket] Помилка", err);
Territory_card.cloud.setStatus('err');
};
},
setStatus(mode) {
const ids = ['cloud_1', 'cloud_2', 'cloud_3'];
ids.forEach((id, idx) => {
const el = document.getElementById(id);
el.setAttribute('data-state', ['sync', 'ok', 'err'].indexOf(mode) === idx ? 'active' : '');
});
},
update(msg) {
if (msg.type !== "apartment" && msg.type !== "building") return;
@@ -189,25 +123,20 @@ const Territory_card = {
const message = {
event: 'message',
id: getTimeInSeconds(),
date: getTimeInSeconds(),
user: {
name: USER.name,
id: USER.id
},
type: "apartment",
data: {
...apt,
sheep_id: USER.id
}
data: apt
};
if (Territory_card.socket?.readyState === WebSocket.OPEN) {
Territory_card.socket.send(JSON.stringify(message));
if (Cloud.socket?.readyState === WebSocket.OPEN) {
Cloud.socket.send(JSON.stringify(message));
} else {
if (confirm("З'єднання розірвано! Перепідключитись?")) {
Territory_card.getEntrances({ update: true });
Territory_card.cloud.start();
Cloud.start();
}
}
},
@@ -241,21 +170,16 @@ const Territory_card = {
const message = {
event: 'message',
id: getTimeInSeconds(),
date: getTimeInSeconds(),
user: {
name: USER.name,
id: USER.id
},
type: "building",
data: {
...apt,
sheep_id: USER.id
}
data: apt
};
if (Territory_card.socket?.readyState === WebSocket.OPEN) {
Territory_card.socket.send(JSON.stringify(message));
if (Cloud.socket?.readyState === WebSocket.OPEN) {
Cloud.socket.send(JSON.stringify(message));
} else {
if (confirm("З'єднання розірвано! Перепідключитись?")) {
Territory_card.getEntrances({ update: true });
@@ -434,9 +358,9 @@ const Territory_card = {
let lng = data.geo?.lng ?? data.points?.[0]?.[0]?.[0]?.lng ?? 25.6145625;
let zoom = 15;
if (map_card && map_Territory_card.remove) {
map_Territory_card.stopLocate();
map_Territory_card.remove();
if (map_card && map_card.remove) {
map_card.stopLocate();
map_card.remove();
}
const mapElement = document.getElementById('map_card');
@@ -471,13 +395,13 @@ const Territory_card = {
});
// слежение в реальном времени
map_Territory_card.locate({ setView: false, watch: true, enableHighAccuracy: true });
map_Territory_card.on('locationfound', (e) => {
if (!map_Territory_card._userMarker) {
map_Territory_card._userMarker = L.marker(e.latlng).addTo(map_card)
map_card.locate({ setView: false, watch: true, enableHighAccuracy: true });
map_card.on('locationfound', (e) => {
if (!map_card._userMarker) {
map_card._userMarker = L.marker(e.latlng).addTo(map_card)
.bindPopup("Ви тут!");
} else {
map_Territory_card._userMarker.setLatLng(e.latlng);
map_card._userMarker.setLatLng(e.latlng);
}
});
@@ -489,7 +413,7 @@ const Territory_card = {
let layerControl = L.control.layers(baseMaps, [], { position: 'bottomright' }).addTo(map_card);
map_Territory_card.pm.setLang("ua");
map_card.pm.setLang("ua");
const polygonOptions = {
color: "#f2bd53",
@@ -501,9 +425,9 @@ const Territory_card = {
L.polygon(data.points, polygonOptions).addTo(map_card);
map_Territory_card.setZoom(data.zoom);
map_card.setZoom(data.zoom);
// map_Territory_card.getZoom()
// map_card.getZoom()
// console.log(data.zoom);