This commit is contained in:
2025-09-09 00:10:53 +03:00
parent 38f2a05107
commit 204fc092d7
239 changed files with 22447 additions and 9536 deletions

View File

@@ -5,25 +5,53 @@
<div id="map_territory_manager"></div>
<div class="menu-picture">
<a id="menu-picture-error" title="Зображення не знайдено!">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30" style="fill: #c14d4d;">
<div class="menu">
<a
id="menu-picture-error"
class="menu-picture-"
title="Зображення не знайдено!"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 30 30"
style="fill: #c14d4d"
>
<path
d="M 3.7070312 2.2929688 L 2.2929688 3.7070312 L 26.292969 27.707031 L 27.707031 26.292969 L 26.375 24.960938 C 27.299776 24.784872 28 23.976233 28 23 L 28 7 C 28 5.895 27.105 5 26 5 L 6.4140625 5 L 3.7070312 2.2929688 z M 2.1367188 6.2851562 C 2.0517188 6.5071563 2 6.747 2 7 L 2 23 C 2 24.105 2.895 25 4 25 L 20.851562 25 L 17.851562 22 L 5 22 L 5 15 L 7.2890625 12.710938 C 7.5140625 12.485938 7.7747812 12.317219 8.0507812 12.199219 L 2.1367188 6.2851562 z M 23 8 C 24.105 8 25 8.895 25 10 C 25 11.105 24.105 12 23 12 C 21.895 12 21 11.105 21 10 C 21 8.895 21.895 8 23 8 z M 19 14.001953 C 19.61925 14.001953 20.238437 14.238437 20.710938 14.710938 L 25 19 L 25 22 L 23.414062 22 L 16.707031 15.292969 L 17.289062 14.710938 C 17.761563 14.238437 18.38075 14.001953 19 14.001953 z"
/>
</svg>
</a>
<a id="menu-picture-ok" style="display: none;" title="Зображення знайдено" target="_blank">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30" style="fill: #8BC34A;">
<a
id="menu-picture-ok"
class="menu-picture"
style="display: none"
title="Зображення знайдено"
target="_blank"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 30 30"
style="fill: #8bc34a"
>
<path
d="M 4 5 C 2.895 5 2 5.895 2 7 L 2 23 C 2 24.105 2.895 25 4 25 L 26 25 C 27.105 25 28 24.105 28 23 L 28 7 C 28 5.895 27.105 5 26 5 L 4 5 z M 23 8 C 24.105 8 25 8.895 25 10 C 25 11.105 24.105 12 23 12 C 21.895 12 21 11.105 21 10 C 21 8.895 21.895 8 23 8 z M 9 13.001953 C 9.61925 13.001953 10.238437 13.238437 10.710938 13.710938 L 13.972656 16.972656 L 15 18 L 16.15625 19.15625 C 16.57825 19.57825 17.259641 19.574344 17.681641 19.152344 C 18.104641 18.730344 18.104641 18.044094 17.681641 17.621094 L 16.529297 16.470703 L 17.289062 15.710938 C 18.234063 14.765937 19.765937 14.765937 20.710938 15.710938 L 25 20 L 25 22 L 5 22 L 5 16 L 7.2890625 13.710938 C 7.7615625 13.238437 8.38075 13.001953 9 13.001953 z"
/>
</svg>
</a>
<button title="Створити нове зображення" onclick="Territory_Manager.getScreen()">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30"> <path d="M 22.828125 3 C 22.316375 3 21.804562 3.1954375 21.414062 3.5859375 L 19 6 L 24 11 L 26.414062 8.5859375 C 27.195062 7.8049375 27.195062 6.5388125 26.414062 5.7578125 L 24.242188 3.5859375 C 23.851688 3.1954375 23.339875 3 22.828125 3 z M 17 8 L 5.2597656 19.740234 C 5.2597656 19.740234 6.1775313 19.658 6.5195312 20 C 6.8615312 20.342 6.58 22.58 7 23 C 7.42 23.42 9.6438906 23.124359 9.9628906 23.443359 C 10.281891 23.762359 10.259766 24.740234 10.259766 24.740234 L 22 13 L 17 8 z M 4 23 L 3.0566406 25.671875 A 1 1 0 0 0 3 26 A 1 1 0 0 0 4 27 A 1 1 0 0 0 4.328125 26.943359 A 1 1 0 0 0 4.3378906 26.939453 L 4.3632812 26.931641 A 1 1 0 0 0 4.3691406 26.927734 L 7 26 L 5.5 24.5 L 4 23 z"/></svg>
</button>
<a
id="editor_button"
class="menu-edit"
style="display: none"
data-route
title="Змінити територію"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30">
<path
d="M 22.828125 3 C 22.316375 3 21.804562 3.1954375 21.414062 3.5859375 L 19 6 L 24 11 L 26.414062 8.5859375 C 27.195062 7.8049375 27.195062 6.5388125 26.414062 5.7578125 L 24.242188 3.5859375 C 23.851688 3.1954375 23.339875 3 22.828125 3 z M 17 8 L 5.2597656 19.740234 C 5.2597656 19.740234 6.1775313 19.658 6.5195312 20 C 6.8615312 20.342 6.58 22.58 7 23 C 7.42 23.42 9.6438906 23.124359 9.9628906 23.443359 C 10.281891 23.762359 10.259766 24.740234 10.259766 24.740234 L 22 13 L 17 8 z M 4 23 L 3.0566406 25.671875 A 1 1 0 0 0 3 26 A 1 1 0 0 0 4 27 A 1 1 0 0 0 4.328125 26.943359 A 1 1 0 0 0 4.3378906 26.939453 L 4.3632812 26.931641 A 1 1 0 0 0 4.3691406 26.927734 L 7 26 L 5.5 24.5 L 4 23 z"
/>
</svg>
</a>
</div>
</div>
@@ -47,9 +75,9 @@
name="info-description"
id="info-description"
placeholder="Примітка"
onchange="Territory_Manager.info.update()"
></textarea>
</div>
<a id="editor_button" style="display: none" data-route>Змінити територію</a>
</div>
<div id="territory-entrance"></div>
@@ -57,10 +85,22 @@
<div id="territory-new" style="display: none; opacity: 0">
<div class="mess">
<span>Налаштування</span>
<select id="new-worker-name" name="new-worker-name" required="">
<select id="new-worker-group" name="new-worker-name">
<option value="" selected="" disabled="">Оберіть...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
<input
id="new-worker-name"
type="text"
name="new-worker-name"
list="list_sheeps"
/>
<div>
<button onclick="Territory_Manager.mess.close()">Закрити</button>
<button
@@ -73,3 +113,5 @@
</div>
</div>
</div>
<datalist id="list_sheeps"></datalist>

View File

@@ -15,7 +15,7 @@ const Territory_Manager = {
}
let editor_button = document.getElementById('editor_button');
if (USER.administrator.uuid || (USER.moderator.uuid && USER.moderator.can_add_territory)){
if (USER.possibilities.can_add_territory) {
editor_button.style.display = "";
editor_button.setAttribute("href", `/territory/editor/${type}/${id}`)
}
@@ -26,481 +26,464 @@ const Territory_Manager = {
for (let i = 0; i < sheeps_list.length; i++) {
const element = sheeps_list[i];
if (Territory_Manager.info.list.group_id == element.group_id) {
document.getElementById('new-worker-name').innerHTML += `
<option value="${element.name}">${element.name}</option>
`;
}
document.getElementById('list_sheeps').innerHTML += `
<option value="${element.name}">${element.name}</option>
`;
}
const card = document.getElementById('territory-new');
const mess = card.querySelector('.mess');
if (!card.dataset.listenerAdded) {
card.addEventListener('click', function (event) {
if (!mess.contains(event.target)) {
Territory_Manager.mess.close();
}
});
card.dataset.listenerAdded = 'true';
}
},
info: {
list: {},
loadAPI: async (url) => {
let uuid = localStorage.getItem("uuid");
Territory_Manager.info.list = await fetch(url, {
const uuid = localStorage.getItem("uuid");
const response = await fetch(url, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
}).then((response) => response.json());
});
Territory_Manager.info.list = await response.json();
return Territory_Manager.info.list;
},
setHTML: async (type, id) => {
if (type == "house") {
let url = `${CONFIG.api}house/${id}`;
let data = await Territory_Manager.info.loadAPI(url);
const url = `${CONFIG.api}${type}/${id}`;
const data = await Territory_Manager.info.loadAPI(url);
Territory_Manager.map(type, data);
Territory_Manager.map(type, data);
const info_picture = document.getElementById('info-picture');
const info_title = document.getElementById('info-title');
const info_number = document.getElementById('info-number');
const info_settlement = document.getElementById('info-settlement');
const info_description = document.getElementById('info-description');
let info_picture = document.getElementById('info-picture');
let info_title = document.getElementById('info-title');
let info_number = document.getElementById('info-number');
let info_settlement = document.getElementById('info-settlement');
let info_description = document.getElementById('info-description');
info_picture.addEventListener("click", (event) => {
let state = info_picture.getAttribute('data-state')
if (state == 'active') info_picture.setAttribute('data-state', '')
else info_picture.setAttribute('data-state', 'active')
if (!info_picture.dataset.listener) {
info_picture.addEventListener("click", () => {
const state = info_picture.getAttribute('data-state');
info_picture.setAttribute('data-state', state === 'active' ? '' : 'active');
});
info_picture.setAttribute("src", ``);
info_title.innerText = data.title;
info_number.innerText = data.number;
info_settlement.innerText = data.settlement;
info_description.value = data.description;
} else if (type == "homestead") {
let url = `${CONFIG.api}homestead/${id}`;
let data = await Territory_Manager.info.loadAPI(url);
Territory_Manager.map(type, data);
let info_picture = document.getElementById('info-picture');
let info_title = document.getElementById('info-title');
let info_number = document.getElementById('info-number');
let info_settlement = document.getElementById('info-settlement');
let info_description = document.getElementById('info-description');
info_picture.addEventListener("click", (event) => {
let state = info_picture.getAttribute('data-state')
if (state == 'active') info_picture.setAttribute('data-state', '')
else info_picture.setAttribute('data-state', 'active')
});
info_picture.setAttribute("src", ``);
info_title.innerText = data.title;
info_number.innerText = data.number;
info_settlement.innerText = data.settlement;
info_description.value = data.description;
info_picture.dataset.listener = "true";
}
urlImage = `https://sheep-service.com/cards/${type}/${type == "house" ? "T" : "H"}${id}.webp`;
const checkImage = await fetch(urlImage);
if(checkImage.ok) {
document.getElementById('menu-picture-error').style.display = 'none';
document.getElementById('menu-picture-ok').style.display = '';
document.getElementById('menu-picture-ok').setAttribute("href", urlImage);
} else {
info_picture.setAttribute("src", "");
info_title.textContent = data.title;
info_number.textContent = data.number;
info_settlement.textContent = data.settlement;
info_description.value = data.description;
const urlImage = `https://sheep-service.com/cards/${type}/${type === "house" ? "T" : "H"}${id}.webp`;
try {
const checkImage = await fetch(urlImage, { method: 'GET' });
const showOk = checkImage.ok;
document.getElementById('menu-picture-ok').style.display = showOk ? '' : 'none';
document.getElementById('menu-picture-error').style.display = showOk ? 'none' : '';
if (showOk) {
document.getElementById('menu-picture-ok').setAttribute("href", urlImage);
}
} catch (err) {
document.getElementById('menu-picture-error').style.display = '';
document.getElementById('menu-picture-ok').style.display = 'none';
}
},
update: async () => {
const uuid = localStorage.getItem('uuid');
const data = Territory_Manager.info.list;
data.description = document.getElementById('info-description').value;
const url = `${CONFIG.api}${type_territory}/${data.id}`;
try {
const response = await fetch(url, {
method: 'PUT',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
},
body: JSON.stringify(data)
});
if (response.ok) {
console.log('ok');
await response.json();
} else {
console.log('err');
}
} catch (e) {
console.log('update error', e);
}
}
},
entrances: {
list: [],
loadAPI: async (url) => {
let uuid = localStorage.getItem("uuid");
Territory_Manager.entrances.list = await fetch(url, {
const uuid = localStorage.getItem("uuid");
const response = await fetch(url, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
}).then((response) => response.json());
});
Territory_Manager.entrances.list = await response.json();
return Territory_Manager.entrances.list;
},
setHTML: async (type, id) => {
if (type == "house") {
let url = `${CONFIG.api}house/${id}/entrances`;
let listEntrances = await Territory_Manager.entrances.loadAPI(url);
const container = document.getElementById('territory-entrance');
container.innerHTML = "";
const sheeps_list = Sheeps.sheeps_list.list;
document.getElementById('territory-entrance').innerHTML = "";
const renderName = (history) => {
if (history.name === "Групова") return `<p>${history.name} ${history.group_id}</p>`;
const sheep = sheeps_list.find(item => item.name === history.name);
return sheep ? `<a href="/sheeps/${sheep.id}" data-route>${history.name}</a>` : `<a>${history.name}</a>`;
};
for (let i = 0; i < listEntrances.length; i++) {
const element = listEntrances[i];
const renderWorking = (element, i = 0) => `
<div class="entrance" data-state="working">
<div id="title">
<h1>${element.title ?? ''}</h1>
<a href="/territory/card/${type}/${id}" title="Редактор квартир" data-route>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><path d="M 12.5 6 C 8.9280619 6 6 8.9280619 6 12.5 L 6 35.5 C 6 39.071938 8.9280619 42 12.5 42 L 35.5 42 C 39.071938 42 42 39.071938 42 35.5 L 42 12.5 C 42 8.9280619 39.071938 6 35.5 6 L 12.5 6 z M 12.5 9 L 14 9 L 14 15 L 9 15 L 9 12.5 C 9 10.549938 10.549938 9 12.5 9 z M 17 9 L 35.5 9 C 37.450062 9 39 10.549938 39 12.5 L 39 15 L 17 15 L 17 9 z M 9 18 L 14 18 L 14 23 L 9 23 L 9 18 z M 17 18 L 39 18 L 39 23 L 17 23 L 17 18 z M 9 26 L 14 26 L 14 31 L 9 31 L 9 26 z M 17 26 L 39 26 L 39 31 L 17 31 L 17 26 z M 9 34 L 14 34 L 14 39 L 12.5 39 C 10.549938 39 9 37.450062 9 35.5 L 9 34 z M 17 34 L 39 34 L 39 35.5 C 39 37.450062 37.450062 39 35.5 39 L 17 39 L 17 34 z"/></svg>
</a>
</div>
<div><h1>Територію опрацьовує:</h1>${renderName(element.history)}</div>
<div><h1>Територія видана:</h1><h2>${formattedDate(element.history.date.start)}</h2></div>
<div><h1>Варто забрати:</h1><h2>${formattedDate(element.history.date.end) ?? formattedDate(element.history.date.start + (1000 * 2629743 * 4))}</h2></div>
<div class="edit_working">
<button onclick="Territory_Manager.endWorker('${type}', ${id}, ${element.history.id})" style="color: #121214;background: #c14d4d;">Забрати</button>
<button onclick="Territory_Manager.share('${type}'${type === "house" ? `, ${i}` : ""})">Відправити посилання</button>
</div>
</div>
`;
let name = () => {
if (element.history.name == "Групова")
return `<p>${element.history.name + " " + element.history.group_id}</p>`;
else {
let sheeps_list = Sheeps.sheeps_list.list;
let filtered = sheeps_list.filter(item => item.group_id === Territory_Manager.info.list.group_id);
let sheep = filtered.find(item => item.name === element.history.name);
const renderFree = (element, i = 0) => `
<div class="entrance">
<div id="title">
<h1>${element.title ?? ''}</h1>
<a href="/territory/card/${type}/${id}" title="Редактор квартир" data-route>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><path d="M 12.5 6 C 8.9280619 6 6 8.9280619 6 12.5 L 6 35.5 C 6 39.071938 8.9280619 42 12.5 42 L 35.5 42 C 39.071938 42 42 39.071938 42 35.5 L 42 12.5 C 42 8.9280619 39.071938 6 35.5 6 L 12.5 6 z M 12.5 9 L 14 9 L 14 15 L 9 15 L 9 12.5 C 9 10.549938 10.549938 9 12.5 9 z M 17 9 L 35.5 9 C 37.450062 9 39 10.549938 39 12.5 L 39 15 L 17 15 L 17 9 z M 9 18 L 14 18 L 14 23 L 9 23 L 9 18 z M 17 18 L 39 18 L 39 23 L 17 23 L 17 18 z M 9 26 L 14 26 L 14 31 L 9 31 L 9 26 z M 17 26 L 39 26 L 39 31 L 17 31 L 17 26 z M 9 34 L 14 34 L 14 39 L 12.5 39 C 10.549938 39 9 37.450062 9 35.5 L 9 34 z M 17 34 L 39 34 L 39 35.5 C 39 37.450062 37.450062 39 35.5 39 L 17 39 L 17 34 z"/></svg>
</a>
</div>
<div><h1>Територія не опрацьовується</h1></div>
<div><h1>Останнє опрацювання:</h1><h2>${formattedDate(element.history.date.end) ?? "..."}</h2></div>
<div class="edit">
<button onclick="Territory_Manager.mess.open({type: '${type}', id: ${id}, number: ${i}, mode: false})" style="color: var(--ColorThemes0);background: var(--ColorThemes3);">Призначити груповою</button>
<button onclick="Territory_Manager.mess.open({type: '${type}', id: ${id}, number: ${i}, mode: true})">Призначити вісника</button>
</div>
</div>
`;
return `<a href="/sheeps/${sheep.uuid}" data-route="">${element.history.name}</a>`;
}
}
let html = "";
if (element.working) {
document.getElementById('territory-entrance').innerHTML += `
<div class="entrance" data-state="working">
<div id="title">
<h1>${element.title}</h1>
<a href="/territory/card/${type}/${id}" title="Редактор квартир" data-route>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><path d="M 12.5 6 C 8.9280619 6 6 8.9280619 6 12.5 L 6 35.5 C 6 39.071938 8.9280619 42 12.5 42 L 35.5 42 C 39.071938 42 42 39.071938 42 35.5 L 42 12.5 C 42 8.9280619 39.071938 6 35.5 6 L 12.5 6 z M 12.5 9 L 14 9 L 14 15 L 9 15 L 9 12.5 C 9 10.549938 10.549938 9 12.5 9 z M 17 9 L 35.5 9 C 37.450062 9 39 10.549938 39 12.5 L 39 15 L 17 15 L 17 9 z M 9 18 L 14 18 L 14 23 L 9 23 L 9 18 z M 17 18 L 39 18 L 39 23 L 17 23 L 17 18 z M 9 26 L 14 26 L 14 31 L 9 31 L 9 26 z M 17 26 L 39 26 L 39 31 L 17 31 L 17 26 z M 9 34 L 14 34 L 14 39 L 12.5 39 C 10.549938 39 9 37.450062 9 35.5 L 9 34 z M 17 34 L 39 34 L 39 35.5 C 39 37.450062 37.450062 39 35.5 39 L 17 39 L 17 34 z"/></svg>
</a>
</div>
<div>
<h1>Територію опрацьовує: </h1>
${name()}
</div>
<div>
<h1>Територія видана: </h1>
<h2>${formattedDate(element.history.date.start)}</h2>
</div>
<div>
<h1>Варто забрати: </h1>
<h2>${formattedDate(element.history.date.end) ?? formattedDate(element.history.date.start + (1000 * 2629743 * 4))}</h2>
</div>
<div class="edit_working">
<button onclick="Territory_Manager.endWorker('${type}', ${id}, ${element.history.id})" id="end-working-button" style="color: #121214;background: #c14d4d;">Забрати</button>
<button onclick="Territory_Manager.share('${type}', ${i})">Відправити посилання</button>
</div>
</div>
`;
} else {
document.getElementById('territory-entrance').innerHTML += `
<div class="entrance">
<div id="title">
<h1>${element.title}</h1>
</div>
<div>
<h1>Територія не опрацьовується</h1>
</div>
<div>
<h1>Останнє опрацювання: </h1>
<h2>${formattedDate(element.history.date.end) ?? "..."}</h2>
</div>
<div class="edit">
<button onclick="Territory_Manager.newWorker('${type}',${id}, ${i}, 'Групова')" id="group-working-button" style="color: var(--ColorThemes0);background: var(--ColorThemes3);">Призначити груповою</button>
<button onclick="Territory_Manager.mess.open('${type}', ${id}, ${i})">Призначити вісника</button>
</div>
</div>
`;
}
console.log(element);
if (type === "house") {
const url = `${CONFIG.api}house/${id}/entrances`;
const list = await Territory_Manager.entrances.loadAPI(url);
for (let i = 0; i < list.length; i++) {
const el = list[i];
html += el.working ? renderWorking(el, i) : renderFree(el, i);
}
} else if (type == "homestead") {
let url = `${CONFIG.api}homestead/${id}`;
let element = await Territory_Manager.entrances.loadAPI(url);
document.getElementById('territory-entrance').innerHTML = "";
let name = () => {
if (element.history.name == "Групова")
return `<p>${element.history.name + " " + element.history.group_id}</p>`;
else
return `<a href="/sheeps/${element.history.name}" data-route="">${element.history.name}</a>`;
}
if (element.working) {
document.getElementById('territory-entrance').innerHTML += `
<div class="entrance" data-state="working">
<div>
<h1>Територію опрацьовує: </h1>
${name()}
</div>
<div>
<h1>Територія видана: </h1>
<h2>${formattedDate(element.history.date.start)}</h2>
</div>
<div>
<h1>Варто забрати: </h1>
<h2>${formattedDate(element.history.date.end) ?? formattedDate(element.history.date.start + (1000 * 2629743 * 4))}</h2>
</div>
<div class="edit_working">
<button onclick="Territory_Manager.endWorker('${type}', ${id}, ${element.history.id})" id="end-working-button" style="color: #121214;background: #c14d4d;">Забрати</button>
<button onclick="Territory_Manager.share('${type}', ${i})">Відправити посилання</button>
</div>
</div>
`;
} else {
document.getElementById('territory-entrance').innerHTML += `
<div class="entrance">
<div>
<h1>Територія не опрацьовується</h1>
</div>
<div>
<h1>Останнє опрацювання: </h1>
<h2>${formattedDate(element.history.date.end) ?? "..."}</h2>
</div>
<div class="edit">
<button onclick="Territory_Manager.newWorker('${type}',${id}, ${i}, 'Групова')" id="group-working-button" style="color: var(--ColorThemes0);background: var(--ColorThemes3);">Призначити груповою</button>
<button onclick="Territory_Manager.mess.open('${type}',${id}, ${i})">Призначити вісника</button>
</div>
</div>
`;
}
console.log(element);
} else if (type === "homestead") {
const url = `${CONFIG.api}homestead/${id}`;
const el = await Territory_Manager.entrances.loadAPI(url);
html += el.working ? renderWorking(el) : renderFree(el);
}
container.innerHTML = html;
}
},
map: (type, data) => {
map_territory = {};
let center = { lat: 49.5629016, lng: 25.6145625 };
let zoom = 19;
let lat = data.geo?.lat ?? data.points?.[0]?.[0]?.[0]?.lat ?? 49.5629016;
let lng = data.geo?.lng ?? data.points?.[0]?.[0]?.[0]?.lng ?? 25.6145625;
let mytile = L.tileLayer('https://tm.rozenrod.com/webp/{z}/{x}/{y}.webp', {
if (map_territory && map_territory.remove) map_territory.remove();
const mapElement = document.getElementById('map_territory_manager');
if (!mapElement) return;
let googleHybrid = L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', {
maxZoom: 20,
minZoom: 15,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
});
let osm = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
});
let mytile = L.tileLayer('https://sheep-service.com/map/{z}/{x}/{y}.webp', {
maxZoom: 20,
minZoom: 15,
tms: true
});
map_territory = L.map('map_territory_manager', {
map_territory = L.map(mapElement, {
renderer: L.canvas(),
center,
zoom,
center: [lat, lng],
zoom: 0,
zoomControl: false,
layers: [
googleHybrid,
osm,
mytile
],
]
});
map_territory.setZoom((data.zoom - 1));
let baseMaps = {
"Google Hybrid": googleHybrid,
"OpenStreetMap": osm,
"Sheep Service Map": mytile,
};
let layerControl = L.control.layers(baseMaps, [], { position: 'bottomright' }).addTo(map_territory);
map_territory.pm.setLang("ua");
if (type == "homestead") {
if (data.geo.lat) map_territory.setView([data.geo.lat, data.geo.lng], 15);
else map_territory.setView([data.points[0][0][0].lat, data.points[0][0][0].lng], 15);
const polygonOptions = type === "homestead" ? {
color: "#f2bd53",
radius: 500,
fillOpacity: 0.3,
dashArray: '20,15',
dashOffset: '20',
} : {
color: "#585858",
fillColor: "#f2bd53",
fillOpacity: 0.8
};
L.polygon(data.points, {
color: colorGroup(data.group_id),
radius: 500,
fillOpacity: 0.3,
dashArray: '20, 15',
dashOffset: '20',
}).on('click', function (e) {
L.polygon(data.points, polygonOptions).addTo(map_territory);
}).addTo(map_territory);
} else if (type == "house") {
map_territory.setView([data.geo.lat, data.geo.lng], 17);
console.log(data.zoom);
L.polygon(data.points, {
color: "#585858",
fillColor: colorGroup(data.group_id),
fillOpacity: 0.8,
tm_id: `house_${i}`
}).on('click', function (e) {
}).addTo(map_territory);
}
// setTimeout(() => {
// map_territory.setZoom(data.zoom);
// }, 200)
},
mess: {
open: (type, id, number) => {
open: ({ type, id, number, mode }) => {
const block = document.getElementById('territory-new');
const new_worker_button = document.getElementById('new-worker-button');
const groupInput = document.getElementById('new-worker-group');
const nameInput = document.getElementById('new-worker-name');
const button = document.getElementById('new-worker-button');
// Показуємо блок
block.style.display = "";
setTimeout(() => {
block.style.opacity = "1";
}, 100)
requestAnimationFrame(() => block.style.opacity = "1");
new_worker_button.setAttribute("onclick", `Territory_Manager.newWorker('${type}', ${id}, ${number})`);
groupInput.style.display = mode ? 'none' : 'flex';
nameInput.style.display = mode ? 'flex' : 'none';
button.onclick = () => Territory_Manager.newWorker({ type, id, number, mode });
},
close: () => {
const block = document.getElementById('territory-new');
close: () => {
// Робимо плавне зникнення
const block = document.getElementById('territory-new');
block.style.opacity = "0";
setTimeout(() => {
const onTransitionEnd = () => {
block.style.display = "none";
}, 200)
block.removeEventListener("transitionend", onTransitionEnd);
};
block.addEventListener("transitionend", onTransitionEnd);
}
},
newWorker: async (type, id, number, name) => {
newWorker: async ({ type, id, number, mode }) => {
const uuid = localStorage.getItem('uuid');
const sheepName = document.getElementById('new-worker-name').value;
const groupId = Number(document.getElementById('new-worker-group').value);
const new_worker_button = document.getElementById('new-worker-button');
const group_worker_button = document.getElementById('group-working-button');
const newButton = document.getElementById('new-worker-button');
const groupButton = document.getElementById('group-working-button');
let URL, territory_id, data;
let territory_id;
let URL;
const sheep = Sheeps.sheeps_list.list.find(e => e.name === sheepName);
const pos = Sheeps.sheeps_list.list.map(e => e.name).indexOf(name ?? document.getElementById("new-worker-name").value);
let sheep = Sheeps.sheeps_list.list[pos];
if (type == "house") {
territory_id = Territory_Manager.entrances.list[number].id;
data = {
name: name ?? document.getElementById("new-worker-name").value,
group_id: Territory_Manager.info.list.group_id,
sheep_id: sheep ? sheep.id : null
}
if (type === "house") {
territory_id = Territory_Manager.entrances.list[number]?.id;
URL = `${CONFIG.api}history/entrance/${territory_id}`;
}
else if (type == "homestead") {
} else if (type === "homestead") {
territory_id = Territory_Manager.info.list.id;
data = {
name: name ?? document.getElementById("new-worker-name").value,
group_id: Territory_Manager.info.list.group_id,
sheep_id: sheep ? sheep.id : null
}
URL = `${CONFIG.api}history/homestead/${territory_id}`;
}
console.log(territory_id, data);
if (!territory_id || !URL) {
console.warn("Невірні дані для призначення.");
return;
}
await fetch(URL, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
},
body: JSON.stringify(data)
})
.then(response => {
if (response.status == 200) {
Territory_Manager.mess.close();
Territory_Manager.entrances.list = [];
Territory_Manager.entrances.setHTML(type, id);
const data = {
name: mode ? sheepName : "Групова",
group_id: mode ? sheep?.group_id : groupId,
sheep_id: mode ? sheep?.id : null
};
return response.json()
} else {
console.log('err');
new_worker_button.innerText = "Помилка";
group_worker_button.innerText = "Помилка";
try {
const response = await fetch(URL, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
},
body: JSON.stringify(data)
});
return
}
})
if (!response.ok) throw new Error("Failed to assign");
Territory_Manager.mess.close();
Territory_Manager.entrances.list = [];
await Territory_Manager.entrances.setHTML(type, id);
} catch (err) {
console.error('❌ Error:', err);
const errorText = "Помилка";
if (newButton) newButton.innerText = errorText;
if (groupButton) groupButton.innerText = errorText;
}
},
endWorker: async (type, id, territory_id) => {
const end_working_button = document.getElementById('end-working-button');
let uuid = localStorage.getItem('uuid');
let URL = "";
const button = document.getElementById('end-working-button');
const uuid = localStorage.getItem('uuid');
if (type == "house") {
URL = `${CONFIG.api}history/entrance/${territory_id}`;
const URL = type === "house"
? `${CONFIG.api}history/entrance/${territory_id}`
: `${CONFIG.api}history/homestead/${territory_id}`;
try {
const response = await fetch(URL, {
method: 'PUT',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
},
body: JSON.stringify({})
});
if (!response.ok) throw new Error("Запит не успішний");
Territory_Manager.entrances.list = [];
await Territory_Manager.entrances.setHTML(type, id);
} catch (error) {
console.error("❌ Помилка зняття призначення:", error);
if (button) button.innerText = "Помилка";
}
else if (type == "homestead") {
URL = `${CONFIG.api}history/homestead/${territory_id}`;
}
await fetch(URL, {
method: 'PUT',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
},
data: JSON.stringify({})
})
.then(response => {
if (response.status == 200) {
Territory_Manager.entrances.list = [];
Territory_Manager.entrances.setHTML(type, id);
return response.json()
} else {
console.log('err');
end_working_button.innerText = "Помилка";
return
}
})
},
share: async (type, number) => {
let territory, id;
const isHouse = type === "house";
const territory = isHouse ? Territory_Manager.entrances.list[number] : Territory_Manager.info.list;
const id = territory.id;
if (type == "house") {
territory = Territory_Manager.entrances.list[number];
id = Territory_Manager.entrances.list[number].id;
}
else if (type == "homestead") {
territory = Territory_Manager.info.list;
id = Territory_Manager.info.list.id;
const pos = Sheeps.sheeps_list.list.map(e => e.id).indexOf(territory.history.sheep_id);
let sheep = Sheeps.sheeps_list.list[pos];
console.log(pos);
const shareUrl = pos > 0
? `\n\nПосилання на програму:\n • https://sheep-service.com/?uuid=${sheep.uuid}`
: '';
const description = Territory_Manager.info.list.description?.length > 0
? `\n\nДодатково:\n${Territory_Manager.info.list.description}`
: '';
if (!navigator.share) {
console.log("Sorry! Your browser does not support Web Share API");
return;
}
try {
const baseUrl = "https://sheep-service.com/cards";
const url = isHouse
? `${baseUrl}/house/T${Territory_Manager.info.list.id}.webp`
: `${baseUrl}/homestead/H${Territory_Manager.info.list.id}.webp`;
let description = () => {
if (Territory_Manager.info.list.description && Territory_Manager.info.list.description.length > 0) {
return `\n\nДодатково:\n${Territory_Manager.info.list.description}`;
} else {
return '';
}
}
let sheepUuid = () => {
const pos = Sheeps.sheeps_list.list.map(e => e.name).indexOf(territory.history.name);
let sheep = Sheeps.sheeps_list.list[pos];
const response = await fetch(url);
if (!response.ok) throw new Error('Image not found');
if (sheep) {
return `\n\nПосилання на Sheep-Service:\n• https://sheep-service.com/?uuid=${sheep.uuid}`;
} else {
return '';
}
}
const blob = await response.blob();
const fileName = `${isHouse ? "E" + id : "H" + id}.webp`;
const file = new File([blob], fileName, { type: blob.type });
if (navigator.share) {
console.log("Congrats! Your browser supports Web Share API")
try {
let url;
if(type == 'house') url = `https://sheep-service.com/cards/house/T${Territory_Manager.info.list.id}.webp`;
if(type == 'homestead') url = `https://sheep-service.com/cards/homestead/H${Territory_Manager.info.list.id}.webp`;
const response = await fetch(url);
const blob = await response.blob();
const file = new File([blob], `${type == "house" ? "E" + id : "H" + id}.webp`, { type: blob.type });
const shareText = `Територія:\n${isHouse ? "E" + id : "H" + id}\n\nНаселений пункт:\n${Territory_Manager.info.list.settlement}\n\nВулиця:\n${Territory_Manager.info.list.title} ${Territory_Manager.info.list.number} (${territory.title})${description}\n\nПризначення:\nЗ ${formattedDate(territory.history.date.start)}\n • До ${formattedDate(territory.history.date.end) ?? formattedDate(territory.history.date.start + (1000 * 2629743 * 4))}${shareUrl}`;
await navigator.share({
text: `Територія:\n${type == "house" ? "E" + id : "H" + id}\n\nНаселений пункт:\n${Territory_Manager.info.list.settlement}\n\nВулиця:\n${Territory_Manager.info.list.title + " " + Territory_Manager.info.list.number}${description()}\n\nПризначення:\nЗ ${formattedDate(territory.history.date.start)}\n • До ${formattedDate(territory.history.date.end) ?? formattedDate(territory.history.date.start + (1000 * 2629743 * 4))}${sheepUuid()}`,
files: [file]
});
console.log('Успешно отправлено!');
} catch (error) {
console.error('Ошибка при отправке:', error);
}
console.log(shareText);
} else {
console.log("Sorry! Your browser does not support Web Share API")
await navigator.share({
text: shareText,
files: [file]
});
console.log('Успешно отправлено!');
} catch (error) {
console.error('Ошибка при отправке:', error);
}
},
getScreen: async () => {
const center = map_territory.getCenter();
console.log(center.lat, center.lng);
const zoom = (map_territory.getZoom() + 2) || 17;
const info = Territory_Manager.info.list;
let lat = center.lat;
let lng = center.lng;
let wayId = Territory_Manager.info.list.osm_id;
let zoom = map_territory.getZoom() + 2 ?? 17;
let address = Territory_Manager.info.list.title;
let number = Territory_Manager.info.list.number;
let id = Territory_Manager.info.list.id;
const params = new URLSearchParams({
lat: center.lat,
lng: center.lng,
type: type_territory,
wayId: info.osm_id,
zoom,
address: info.title,
number: info.number,
id: info.id
});
let url = `https://sheep-service.com/api/generator/cards?lat=${lat}&lng=${lng}&type=${type_territory}&wayId=${wayId}&zoom=${zoom}&address=${address}&number=${number}&id=${id}`;
let uuid = localStorage.getItem("uuid");
let result = await fetch(url, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
const url = `https://sheep-service.com/api/generator/cards?${params.toString()}`;
const uuid = localStorage.getItem("uuid");
try {
const response = await fetch(url, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
});
const result = await response.json();
const urlImage = `https://sheep-service.com/cards/${type_territory}/${type_territory === "house" ? "T" : "H"}${info.id}.webp`;
const errorElem = document.getElementById('menu-picture-error');
const okElem = document.getElementById('menu-picture-ok');
if (result) {
errorElem.style.display = 'none';
okElem.style.display = '';
okElem.setAttribute("href", urlImage);
} else {
errorElem.style.display = '';
okElem.style.display = 'none';
}
}).then((response) => response.json());
urlImage = `https://sheep-service.com/cards/${type}/${type == "house" ? "T" : "H"}${id}.webp`;
if(result) {
document.getElementById('menu-picture-error').style.display = 'none';
document.getElementById('menu-picture-ok').style.display = '';
document.getElementById('menu-picture-ok').setAttribute("href", urlImage);
} else {
document.getElementById('menu-picture-error').style.display = '';
document.getElementById('menu-picture-ok').style.display = 'none';
} catch (err) {
console.error('Ошибка при получении скрина:', err);
}
}
}

View File

@@ -62,7 +62,7 @@
object-fit: contain;
}
#territory-info>.territory-info-image>.menu-picture {
#territory-info>.territory-info-image>.menu {
position: absolute;
right: 10px;
top: 10px;
@@ -71,12 +71,11 @@
border: 1px solid var(--ColorThemes2);
padding: 5px;
border-radius: 6px;
min-width: 70px;
display: flex;
justify-content: space-between;
}
#territory-info>.territory-info-image>.menu-picture>a {
#territory-info>.territory-info-image>.menu>.menu-picture {
width: 30px;
height: 30px;
display: flex;
@@ -85,12 +84,12 @@
}
#territory-info>.territory-info-image>.menu-picture>a>svg {
#territory-info>.territory-info-image>.menu>.menu-picture>svg {
width: 22px;
height: 22px;
}
#territory-info>.territory-info-image>.menu-picture>button {
#territory-info>.territory-info-image>.menu>.menu-edit {
width: 30px;
height: 30px;
border-radius: 2px;
@@ -99,9 +98,10 @@
display: flex;
align-items: center;
justify-content: center;
margin-left: 10px;
}
#territory-info>.territory-info-image>.menu-picture>button>svg {
#territory-info>.territory-info-image>.menu>.menu-edit>svg {
width: 20px;
height: 20px;
fill: var(--PrimaryColorText);
@@ -121,13 +121,13 @@
}
#territory-info>.territory-info-text>h1 {
font-size: 14px;
font-size: var(--FontSize3);
font-weight: 400;
color: var(--ColorThemes3);
}
#territory-info>.territory-info-text>h2 {
font-size: 14px;
font-size: var(--FontSize3);
font-weight: 300;
color: var(--ColorThemes3);
opacity: 0.8;
@@ -139,14 +139,14 @@
min-height: 100px;
background: var(--ColorThemes0);
color: var(--ColorThemes3);
font-size: 14px;
font-size: var(--FontSize3);
resize: vertical;
border-radius: 0;
}
#territory-info>#editor_button {
width: calc(100% - 20px);
font-size: 13px;
font-size: var(--FontSize2);
font-weight: 400;
min-height: 40px;
display: flex;
@@ -196,7 +196,7 @@
background: var(--ColorThemes0);
color: var(--ColorThemes3);
border-radius: 6px;
font-size: 16px;
font-size: var(--FontSize5);
font-weight: 400;
display: flex;
align-items: center;
@@ -229,7 +229,7 @@
}
#territory-entrance>.entrance>div>h1 {
font-size: 14px;
font-size: var(--FontSize3);
font-weight: 400;
color: var(--ColorThemes3);
}
@@ -237,7 +237,7 @@
#territory-entrance>.entrance>div>h2,
#territory-entrance>.entrance>div>a,
#territory-entrance>.entrance>div>p {
font-size: 14px;
font-size: var(--FontSize3);
font-weight: 300;
color: var(--ColorThemes3);
opacity: 0.8;
@@ -271,7 +271,7 @@
#territory-entrance>.entrance>.edit_working>button,
#territory-entrance>.entrance>.edit>button {
width: 100%;
font-size: 13px;
font-size: var(--FontSize2);
font-weight: 400;
min-height: 40px;
display: flex;
@@ -308,7 +308,7 @@
#territory-entrance>.entrance>.apartment_button {
width: 100%;
font-size: 13px;
font-size: var(--FontSize2);
font-weight: 400;
min-height: 40px;
display: flex;
@@ -340,14 +340,14 @@
#territory-new>.mess {
display: flex;
width: 300px;
height: 200px;
height: 100px;
border: 1px solid var(--ColorThemes2);
background: var(--ColorThemes0);
box-shadow: 0px 2px 3px rgb(0 0 0 / 5%), 0px 5px 15px rgb(0 0 0 / 5%), 0px 4px 8px rgb(0 0 0 / 5%), 0px 0px 1px rgb(0 0 0 / 5%);
position: absolute;
top: 50%;
left: 50%;
margin-top: -110px;
margin-top: -50px;
margin-left: -160px;
flex-direction: column;
align-items: center;
@@ -374,6 +374,16 @@
color: var(--ColorThemes3);
}
#territory-new>.mess>input {
width: calc(100% - 10px);
min-width: 140px;
padding: 0 5px;
border-radius: 6px;
height: 30px;
background-color: var(--ColorThemes2);
color: var(--ColorThemes3);
}
#territory-new>.mess>div {
width: 100%;
display: flex;
@@ -383,7 +393,7 @@
#territory-new>.mess>div>button {
text-decoration: none;
font-size: 15px;
font-size: var(--FontSize4);
font-weight: 400;
height: 35px;
color: var(--ColorThemes0);